Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fnmatch patterns in --exclude args #411

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.7"
python-version: "3.11"
- uses: pre-commit/[email protected]

test-dist:
Expand Down
92 changes: 46 additions & 46 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@
# See https://pre-commit.com/hooks.html for more hooks

default_language_version:
python: python3.7
python: python3.11

exclude: ^src/auditwheel/_vendor/

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-builtin-literals
- id: check-added-large-files
- id: check-case-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: ^cache/
- id: forbid-new-submodules
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: pyupgrade
args: ["--py37-plus"]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
args: ["-a", "from __future__ import annotations"]
exclude: ^tests/integration/.*/src/.*pyx$

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
exclude: ^tests/integration/.*/.*$
additional_dependencies:
- types-requests
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-builtin-literals
- id: check-added-large-files
- id: check-case-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
exclude: ^cache/
- id: forbid-new-submodules
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: pyupgrade
args: ["--py37-plus"]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["-a", "from __future__ import annotations"]
exclude: ^tests/integration/.*/src/.*pyx$

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
exclude: ^tests/integration/.*/.*$
additional_dependencies:
- types-requests
4 changes: 2 additions & 2 deletions src/auditwheel/repair.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import fnmatch
import itertools
import logging
import os
Expand Down Expand Up @@ -73,8 +74,7 @@ def repair_wheel(
ext_libs = v[abis[0]]["libs"] # type: Dict[str, str]
replacements = [] # type: List[Tuple[str, str]]
for soname, src_path in ext_libs.items():

if soname in exclude:
if any(fnmatch.fnmatch(soname, e) for e in exclude):
logger.info(f"Excluding {soname}")
continue

Expand Down
18 changes: 13 additions & 5 deletions tests/integration/test_manylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"manylinux_2_12": "devtoolset-8",
"manylinux_2_17": "devtoolset-10",
"manylinux_2_24": "devtoolset-not-present",
"manylinux_2_28": "gcc-toolset-11",
"manylinux_2_28": "gcc-toolset-12",
"musllinux_1_1": "devtoolset-not-present",
}
PATH_DIRS = [
Expand Down Expand Up @@ -314,10 +314,13 @@ def test_build_repair_numpy(
# at once in the same Python program:
docker_exec(docker_python, ["python", "-c", "'import numpy; import foo'"])

@pytest.mark.parametrize("exclude_with_wildcard", (True, False))
@pytest.mark.skipif(
PLATFORM != "x86_64", reason="Only needs checking on one platform"
)
def test_repair_exclude(self, any_manylinux_container, io_folder):
def test_repair_exclude(
self, any_manylinux_container, io_folder, exclude_with_wildcard
):
"""Test the --exclude argument to avoid grafting certain libraries."""

policy, tag, manylinux_ctr = any_manylinux_container
Expand All @@ -327,14 +330,19 @@ def test_repair_exclude(self, any_manylinux_container, io_folder):
assert "manylinux" not in orig_wheel

# Exclude libgfortran from grafting into the wheel
excludes = {
excludes_map = {
"manylinux_2_5_x86_64": ["libgfortran.so.1", "libgfortran.so.3"],
"manylinux_2_12_x86_64": ["libgfortran.so.3", "libgfortran.so.5"],
"manylinux_2_17_x86_64": ["libgfortran.so.3", "libgfortran.so.5"],
"manylinux_2_24_x86_64": ["libgfortran.so.3"],
"manylinux_2_28_x86_64": ["libgfortran.so.5"],
"musllinux_1_1_x86_64": ["libgfortran.so.5"],
}[policy]
}

excludes = exclude_args = excludes_map[policy]

if exclude_with_wildcard:
exclude_args = ["libgfortran*"]

repair_command = [
"auditwheel",
Expand All @@ -345,7 +353,7 @@ def test_repair_exclude(self, any_manylinux_container, io_folder):
"-w",
"/io",
]
for exclude in excludes:
for exclude in exclude_args:
repair_command.extend(["--exclude", exclude])
repair_command.append(f"/io/{orig_wheel}")
output = docker_exec(manylinux_ctr, repair_command)
Expand Down