From 81d6f589ca7e2fca2a57d7cd96d52b07c01a9ac3 Mon Sep 17 00:00:00 2001 From: "John D. Fisher" Date: Sat, 27 Apr 2024 16:02:09 -0700 Subject: [PATCH] build(uv): add astral-sh/uv build(pre-commit): adopt https://learn.scientific-python.org/ recommendations. build(pre-commit): replace pyupgrade, autoflake, isort, black, flake8 with ruff. docs(CONTRIBUTING): adopt uv. --- .pre-commit-config.yaml | 80 ++++++++++++++++++++++++----------------- .vim/coc-settings.json | 12 ------- CONTRIBUTING.md | 34 +++++++++--------- README.md | 1 + environment.yml | 7 ++-- requirements-dev.txt | 32 +++++++++++++++++ requirements.txt | 12 +++++++ setup.cfg | 3 +- 8 files changed, 114 insertions(+), 67 deletions(-) create mode 100644 requirements-dev.txt create mode 100644 requirements.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9c5125b..b54547a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,48 +6,62 @@ exclude: | repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - - id: trailing-whitespace - id: check-added-large-files - id: check-ast + - id: check-case-conflict - id: check-json - id: check-merge-conflict + - id: check-symlinks - id: check-xml - id: check-yaml - id: debug-statements - id: end-of-file-fixer - - id: requirements-txt-fixer - id: mixed-line-ending args: ["--fix=auto"] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows + - id: name-tests-test + args: ["--pytest-test-first"] + - id: requirements-txt-fixer + - id: trailing-whitespace ## If you want to automatically "modernize" your Python code: - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 + # - repo: https://github.com/asottile/pyupgrade + # rev: v3.15.2 + # hooks: + # - id: pyupgrade + # args: ["--py37-plus"] + + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.4.2 hooks: - - id: pyupgrade - args: ["--py37-plus"] + # Run the linter. + - id: ruff + args: ["--fix", "--show-fixes"] + # Run the formatter. + - id: ruff-format ## If you want to avoid flake8 errors due to unused vars or imports: - - repo: https://github.com/PyCQA/autoflake - rev: v2.3.1 - hooks: - - id: autoflake - args: - - "--in-place" - - "--remove-all-unused-imports" - - "--remove-unused-variables" + # - repo: https://github.com/PyCQA/autoflake + # rev: v2.3.1 + # hooks: + # - id: autoflake + # args: + # - "--in-place" + # - "--remove-all-unused-imports" + # - "--remove-unused-variables" - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort + # - repo: https://github.com/PyCQA/isort + # rev: 5.13.2 + # hooks: + # - id: isort - - repo: https://github.com/psf/black - rev: 24.3.0 - hooks: - - id: black - language_version: python3 + # - repo: https://github.com/psf/black + # rev: 24.4.2 + # hooks: + # - id: black + # language_version: python3 ## If like to embrace black styles even in the docs: - repo: https://github.com/asottile/blacken-docs @@ -56,21 +70,21 @@ repos: - id: blacken-docs additional_dependencies: [black] - - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - ## You can add flake8 plugins via `additional_dependencies`: - # additional_dependencies: [flake8-bugbear] + # - repo: https://github.com/PyCQA/flake8 + # rev: 7.0.0 + # hooks: + # - id: flake8 + # ## You can add flake8 plugins via `additional_dependencies`: + # # additional_dependencies: [flake8-bugbear] ## Check for misspells in documentation files: - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: - id: codespell - args: - - "--ignore-regex" - - "eference|reate|rocess" + # args: + # - "--ignore-regex" + # - "eference|reate|rocess" ## Markdown Lint - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.39.0 diff --git a/.vim/coc-settings.json b/.vim/coc-settings.json index 77835c7..59dfa17 100644 --- a/.vim/coc-settings.json +++ b/.vim/coc-settings.json @@ -1,26 +1,14 @@ { - "python.formatting.provider": "black", - "python.formatting.blackPath": "black", "python.linting.enabled": true, "python.linting.mypyEnabled": true, - "python.linting.mypyPath": "mypy", "python.linting.pydocstyleEnabled": true, - "python.linting.flake8Enabled": true, - "python.linting.pylintEnabled": false, - "python.linting.pylintArgs": [ - "-d", - "C0411" - ], - "python.linting.pylintPath": "pylint", "python.sortImports.args": [ "--multi-line=VERTICAL_HANGING_INDENT", "--trailing-comma", "--line-length=88" ], - "python.sortImports.path": "isort", "python.linting.mypyArgs": [ "--no-pretty", - "--ignore-missing-imports", "--follow-imports=silent", "--show-column-numbers", "--check_untyped_defs" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b6a018d..fd2cfc9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -99,17 +99,18 @@ This often provides additional considerations and avoids unnecessary work. Before you start coding, we recommend creating an isolated [virtual environment] to avoid any problems with your installed Python packages. -This can easily be done via either [virtualenv]: +This can easily be done via either [uv]: ```bash -virtualenv +uv venv source /bin/activate +uv pip install --requirement requirements-dev.txt ``` or [Miniconda]: ```bash -conda create -n panvimwiki python=3 six virtualenv pytest pytest-cov +conda env create --file=environment.yml conda activate panvimwiki ``` @@ -130,7 +131,7 @@ conda activate panvimwiki 4. You should run: ```bash - pip install -U pip setuptools -e . + uv pip install --upgrade --editable . ``` to be able to import the package under development in the Python REPL. @@ -138,7 +139,7 @@ conda activate panvimwiki 5. Install [pre-commit]: ```bash - pip install pre-commit + pipx install pre-commit pre-commit install ``` @@ -171,7 +172,7 @@ conda activate panvimwiki Please make sure to see the validation messages from [pre-commit] and fix any eventual issues. - This should automatically use [flake8]/[black] to check/fix the code style + This should automatically use [ruff] to check/fix the code style in a way that is compatible with the project. :::{important} @@ -194,7 +195,7 @@ conda activate panvimwiki tox ``` - (after having installed [tox] with `pip install tox` or `pipx`). + (after having installed [tox] with `pipx`). You can also use [tox] to run several other pre-configured tasks in the repository. Try `tox -av` to see a list of the available checks. @@ -256,9 +257,9 @@ package: freshly installed. For example: ```bash - virtualenv .venv + uv venv source .venv/bin/activate - .venv/bin/pip install tox + uv pip install tox tox-uv .venv/bin/tox -e all ``` @@ -295,16 +296,16 @@ on [PyPI], the following steps can be used to release a new version for to collectively create software are general and can be applied to all sorts of environments, including private companies and proprietary code bases. -[black]: https://pypi.org/project/black/ [commonmark]: https://commonmark.org/ [contribution-guide.org]: https://www.contribution-guide.org/ [creating a pr]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request [descriptive commit message]: https://cbea.ms/git-commit/ [docstrings]: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html -[flake8]: https://flake8.pycqa.org/en/stable/ +[gitHub actions]: https://github.com/jfishe/panvimwiki/actions [git]: https://git-scm.com [github web interface]: https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files [guide created by freecodecamp]: https://github.com/freecodecamp/how-to-contribute-to-open-source +[issue tracker]: https://github.com/jfishe/panvimwiki/issues [miniconda]: https://docs.conda.io/en/latest/miniconda.html [myst]: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html [other kinds of contributions]: https://opensource.guide/how-to-contribute @@ -313,11 +314,10 @@ on [PyPI], the following steps can be used to release a new version for [pypi]: https://pypi.org/ [pytest can drop you]: https://docs.pytest.org/en/stable/how-to/failures.html#dropping-to-pdb-on-failures [python software foundation's code of conduct]: https://www.python.org/psf/conduct/ +[releases]: https://github.com/jfishe/panvimwiki/releases +[repository]: https://github.com/jfishe/panvimwiki +[ruff]: https://github.com/astral-sh/ruff [sphinx]: https://www.sphinx-doc.org/en/master/ -[tox]: https://tox.readthedocs.io/en/stable/ +[tox]: https://tox.wiki/ +[uv]: https://github.com/astral-sh/uv [virtual environment]: https://realpython.com/python-virtual-environments-a-primer/ -[virtualenv]: https://virtualenv.pypa.io/en/stable/ -[repository]: https://github.com/jfishe/panvimwiki -[issue tracker]: https://github.com/jfishe/panvimwiki/issues -[gitHub actions]: https://github.com/jfishe/panvimwiki/actions -[releases]: https://github.com/jfishe/panvimwiki/releases diff --git a/README.md b/README.md index f7dd37c..ed8900c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ vimversion: Vim v9.0 [![Documentation Status][]][1] [![PyPI-Server][]][2] [![Test and Publish Python 🐍 distribution 📦 to PyPI and TestPyPI][]][3] [![Project generated with PyScaffold]][4] +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) ## Introduction diff --git a/environment.yml b/environment.yml index 8110127..9f8dc00 100644 --- a/environment.yml +++ b/environment.yml @@ -3,8 +3,7 @@ channels: - conda-forge - defaults dependencies: - - black - - flake8 + - ruff - html2text - myst-parser - mypy @@ -19,14 +18,14 @@ dependencies: - pytest - pytest-cov - pytest-freezegun - - python # [version='<3.12'] # Should match vim --version | grep python3 + - python [version='<3.12'] # Should match vim --version | grep python3 - sphinx - tox - tox-conda - unify - yapf - pip: - # - -e . + - -e . # - vim-tools - vim_bridge3 # - covimerage dependencies conflict with pytest. `pipx run covimerage` works. diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..46cf05a --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,32 @@ +# This file was autogenerated by uv via the following command: +# uv pip compile --all-extras pyproject.toml -o requirements-dev.txt +click==8.1.7 + # via panflute +coverage==7.5.0 + # via pytest-cov +freezegun==1.5.0 + # via pytest-freezegun +iniconfig==2.0.0 + # via pytest +packaging==24.0 + # via pytest +panflute==2.3.1 +pluggy==1.5.0 + # via pytest +pypandoc @ git+https://github.com/JessicaTegner/pypandoc@7b65192ae9709eca8a9084fc9809a34ea63f1f0f +pytest==8.1.2 + # via + # pytest-cov + # pytest-freezegun + # pytest-pretty-terminal +pytest-cov==5.0.0 +pytest-freezegun==0.4.2 +pytest-pretty-terminal==1.1.0 +python-dateutil==2.9.0.post0 + # via freezegun +pyyaml==6.0.1 + # via panflute +setuptools==69.5.1 +six==1.16.0 + # via python-dateutil +vim-bridge3==0.6 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1634da1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +# This file was autogenerated by uv via the following command: +# uv pip compile pyproject.toml -o requirements.txt +click==8.1.7 + # via panflute +panflute==2.3.1 +pypandoc @ git+https://github.com/JessicaTegner/pypandoc@7b65192ae9709eca8a9084fc9809a34ea63f1f0f +python-dateutil==2.9.0.post0 +pyyaml==6.0.1 + # via panflute +six==1.16.0 + # via python-dateutil +vim-bridge3==0.6 diff --git a/setup.cfg b/setup.cfg index 7f177c4..a3af842 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,7 +65,7 @@ python_requires = >=3.8 install_requires = python-dateutil >=2.8 panflute - pypandoc + pypandoc @ git+https://github.com/JessicaTegner/pypandoc vim-bridge3 @@ -113,6 +113,7 @@ console_scripts = # in order to write a coverage file that can be read by Jenkins. # CAUTION: --cov flags may prohibit setting breakpoints while debugging. # Comment those flags to avoid this pytest issue. +xfail_strict = true addopts = --cov panvimwiki --cov-report term-missing --verbose