From 1f4d52d27ee8e755db2d23f76a5e5c97907a3e33 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 3 Jun 2023 20:12:45 +0300 Subject: [PATCH 1/2] Drop support for EOL Python 3.7 --- .github/workflows/test.yml | 2 +- .pre-commit-config.yaml | 14 +++++++------- pyproject.toml | 39 ++++++++++++++++---------------------- src/humanize/__init__.py | 11 +++-------- src/humanize/i18n.py | 11 +---------- tox.ini | 10 ++++++---- 6 files changed, 34 insertions(+), 53 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 323d91d..29fd6e4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["pypy3.8", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["pypy3.8", "3.8", "3.9", "3.10", "3.11", "3.12"] os: [windows-latest, macos-latest, ubuntu-latest] steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 22051c7..901bb8e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,9 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.4.0 hooks: - id: pyupgrade - args: [--py37-plus] + args: [--py38-plus] - repo: https://github.com/psf/black rev: 23.3.0 @@ -16,7 +16,7 @@ repos: - id: isort - repo: https://github.com/PyCQA/autoflake - rev: v2.0.2 + rev: v2.1.1 hooks: - id: autoflake name: autoflake @@ -61,24 +61,24 @@ repos: files: "src/" - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.1.1 + rev: v1.3.0 hooks: - id: mypy additional_dependencies: [pytest, types-freezegun, types-setuptools] args: [--strict] - repo: https://github.com/tox-dev/pyproject-fmt - rev: 0.9.2 + rev: 0.10.0 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.12.2 + rev: v0.13 hooks: - id: validate-pyproject - repo: https://github.com/tox-dev/tox-ini-fmt - rev: 1.0.0 + rev: 1.3.0 hooks: - id: tox-ini-fmt diff --git a/pyproject.toml b/pyproject.toml index 5ca779c..a2bc7ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,31 +15,27 @@ keywords = [ license = {text = "MIT"} maintainers = [{name = "Hugo van Kemenade"}] authors = [{name = "Jason Moiron", email = "jmoiron@jmoiron.net"}] -requires-python = ">=3.7" +requires-python = ">=3.8" classifiers = [ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: Text Processing", - "Topic :: Text Processing :: General", + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Text Processing", + "Topic :: Text Processing :: General", ] dynamic = [ "version", ] -dependencies = [ - 'importlib-metadata; python_version < "3.8"', -] [project.optional-dependencies] tests = [ "freezegun", @@ -65,9 +61,6 @@ artifacts = [ [tool.hatch.version.raw-options] local_scheme = "no-local-version" -[tool.black] -target_version = ["py37"] - [tool.isort] profile = "black" diff --git a/src/humanize/__init__.py b/src/humanize/__init__.py index 7d3ae65..f06bb6c 100644 --- a/src/humanize/__init__.py +++ b/src/humanize/__init__.py @@ -1,5 +1,7 @@ """Main package for humanize.""" +import importlib.metadata + from humanize.filesize import naturalsize from humanize.i18n import activate, deactivate, decimal_separator, thousands_separator from humanize.number import ( @@ -20,14 +22,7 @@ precisedelta, ) -try: - # Python 3.8+ - import importlib.metadata as importlib_metadata -except ImportError: - # str: Returns: str: Translated text. """ - # This GNU gettext function was added in Python 3.8, so for older versions we - # reimplement it. It works by joining `msgctx` and `message` by '4' byte. - try: - # Python 3.8+ - return get_translation().pgettext(msgctxt, message) - except AttributeError: - # Python 3.7 and older - key = msgctxt + "\x04" + message - translation = get_translation().gettext(key) - return message if translation == key else translation + return get_translation().pgettext(msgctxt, message) def _ngettext(message: str, plural: str, num: int) -> str: diff --git a/tox.ini b/tox.ini index ca81785..ad218ae 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,15 @@ [tox] -envlist = +requires = + tox>=4.2 +env_list = docs lint - py{py3, 312, 311, 310, 39, 38, 37} + py{py3, 312, 311, 310, 39, 38} [testenv] extras = tests -passenv = +pass_env = FORCE_COLOR commands = {envpython} -m pytest --cov humanize --cov tests --cov-report xml {posargs} @@ -22,7 +24,7 @@ commands = skip_install = true deps = pre-commit -passenv = +pass_env = PRE_COMMIT_COLOR commands = pre-commit run --all-files --show-diff-on-failure From bf3fdf9ac0a9761e1e30b5bc387710153f90b404 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 4 Jun 2023 12:24:07 +0300 Subject: [PATCH 2/2] Use RTD v2 config to require Python newer than default 3.7 in v1 https://readthedocs.org/projects/python-humanize/builds/20906653/ --- .readthedocs.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 73e1f82..11d0ab3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,2 +1,19 @@ -python: - pip_install: true +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details +# Project page: https://readthedocs.org/projects/python-humanize/ + +version: 2 + +mkdocs: + configuration: mkdocs.yml + +build: + os: ubuntu-22.04 + tools: + python: "3" + + commands: + - pip install -U tox + - tox -e docs + - mkdir _readthedocs + - mv site _readthedocs/html