Skip to content

Commit 1064dc8

Browse files
committed
linting update
1 parent 6048957 commit 1064dc8

1 file changed

Lines changed: 37 additions & 29 deletions

File tree

setup.py

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@
3232

3333
class Config:
3434
libzim_dl_version: str = os.getenv("LIBZIM_DL_VERSION", "9.1.0")
35-
use_system_libzim: bool = bool(os.getenv("USE_SYSTEM_LIBZIM", False))
36-
download_libzim: bool = not bool(os.getenv("DONT_DOWNLOAD_LIBZIM", False))
35+
use_system_libzim: bool = bool(os.getenv("USE_SYSTEM_LIBZIM") or False)
36+
download_libzim: bool = not bool(os.getenv("DONT_DOWNLOAD_LIBZIM") or False)
3737

3838
# toggle profiling for coverage report in Cython
3939
profiling: bool = os.getenv("PROFILE", "") == "1"
4040

4141
# macOS signing
42-
should_sign_apple: bool = bool(os.getenv("SIGN_APPLE", False))
43-
apple_signing_identity: str = os.getenv("APPLE_SIGNING_IDENTITY")
44-
apple_signing_keychain: str = os.getenv("APPLE_SIGNING_KEYCHAIN_PATH")
45-
apple_signing_keychain_profile: str = os.getenv("APPLE_SIGNING_KEYCHAIN_PROFILE")
42+
should_sign_apple: bool = bool(os.getenv("SIGN_APPLE") or False)
43+
apple_signing_identity: str = os.getenv("APPLE_SIGNING_IDENTITY") or ""
44+
apple_signing_keychain: str = os.getenv("APPLE_SIGNING_KEYCHAIN_PATH") or ""
45+
apple_signing_keychain_profile: str = (
46+
os.getenv("APPLE_SIGNING_KEYCHAIN_PROFILE") or ""
47+
)
4648

4749
# windows
4850
_msvc_debug: bool = bool(os.getenv("MSVC_DEBUG"))
@@ -69,11 +71,11 @@ class Config:
6971
@property
7072
def libzim_major(self) -> str:
7173
# assuming nightlies are for version 8.x
72-
return 9 if self.is_nightly else self.libzim_dl_version[0]
74+
return "9" if self.is_nightly else self.libzim_dl_version[0]
7375

7476
@property
7577
def found_libzim(self) -> str:
76-
return find_library("zim")
78+
return find_library("zim") or ""
7779

7880
@property
7981
def is_latest_nightly(self) -> bool:
@@ -82,8 +84,8 @@ def is_latest_nightly(self) -> bool:
8284

