From d4f6f137c3b49bee4256fd444b82770e293719a2 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 25 Dec 2023 03:45:44 +0100 Subject: [PATCH 1/2] move most settings to pyproject.toml except: flake8, which will get replaced by ruff. --- pyproject.toml | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 5 --- setup.py | 82 ++------------------------------------------------ 3 files changed, 82 insertions(+), 84 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cc5169bc9..e728c86ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,76 @@ +[project] +name = "borgbackup" +dynamic = ["version"] +authors = [{name="The Borg Collective (see AUTHORS file)"}] +maintainers = [ + {name="Thomas Waldmann", email="tw@waldmann-edv.de"}, +] +description = "Deduplicated, encrypted, authenticated and compressed backups" +readme = "README.rst" +requires-python = ">=3.9" +keywords = ["backup", "borgbackup"] +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: BSD License", + "Operating System :: POSIX :: BSD :: FreeBSD", + "Operating System :: POSIX :: BSD :: OpenBSD", + "Operating System :: POSIX :: BSD :: NetBSD", + "Operating System :: MacOS :: MacOS X", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Security :: Cryptography", + "Topic :: System :: Archiving :: Backup", +] +license = {text="BSD"} +dependencies = [ + # we are rather picky about msgpack versions, because a good working msgpack is + # very important for borg, see: https://github.com/borgbackup/borg/issues/3753 + # Please note: + # using any other msgpack version is not supported by borg development and + # any feedback related to issues caused by this will be ignored. + "msgpack >=1.0.3, <=1.0.7", + "packaging", +] + +# note for package maintainers: if you package borgbackup for distribution, +# please (if available) add pyfuse3 (preferably) or llfuse as a *requirement*. +# "borg mount" needs one of them to work. +# if neither is available, do not require it, most of borgbackup will work. +[project.optional-dependencies] +llfuse = ["llfuse >= 1.3.8"] +pyfuse3 = ["pyfuse3 >= 3.1.1"] +nofuse = [] + +[project.urls] +"Homepage" = "https://borgbackup.org/" +"Bug Tracker" = "https://github.com/borgbackup/borg/issues" +"Documentation" = "https://borgbackup.readthedocs.io/" +"Repository" = "https://github.com/borgbackup/borg" +"Changelog" = "https://github.com/borgbackup/borg/blob/1.4-maint/docs/changes.rst" + +[project.scripts] +borg = "borg.archiver:main" +borgfs = "borg.archiver:main" + +[tool.setuptools] +# See also the MANIFEST.in file. +# We want to install all the files in the package directories... +include-package-data = true + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.setuptools.exclude-package-data] +# ...except the source files which have been compiled (C extensions): +"*" = ["*.c", "*.h", "*.pyx"] + [build-system] requires = ["setuptools>=64", "setuptools_scm>=8", "wheel", "pkgconfig", "Cython>=3"] build-backend = "setuptools.build_meta" @@ -8,3 +81,9 @@ build-backend = "setuptools.build_meta" # https://github.com/borgbackup/borg/issues/6875 write_to = "src/borg/_version.py" write_to_template = "__version__ = version = {version!r}\n" + +[tool.pytest.ini_options] +python_files = "testsuite/*.py" +markers = [ + "allow_cache_wipe", +] diff --git a/setup.cfg b/setup.cfg index 53aa80269..e2787403c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,8 +1,3 @@ -[tool:pytest] -python_files = testsuite/*.py -markers = - allow_cache_wipe - [flake8] # for reference ... # E121 continuation line under-indented for hanging indent diff --git a/setup.py b/setup.py index fab8e3521..0d16f943c 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# borgbackup - main setup code (see also other setup_*.py files) +# borgbackup - main setup code (see also pyproject.toml and other setup_*.py files) import os import sys @@ -11,7 +11,7 @@ except ImportError: multiprocessing = None from setuptools.command.build_ext import build_ext -from setuptools import setup, find_namespace_packages, Extension, Command +from setuptools import setup, Extension, Command from setuptools.command.sdist import sdist try: @@ -64,30 +64,6 @@ cpu_threads = multiprocessing.cpu_count() if multiprocessing and multiprocessing # Are we building on ReadTheDocs? on_rtd = os.environ.get('READTHEDOCS') -install_requires = [ - # we are rather picky about msgpack versions, because a good working msgpack is - # very important for borg, see: https://github.com/borgbackup/borg/issues/3753 - # Please note: - # using any other msgpack version is not supported by borg development and - # any feedback related to issues caused by this will be ignored. - 'msgpack >=1.0.2, <=1.0.7', - 'packaging', -] - -# note for package maintainers: if you package borgbackup for distribution, -# please (if available) add pyfuse3 (preferably) or llfuse (not maintained any more) -# as a *requirement*. "borg mount" needs one of them to work. -# if neither is available, do not require it, most of borgbackup will work. -extras_require = { - 'llfuse': [ - 'llfuse >= 1.3.8', - ], - 'pyfuse3': [ - 'pyfuse3 >= 3.1.1', - ], - 'nofuse': [], -} - # Extra cflags for all extensions, usually just warnings we want to explicitly enable cflags = [ '-Wall', @@ -257,56 +233,4 @@ if not on_rtd: # generate C code from Cython for THIS platform (and for all platform-independent Cython parts). ext_modules = cythonize(ext_modules, **cython_opts) -# make sure we have the same versioning scheme with all setuptools_scm versions, to avoid different autogenerated files -# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1015052 -# https://github.com/borgbackup/borg/issues/6875 -setup( - name='borgbackup', - author='The Borg Collective (see AUTHORS file)', - author_email='borgbackup@python.org', - url='https://borgbackup.readthedocs.io/', - description='Deduplicated, encrypted, authenticated and compressed backups', - long_description=setup_docs.long_desc_from_readme(), - license='BSD', - platforms=['Linux', 'MacOS X', 'FreeBSD', 'OpenBSD', 'NetBSD', ], - classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Console', - 'Intended Audience :: System Administrators', - 'License :: OSI Approved :: BSD License', - 'Operating System :: POSIX :: BSD :: FreeBSD', - 'Operating System :: POSIX :: BSD :: OpenBSD', - 'Operating System :: POSIX :: BSD :: NetBSD', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Topic :: Security :: Cryptography', - 'Topic :: System :: Archiving :: Backup', - ], - packages=find_namespace_packages('src'), - package_dir={'': 'src'}, - zip_safe=False, - entry_points={ - 'console_scripts': [ - 'borg = borg.archiver:main', - 'borgfs = borg.archiver:main', - ] - }, - # See also the MANIFEST.in file. - # We want to install all the files in the package directories... - include_package_data=True, - # ...except the source files which have been compiled (C extensions): - exclude_package_data={ - '': ['*.c', '*.h', '*.pyx', ], - }, - cmdclass=cmdclass, - ext_modules=ext_modules, - install_requires=install_requires, - extras_require=extras_require, - python_requires='>=3.9', -) +setup(cmdclass=cmdclass, ext_modules=ext_modules, long_description=setup_docs.long_desc_from_readme()) From 915e58653b1b60100ee9ad29a009ce08d572f946 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 4 Sep 2023 22:15:42 +0200 Subject: [PATCH 2/2] replace flake8 by ruff --- .github/workflows/ci.yml | 13 ++---- .pre-commit-config.yaml | 9 ++-- docs/conf.py | 6 ++- pyproject.toml | 79 ++++++++++++++++++++++++++++++++++++ setup.cfg | 88 ---------------------------------------- tox.ini | 6 +-- 6 files changed, 93 insertions(+), 108 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d85d391c..ab8f0b5f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,19 +31,12 @@ on: jobs: lint: - runs-on: ubuntu-20.04 - timeout-minutes: 10 + runs-on: ubuntu-22.04 + timeout-minutes: 2 steps: - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.9 - - name: Lint with flake8 - run: | - pip install flake8 - flake8 src scripts conftest.py + - uses: chartboost/ruff-action@v1 pytest: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7a03542b..58fa52a49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,5 @@ repos: -- repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - files: '(src|scripts|conftest.py)' +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.287 + hooks: + - id: ruff diff --git a/docs/conf.py b/docs/conf.py index 8ac407cc6..b2255c583 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,8 +12,10 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -import sys, os -sys.path.insert(0, os.path.abspath('../src')) +import sys +import os + +sys.path.insert(0, os.path.abspath("../src")) from borg import __version__ as sw_version diff --git a/pyproject.toml b/pyproject.toml index e728c86ba..1fc3441e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,6 +82,85 @@ build-backend = "setuptools.build_meta" write_to = "src/borg/_version.py" write_to_template = "__version__ = version = {version!r}\n" +[tool.ruff] +line-length = 120 +target-version = "py39" + +# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. +select = ["E", "F"] + +# for reference ... +# E402 module level import not at top +# E501 line too long +# F401 import unused +# F405 undefined or defined from star imports +# F811 redef of unused var + +# borg code style guidelines: +# Ignoring E203 due to https://github.com/PyCQA/pycodestyle/issues/373 +ignore = ["E203", "F405", "E402"] + +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"] +unfixable = [] + +# Exclude a variety of commonly ignored directories. +exclude = [ + ".cache", + ".eggs", + ".git", + ".git-rewrite", + ".idea", + ".mypy_cache", + ".ruff_cache", + ".tox", + "build", + "dist", +] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +# Code style violation exceptions: +# please note that the values are adjusted so that they do not cause failures +# with existing code. if you want to change them, you should first fix all +# ruff failures that appear with your change. +[tool.ruff.per-file-ignores] +"setup.py" = ["E501"] +"setup_docs.py" = ["E501"] +"src/borg/archive.py" = ["E501", "F401"] +"src/borg/archiver.py" = ["E501", "F401", "E722", "E741"] +"src/borg/cache.py" = ["E501", "E722"] +"src/borg/crypto/key.py" = ["E501", "F401"] +"src/borg/crypto/keymanager.py" = ["E501", "F401"] +"src/borg/crypto/nonces.py" = ["E501"] +"src/borg/fuse.py" = ["E501", "E722"] +"src/borg/fuse_impl.py" = ["F811"] +"src/borg/helpers/__init__.py" = ["F401"] +"src/borg/helpers/checks.py" = ["F401"] +"src/borg/helpers/manifest.py" = ["E501"] +"src/borg/helpers/misc.py" = ["F401", "E722"] +"src/borg/helpers/parseformat.py" = ["E501", "F401", "E741"] +"src/borg/helpers/process.py" = ["F401"] +"src/borg/locking.py" = ["E501", "E722"] +"src/borg/platform/__init__.py" = ["F401", "F811"] +"src/borg/remote.py" = ["E501"] +"src/borg/repository.py" = ["E501", "F401"] +"src/borg/shellpattern.py" = ["E501"] +"src/borg/testsuite/__init__.py" = ["E501", "F401"] +"src/borg/testsuite/archiver.py" = ["E501", "E722", "F401"] +"src/borg/testsuite/benchmark.py" = ["F811", "F401"] +"src/borg/testsuite/chunker.py" = ["E501"] +"src/borg/testsuite/crypto.py" = ["E501", "E741"] +"src/borg/testsuite/file_integrity.py" = ["F401"] +"src/borg/testsuite/hashindex.py" = ["F401"] +"src/borg/testsuite/helpers.py" = ["E501"] +"src/borg/testsuite/key.py" = ["F401"] +"src/borg/testsuite/locking.py" = ["E501", "E722", "F401"] +"src/borg/testsuite/platform.py" = ["E501", "F811", "F401"] +"src/borg/testsuite/repository.py" = ["E501", "F401"] +"src/borg/upgrader.py" = ["E501"] + [tool.pytest.ini_options] python_files = "testsuite/*.py" markers = [ diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e2787403c..000000000 --- a/setup.cfg +++ /dev/null @@ -1,88 +0,0 @@ -[flake8] -# for reference ... -# E121 continuation line under-indented for hanging indent -# E122 continuation line missing indentation or outdented -# E123 closing bracket does not match indentation of opening bracket's line -# E125 continuation line with same indent as next logical line -# E126 continuation line over-indented for hanging indent -# E127 continuation line over-indented for visual indent -# E128 continuation line under-indented for visual indent -# E221 multiple spaces before operator -# E226 missing whitespace around arithmetic operator -# E261 at least two spaces before inline comment -# E265 block comment should start with '# ' -# E301 expected 1 blank line -# E305 expected 2 blank lines after class or function definition -# E401 multiple imports on one line -# E402 module level import not at top -# E501 line too long -# E722 do not use bare except -# E731 do not assign a lambda expression, use def -# E741 ambiguous variable name -# F401 import unused -# F403 from ... import * used, unable to detect undefined names -# F405 undefined or defined from star imports -# F811 redef of unused var -# F821 undefined name -# W391 blank line at end of file -# #### Pick either W503, or W504 - latest recommendation from pep8 is to ignore W503 -# W503 line break before binary operator -# W504 line break after binary operator - -# borg code style guidelines: -ignore = E226, W503 - -# Code style violation exceptions: -# please note that the values are adjusted so that they do not cause failures -# with existing code. if you want to change them, you should first fix all -# flake8 failures that appear with your change. -per_file_ignores = - docs/conf.py:E121,E126,E265,E305,E401,E402 - src/borg/archive.py:E122,E125,E127,E402,E501,F401,F405,W504 - src/borg/archiver.py:E125,E126,E127,E128,E501,E722,E731,E741,F401,F405,W504 - src/borg/cache.py:E127,E128,E402,E501,E722,W504 - src/borg/fuse.py:E402,E501,E722,W504 - src/borg/fuse_impl.py:F811 - src/borg/locking.py:E128,E501,E722 - src/borg/remote.py:E128,E501,F405 - src/borg/repository.py:E126,E128,E501,F401,F405,W504 - src/borg/shellpattern.py:E501 - src/borg/upgrader.py:E501 - src/borg/xattr.py:E402 - src/borg/crypto/key.py:E125,E128,E402,E501,F401,F405,W504 - src/borg/crypto/keymanager.py:E126,E128,E501,F401 - src/borg/crypto/nonces.py:E128,E501 - src/borg/helpers/__init__.py:F401,F405 - src/borg/helpers/checks.py:F401 - src/borg/helpers/errors.py:F405 - src/borg/helpers/fs.py:F405 - src/borg/helpers/manifest.py:E128,E402,E501,F405 - src/borg/helpers/misc.py:E402,E722,F401,F405 - src/borg/helpers/msgpack.py:E127,F405 - src/borg/helpers/parseformat.py:E402,E501,E741,F401,F405 - src/borg/helpers/process.py:E402,F401,W504 - src/borg/helpers/progress.py:E402 - src/borg/platform/__init__.py:F401,F811 - src/borg/platform/base.py:E402 - src/borg/testsuite/__init__.py:E501,F401 - src/borg/testsuite/archive.py:E128,W504 - src/borg/testsuite/archiver.py:E128,E501,E722,F401,F405,F811 - src/borg/testsuite/benchmark.py:F401,F811 - src/borg/testsuite/chunker.py:E501,F405 - src/borg/testsuite/chunker_pytest.py:F401 - src/borg/testsuite/chunker_slow.py:F405 - src/borg/testsuite/crypto.py:E126,E501,E741 - src/borg/testsuite/file_integrity.py:F401 - src/borg/testsuite/hashindex.py:F401 - src/borg/testsuite/helpers.py:E126,E127,E128,E501,F401 - src/borg/testsuite/key.py:E501,F401 - src/borg/testsuite/locking.py:E126,E128,E501,E722,F401 - src/borg/testsuite/patterns.py:E123 - src/borg/testsuite/platform.py:E128,E501,F401,F811 - src/borg/testsuite/repository.py:E128,E501,F401 - src/borg/testsuite/shellpattern.py:E123 - src/borg/testsuite/upgrader.py:F405 - -max_line_length = 120 -exclude = build,dist,.git,.idea,.cache,.tox - diff --git a/tox.ini b/tox.ini index 61707dcbf..1695b50bc 100644 --- a/tox.ini +++ b/tox.ini @@ -25,10 +25,10 @@ passenv = * passenv = * # needed by tox4, so env vars are visible for building borg -[testenv:flake8] +[testenv:ruff] skip_sdist=true skip_install=true changedir = deps = - flake8 -commands = flake8 src scripts conftest.py + ruff +commands = ruff check .