python-poetry / python-poetry/poetry
`poetry add` does not support paths without a directory component
Open
Nobody has claimed this yet.
kind/bug
status/triage
- Dominant language
- Python
- Stars
- 34.3k
- Forks
- 2.5k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
- Poetry version: 1.2.2
- Python version: 3.8.10
- OS version and name: Windows 10
- pyproject.toml: N/A
- I am on the latest stable Poetry version, installed using a recommended method.
- I have searched the issues of this repo and believe that this is not a duplicate.
- I have consulted the FAQ and blog for any relevant entries or release notes.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption) and have included the output below.
Issue
poetry add my-wheel.whl results in the following error, however the same command poetry add ./my-wheel.whl works fine:
Using virtualenv: C:\Users\*\AppData\Local\pypoetry\Cache\virtualenvs\*-NWGIXhkQ-py3.8
Stack trace:
14 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:329 in run
327│
328│ try:
→ 329│ exit_code = self._run(io)
330│ except Exception as e:
331│ if not self._catch_exceptions:
13 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\application.py:185 in _run
183│ self._load_plugins(io)
184│
→ 185│ exit_code: int = super()._run(io)
186│ return exit_code
187│
12 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:423 in _run
421│ io.input.set_stream(stream)
422│
→ 423│ exit_code = self._run_command(command, io)
424│ self._running_command = None
425│
11 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:465 in _run_command
463│
464│ if error is not None:
→ 465│ raise error
466│
467│ return event.exit_code
10 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:449 in _run_command
447│
448│ if event.command_should_run():
→ 449│ exit_code = command.run(io)
450│ else:
451│ exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED
9 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\commands\base_command.py:119 in run
117│ io.input.validate()
118│
→ 119│ status_code = self.execute(io)
120│
121│ if status_code is None:
8 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\commands\command.py:83 in execute
81│
82│ try:
→ 83│ return self.handle()
84│ except KeyboardInterrupt:
85│ return 1
7 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\commands\add.py:158 in handle
156│ return 0
157│
→ 158│ requirements = self._determine_requirements(
159│ packages,
160│ allow_prereleases=self.option("allow-prereleases"),
6 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\commands\init.py:357 in _determine_requirements
355│
356│ result = []
→ 357│ for requirement in self._parse_requirements(requires):
358│ if "git" in requirement or "url" in requirement or "path" in requirement:
359│ result.append(requirement)
5 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\commands\init.py:416 in _parse_requirements
414│ cwd = Path.cwd()
415│
→ 416│ return [
417│ parse_dependency_specification(
418│ requirement=requirement,
4 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\commands\init.py:417 in <listcomp>
415│
416│ return [
→ 417│ parse_dependency_specification(
418│ requirement=requirement,
419│ env=self.env if isinstance(self, EnvCommand) else None,
3 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\dependency_specification.py:204 in parse_dependency_specification
202│ cwd = cwd or Path.cwd()
203│
→ 204│ specification = pep508_to_dependency_specification(requirement)
205│
206│ if specification is not None:
2 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\dependency_specification.py:187 in pep508_to_dependency_specification
185│
186│ with contextlib.suppress(ValueError):
→ 187│ dependency = Dependency.create_from_pep_508(requirement)
188│ specification: DependencySpec = {}
189│ specification = dependency_to_specification(dependency, specification)
1 ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\core\packages\dependency.py:448 in create_from_pep_508
446│ elif is_file_uri:
447│ # handle RFC 8089 references
→ 448│ path = url_to_path(req.url)
449│ dep = _make_file_or_dir_dep(
450│ name=name, path=path, base=relative_to, extras=req.extras
AttributeError
'NoneType' object has no attribute 'startswith'
at ~\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\core\packages\utils\utils.py:72 in url_to_path
68│
69│ The logic used here is borrowed from pip
70│ https://github.com/pypa/pip/blob/4d1932fcdd1974c820ea60b3286984ebb0c3beaa/src/pip/_internal/utils/urls.py#L31
71│ """
→ 72│ if not url.startswith("file:"):
73│ raise ValueError(f"{url} is not a valid file URI")
74│
75│ _, netloc, path, _, _ = urlsplit(url)
76│
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with poetry/console/commands/add.py and poetry/console/commands/init.py, following the requirement parsing path shown in the traceback into poetry/utils/dependency_specification.py and poetry/core/packages/utils/utils.py. Reproduce both poetry add my-wheel.whl and poetry add ./my-wheel.whl; done means the bare wheel filename is accepted without the AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100