install: Escape curly brackets in virtualenv path#400
Open
helasraizam wants to merge 2 commits intopypa:mainfrom
Open
install: Escape curly brackets in virtualenv path#400helasraizam wants to merge 2 commits intopypa:mainfrom
helasraizam wants to merge 2 commits intopypa:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of error
As mentioned in #281 if a virtual environment contains curly brackets (/path/{W}/project), setuptools fails with the error "ValueError: invalid variable 'W'", which is difficult to diagnose and is readily misattributed to the package being installed.
Under the hood
In
distutils.command.install,install.finalize_options()callsinstall.expand_basedirs(), which expandsinstall.install_base,install.install_platbase, andinstall.rootpaths using format_map to expand curly bracket variables supported in these paths through --user, --home, --prefix flags, sysconfig, etc.. Without these flags/configs,, sys.prefix and sys.exec_prefix are invoked, for which curly brackets in the path should be interpreted literally.What this PR does
This PR escapes curly brackets when reading
sys.prefixandsys.exec_prefixintoinstall.prefixto prevent them from later being interpreted as variables, which resulted in the error. It assumes thatinstall.prefixis always formatted (throughutil.subst_varsandformat_map) before usage, which appears to be the case. It does not change the curly bracket expansion behavior of config and flag arguments.Test/MWE
The above fails with "ValueError: invalid variable 'W'" in the current main branch of setuptools and works if this patch is applied to setuptools. Tests with tox on distutils and patched setuptools appeared to show no relevant errors.
This is my first PR, kindly treat with scrutiny and do not hesitate with feedback.