8385
@property
8486
def is_nightly(self) -> bool:
85-
return self.is_latest_nightly or re.match(
86-
r"\d{4}-\d{2}-\d{2}", self.libzim_dl_version
87+
return self.is_latest_nightly or bool(
88+
re.match(r"\d{4}-\d{2}-\d{2}", self.libzim_dl_version)
8789
)
8890

8991
@property
@@ -145,7 +147,10 @@ def archive_format(self):
145147
def is_musl(self) -> bool:
146148
"""whether running on a musl system (Alpine)"""
147149
ps = subprocess.run(
148-
["/usr/bin/env", "ldd", "--version"], capture_output=True, text=True
150+
["/usr/bin/env", "ldd", "--version"],
151+
capture_output=True,
152+
text=True,
153+
check=False,
149154
)
150155
try:
151156
return "musl libc" in ps.stderr.splitlines()[0]
@@ -250,7 +255,7 @@ def _download_and_extract(self, filename: str) -> pathlib.Path:
250255
# download a local copy if none present
251256
if not fpath.exists():
252257
print(f"> from {url}")
253-
with urllib.request.urlopen(url) as response, open( # nosec
258+
with urllib.request.urlopen(url) as response, open( # nosec # noqa: S310
254259
fpath, "wb"
255260
) as fh: # nosec
256261
fh.write(response.read())
@@ -264,7 +269,7 @@ def _download_and_extract(self, filename: str) -> pathlib.Path:
264269
# TODO: FIX for zip
265270
if self.is_latest_nightly:
266271
tar = tarfile.open(fpath)
267-
folder = pathlib.Path(pathlib.Path(tar.firstmember.name).parts[0])
272+
folder = pathlib.Path(pathlib.Path(tar.getmembers()[0].name).parts[0])
268273
else:
269274
folder = fpath.with_name(fpath.name.replace(self.archive_suffix, ""))
270275
# unless for ZIP, extract to current folder (all files inside an in-tar folder)
@@ -300,7 +305,7 @@ def _install_from(self, folder: pathlib.Path):
300305

301306
# remove temp folder
302307
shutil.rmtree(folder, ignore_errors=True)
303-
assert self.base_dir.joinpath("include", "zim", "zim.h").exists()
308+
assert self.base_dir.joinpath("include", "zim", "zim.h").exists() # noqa: S101
304309

305310
if config.platform == "Darwin":
306311
print("> ensure libzim is notarized")
@@ -370,21 +375,21 @@ def can_sign_apple(self) -> bool:
370375
config = Config()
371376

372377

373-
def get_cython_extension():
378+
def get_cython_extension() -> Extension:
374379
define_macros = []
375380
compiler_directives = {"language_level": "3"}
376381

377382
if config.profiling:
378383
define_macros += [("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1")]
379-
compiler_directives.update(linetrace=True)
384+
compiler_directives.update(linetrace="true")
380385

381386
include_dirs = []
382387
library_dirs = []
383388
runtime_library_dirs = []
384389

385390
if config.use_system_libzim:
386391
if not config.found_libzim:
387-
raise EnvironmentError(
392+
raise OSError(
388393
"[!] The libzim library cannot be found.\n"
389394
"Please verify it is correctly installed and can be found."
390395
)
@@ -399,7 +404,7 @@ def get_cython_extension():
399404

400405
# Check for the CPP Libzim library headers in expected directory
401406
if not config.header_file.exists() or not config.dylib_file.exists():
402-
raise EnvironmentError(
407+
raise OSError(
403408
"Unable to find a local copy of libzim "
404409
f"at {config.header_file} and {config.dylib_file}"
405410
)
@@ -480,7 +485,7 @@ def sign_extension_macos(self, ext):
480485
print("Signing & Notarization of the extension")
481486

482487
if not config.can_sign_apple:
483-
raise EnvironmentError("Can't sign for apple. Missing information")
488+
raise OSError("Can't sign for apple. Missing information")
484489

485490
ext_fpath = pathlib.Path(self.get_ext_fullpath(ext.name))
486491

@@ -510,7 +515,8 @@ def sign_extension_macos(self, ext):
510515
"--keepParent",
511516
str(ext_fpath),
512517
str(ext_zip),
513-
]
518+
],
519+
check=True,
514520
)
515521

516522
print("> request notarization")
@@ -552,7 +558,7 @@ def sign_extension_macos(self, ext):
552558
class DownloadLibzim(Command):
553559
"""dedicated command to solely download libzim binary"""
554560

555-
user_options = []
561+
user_options = [] # noqa: RUF012
556562

557563
def initialize_options(self): ...
558564

@@ -563,7 +569,7 @@ def run(self):
563569

564570

565571
class LibzimClean(Command):
566-
user_options = []
572+
user_options = [] # noqa: RUF012
567573

568574
def initialize_options(self): ...
569575

@@ -580,12 +586,14 @@ class RepairWindowsWheel(Command):
580586
]
581587

582588
def initialize_options(self):
583-
self.wheel = None
584-
self.destdir = None
589+
self.wheel: str = ""
590+
self.destdir: str = ""
585591

586592
def finalize_options(self):
587-
assert Path(self.wheel).exists(), "wheel file does not exists"
588-
assert (
593+
assert ( # noqa: S101
594+
self.wheel and Path(self.wheel).exists()
595+
), "wheel file does not exists"
596+
assert self.destdir and ( # noqa: S101
589597
Path(self.destdir).exists() and Path(self.destdir).is_dir()
590598
), "dest_dir does not exists"
591599

@@ -594,11 +602,11 @@ def run(self):
594602

595603

596604
if len(sys.argv) == 1 or (
597-
len(sys.argv) == 2 and sys.argv[1] in config.buildless_commands
605+
len(sys.argv) == 2 and sys.argv[1] in config.buildless_commands # noqa: PLR2004
598606
):
599-
ext_modules = None
607+
ext_modules = []
600608
else:
601-
ext_modules = get_cython_extension()
609+
ext_modules = [get_cython_extension()]
602610

603611
setup(
604612
cmdclass={

0 commit comments

Comments
 (0)