python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.74k stars 2.27k forks source link

`poetry add` does not support paths without a directory component #6951

Open tyteen4a03 opened 2 years ago

tyteen4a03 commented 2 years ago

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│
toaster-code commented 1 year ago

I've got the same problem. Changing the folder of the whl files seems to work.

will-tha-mise commented 1 year ago

I've got a similar seeming issue with a fresh install of poetry on a new machine when i run poetry install (regardless of the in_project config setting) I am seeing:


Loading configuration file C:\Users\my_name\AppData\Roaming\pypoetry\config.toml
Creating virtualenv my_name-iIWhMjqI-py3.9 in C:\Users\my_name\AppData\Local\pypoetry\Cache\virtualenvs

  Stack trace:

  19  AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:327 in run
       325│
       326│             try:
     → 327│                 exit_code = self._run(io)
       328│             except BrokenPipeError:
       329│                 # If we are piped to another process, it may close early and send a

  18  AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\application.py:190 in _run
       188│         self._load_plugins(io)
       189│
     → 190│         exit_code: int = super()._run(io)
       191│         return exit_code
       192│

  17  AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:431 in _run
       429│             io.input.interactive(interactive)
       430│
     → 431│         exit_code = self._run_command(command, io)
       432│         self._running_command = None
       433│

  16  AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:473 in _run_command
       471│
       472│         if error is not None:
     → 473│             raise error
       474│
       475│         return terminate_event.exit_code

  15  AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\application.py:454 in _run_command
       452│
       453│         try:
     → 454│             self._event_dispatcher.dispatch(command_event, COMMAND)
       455│
       456│             if command_event.command_should_run():

  14  AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\events\event_dispatcher.py:26 in dispatch
        24│
        25│         if listeners:
     →  26│             self._do_dispatch(listeners, event_name, event)
        27│
        28│         return event

  13  AppData\Roaming\pypoetry\venv\lib\site-packages\cleo\events\event_dispatcher.py:89 in _do_dispatch
        87│                 break
        88│
     →  89│             listener(event, event_name, self)
        90│
        91│     def _sort_listeners(self, event_name: str) -> None:

  12  AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\application.py:299 in configure_env
       297│
       298│         env_manager = EnvManager(poetry, io=io)
     → 299│         env = env_manager.create_venv()
       300│
       301│         if env.is_venv() and io.is_verbose():

  11  AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\env.py:1046 in create_venv
       1044│
       1045│         if create_venv:
     → 1046│             self.build_venv(
       1047│                 venv,
       1048│                 executable=executable,

  10  AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\utils\env.py:1125 in build_venv
       1123│         args.append(str(path))
       1124│
     → 1125│         cli_result = virtualenv.cli_run(args)
       1126│
       1127│         # Exclude the venv folder from from macOS Time Machine backups

   9  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\run\__init__.py:30 in cli_run
        28│     of_session = session_via_cli(args, options, setup_logging, env)
        29│     with of_session:
     →  30│         of_session.run()
        31│     return of_session
        32│

   8  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\run\session.py:42 in run
        40│
        41│     def run(self):
     →  42│         self._create()
        43│         self._seed()
        44│         self._activate()

   7  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\run\session.py:49 in _create
        47│     def _create(self):
        48│         logging.info("create virtual environment via %s", self.creator)
     →  49│         self.creator.run()
        50│         logging.debug(_DEBUG_MARKER)
        51│         logging.debug("%s", _Debug(self.creator))

   6  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\creator.py:153 in run
       151│             logging.debug("delete %s", self.dest)
       152│             safe_delete(self.dest)
     → 153│         self.create()
       154│         self.set_pyenv_cfg()
       155│         if not self.no_vcs_ignore:

   5  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\via_global_ref\builtin\via_global_self_do.py:71 in create
        69│
        70│     def create(self):
     →  71│         dirs = self.ensure_directories()
        72│         for directory in list(dirs):
        73│             if any(i for i in dirs if i is not directory and directory.parts == i.parts[: len(directory.parts)]):

   4  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\via_global_ref\builtin\via_global_self_do.py:96 in ensure_directories
        94│
        95│     def ensure_directories(self):
     →  96│         return {self.dest, self.bin_dir, self.script_dir, self.stdlib} | set(self.libs)
        97│
        98│     def set_pyenv_cfg(self):

   3  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\describe.py:44 in stdlib
        42│     def stdlib(self):
        43│         if self._stdlib is None:
     →  44│             self._stdlib = Path(self.interpreter.sysconfig_path("stdlib", config_var=self._config_vars))
        45│         return self._stdlib
        46│

   2  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\describe.py:56 in _config_vars
        54│     def _config_vars(self):
        55│         if self._conf_vars is None:
     →  56│             self._conf_vars = self._calc_config_vars(self.dest)
        57│         return self._conf_vars
        58│

   1  AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\describe.py:61 in _calc_config_vars
        59│     def _calc_config_vars(self, to):
        60│         sys_vars = self.interpreter.sysconfig_vars
     →  61│         return {k: (to if v.startswith(self.interpreter.prefix) else v) for k, v in sys_vars.items()}
        62│
        63│     @classmethod

  AttributeError

  'NoneType' object has no attribute 'startswith'

  at AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\describe.py:61 in <dictcomp>
       57│         return self._conf_vars
       58│
       59│     def _calc_config_vars(self, to):
       60│         sys_vars = self.interpreter.sysconfig_vars
    →  61│         return {k: (to if v.startswith(self.interpreter.prefix) else v) for k, v in sys_vars.items()}
       62│
       63│     @classmethod
       64│     def can_describe(cls, interpreter):  # noqa: U100
       65│         """Knows means it knows how the output will look"""```

       Maybe not related, I am somewhat new to poetry
rlleshi commented 1 year ago

Getting the same error on Windows. @will-tha-mise did you find a work around for this?

will-tha-mise commented 1 year ago

Getting the same error on Windows. @will-tha-mise did you find a work around for this?

I ended up uninstalling and reinstalling python (and poetry) and it worked ok, suspect something was odd with my python install before

rlleshi commented 1 year ago

@will-tha-mise had u installed that python using pyenv?

will-tha-mise commented 1 year ago

@will-tha-mise had u installed that python using pyenv?

I'm not sure sorry, it was a work laptop with python pre-installed and unsure how they did it.

mbwhite commented 3 months ago

Just stumbled across this - and yes the python was installed with pyenv