Skip to content

Commit

Permalink
Merge pull request #206 from HexDecimal/ruff-pydocstyle
Browse files Browse the repository at this point in the history
Enable pydocstyle linting
  • Loading branch information
HexDecimal authored Feb 27, 2024
2 parents 5bad72b + 5a45ac7 commit 43ad6b3
Show file tree
Hide file tree
Showing 60 changed files with 216 additions and 178 deletions.
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ repos:
- id: fix-byte-order-marker
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
rev: v0.2.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
default_language_version:
python: python3.12
2 changes: 1 addition & 1 deletion delocate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Init for delocate package
"""Delocate package."""

import warnings

Expand Down
1 change: 1 addition & 0 deletions delocate/cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Delocate commands package."""
5 changes: 2 additions & 3 deletions delocate/cmd/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Code shared among multiple commands.
"""Code shared among multiple commands.
All functions in this module are private.
"""
Expand Down Expand Up @@ -94,11 +94,10 @@ class DelocateArgs(TypedDict):

def delocate_values(args: Namespace) -> DelocateArgs:
"""Return the common kwargs for delocate_path and delocate_wheel."""

exclude_files: List[str] = args.exclude

def copy_filter_exclude(name: str) -> bool:
"""Returns False if name is excluded, uses normal rules otherwise."""
"""Return False if name is excluded, uses normal rules otherwise."""
for exclude_str in exclude_files:
if exclude_str in name:
logger.info(
Expand Down
4 changes: 2 additions & 2 deletions delocate/cmd/delocate_addplat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
""" Add platform tags to wheel filename(s) and WHEEL file in wheel
"""Add platform tags to wheel filename(s) and WHEEL file in wheel.
Example:
Expand Down Expand Up @@ -91,7 +91,7 @@
)


def main() -> None:
def main() -> None: # noqa: D103
args = parser.parse_args()
verbosity_config(args)
wheels = list(glob_paths(args.wheels))
Expand Down
6 changes: 3 additions & 3 deletions delocate/cmd/delocate_fuse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
""" Fuse two (probably delocated) wheels
"""Fuse two (probably delocated) wheels.
Overwrites the first wheel in-place by default
Overwrites the first wheel in-place by default.
"""
# vim: ft=python
from __future__ import absolute_import, division, print_function
Expand All @@ -27,7 +27,7 @@
)


def main() -> None:
def main() -> None: # noqa: D103
args = parser.parse_args()
verbosity_config(args)
wheel1, wheel2 = [abspath(expanduser(wheel)) for wheel in args.wheels]
Expand Down
5 changes: 2 additions & 3 deletions delocate/cmd/delocate_listdeps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
""" List library dependencies for libraries in path or wheel
"""
"""List library dependencies for libraries in path or wheel."""
# vim: ft=python
from __future__ import absolute_import, division, print_function

Expand Down Expand Up @@ -37,7 +36,7 @@
)


def main() -> None:
def main() -> None: # noqa: D103
args = parser.parse_args()
verbosity_config(args)
paths = list(glob_paths(args.paths))
Expand Down
6 changes: 3 additions & 3 deletions delocate/cmd/delocate_patch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
""" Apply patch to tree stored in wheel
"""Apply patch to tree stored in wheel.
Overwrites the wheel in-place by default
Overwrites the wheel in-place by default.
"""
# vim: ft=python
from __future__ import absolute_import, division, print_function
Expand Down Expand Up @@ -30,7 +30,7 @@
)


def main() -> None:
def main() -> None: # noqa: D103
args = parser.parse_args()
verbosity_config(args)
if args.wheel_dir:
Expand Down
5 changes: 2 additions & 3 deletions delocate/cmd/delocate_path.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
""" Copy, relink library dependencies for libraries in path
"""
"""Copy, relink library dependencies for libraries in path."""
# vim: ft=python
from __future__ import absolute_import, division, print_function

Expand Down Expand Up @@ -36,7 +35,7 @@
)


def main() -> None:
def main() -> None: # noqa: D103
args = parser.parse_args()
verbosity_config(args)
paths = list(glob_paths(args.paths))
Expand Down
6 changes: 3 additions & 3 deletions delocate/cmd/delocate_wheel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
""" Copy, relink library dependencies for wheel
"""Copy, relink library dependencies for wheel.
Overwrites the wheel in-place by default
Overwrites the wheel in-place by default.
"""
# vim: ft=python
from __future__ import annotations
Expand Down Expand Up @@ -71,7 +71,7 @@
)


