Skip to content

venv.EnvBuilder.ensure_directories() no longer accepts Path for env_dir parameter #92675

Closed
@davidfstr

Description

@davidfstr

Bug report

The Poetry project's install-poetry.py setup script relies on the ability to pass a Path instance to venv.EnvBuilder.ensure_directories(), which is possible in Python 3.10. However Python 3.11b1 introduced code that assumed the use of a str path which crashes when given a Path.

Repro steps:

$ wget https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py
$ python3 install-poetry.py 
[...]
Installing Poetry (1.1.13): Creating environment
Traceback (most recent call last):
  File "/Users/davidf/Projects/trycast/install-poetry.py", line 908, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/davidf/Projects/trycast/install-poetry.py", line 876, in main
    return installer.run()
           ^^^^^^^^^^^^^^^
  File "/Users/davidf/Projects/trycast/install-poetry.py", line 507, in run
    self.install(version)
    ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/davidf/Projects/trycast/install-poetry.py", line 528, in install
    with self.make_env(version) as env:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/Users/davidf/Projects/trycast/install-poetry.py", line 600, in make_env
    raise e
    ^^^^^^^
  File "/Users/davidf/Projects/trycast/install-poetry.py", line 586, in make_env
    yield VirtualEnvironment.make(env_path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/davidf/Projects/trycast/install-poetry.py", line 292, in make
    builder.ensure_directories(target)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/venv/__init__.py", line 119, in ensure_directories
    if os.pathsep in env_dir:
       ^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'PosixPath' is not iterable

Your environment

  • CPython 3.11b1

I have a patch to fix, which I will be posting as a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions