Skip to content

Commit

Permalink
build(uv): add astral-sh/uv
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jfishe committed Apr 27, 2024
1 parent dcde4e3 commit 81d6f58
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 67 deletions.
80 changes: 47 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions .vim/coc-settings.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
34 changes: 17 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PATH TO VENV>
uv venv <PATH TO VENV>
source <PATH TO VENV>/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
```

Expand All @@ -130,15 +131,15 @@ 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.

5. Install [pre-commit]:

```bash
pip install pre-commit
pipx install pre-commit
pre-commit install
```

Expand Down Expand Up @@ -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}
Expand All @@ -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.
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ channels:
- conda-forge
- defaults
dependencies:
- black
- flake8
- ruff
- html2text
- myst-parser
- mypy
Expand All @@ -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.
Expand Down
32 changes: 32 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 81d6f58

Please sign in to comment.