def main() -> None:
def main() -> None: # noqa: D103
args = parser.parse_args()
verbosity_config(args)
wheels = list(glob_paths(args.wheels))
Expand Down
48 changes: 24 additions & 24 deletions delocate/delocating.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Routines to copy / relink library dependencies in trees and wheels
"""
"""Routines to copy / relink library dependencies in trees and wheels."""

from __future__ import annotations

Expand Down Expand Up @@ -75,7 +74,7 @@ def delocate_tree_libs(
*,
sanitize_rpaths: bool = False,
) -> Dict[Text, Dict[Text, Text]]:
"""Move needed libraries in `lib_dict` into `lib_path`
"""Move needed libraries in `lib_dict` into `lib_path`.
`lib_dict` has keys naming libraries required by the files in the
corresponding value. Call the keys, "required libs". Call the values
Expand Down Expand Up @@ -265,7 +264,7 @@ def copy_recurse(
copy_filt_func: Optional[Callable[[Text], bool]] = None,
copied_libs: Optional[Dict[Text, Dict[Text, Text]]] = None,
) -> Dict[Text, Dict[Text, Text]]:
"""Analyze `lib_path` for library dependencies and copy libraries
"""Analyze `lib_path` for library dependencies and copy libraries.
`lib_path` is a directory containing libraries. The libraries might
themselves have dependencies. This function analyzes the dependencies and
Expand Down Expand Up @@ -324,7 +323,7 @@ def _copy_required(
copy_filt_func: Optional[Callable[[Text], bool]],
copied_libs: Dict[Text, Dict[Text, Text]],
) -> None:
"""Copy libraries required for files in `lib_path` to `copied_libs`
"""Copy libraries required for files in `lib_path` to `copied_libs`.
Augment `copied_libs` dictionary with any newly copied libraries, modifying
`copied_libs` in-place - see Notes.
Expand Down Expand Up @@ -419,6 +418,7 @@ def _dylibs_only(filename: str) -> bool:


def filter_system_libs(libname: str) -> bool:
"""Return False for system libraries."""
return not (libname.startswith("/usr/lib") or libname.startswith("/System"))


Expand All @@ -428,8 +428,10 @@ def _delocate_filter_function(
lib_filt_func: Callable[[str], bool],
copy_filt_func: Callable[[str], bool],
) -> bool:
"""Combines the library inspection and copy filters so that libraries
which won't be copied will not be followed."""
"""Combine the library inspection and copy filters into one function.
So that libraries which won't be copied will not be followed.
"""
return lib_filt_func(path) and copy_filt_func(path)


