Skip to content

install: Escape curly brackets in virtualenv path#400

Open
helasraizam wants to merge 2 commits intopypa:mainfrom
helasraizam:install-escape-braces
Open

install: Escape curly brackets in virtualenv path#400
helasraizam wants to merge 2 commits intopypa:mainfrom
helasraizam:install-escape-braces

Conversation

@helasraizam
Copy link

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() calls install.expand_basedirs(), which expands install.install_base, install.install_platbase, and install.root paths 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.prefix and sys.exec_prefix into install.prefix to prevent them from later being interpreted as variables, which resulted in the error. It assumes that install.prefix is always formatted (through util.subst_vars and format_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

mkdir -p /tmp/{W}/project
cd /tmp/{W}/project
virtualenv venv
source venv/bin/activate
pip install -U pip wheel setuptools
pip install --no-build-isolation --no-binary :all: mysqlclient

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant