Skip to content

Commit

Permalink
chore: un-pin virtualenv update (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed May 20, 2024
1 parent 78bca57 commit d1a4c9c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
19 changes: 10 additions & 9 deletions bin/update_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def git_ls_remote_versions(url) -> list[VersionTuple]:
if version.is_prerelease:
log.info("Ignoring pre-release %r", str(version))
continue
# Do not upgrade past 20.22.0 to keep python 3.6 compat
if version >= Version("20.22.0"):
log.info("Ignoring %r which is not compatible with python 3.6", str(version))
continue
versions.append(VersionTuple(version, version_string))
except InvalidVersion:
log.warning("Ignoring ref %r", ref)
Expand All @@ -82,15 +78,20 @@ def update_virtualenv(force: bool, level: str) -> None:

original_toml = toml_file_path.read_text()
with toml_file_path.open("rb") as f:
loaded_file = tomllib.load(f)
version = str(loaded_file["version"])
configurations = tomllib.load(f)
default = configurations.pop("default")
version = str(default["version"])
versions = git_ls_remote_versions(GET_VIRTUALENV_GITHUB)
if versions[0].version > Version(version):
version = versions[0].version_string

result_toml = (
f'version = "{version}"\n'
f'url = "{GET_VIRTUALENV_URL_TEMPLATE.format(version=version)}"\n'
configurations["default"] = {
"version": version,
"url": GET_VIRTUALENV_URL_TEMPLATE.format(version=version),
}
result_toml = "".join(
f'{key} = {{ version = "{value["version"]}", url = "{value["url"]}" }}\n'
for key, value in configurations.items()
)

rich.print() # spacer
Expand Down
4 changes: 3 additions & 1 deletion cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def setup_python(

log.step("Setting up build environment...")
venv_path = tmp / "venv"
env = virtualenv(base_python, venv_path, dependency_constraint_flags)
env = virtualenv(
python_configuration.version, base_python, venv_path, dependency_constraint_flags
)
venv_bin_path = venv_path / "bin"
assert venv_bin_path.exists()
# Fix issue with site.py setting the wrong `sys.prefix`, `sys.exec_prefix`,
Expand Down
4 changes: 2 additions & 2 deletions cibuildwheel/resources/virtualenv.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "20.21.1"
url = "https://github.com/pypa/get-virtualenv/blob/20.21.1/public/virtualenv.pyz?raw=true"
py36 = { version = "20.21.1", url = "https://github.com/pypa/get-virtualenv/blob/20.21.1/public/virtualenv.pyz?raw=true" }
default = { version = "20.26.2", url = "https://github.com/pypa/get-virtualenv/blob/20.26.2/public/virtualenv.pyz?raw=true" }
13 changes: 8 additions & 5 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,15 @@ def get_pip_version(env: Mapping[str, str]) -> str:


@lru_cache(maxsize=None)
def _ensure_virtualenv() -> Path:
def _ensure_virtualenv(version: str) -> Path:
version_parts = version.split(".")
key = f"py{version_parts[0]}{version_parts[1]}"
input_file = resources_dir / "virtualenv.toml"
with input_file.open("rb") as f:
loaded_file = tomllib.load(f)
version = str(loaded_file["version"])
url = str(loaded_file["url"])
configuration = loaded_file.get(key, loaded_file["default"])
version = str(configuration["version"])
url = str(configuration["url"])
path = CIBW_CACHE_PATH / f"virtualenv-{version}.pyz"
with FileLock(str(path) + ".lock"):
if not path.exists():
Expand Down Expand Up @@ -587,10 +590,10 @@ def _parse_constraints_for_virtualenv(


def virtualenv(
python: Path, venv_path: Path, dependency_constraint_flags: Sequence[PathOrStr]
version: str, python: Path, venv_path: Path, dependency_constraint_flags: Sequence[PathOrStr]
) -> dict[str, str]:
assert python.exists()
virtualenv_app = _ensure_virtualenv()
virtualenv_app = _ensure_virtualenv(version)
allowed_seed_packages = ["pip", "setuptools", "wheel"]
constraints = _parse_constraints_for_virtualenv(
allowed_seed_packages, dependency_constraint_flags
Expand Down
4 changes: 3 additions & 1 deletion cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def setup_python(

log.step("Setting up build environment...")
venv_path = tmp / "venv"
env = virtualenv(base_python, venv_path, dependency_constraint_flags)
env = virtualenv(
python_configuration.version, base_python, venv_path, dependency_constraint_flags
)

# set up environment variables for run_with_env
env["PYTHON_VERSION"] = python_configuration.version
Expand Down
1 change: 0 additions & 1 deletion test/test_dependency_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def test_dependency_constraints_file(tmp_path, build_frontend_env):
"""
pip=={pip}
delocate=={delocate}
importlib-metadata<3,>=0.12; python_version < "3.8"
""".format(**tool_versions)
)
)
Expand Down

0 comments on commit d1a4c9c

Please sign in to comment.