Expand All @@ -443,7 +445,7 @@ def delocate_path(
*,
sanitize_rpaths: bool = False,
) -> Dict[Text, Dict[Text, Text]]:
"""Copy required libraries for files in `tree_path` into `lib_path`
"""Copy required libraries for files in `tree_path` into `lib_path`.
Parameters
----------
Expand Down Expand Up @@ -520,7 +522,7 @@ def delocate_path(
def _copy_lib_dict(
lib_dict: Mapping[Text, Mapping[Text, Text]],
) -> Dict[Text, Dict[Text, Text]]:
"""Returns a copy of lib_dict."""
"""Return a copy of lib_dict."""
return { # Convert nested Mapping types into nested Dict types.
required: dict(requiring) for required, requiring in lib_dict.items()
}
Expand Down Expand Up @@ -630,8 +632,7 @@ def _get_macos_min_version(dylib_path: Path) -> Iterator[tuple[str, Version]]:
def _get_archs_and_version_from_wheel_name(
wheel_name: str,
) -> dict[str, Version]:
"""
Get the architecture and minimum macOS version from the wheel name.
"""Get the architecture and minimum macOS version from the wheel name.
Parameters
----------
Expand Down Expand Up @@ -660,9 +661,7 @@ def _get_problematic_libs(
version_lib_dict: Dict[Version, List[Path]],
arch: str,
) -> set[tuple[Path, Version]]:
"""
Filter libraries that require more modern macOS
version than the provided one.
"""Find libraries which require a more modern macOS version.
Parameters
----------
Expand Down Expand Up @@ -703,9 +702,10 @@ def _calculate_minimum_wheel_name(
wheel_dir: Path,
require_target_macos_version: Optional[Version],
) -> tuple[str, set[tuple[Path, Version]]]:
"""
Update wheel name platform tag, based on the architecture
of the libraries in the wheel and actual platform tag.
"""Return a wheel name with an updated platform tag.
Based on the architecture of the libraries in the wheel and actual platform
tag.
Parameters
----------
Expand Down Expand Up @@ -811,9 +811,9 @@ def _check_and_update_wheel_name(
wheel_dir: Path,
require_target_macos_version: Optional[Version],
) -> Path:
"""
Based on curren wheel name and binary files in the wheel,
determine the minimum platform tag and update the wheel name if needed.
"""Determine the minimum platform tag and update the wheel name if needed.
Based on current wheel name and binary files in the wheel.
Parameters
----------
Expand Down Expand Up @@ -884,7 +884,7 @@ def delocate_wheel(
sanitize_rpaths: bool = False,
require_target_macos_version: Optional[Version] = None,
) -> Dict[str, Dict[str, str]]:
"""Update wheel by copying required libraries to `lib_sdir` in wheel
"""Update wheel by copying required libraries to `lib_sdir` in wheel.
Create `lib_sdir` in wheel tree only if we are copying one or more
libraries.
Expand Down Expand Up @@ -1018,7 +1018,7 @@ def delocate_wheel(
def patch_wheel(
in_wheel: Text, patch_fname: Text, out_wheel: Optional[Text] = None
) -> None:
"""Apply ``-p1`` style patch in `patch_fname` to contents of `in_wheel`
"""Apply ``-p1`` style patch in `patch_fname` to contents of `in_wheel`.
If `out_wheel` is None (the default), overwrite the wheel `in_wheel`
in-place.
Expand Down Expand Up @@ -1063,7 +1063,7 @@ def check_archs(
) -> Set[
Union[Tuple[Text, FrozenSet[Text]], Tuple[Text, Text, FrozenSet[Text]]]
]:
"""Check compatibility of archs in `copied_libs` dict
"""Check compatibility of archs in `copied_libs` dict.
Parameters
----------
Expand Down Expand Up @@ -1127,7 +1127,7 @@ def check_archs(


def bads_report(bads, path_prefix=None):
"""Return a nice report of bad architectures in `bads`
"""Return a nice report of bad architectures in `bads`.
Parameters
----------
Expand Down
10 changes: 5 additions & 5 deletions delocate/fuse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Utilities to fuse trees and wheels
"""Utilities to fuse trees and wheels.
To "fuse" is to merge two binary libraries of different architectures - see
func:`delocate.tools.lipo_fuse`.
Expand Down Expand Up @@ -41,7 +41,7 @@ def _copyfile(in_fname, out_fname):


def fuse_trees(to_tree, from_tree, lib_exts=(".so", ".dylib", ".a")):
"""Fuse path `from_tree` into path `to_tree`
"""Fuse path `from_tree` into path `to_tree`.
For each file in `from_tree` - check for library file extension (in
`lib_exts` - if present, check if there is a file with matching relative
Expand All @@ -50,7 +50,7 @@ def fuse_trees(to_tree, from_tree, lib_exts=(".so", ".dylib", ".a")):
conditions are not met, just copy the file from `from_tree` to `to_tree`.
Parameters
---------
----------
to_tree : str
path of tree to fuse into (update into)
from_tree : str
Expand Down Expand Up @@ -85,10 +85,10 @@ def fuse_trees(to_tree, from_tree, lib_exts=(".so", ".dylib", ".a")):


def fuse_wheels(to_wheel, from_wheel, out_wheel):
"""Fuse `from_wheel` into `to_wheel`, write to `out_wheel`
"""Fuse `from_wheel` into `to_wheel`, write to `out_wheel`.
Parameters
---------
----------
to_wheel : str
filename of wheel to fuse into
from_wheel : str
Expand Down
Loading

0 comments on commit 43ad6b3

Please sign in to comment.