Skip to content

style: pre-commit additions, remove <3.7 code #432

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

Merged
merged 2 commits into from
Dec 30, 2021
Merged
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
61 changes: 39 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
args: [--target-version=py37]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: ["--fix=lf"]
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: ["-a", "from __future__ import annotations"]

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

- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
args: [--target-version=py37]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# wheel documentation build configuration file, created by
# sphinx-quickstart on Thu Jul 12 00:14:09 2012.
Expand All @@ -10,7 +9,8 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import io
from __future__ import annotations

import os
import re

Expand Down Expand Up @@ -49,7 +49,7 @@
# built documents.
#
here = os.path.abspath(os.path.dirname(__file__))
with io.open(
with open(
os.path.join(here, "..", "src", "wheel", "__init__.py"), encoding="utf8"
) as version_file:
match = re.search(r"__version__ = '((\d+\.\d+\.\d+).*)'", version_file.read())
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from setuptools import setup

setup()
2 changes: 2 additions & 0 deletions src/wheel/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from __future__ import annotations

__version__ = "0.37.1"
2 changes: 2 additions & 0 deletions src/wheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Wheel command line tool (enable python -m wheel syntax)
"""

from __future__ import annotations

import sys


Expand Down
2 changes: 2 additions & 0 deletions src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
A wheel is a built archive format.
"""

from __future__ import annotations

import distutils
import os
import re
Expand Down
2 changes: 2 additions & 0 deletions src/wheel/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Wheel command-line utility.
"""

from __future__ import annotations

import argparse
import os
import sys
Expand Down
2 changes: 2 additions & 0 deletions src/wheel/cli/convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os.path
import re
import shutil
Expand Down
4 changes: 3 additions & 1 deletion src/wheel/macosx_libfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
target when the arm64 target is 11.0.
"""

from __future__ import annotations

import ctypes
import os
import sys
Expand Down Expand Up @@ -421,7 +423,7 @@ def calculate_macosx_platform_tag(archive_root, platform_tag):
assert len(base_version) == 2
start_version = base_version
versions_dict = {}
for (dirpath, dirnames, filenames) in os.walk(archive_root):
for (dirpath, _dirnames, filenames) in os.walk(archive_root):
for filename in filenames:
if filename.endswith(".dylib") or filename.endswith(".so"):
lib_path = os.path.join(dirpath, filename)
Expand Down
4 changes: 2 additions & 2 deletions src/wheel/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import textwrap
from email.message import Message
from email.parser import Parser
from typing import Iterator, Tuple
from typing import Iterator

from pkg_resources import Requirement, safe_extra, split_sections

Expand Down Expand Up @@ -41,7 +41,7 @@ def convert_requirements(requirements: list[str]) -> Iterator[str]:

def generate_requirements(
extras_require: dict[str, list[str]]
) -> Iterator[Tuple[str, str]]:
) -> Iterator[tuple[str, str]]:
"""
Convert requirements from a setup()-style dictionary to
('Requires-Dist', 'requirement') and ('Provides-Extra', 'extra') tuples.
Expand Down
20 changes: 11 additions & 9 deletions src/wheel/vendored/packaging/_manylinux.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

import collections
import functools
import os
import re
import struct
import sys
import warnings
from typing import IO, Dict, Iterator, NamedTuple, Optional, Tuple
from typing import IO, Iterator, NamedTuple


# Python does not provide platform information at sufficient granularity to
Expand Down Expand Up @@ -36,7 +38,7 @@ def __init__(self, file: IO[bytes]) -> None:
def unpack(fmt: str) -> int:
try:
data = file.read(struct.calcsize(fmt))
result: Tuple[int, ...] = struct.unpack(fmt, data)
result: tuple[int, ...] = struct.unpack(fmt, data)
except struct.error:
raise _ELFFileHeader._InvalidELFFileHeader()
return result[0]
Expand Down Expand Up @@ -73,7 +75,7 @@ def unpack(fmt: str) -> int:
self.e_shstrndx = unpack(format_h)


def _get_elf_header() -> Optional[_ELFFileHeader]:
def _get_elf_header() -> _ELFFileHeader | None:
try:
with open(sys.executable, "rb") as f:
elf_header = _ELFFileHeader(f)
Expand Down Expand Up @@ -124,15 +126,15 @@ def _have_compatible_abi(arch: str) -> bool:
# For now, guess what the highest minor version might be, assume it will
# be 50 for testing. Once this actually happens, update the dictionary
# with the actual value.
_LAST_GLIBC_MINOR: Dict[int, int] = collections.defaultdict(lambda: 50)
_LAST_GLIBC_MINOR: dict[int, int] = collections.defaultdict(lambda: 50)


class _GLibCVersion(NamedTuple):
major: int
minor: int


def _glibc_version_string_confstr() -> Optional[str]:
def _glibc_version_string_confstr() -> str | None:
"""
Primary implementation of glibc_version_string using os.confstr.
"""
Expand All @@ -151,7 +153,7 @@ def _glibc_version_string_confstr() -> Optional[str]:
return version


def _glibc_version_string_ctypes() -> Optional[str]:
def _glibc_version_string_ctypes() -> str | None:
"""
Fallback implementation of glibc_version_string using ctypes.
"""
Expand Down Expand Up @@ -195,12 +197,12 @@ def _glibc_version_string_ctypes() -> Optional[str]:
return version_str


def _glibc_version_string() -> Optional[str]:
def _glibc_version_string() -> str | None:
"""Returns glibc version string, or None if not using glibc."""
return _glibc_version_string_confstr() or _glibc_version_string_ctypes()


def _parse_glibc_version(version_str: str) -> Tuple[int, int]:
def _parse_glibc_version(version_str: str) -> tuple[int, int]:
"""Parse glibc version.

