Skip to content

Commit

Permalink
Fix broken Windows zipapp
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Oct 17, 2024
1 parent 228b615 commit 6eaa3c2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 59 deletions.
3 changes: 3 additions & 0 deletions docs/changelog/2783.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Upgrade embedded wheels:

* setuptools to ``75.2.0`` from ``75.1.0``
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ lint.ignore = [
"S104", # Possible binding to all interfaces
"S404", # Using subprocess is alright
"S603", # subprocess calls are fine
"PLW1510", # no need for check for subprocess
]
lint.per-file-ignores."src/virtualenv/activation/python/activate_this.py" = [
"F821", # ignore undefined template string placeholders
Expand Down
14 changes: 7 additions & 7 deletions src/virtualenv/seed/wheels/embed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@
},
"3.8": {
"pip": "pip-24.2-py3-none-any.whl",
"setuptools": "setuptools-75.1.0-py3-none-any.whl",
"setuptools": "setuptools-75.2.0-py3-none-any.whl",
"wheel": "wheel-0.44.0-py3-none-any.whl",
},
"3.9": {
"pip": "pip-24.2-py3-none-any.whl",
"setuptools": "setuptools-75.1.0-py3-none-any.whl",
"setuptools": "setuptools-75.2.0-py3-none-any.whl",
"wheel": "wheel-0.44.0-py3-none-any.whl",
},
"3.10": {
"pip": "pip-24.2-py3-none-any.whl",
"setuptools": "setuptools-75.1.0-py3-none-any.whl",
"setuptools": "setuptools-75.2.0-py3-none-any.whl",
"wheel": "wheel-0.44.0-py3-none-any.whl",
},
"3.11": {
"pip": "pip-24.2-py3-none-any.whl",
"setuptools": "setuptools-75.1.0-py3-none-any.whl",
"setuptools": "setuptools-75.2.0-py3-none-any.whl",
"wheel": "wheel-0.44.0-py3-none-any.whl",
},
"3.12": {
"pip": "pip-24.2-py3-none-any.whl",
"setuptools": "setuptools-75.1.0-py3-none-any.whl",
"setuptools": "setuptools-75.2.0-py3-none-any.whl",
"wheel": "wheel-0.44.0-py3-none-any.whl",
},
"3.13": {
"pip": "pip-24.2-py3-none-any.whl",
"setuptools": "setuptools-75.1.0-py3-none-any.whl",
"setuptools": "setuptools-75.2.0-py3-none-any.whl",
"wheel": "wheel-0.44.0-py3-none-any.whl",
},
"3.14": {
"pip": "pip-24.2-py3-none-any.whl",
"setuptools": "setuptools-75.1.0-py3-none-any.whl",
"setuptools": "setuptools-75.2.0-py3-none-any.whl",
"wheel": "wheel-0.44.0-py3-none-any.whl",
},
}
Expand Down
Binary file not shown.
75 changes: 33 additions & 42 deletions tasks/__main__zipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import os
import sys
import zipfile
from importlib.abc import SourceLoader
from importlib.util import spec_from_file_location

ABS_HERE = os.path.abspath(os.path.dirname(__file__))
NEW_IMPORT_SYSTEM = sys.version_info[0] >= 3 # noqa: PLR2004


class VersionPlatformSelect:
Expand Down Expand Up @@ -69,18 +70,34 @@ def _register_distutils_finder(self):
if "distlib" not in self.modules:
return

class Resource:
def __init__(self, content) -> None:
self.bytes = content
self.is_container = False

class DistlibFinder:
def __init__(self, path, loader) -> None:
self.path = path
self.loader = loader

def find(self, name):
class Resource:
def __init__(self, content) -> None:
self.bytes = content

full_path = os.path.join(self.path, name)
return Resource(self.loader.get_data(full_path))
return Resource(self.loader.get_data(os.path.join(self.path, name)))

def iterator(self, resource_name):
resource = self.find(resource_name)
if resource is not None:
todo = [resource]
while todo:
resource = todo.pop(0)
yield resource
if resource.is_container:
rname = resource.name
for name in resource.resources:
child = self.find(f"{rname}/{name}" if rname else name)
if child.is_container:
todo.append(child)
else:
yield child

from distlib.resources import register_finder # noqa: PLC0415

Expand Down Expand Up @@ -113,41 +130,15 @@ def locate_file(self, path):
return _VER_DISTRIBUTION_CLASS


if NEW_IMPORT_SYSTEM:
from importlib.abc import SourceLoader
from importlib.util import spec_from_file_location

class VersionedFindLoad(VersionPlatformSelect, SourceLoader):
def find_spec(self, fullname, path, target=None): # noqa: ARG002
zip_path = self.find_mod(fullname)
if zip_path is not None:
return spec_from_file_location(name=fullname, loader=self)
return None

def module_repr(self, module):
raise NotImplementedError

else:
from imp import new_module

class VersionedFindLoad(VersionPlatformSelect):
def find_module(self, fullname, path=None): # noqa: ARG002
return self if self.find_mod(fullname) else None

def load_module(self, fullname):
filename = self.get_filename(fullname)
code = self.get_data(filename)
mod = sys.modules.setdefault(fullname, new_module(fullname))
mod.__file__ = filename
mod.__loader__ = self
is_package = filename.endswith("__init__.py")
if is_package:
mod.__path__ = [os.path.dirname(filename)]
mod.__package__ = fullname
else:
mod.__package__ = fullname.rpartition(".")[0]
exec(code, mod.__dict__) # noqa: S102
return mod
class VersionedFindLoad(VersionPlatformSelect, SourceLoader):
def find_spec(self, fullname, path, target=None): # noqa: ARG002
zip_path = self.find_mod(fullname)
if zip_path is not None:
return spec_from_file_location(name=fullname, loader=self)
return None

def module_repr(self, module):
raise NotImplementedError


def run():
Expand Down
13 changes: 3 additions & 10 deletions tasks/upgrade_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def run(): # noqa: C901

added = collect_package_versions(new_packages)
removed = collect_package_versions(remove_packages)

outcome = (1 if STRICT else 0) if (added or removed) else 0
print(f"Outcome {outcome} added {added} removed {removed}") # noqa: T201
lines = ["Upgrade embedded wheels:", ""]
for key, versions in added.items():
text = f"* {key} to {fmt_version(versions)}"
Expand Down Expand Up @@ -119,15 +119,8 @@ def get_embed_wheel(distribution, for_py_version):
)
dest_target = DEST / "__init__.py"
dest_target.write_text(msg, encoding="utf-8")

subprocess.run(
[sys.executable, "-m", "ruff", "check", str(dest_target), "--fix", "--unsafe-fixes"],
check=False,
)
subprocess.run(
[sys.executable, "-m", "ruff", "format", str(dest_target), "--preview"],
check=False,
)
subprocess.run([sys.executable, "-m", "ruff", "format", str(dest_target), "--preview"])
subprocess.run([sys.executable, "-m", "ruff", "check", str(dest_target), "--fix", "--unsafe-fixes"])

raise SystemExit(outcome)

Expand Down

0 comments on commit 6eaa3c2

Please sign in to comment.