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:
Henry Schreiner
2022-10-07 08:47:31 -04:00
committed by GitHub
parent c85450161c
commit 7c4bbf8cb3
8 changed files with 34 additions and 41 deletions
+2 -2
View File
@@ -162,7 +162,7 @@ def main() -> None:
# cleanup manually
shutil.rmtree(temp_dir, ignore_errors=sys.platform.startswith("win"))
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:
@@ -300,7 +300,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
# cleanup manually
shutil.rmtree(tmp_path, ignore_errors=sys.platform.startswith("win"))
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:
+1 -1
View File
@@ -448,4 +448,4 @@ def troubleshoot(options: Options, error: Exception) -> None:
print(" Files detected:")
print("\n".join(f" {f}" for f in so_files))
print("")
print()
+3 -4
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import contextlib
import functools
import os
import platform
@@ -283,7 +284,7 @@ def build(options: Options, tmp_path: Path) -> None:
options.globals.build_selector, options.globals.architectures
)
if len(python_configurations) == 0:
if not python_configurations:
return
try:
@@ -574,10 +575,8 @@ def build(options: Options, tmp_path: Path) -> None:
# we're all done here; move it to output (overwrite existing)
if compatible_wheel is None:
try:
with contextlib.suppress(FileNotFoundError):
(build_options.output_dir / repaired_wheel.name).unlink()
except FileNotFoundError:
pass
shutil.move(str(repaired_wheel), build_options.output_dir)
built_wheels.append(build_options.output_dir / repaired_wheel.name)
+13 -15
View File
@@ -1,14 +1,14 @@
from __future__ import annotations
import configparser
import contextlib
import dataclasses
import difflib
import functools
import os
import shlex
import sys
import traceback
from configparser import ConfigParser
from contextlib import contextmanager
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import Any, Callable, Dict, Generator, Iterator, List, Mapping, Union, cast
@@ -40,7 +40,7 @@ from .util import (
)
@dataclass
@dataclasses.dataclass
class CommandLineArguments:
platform: Literal["auto", "linux", "macos", "windows"] | None
archs: str | None
@@ -53,7 +53,7 @@ class CommandLineArguments:
prerelease_pythons: bool
@dataclass(frozen=True)
@dataclasses.dataclass(frozen=True)
class GlobalOptions:
package_dir: Path
output_dir: Path
@@ -63,7 +63,7 @@ class GlobalOptions:
container_engine: ContainerEngine
@dataclass(frozen=True)
@dataclasses.dataclass(frozen=True)
class BuildOptions:
globals: GlobalOptions
environment: ParsedEnvironment
@@ -105,7 +105,7 @@ class BuildOptions:
Setting = Union[Dict[str, str], List[str], str, int]
@dataclass(frozen=True)
@dataclasses.dataclass(frozen=True)
class Override:
select_pattern: str
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)
]
@contextmanager
@contextlib.contextmanager
def identifier(self, identifier: str | None) -> Generator[None, None, None]:
self.current_identifier = identifier
try:
@@ -496,10 +496,8 @@ class Options:
# Pass through environment variables
if self.platform == "linux":
for env_var_name in environment_pass:
try:
with contextlib.suppress(KeyError):
environment.add(env_var_name, os.environ[env_var_name])
except KeyError:
pass
if dependency_versions == "pinned":
dependency_constraints: None | (
@@ -574,7 +572,7 @@ class Options:
)
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}
if len(before_all_values) > 1:
@@ -599,7 +597,7 @@ class Options:
def summary(self, identifiers: list[str]) -> str:
lines = [
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)
@@ -607,7 +605,7 @@ class Options:
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":
continue
@@ -642,7 +640,7 @@ def _get_pinned_container_images() -> Mapping[str, Mapping[str, str]]:
"""
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)
return all_pinned_images
+10 -13
View File
@@ -1,8 +1,9 @@
from __future__ import annotations
import ast
import configparser
import contextlib
import sys
from configparser import ConfigParser
from pathlib import Path
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"""
# Read in from pyproject.toml:project.requires-python
try:
with contextlib.suppress(FileNotFoundError):
with (package_dir / "pyproject.toml").open("rb") as f1:
info = tomllib.load(f1)
return str(info["project"]["requires-python"])
except (FileNotFoundError, KeyError, IndexError, TypeError):
pass
with contextlib.suppress(KeyError, IndexError, TypeError):
return str(info["project"]["requires-python"])
# Read in from setup.cfg:options.python_requires
try:
config = ConfigParser()
config = configparser.ConfigParser()
with contextlib.suppress(FileNotFoundError):
config.read(package_dir / "setup.cfg")
return str(config["options"]["python_requires"])
except (FileNotFoundError, KeyError, IndexError, TypeError):
pass
with contextlib.suppress(KeyError, IndexError, TypeError):
return str(config["options"]["python_requires"])
try:
with contextlib.suppress(FileNotFoundError):
with (package_dir / "setup.py").open(encoding="utf8") as f2:
return setup_py_python_requires(f2.read())
except FileNotFoundError:
pass
return None
+2 -3
View File
@@ -6,6 +6,7 @@
# for the ssl module. Uses the certificates provided by the certifi package:
# https://pypi.org/project/certifi/
import contextlib
import os
import os.path
import ssl
@@ -39,10 +40,8 @@ def main():
relpath_to_certifi_cafile = os.path.relpath(certifi.where())
print(" -- removing any existing file or link")
try:
with contextlib.suppress(FileNotFoundError):
os.remove(openssl_cafile)
except FileNotFoundError:
pass
print(" -- creating symlink to certifi certificate bundle")
os.symlink(relpath_to_certifi_cafile, openssl_cafile)
+2 -2
View File
@@ -461,7 +461,7 @@ def print_new_wheels(msg: str, output_dir: Path) -> Generator[None, None, None]:
for wheel in final_contents - existing_contents
]
if len(new_contents) == 0:
if not new_contents:
return
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:
for line in constraint_file:
line = line.strip()
if len(line) == 0:
if not line:
continue
if line.startswith("#"):
continue
+1 -1
View File
@@ -242,7 +242,7 @@ def build(options: Options, tmp_path: Path) -> None:
options.globals.build_selector, options.globals.architectures
)
if len(python_configurations) == 0:
if not python_configurations:
return
try: