Skip to content

Commit

Permalink
Merge pull request #331 from mayeut/pre-commit5
Browse files Browse the repository at this point in the history
chore: add pre-commit for linting
  • Loading branch information
mayeut authored Sep 3, 2021
2 parents fa84066 + 21a0db7 commit b2d597c
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 63 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install CPython 3.8
uses: actions/setup-python@v2
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
architecture: x64

- name: Run linter
run: pipx run nox -s lint
python-version: 3.6
- uses: pre-commit/[email protected]
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

default_language_version:
python: python3.6

exclude: ^auditwheel/_vendor/

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
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: v2.24.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]

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

- repo: https://github.com/PyCQA/isort
rev: 5.9.3
hooks:
- id: isort

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

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
hooks:
- id: mypy
exclude: ^tests/integration/.*/.*$
additional_dependencies:
- types-requests
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ notifications:

install:
- pip install nox

script:
- nox -s tests-3.8

Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Released Apr. 3, 2021
### User-facing changes
- [BUGFIX] Patch RPATHs of non-Python extension dependencies ([#136](https://github.com/pypa/auditwheel/issues/136), [#298](https://github.com/pypa/auditwheel/pull/298))
- [BUGFIX] Ensure policies in `policy.json` are compliant with PEP600 ([#287](https://github.com/pypa/auditwheel/pull/287))
- This removes 2 non existing symbols from manylinux1 i686 policy and removes ncurses librairies from manylinux1 whitelist.
- This removes 2 non existing symbols from manylinux1 i686 policy and removes ncurses librairies from manylinux1 whitelist.
- [FEATURE] Use PEP600 policy names ([#288](https://github.com/pypa/auditwheel/pull/288), [#297](https://github.com/pypa/auditwheel/pull/297))
- The platform tag passed to `auditwheel repair` `--plat` argument can use either the PEP600 tag or the legacy tag. The repaired wheel will get both platform tags.
- Inform about aliases in `auditwheel repair --help`
- [FEATURE] Always repair as a single wheel ([#289](https://github.com/pypa/auditwheel/pull/289))
- Add argument `--only-plat` to `auditwheel repair` for those who were keeping only the lowest priority tag wheel (i.e. the one requested by `--plat` argument).
- Add argument `--only-plat` to `auditwheel repair` for those who were keeping only the lowest priority tag wheel (i.e. the one requested by `--plat` argument).
- [FEATURE] Add manylinux_2_27 policy ([#299](https://github.com/pypa/auditwheel/issues/299), [#300](https://github.com/pypa/auditwheel/pull/300))
- [FEATURE] Add libexpat.so.1 to whitelisted libraries starting with manylinux2010 ([#152](https://github.com/pypa/auditwheel/issues/152), [#301](https://github.com/pypa/auditwheel/pull/301))

Expand Down Expand Up @@ -63,7 +63,7 @@ Released Dec. 6, 2020
Released Jul. 1, 2020

### User-facing changes
- [FEATURE] Ensure that system-copied libraries are writable before running patchelf
- [FEATURE] Ensure that system-copied libraries are writable before running patchelf
([https://github.com/pypa/auditwheel/pull/237](#237))
- [FEATURE] Preserve RPATH in extension modules ([https://github.com/pypa/auditwheel/pull/245](#245))

Expand All @@ -86,7 +86,7 @@ Released Apr. 25, 2020
Released Jan. 29, 2020

### User-facing changes
- [FEATURE] Put libraries in `$WHEELNAME.libs` to avoid vendoring multiple copies
- [FEATURE] Put libraries in `$WHEELNAME.libs` to avoid vendoring multiple copies
of the same library ([#90](https://github.com/pypa/auditwheel/pull/90))

### Housekeeping
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The auditwheel package is covered by the MIT license.
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


3rd party code and data
=======================
Expand Down
6 changes: 3 additions & 3 deletions auditwheel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pathlib
import sys

try:
if sys.version_info[:2] >= (3, 8):
from importlib import metadata
except ImportError:
import importlib_metadata as metadata # type: ignore
else:
import importlib_metadata as metadata

from typing import Optional

Expand Down
20 changes: 9 additions & 11 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import os
import sys

from pathlib import Path
from typing import List

import nox


RUNNING_CI = "TRAVIS" in os.environ or "GITHUB_ACTIONS" in os.environ


@nox.session(reuse_venv=True)
def lint(session: nox.Session) -> str:
@nox.session(python=["3.6"], reuse_venv=True)
def lint(session: nox.Session) -> None:
"""
Run linters on the codebase.
"""
session.install("flake8", "mypy")
session.run("flake8", "auditwheel")
session.run("mypy", "auditwheel")
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files")


@nox.session()
def coverage(session: nox.Session) -> str:
def coverage(session: nox.Session) -> None:
"""
Run coverage using unit tests.
"""
Expand All @@ -31,11 +29,11 @@ def coverage(session: nox.Session) -> str:
"pytest",
"tests/unit",
"--cov=auditwheel",
"--cov-report=term-missing"
"--cov-report=term-missing",
)


def _docker_images(session):
def _docker_images(session: nox.Session) -> List[str]:
tmp_dir = Path(session.create_tmp())
script = tmp_dir / "list_images.py"
images_file = tmp_dir / "images.lst"
Expand All @@ -52,7 +50,7 @@ def _docker_images(session):


@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
def tests(session: nox.Session) -> str:
def tests(session: nox.Session) -> None:
"""
Run tests.
"""
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
requires = ["setuptools", "wheel", "pbr"]
build-backend = "setuptools.build_meta"

[tool.black]
target-version = ["py36", "py37", "py38", "py39"]

[tool.isort]
profile = "black"

[tool.mypy]
follow_imports = "silent"
ignore_missing_imports = true
Expand Down
44 changes: 22 additions & 22 deletions scripts/calculate_symbol_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
This should be run inside a manylinux Docker container.
"""
import argparse
import json
import os
import platform
import json

from elftools.elf.elffile import ELFFile

if platform.architecture()[0] == '64bit':
LIBRARY_PATHS = ['/lib64', '/usr/lib64']
if platform.architecture()[0] == "64bit":
LIBRARY_PATHS = ["/lib64", "/usr/lib64"]
else:
LIBRARY_PATHS = ['/lib', '/usr/lib']
LIBRARY_PATHS = ["/lib", "/usr/lib"]

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("policy", help="The policy name")
Expand All @@ -26,9 +27,9 @@ def load_policies(path):

def choose_policy(name, policies):
try:
return next(policy for policy in policies if policy['name'] == name)
return next(policy for policy in policies if policy["name"] == name)
except StopIteration:
raise RuntimeError("Unknown policy {}".format(name))
raise RuntimeError(f"Unknown policy {name}")


def find_library(library):
Expand All @@ -37,12 +38,12 @@ def find_library(library):
if os.path.exists(path):
return path
else:
raise RuntimeError("Unknown library {}".format(library))
raise RuntimeError(f"Unknown library {library}")


def versionify(version_string):
try:
result = [int(n) for n in version_string.split('.')]
result = [int(n) for n in version_string.split(".")]
assert len(result) <= 3
except ValueError:
result = [999999, 999999, 999999, version_string]
Expand All @@ -51,30 +52,29 @@ def versionify(version_string):

def calculate_symbol_versions(libraries, symbol_versions, arch):
calculated_symbol_versions = {k: set() for k in symbol_versions}
prefixes = ['/lib', '/usr/lib']
if arch == '64bit':
prefixes = [p + '64' for p in prefixes]
prefixes = ["/lib", "/usr/lib"]
if arch == "64bit":
prefixes = [p + "64" for p in prefixes]

for library in libraries:
library_path = find_library(library)
with open(library_path, 'rb') as f:
with open(library_path, "rb") as f:
e = ELFFile(f)
section = e.get_section_by_name('.gnu.version_d')
section = e.get_section_by_name(".gnu.version_d")
if section:
for _, verdef_iter in section.iter_versions():
for vernaux in verdef_iter:
for symbol_name in symbol_versions:
try:
name, version = vernaux.name.split('_', 1)
name, version = vernaux.name.split("_", 1)
except ValueError:
pass
if name in calculated_symbol_versions \
and version != 'PRIVATE':
if (
name in calculated_symbol_versions
and version != "PRIVATE"
):
calculated_symbol_versions[name].add(version)
return {
k: sorted(v, key=versionify)
for k, v in calculated_symbol_versions.items()
}
return {k: sorted(v, key=versionify) for k, v in calculated_symbol_versions.items()}


def main():
Expand All @@ -85,8 +85,8 @@ def main():
print(
json.dumps(
calculate_symbol_versions(
policy['lib_whitelist'],
policy['symbol_versions'],
policy["lib_whitelist"],
policy["symbol_versions"],
arch,
)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/foo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

subroutine selectedrealkind(p, r, res)
implicit none

integer, intent(in) :: p, r
!f2py integer :: r=0
integer, intent(out) :: res
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/sample_extension/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools >= 45.0.0", "cython"]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ def test_func(x):
return _test_func(x)

cdef _test_func(x):
return x + 1
return x + 1
9 changes: 6 additions & 3 deletions tests/integration/test_manylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def test_build_wheel_with_binary_executable(
[
"bash",
"-c",
"cd /auditwheel_src/tests/integration/testpackage && python -m pip wheel --no-deps -w /io .",
"cd /auditwheel_src/tests/integration/testpackage && "
"python -m pip wheel --no-deps -w /io .",
],
)

Expand Down Expand Up @@ -391,7 +392,8 @@ def test_build_wheel_with_image_dependencies(
assert "manylinux" not in orig_wheel

repair_command = (
"LD_LIBRARY_PATH=/auditwheel_src/tests/integration/testdependencies:$LD_LIBRARY_PATH "
"LD_LIBRARY_PATH="
"/auditwheel_src/tests/integration/testdependencies:$LD_LIBRARY_PATH "
"auditwheel -v repair --plat {policy} -w /io /io/{orig_wheel}"
)

Expand Down Expand Up @@ -522,7 +524,8 @@ def test_build_wheel_depending_on_library_with_rpath(
[
"bash",
"-c",
"LD_LIBRARY_PATH=/auditwheel_src/tests/integration/testrpath/a:$LD_LIBRARY_PATH "
"LD_LIBRARY_PATH="
"/auditwheel_src/tests/integration/testrpath/a:$LD_LIBRARY_PATH "
+ repair_command,
],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/testpackage/testpackage/testprogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char **argv)
fputs("Expected command line argument to be a float\n", stderr);
return EXIT_FAILURE;
}

x = gsl_pow_2(x);
printf("%g\n", x);
return EXIT_SUCCESS;
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_elfpatcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from subprocess import CalledProcessError
from unittest.mock import call, patch

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_elfutils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import MagicMock, Mock, patch
from unittest.mock import Mock, patch

import pytest
from elftools.common.exceptions import ELFError
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_wheel_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ class TestGetWheelElfdata:
(
# A single invalid file
[os.sep.join(["purelib", "foo"])],
"Invalid binary wheel, found the following shared library/libraries in purelib folder:\n\tfoo\nThe wheel has to be platlib compliant in order to be repaired by auditwheel.",
"Invalid binary wheel, found the following shared library/libraries in"
" purelib folder:\n\tfoo\nThe wheel has to be platlib compliant in "
"order to be repaired by auditwheel.",
),
(
# Multiple invalid files
[os.sep.join(["purelib", "foo"]), os.sep.join(["purelib", "bar"])],
"Invalid binary wheel, found the following shared library/libraries in purelib folder:\n\tfoo\n\tbar\nThe wheel has to be platlib compliant in order to be repaired by auditwheel.",
"Invalid binary wheel, found the following shared library/libraries in"
" purelib folder:\n\tfoo\n\tbar\nThe wheel has to be platlib compliant"
" in order to be repaired by auditwheel.",
),
],
)
Expand Down

0 comments on commit b2d597c

Please sign in to comment.