We use a regexp instead of str.split because we want to discard any
Expand All @@ -220,7 +222,7 @@ def _parse_glibc_version(version_str: str) -> Tuple[int, int]:


@functools.lru_cache()
def _get_glibc_version() -> Tuple[int, int]:
def _get_glibc_version() -> tuple[int, int]:
version_str = _glibc_version_string()
if version_str is None:
return (-1, -1)
Expand Down
14 changes: 8 additions & 6 deletions src/wheel/vendored/packaging/_musllinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
linked against musl, and what musl version is used.
"""

from __future__ import annotations

import contextlib
import functools
import operator
Expand All @@ -12,14 +14,14 @@
import struct
import subprocess
import sys
from typing import IO, Iterator, NamedTuple, Optional, Tuple
from typing import IO, Iterator, NamedTuple


def _read_unpacked(f: IO[bytes], fmt: str) -> Tuple[int, ...]:
def _read_unpacked(f: IO[bytes], fmt: str) -> tuple[int, ...]:
return struct.unpack(fmt, f.read(struct.calcsize(fmt)))


def _parse_ld_musl_from_elf(f: IO[bytes]) -> Optional[str]:
def _parse_ld_musl_from_elf(f: IO[bytes]) -> str | None:
"""Detect musl libc location by parsing the Python executable.

Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
Expand Down Expand Up @@ -73,7 +75,7 @@ class _MuslVersion(NamedTuple):
minor: int


def _parse_musl_version(output: str) -> Optional[_MuslVersion]:
def _parse_musl_version(output: str) -> _MuslVersion | None:
lines = [n for n in (n.strip() for n in output.splitlines()) if n]
if len(lines) < 2 or lines[0][:4] != "musl":
return None
Expand All @@ -84,7 +86,7 @@ def _parse_musl_version(output: str) -> Optional[_MuslVersion]:


@functools.lru_cache()
def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
def _get_musl_version(executable: str) -> _MuslVersion | None:
"""Detect currently-running musl runtime version.

This is done by checking the specified executable's dynamic linking
Expand All @@ -103,7 +105,7 @@ def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
ld = _parse_ld_musl_from_elf(f)
if not ld:
return None
proc = subprocess.run([ld], stderr=subprocess.PIPE, universal_newlines=True)
proc = subprocess.run([ld], stderr=subprocess.PIPE, text=True)
return _parse_musl_version(proc.stderr)


Expand Down
Loading