chore: minor cleanups from reverb (#1293)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
@@ -162,7 +162,7 @@ def main() -> None:
|
|||||||
# cleanup manually
|
# cleanup manually
|
||||||
shutil.rmtree(temp_dir, ignore_errors=sys.platform.startswith("win"))
|
shutil.rmtree(temp_dir, ignore_errors=sys.platform.startswith("win"))
|
||||||
if temp_dir.exists():
|
if temp_dir.exists():
|
||||||
log.warning(f"Can't delete temporary folder '{str(temp_dir)}'")
|
log.warning(f"Can't delete temporary folder '{temp_dir}'")
|
||||||
|
|
||||||
|
|
||||||
def build_in_directory(args: CommandLineArguments) -> None:
|
def build_in_directory(args: CommandLineArguments) -> None:
|
||||||
@@ -300,7 +300,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
|
|||||||
# cleanup manually
|
# cleanup manually
|
||||||
shutil.rmtree(tmp_path, ignore_errors=sys.platform.startswith("win"))
|
shutil.rmtree(tmp_path, ignore_errors=sys.platform.startswith("win"))
|
||||||
if tmp_path.exists():
|
if tmp_path.exists():
|
||||||
log.warning(f"Can't delete temporary folder '{str(tmp_path)}'")
|
log.warning(f"Can't delete temporary folder '{tmp_path}'")
|
||||||
|
|
||||||
|
|
||||||
def print_preamble(platform: str, options: Options, identifiers: list[str]) -> None:
|
def print_preamble(platform: str, options: Options, identifiers: list[str]) -> None:
|
||||||
|
|||||||
@@ -448,4 +448,4 @@ def troubleshoot(options: Options, error: Exception) -> None:
|
|||||||
|
|
||||||
print(" Files detected:")
|
print(" Files detected:")
|
||||||
print("\n".join(f" {f}" for f in so_files))
|
print("\n".join(f" {f}" for f in so_files))
|
||||||
print("")
|
print()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -283,7 +284,7 @@ def build(options: Options, tmp_path: Path) -> None:
|
|||||||
options.globals.build_selector, options.globals.architectures
|
options.globals.build_selector, options.globals.architectures
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(python_configurations) == 0:
|
if not python_configurations:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -574,10 +575,8 @@ def build(options: Options, tmp_path: Path) -> None:
|
|||||||
|
|
||||||
# we're all done here; move it to output (overwrite existing)
|
# we're all done here; move it to output (overwrite existing)
|
||||||
if compatible_wheel is None:
|
if compatible_wheel is None:
|
||||||
try:
|
with contextlib.suppress(FileNotFoundError):
|
||||||
(build_options.output_dir / repaired_wheel.name).unlink()
|
(build_options.output_dir / repaired_wheel.name).unlink()
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
shutil.move(str(repaired_wheel), build_options.output_dir)
|
shutil.move(str(repaired_wheel), build_options.output_dir)
|
||||||
built_wheels.append(build_options.output_dir / repaired_wheel.name)
|
built_wheels.append(build_options.output_dir / repaired_wheel.name)
|
||||||
|
|||||||
+13
-15
@@ -1,14 +1,14 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
import contextlib
|
||||||
|
import dataclasses
|
||||||
import difflib
|
import difflib
|
||||||
import functools
|
import functools
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from configparser import ConfigParser
|
|
||||||
from contextlib import contextmanager
|
|
||||||
from dataclasses import asdict, dataclass
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, Dict, Generator, Iterator, List, Mapping, Union, cast
|
from typing import Any, Callable, Dict, Generator, Iterator, List, Mapping, Union, cast
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ from .util import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclasses.dataclass
|
||||||
class CommandLineArguments:
|
class CommandLineArguments:
|
||||||
platform: Literal["auto", "linux", "macos", "windows"] | None
|
platform: Literal["auto", "linux", "macos", "windows"] | None
|
||||||
archs: str | None
|
archs: str | None
|
||||||
@@ -53,7 +53,7 @@ class CommandLineArguments:
|
|||||||
prerelease_pythons: bool
|
prerelease_pythons: bool
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class GlobalOptions:
|
class GlobalOptions:
|
||||||
package_dir: Path
|
package_dir: Path
|
||||||
output_dir: Path
|
output_dir: Path
|
||||||
@@ -63,7 +63,7 @@ class GlobalOptions:
|
|||||||
container_engine: ContainerEngine
|
container_engine: ContainerEngine
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class BuildOptions:
|
class BuildOptions:
|
||||||
globals: GlobalOptions
|
globals: GlobalOptions
|
||||||
environment: ParsedEnvironment
|
environment: ParsedEnvironment
|
||||||
@@ -105,7 +105,7 @@ class BuildOptions:
|
|||||||
Setting = Union[Dict[str, str], List[str], str, int]
|
Setting = Union[Dict[str, str], List[str], str, int]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class Override:
|
class Override:
|
||||||
select_pattern: str
|
select_pattern: str
|
||||||
options: dict[str, Setting]
|
options: dict[str, Setting]
|
||||||
@@ -277,7 +277,7 @@ class OptionsReader:
|
|||||||
o for o in self.overrides if selector_matches(o.select_pattern, self.current_identifier)
|
o for o in self.overrides if selector_matches(o.select_pattern, self.current_identifier)
|
||||||
]
|
]
|
||||||
|
|
||||||
@contextmanager
|
@contextlib.contextmanager
|
||||||
def identifier(self, identifier: str | None) -> Generator[None, None, None]:
|
def identifier(self, identifier: str | None) -> Generator[None, None, None]:
|
||||||
self.current_identifier = identifier
|
self.current_identifier = identifier
|
||||||
try:
|
try:
|
||||||
@@ -496,10 +496,8 @@ class Options:
|
|||||||
# Pass through environment variables
|
# Pass through environment variables
|
||||||
if self.platform == "linux":
|
if self.platform == "linux":
|
||||||
for env_var_name in environment_pass:
|
for env_var_name in environment_pass:
|
||||||
try:
|
with contextlib.suppress(KeyError):
|
||||||
environment.add(env_var_name, os.environ[env_var_name])
|
environment.add(env_var_name, os.environ[env_var_name])
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if dependency_versions == "pinned":
|
if dependency_versions == "pinned":
|
||||||
dependency_constraints: None | (
|
dependency_constraints: None | (
|
||||||
@@ -574,7 +572,7 @@ class Options:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def check_for_invalid_configuration(self, identifiers: list[str]) -> None:
|
def check_for_invalid_configuration(self, identifiers: list[str]) -> None:
|
||||||
if self.platform in ["macos", "windows"]:
|
if self.platform in {"macos", "windows"}:
|
||||||
before_all_values = {self.build_options(i).before_all for i in identifiers}
|
before_all_values = {self.build_options(i).before_all for i in identifiers}
|
||||||
|
|
||||||
if len(before_all_values) > 1:
|
if len(before_all_values) > 1:
|
||||||
@@ -599,7 +597,7 @@ class Options:
|
|||||||
def summary(self, identifiers: list[str]) -> str:
|
def summary(self, identifiers: list[str]) -> str:
|
||||||
lines = [
|
lines = [
|
||||||
f"{option_name}: {option_value!r}"
|
f"{option_name}: {option_value!r}"
|
||||||
for option_name, option_value in sorted(asdict(self.globals).items())
|
for option_name, option_value in sorted(dataclasses.asdict(self.globals).items())
|
||||||
]
|
]
|
||||||
|
|
||||||
build_option_defaults = self.build_options(identifier=None)
|
build_option_defaults = self.build_options(identifier=None)
|
||||||
@@ -607,7 +605,7 @@ class Options:
|
|||||||
identifier: self.build_options(identifier) for identifier in identifiers
|
identifier: self.build_options(identifier) for identifier in identifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
for option_name, default_value in sorted(asdict(build_option_defaults).items()):
|
for option_name, default_value in sorted(dataclasses.asdict(build_option_defaults).items()):
|
||||||
if option_name == "globals":
|
if option_name == "globals":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -642,7 +640,7 @@ def _get_pinned_container_images() -> Mapping[str, Mapping[str, str]]:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
pinned_images_file = resources_dir / "pinned_docker_images.cfg"
|
pinned_images_file = resources_dir / "pinned_docker_images.cfg"
|
||||||
all_pinned_images = ConfigParser()
|
all_pinned_images = configparser.ConfigParser()
|
||||||
all_pinned_images.read(pinned_images_file)
|
all_pinned_images.read(pinned_images_file)
|
||||||
return all_pinned_images
|
return all_pinned_images
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
|
import configparser
|
||||||
|
import contextlib
|
||||||
import sys
|
import sys
|
||||||
from configparser import ConfigParser
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -59,25 +60,21 @@ def get_requires_python_str(package_dir: Path) -> str | None:
|
|||||||
"""Return the python requires string from the most canonical source available, or None"""
|
"""Return the python requires string from the most canonical source available, or None"""
|
||||||
|
|
||||||
# Read in from pyproject.toml:project.requires-python
|
# Read in from pyproject.toml:project.requires-python
|
||||||
try:
|
with contextlib.suppress(FileNotFoundError):
|
||||||
with (package_dir / "pyproject.toml").open("rb") as f1:
|
with (package_dir / "pyproject.toml").open("rb") as f1:
|
||||||
info = tomllib.load(f1)
|
info = tomllib.load(f1)
|
||||||
return str(info["project"]["requires-python"])
|
with contextlib.suppress(KeyError, IndexError, TypeError):
|
||||||
except (FileNotFoundError, KeyError, IndexError, TypeError):
|
return str(info["project"]["requires-python"])
|
||||||
pass
|
|
||||||
|
|
||||||
# Read in from setup.cfg:options.python_requires
|
# Read in from setup.cfg:options.python_requires
|
||||||
try:
|
config = configparser.ConfigParser()
|
||||||
config = ConfigParser()
|
with contextlib.suppress(FileNotFoundError):
|
||||||
config.read(package_dir / "setup.cfg")
|
config.read(package_dir / "setup.cfg")
|
||||||
return str(config["options"]["python_requires"])
|
with contextlib.suppress(KeyError, IndexError, TypeError):
|
||||||
except (FileNotFoundError, KeyError, IndexError, TypeError):
|
return str(config["options"]["python_requires"])
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
with contextlib.suppress(FileNotFoundError):
|
||||||
with (package_dir / "setup.py").open(encoding="utf8") as f2:
|
with (package_dir / "setup.py").open(encoding="utf8") as f2:
|
||||||
return setup_py_python_requires(f2.read())
|
return setup_py_python_requires(f2.read())
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
# for the ssl module. Uses the certificates provided by the certifi package:
|
# for the ssl module. Uses the certificates provided by the certifi package:
|
||||||
# https://pypi.org/project/certifi/
|
# https://pypi.org/project/certifi/
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import ssl
|
import ssl
|
||||||
@@ -39,10 +40,8 @@ def main():
|
|||||||
relpath_to_certifi_cafile = os.path.relpath(certifi.where())
|
relpath_to_certifi_cafile = os.path.relpath(certifi.where())
|
||||||
|
|
||||||
print(" -- removing any existing file or link")
|
print(" -- removing any existing file or link")
|
||||||
try:
|
with contextlib.suppress(FileNotFoundError):
|
||||||
os.remove(openssl_cafile)
|
os.remove(openssl_cafile)
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
print(" -- creating symlink to certifi certificate bundle")
|
print(" -- creating symlink to certifi certificate bundle")
|
||||||
os.symlink(relpath_to_certifi_cafile, openssl_cafile)
|
os.symlink(relpath_to_certifi_cafile, openssl_cafile)
|
||||||
|
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ def print_new_wheels(msg: str, output_dir: Path) -> Generator[None, None, None]:
|
|||||||
for wheel in final_contents - existing_contents
|
for wheel in final_contents - existing_contents
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(new_contents) == 0:
|
if not new_contents:
|
||||||
return
|
return
|
||||||
|
|
||||||
max_name_len = max(len(f.name) for f in new_contents)
|
max_name_len = max(len(f.name) for f in new_contents)
|
||||||
@@ -526,7 +526,7 @@ def _parse_constraints_for_virtualenv(
|
|||||||
with constraint_path.open(encoding="utf-8") as constraint_file:
|
with constraint_path.open(encoding="utf-8") as constraint_file:
|
||||||
for line in constraint_file:
|
for line in constraint_file:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if len(line) == 0:
|
if not line:
|
||||||
continue
|
continue
|
||||||
if line.startswith("#"):
|
if line.startswith("#"):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ def build(options: Options, tmp_path: Path) -> None:
|
|||||||
options.globals.build_selector, options.globals.architectures
|
options.globals.build_selector, options.globals.architectures
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(python_configurations) == 0:
|
if not python_configurations:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user