From 07559fc97e37d9fb5373465f0826d59d472e9cbf Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Fri, 3 Nov 2023 09:23:06 +0100 Subject: [PATCH] v23.10.6 --- .pre-commit-config.yaml | 16 +++--- CHANGES.md | 4 ++ README.md | 4 +- ambient_package_update/__init__.py | 2 +- ambient_package_update/cli.py | 20 ++++---- ambient_package_update/metadata/constants.py | 38 +++++++------- .../templates/.coveragerc.tpl | 9 ++++ .../templates/.pre-commit-config.yaml.tpl | 16 +++--- .../templates/README.md.tpl | 2 +- .../templates/docs/conf.py.tpl | 50 +++++++++---------- .../templates/pyproject.toml.tpl | 22 ++++---- pyproject.toml | 21 +++++--- requirements.txt | 40 ++++++--------- 13 files changed, 125 insertions(+), 119 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c3cffc..3ec18a7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,18 +2,14 @@ # https://pre-commit.com/ repos: - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.10.0 - hooks: - - id: black - args: [ --check, --diff, --config, ./pyproject.toml ] - stages: [ push ] - - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.1.1' + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.3 hooks: + # Run the Ruff linter. - id: ruff - args: [ --fix, --unsafe-fixes, --exit-non-zero-on-fix ] + args: [--fix, --exit-non-zero-on-fix] + # Run the Ruff formatter. + - id: ruff-format - repo: https://github.com/asottile/pyupgrade rev: v3.15.0 diff --git a/CHANGES.md b/CHANGES.md index 07c4ceb..f544873 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changelog +**23.10.6 (2023-11-03)** +* Replaced `black` formatter with `ruff format` +* Improved coverage configuration + **23.10.5 (2023-10-26)** * Fixed RTD build diff --git a/README.md b/README.md index 21efbe8..d12edc6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![PyPI release](https://img.shields.io/pypi/v/ambient-package-update.svg)](https://pypi.org/project/ambient-package-update/) [![Downloads](https://static.pepy.tech/badge/ambient-package-update)](https://pepy.tech/project/ambient-package-update) [![Linting](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) -[![Coding Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black) +[![Coding Style](https://img.shields.io/badge/code%20style-Ruff-000000.svg)](https://github.com/astral-sh/ruff) # Ambient Package Update @@ -98,7 +98,7 @@ The dependencies of this package are being maintained with `pip-tools`. To add/update/remove a package, please do so in the main `pyproject.toml`. Afterward, call the following command to reflect your changes in the `requirements.txt`. -> pip-compile --upgrade +> pip-compile --extra dev -o requirements.txt pyproject.toml --resolver=backtracking To install the packages, run: diff --git a/ambient_package_update/__init__.py b/ambient_package_update/__init__.py index bbd6604..60aee51 100644 --- a/ambient_package_update/__init__.py +++ b/ambient_package_update/__init__.py @@ -1,3 +1,3 @@ """Ambient package update tool for clean and swift maintenance""" -__version__ = '23.10.5' +__version__ = "23.10.6" diff --git a/ambient_package_update/cli.py b/ambient_package_update/cli.py index a384a19..4abdb99 100644 --- a/ambient_package_update/cli.py +++ b/ambient_package_update/cli.py @@ -21,7 +21,7 @@ def get_metadata() -> PackageMetadata: sys.path.append("./.ambient-package-update") try: - m = import_module('metadata') + m = import_module("metadata") except ModuleNotFoundError as e: raise RuntimeError('Please create a directory ".ambient-package-update" and add a "metadata.py".') from e sys.path.pop() @@ -40,9 +40,9 @@ def create_rendered_file(*, template: Path, relative_target_path: Path | str) -> metadata_dict = get_metadata().__dict__ j2_template = Template(template.read_text(), keep_trailing_newline=True) - j2_template.globals['current_year'] = datetime.now(tz=UTC).date().year - j2_template.globals['license_label'] = ( - "GNU General Public License (GPL)" if metadata_dict['license'] == LICENSE_GPL else "MIT License" + j2_template.globals["current_year"] = datetime.now(tz=UTC).date().year + j2_template.globals["license_label"] = ( + "GNU General Public License (GPL)" if metadata_dict["license"] == LICENSE_GPL else "MIT License" ) print(f"> Rendering template {basename(template)!r}...") @@ -53,7 +53,7 @@ def create_rendered_file(*, template: Path, relative_target_path: Path | str) -> if relative_target_dir: os.makedirs(os.path.dirname(relative_target_path), exist_ok=True) - with open(relative_target_path, 'w') as f: + with open(relative_target_path, "w") as f: f.write(rendered_string) abs_path = Path(relative_target_path).resolve() @@ -68,7 +68,7 @@ def render_templates(): print(path, subdirs, files) [template_list.append(Path(f"{path}/{file}")) for file in files] - print('Start rending distribution templates.') + print("Start rending distribution templates.") for template in template_list: create_rendered_file( @@ -78,10 +78,10 @@ def render_templates(): # License file is conditional so we have to render it separately metadata_dict = get_metadata().__dict__ create_rendered_file( - template=BASE_PATH / f"licenses/{metadata_dict['license']}.md", relative_target_path='LICENSE.md' + template=BASE_PATH / f"licenses/{metadata_dict['license']}.md", relative_target_path="LICENSE.md" ) - print('Rendering finished.') + print("Rendering finished.") @app.command() @@ -92,7 +92,7 @@ def build_docs(package_name: str): @app.command() def run_tests(): - print('Running tests') + print("Running tests") package_data = get_metadata() dependency_list = package_data.dependencies @@ -101,7 +101,7 @@ def run_tests(): for opt_dependency in package_data.optional_dependencies.values(): dependency_list += opt_dependency - dependency_list = ' '.join(f'"{d}"' for d in dependency_list) + dependency_list = " ".join(f'"{d}"' for d in dependency_list) subprocess.call(f"pip install {dependency_list}", shell=True) subprocess.call("pytest --ds settings tests", shell=True) diff --git a/ambient_package_update/metadata/constants.py b/ambient_package_update/metadata/constants.py index bc47ac1..ec3261e 100644 --- a/ambient_package_update/metadata/constants.py +++ b/ambient_package_update/metadata/constants.py @@ -2,34 +2,34 @@ DEV_DEPENDENCIES = [ # Test runner - 'freezegun~=1.2', - 'pytest-django~=4.5', - 'pytest-mock~=3.10', - 'coverage~=7.3', + "freezegun~=1.2", + "pytest-django~=4.5", + "pytest-mock~=3.10", + "coverage~=7.3", # Linting - 'pre-commit~=3.5', - 'black~=23.10', + "pre-commit~=3.5", + "ruff~=0.1", # Documentation - 'sphinx==4.2.0', - 'sphinx-rtd-theme==1.0.0', - 'm2r2==0.3.1', - 'mistune<2.0.0', # fixes a problem mit m2r2 + "sphinx==4.2.0", + "sphinx-rtd-theme==1.0.0", + "m2r2==0.3.1", + "mistune<2.0.0", # fixes a problem mit m2r2 # Build - f'ambient-package-update~={__version__}', + f"ambient-package-update~={__version__}", ] SUPPORTED_DJANGO_VERSIONS = [ - '3.2', - '4.1', - '4.2', + "3.2", + "4.1", + "4.2", ] SUPPORTED_PYTHON_VERSIONS = [ - '3.8', - '3.9', - '3.10', - '3.11', - '3.12', + "3.8", + "3.9", + "3.10", + "3.11", + "3.12", ] LICENSE_MIT = "MIT" diff --git a/ambient_package_update/templates/.coveragerc.tpl b/ambient_package_update/templates/.coveragerc.tpl index c69ce5c..6c92442 100644 --- a/ambient_package_update/templates/.coveragerc.tpl +++ b/ambient_package_update/templates/.coveragerc.tpl @@ -5,3 +5,12 @@ omit = tests.py, *tests*, conftest.py + +[report] +precision = 2 +show_missing = True +exclude_lines = + # Don't complain if tests don't hit defensive assertion code: + raise NotImplementedError + # Ignore type checking conditions + if TYPE_CHECKING: diff --git a/ambient_package_update/templates/.pre-commit-config.yaml.tpl b/ambient_package_update/templates/.pre-commit-config.yaml.tpl index 476fb5e..79b64b2 100644 --- a/ambient_package_update/templates/.pre-commit-config.yaml.tpl +++ b/ambient_package_update/templates/.pre-commit-config.yaml.tpl @@ -2,18 +2,14 @@ # https://pre-commit.com/ repos: - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.10.0 - hooks: - - id: black - args: [ --check, --diff, --config, ./pyproject.toml ] - stages: [ push ] - - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.1.1' + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.3 hooks: + # Run the Ruff linter. - id: ruff - args: [ --fix, --unsafe-fixes, --exit-non-zero-on-fix ] + args: [--fix, --exit-non-zero-on-fix] + # Run the Ruff formatter. + - id: ruff-format - repo: https://github.com/asottile/pyupgrade rev: v3.15.0 diff --git a/ambient_package_update/templates/README.md.tpl b/ambient_package_update/templates/README.md.tpl index 905f0dc..d5c3b30 100644 --- a/ambient_package_update/templates/README.md.tpl +++ b/ambient_package_update/templates/README.md.tpl @@ -2,7 +2,7 @@ [![Downloads](https://static.pepy.tech/badge/{{ package_name|replace("_", "-") }})](https://pepy.tech/project/{{ package_name|replace("_", "-") }}) [![Coverage](https://img.shields.io/badge/Coverage-100%25-success)](https://github.com/ambient-innovation/{{ package_name|replace("_", "-") }}/actions?workflow=CI) [![Linting](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) -[![Coding Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black) +[![Coding Style](https://img.shields.io/badge/code%20style-Ruff-000000.svg)](https://github.com/astral-sh/ruff) [![Documentation Status](https://readthedocs.org/projects/{{ package_name|replace("_", "-") }}/badge/?version=latest)](https://{{ package_name|replace("_", "-") }}.readthedocs.io/en/latest/?badge=latest) {{ readme_content.tagline }} diff --git a/ambient_package_update/templates/docs/conf.py.tpl b/ambient_package_update/templates/docs/conf.py.tpl index 5fad9c4..3333080 100644 --- a/ambient_package_update/templates/docs/conf.py.tpl +++ b/ambient_package_update/templates/docs/conf.py.tpl @@ -16,18 +16,18 @@ import sys import django from django.conf import settings -sys.path.insert(0, os.path.abspath('..')) # so that we can access the "{{ package_name }}" package +sys.path.insert(0, os.path.abspath("..")) # so that we can access the "{{ package_name }}" package settings.configure( INSTALLED_APPS=[ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - '{{ package_name }}', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "{{ package_name }}", ], - SECRET_KEY='ASDFjklö123456890', + SECRET_KEY="ASDFjklö123456890", ) django.setup() @@ -35,32 +35,32 @@ from {{ package_name }} import __version__ # noqa: E402 # -- Project information ----------------------------------------------------- -project = '{{ package_name|replace("_", "-") }}' -copyright = '{{ current_year }}, Ambient Innovation: GmbH' # noqa: A001 -author = 'Ambient Innovation: GmbH ' +project = "{{ package_name|replace("_", "-") }}" +copyright = "{{ current_year }}, Ambient Innovation: GmbH" # noqa: A001 +author = "Ambient Innovation: GmbH " version = __version__ release = __version__ # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# extensions coming with Sphinx (named "sphinx.ext.*") or your custom # ones. extensions = [ - 'sphinx_rtd_theme', - 'sphinx.ext.autodoc', - 'm2r2', + "sphinx_rtd_theme", + "sphinx.ext.autodoc", + "m2r2", ] -source_suffix = ['.rst', '.md'] +source_suffix = [".rst", ".md"] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # -- Options for HTML output ------------------------------------------------- @@ -68,17 +68,17 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -# html_theme = 'alabaster' -html_theme = 'sphinx_rtd_theme' +# html_theme = "alabaster" +html_theme = "sphinx_rtd_theme" html_theme_options = { - 'display_version': False, - 'style_external_links': False, + "display_version": False, + "style_external_links": False, } # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Set master doc file -master_doc = 'index' +master_doc = "index" diff --git a/ambient_package_update/templates/pyproject.toml.tpl b/ambient_package_update/templates/pyproject.toml.tpl index a3f7a29..7091d2c 100644 --- a/ambient_package_update/templates/pyproject.toml.tpl +++ b/ambient_package_update/templates/pyproject.toml.tpl @@ -44,15 +44,6 @@ name = "{{ package_name }}" 'Bugtracker' = 'https://github.com/ambient-innovation/{{ package_name|replace("_", "-") }}/issues' 'Changelog' = 'https://{{ package_name|replace("_", "-") }}.readthedocs.io/en/latest/features/changelog.html' - -[tool.black] -# use force-exclude, so that black also applies exclude when run using pre-commit: https://github.com/psf/black/issues/395 -force-exclude = '''.*/migrations/.*''' -line-length = 120 -multi_line_output = 3 -skip-string-normalization = true -include_trailing_comma = true - [tool.ruff] select = [ "E", # pycodestyle errors @@ -136,6 +127,19 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" # Assume Python 3.12 target-version = "py312" +[tool.ruff.format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" + [tool.tox] legacy_tox_ini = """ [tox] diff --git a/pyproject.toml b/pyproject.toml index b7a8028..6d1e2c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dev = [ 'keyring~=24.2', # Linting 'pre-commit~=3.5', - 'black~=23.10', + 'ruff~=0.1', ] [project.urls] @@ -47,12 +47,6 @@ dev = [ 'Bugtracker' = 'https://github.com/ambient-innovation/ambient-package-update/issues' 'Changelog' = 'https://github.com/ambient-innovation/ambient-package-update/blob/master/CHANGES.md' -[tool.black] -line-length = 120 -multi_line_output = 3 -skip-string-normalization = true -include_trailing_comma = true - [tool.ruff] select = [ "E", # pycodestyle errors @@ -137,3 +131,16 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" # Assume Python 3.12 target-version = "py312" + +[tool.ruff.format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" diff --git a/requirements.txt b/requirements.txt index 2f74841..63de649 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,33 +2,29 @@ # This file is autogenerated by pip-compile with Python 3.11 # by the following command: # -# pip-compile +# pip-compile --extra=dev --output-file=requirements.txt --resolver=backtracking pyproject.toml # -black==23.7.0 - # via ambient-package-update (pyproject.toml) certifi==2023.7.22 # via requests cfgv==3.4.0 # via pre-commit -charset-normalizer==3.2.0 +charset-normalizer==3.3.2 # via requests -click==8.1.6 - # via - # black - # typer +click==8.1.7 + # via typer colorama==0.4.6 # via click distlib==0.3.7 # via virtualenv docutils==0.20.1 # via flit -filelock==3.12.2 +filelock==3.13.1 # via virtualenv flit==3.9.0 # via ambient-package-update (pyproject.toml) flit-core==3.9.0 # via flit -identify==2.5.26 +identify==2.5.31 # via pre-commit idna==3.4 # via requests @@ -44,19 +40,11 @@ markupsafe==2.1.3 # via jinja2 more-itertools==10.1.0 # via jaraco-classes -mypy-extensions==1.0.0 - # via black nodeenv==1.8.0 # via pre-commit -packaging==23.1 - # via black -pathspec==0.11.2 - # via black -platformdirs==3.10.0 - # via - # black - # virtualenv -pre-commit==3.3.3 +platformdirs==3.11.0 + # via virtualenv +pre-commit==3.5.0 # via ambient-package-update (pyproject.toml) pywin32-ctypes==0.2.2 # via keyring @@ -64,17 +52,19 @@ pyyaml==6.0.1 # via pre-commit requests==2.31.0 # via flit +ruff==0.1.3 + # via ambient-package-update (pyproject.toml) tomli-w==1.0.0 # via flit typer==0.9.0 # via ambient-package-update (pyproject.toml) -typing-extensions==4.7.1 +typing-extensions==4.8.0 # via typer -urllib3==2.0.4 +urllib3==2.0.7 # via requests -virtualenv==20.24.3 +virtualenv==20.24.6 # via pre-commit -zipp==3.16.2 +zipp==3.17.0 # via importlib-metadata # The following packages are considered to be unsafe in a requirements file: