Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the "venv" scheme if available to obtain prefixed lib paths #11598

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

dnicolodi
Copy link
Contributor

get_prefixed_libs() computes the Python path for libraries in a pip isolation environment. Python 3.11 introduced the "venv" path scheme to be used in these cases. Use it if available.

This solves a bug on Homebrew's Python 3.10 and later where the default paths scheme when Python is invoked outside a virtual environment is "osx_framework_library" and does not relative to the "{base}" or "{platbase}" variables.

Fixes #11539.

@dnicolodi dnicolodi force-pushed the homebrew-scheme branch 4 times, most recently from 90ae2c9 to 418771a Compare November 15, 2022 17:05
dnicolodi added a commit to dnicolodi/meson-python that referenced this pull request Nov 16, 2022
dnicolodi added a commit to dnicolodi/meson-python that referenced this pull request Nov 16, 2022
Comment on lines 216 to 222
def get_prefixed_libs(prefix: str) -> typing.Tuple[str, str]:
paths = sysconfig.get_paths(vars={"base": prefix, "platbase": prefix})
vars = {"base": prefix, "platbase": prefix}
if "venv" in sysconfig.get_scheme_names():
paths = sysconfig.get_paths(vars=vars, scheme="venv")
else:
paths = sysconfig.get_paths(vars=vars)
return (paths["purelib"], paths["platlib"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is only used for creating isolated environments, let’s rename it to better describe what it does. This avoids needing to think about why this always sets venv even when pip is not running in a virtual environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought prefixed in the name carried this message. Do you have a better name in mind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just get_isolated_environment_lib_paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds descriptive enough. Should I change the argument name to environment then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix is probably fine (it is the environment’s path prefix after all)

Copy link
Contributor Author

@dnicolodi dnicolodi Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that the function name is meant to reflect the name of a similar function in distutils. It is also called from a function with the same name in another module, see

def get_prefixed_libs(prefix: str) -> List[str]:
"""Return the lib locations under ``prefix``."""
new_pure, new_plat = _sysconfig.get_prefixed_libs(prefix)
if _USE_SYSCONFIG:
return _deduplicated(new_pure, new_plat)
Should we still change just this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, change them all.

FFY00 pushed a commit to mesonbuild/meson-python that referenced this pull request Nov 16, 2022
get_prefixed_libs() computes the Python path for libraries in a pip
isolation environment. Python 3.11 introduced the "venv" path scheme
to be used in these cases. Use it if available.

This solves a bug on Homebrew's Python 3.10 and later where the
default paths scheme when Python is invoked outside a virtual
environment is "osx_framework_library" and does not relative to the
"{base}" or "{platbase}" variables.

Fixes pypa#11539.
Since this function is only used for creating isolated environments,
rename it to better describe what it does.  This avoids needing to
think about why the implementation uses the "venv" paths scheme even
when pip is not running in a virtual environment.
@wimglenn
Copy link
Contributor

This also fixes #11053

@pradyunsg
Copy link
Member

I've triggered a CI re-run for some flakiness.

@dnicolodi
Copy link
Contributor Author

All green now. Can this be merged or there is anything left to do?

@pradyunsg pradyunsg merged commit 17e84a9 into pypa:main Nov 18, 2022
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 27, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 27, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 27, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 27, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 27, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 27, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 29, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
dnicolodi added a commit to dnicolodi/pip that referenced this pull request Nov 29, 2022
The scripts path was looked up passing explicitly the scheme to be
used using "nt" on Windows and "posix_prefix" everywhere else.
However, when the isolated build environment is created, packages are
installed using the default scheme for the platform. On most platforms
this works because normally "nt" and "posix_prefix" are the default
schemes.

However, Debian customizes sysconfig to use a "posix_local" scheme by
default and under this scheme the scripts path does not match the one
of the "posix_prefix" scheme. This results in scripts installed as
part of the build dependencies not to be found during the build, as
reported here mesonbuild/meson-python#109
and here https://bugs.debian.org/1019293.

The problem can be solved omitting to specify a scheme when looking up
the scripts path. To future proof the path lookup, use the "venv"
scheme if available as done in pypa#11598. For uniformity use similar
functions as used to lookup the library paths.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Isolated build environment is corrupted on Homebrew Python 3.10 without active virtual environment
4 participants