Skip to content

Commit

Permalink
Add a very simple pre-commit to keep ci happy (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair authored Feb 9, 2024
1 parent 2f1b3f3 commit 3790c38
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 34 deletions.
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: trailing-whitespace
- id: check-added-large-files
- id: end-of-file-fixer
- id: mixed-line-ending
# Ignore the template for checks which will be confused by jinja syntax
- id: check-ast
exclude: "{{ cookiecutter.package_name }}"
- id: check-yaml
exclude: "{{ cookiecutter.package_name }}"
- id: debug-statements
exclude: "{{ cookiecutter.package_name }}"
32 changes: 16 additions & 16 deletions docs/minimal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ declared in :ref:`pyproject` or set by the `setuptools_scm
``pyproject.toml``
------------------

The ``pyproject.toml`` file is where we will define the metadata about the package.
At a minimum, this file should contain the ``[project]`` table (defined by
The ``pyproject.toml`` file is where we will define the metadata about the package.
At a minimum, this file should contain the ``[project]`` table (defined by
`PEP621 <https://peps.python.org/pep-0621/>`_) and the ``[build-system]`` table
(defined by `PEP518 <https://peps.python.org/pep-0518/>`__).

Expand Down Expand Up @@ -124,10 +124,10 @@ the same as the module name, so in this case we've set the package name to
the case where the package name has a hyphen and the module name has an underscore,
we strongly recommend making the package and the module name the same to avoid confusion.

Note that the version of the package is **not** explicitly defined in the file above,
(rather, defined as ``dynamic``), because we are using the
`setuptools_scm <https://pypi.org/project/setuptools-scm/>`_ package to automatically
retrieve the latest version from Git tags. However, if you choose to not use that
Note that the version of the package is **not** explicitly defined in the file above,
(rather, defined as ``dynamic``), because we are using the
`setuptools_scm <https://pypi.org/project/setuptools-scm/>`_ package to automatically
retrieve the latest version from Git tags. However, if you choose to not use that
package, you can explicitly set the version in the ``[project]`` section (and remove it
from the ``dynamic`` list):

Expand All @@ -154,11 +154,11 @@ In the previous section we discussed the ``dependencies`` which can
be used to declare run-time dependencies for the package, which are
dependencies that are needed for the package to import and run correctly.
However, your package may have dependencies that are needed to build the
package in the first place. For example, the :ref:`setup_py` file
will only run correctly if `setuptools <https://setuptools.readthedocs.io>`_
package in the first place. For example, the :ref:`setup_py` file
will only run correctly if `setuptools <https://setuptools.readthedocs.io>`_
is installed.

The recommended way to specify build-time dependencies is to define the
The recommended way to specify build-time dependencies is to define the
``build-system`` table:

.. code-block:: toml
Expand Down Expand Up @@ -198,7 +198,7 @@ producing application bundles with Python packages.
The ``packages.find`` line can be left as-is - this will automatically determine the
Python modules to install based on the presence of ``__init__.py`` files.

A complete list of keywords in ``[tool.setuptools]`` can be found in the
A complete list of keywords in ``[tool.setuptools]`` can be found in the
`setuptools documentation <https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html>`_.

``[tool.setuptools_scm]``
Expand All @@ -213,18 +213,18 @@ The ``[tool.setuptools_scm]`` table indicates that we want to use the `setuptool
<https://pypi.org/project/setuptools-scm/>`_ package to set the version
automatically based on git tags, which will produce version strings such as
``0.13`` for a stable release, or ``0.16.0.dev113+g3d1a8747`` for a developer
version. The ``write_to`` option is not necessary; it will write the parsed version
to a ``version.py`` with a ``__version__`` variable that can be imported by the
version. The ``write_to`` option is not necessary; it will write the parsed version
to a ``version.py`` with a ``__version__`` variable that can be imported by the
package itself.

.. _setup_py:

``setup.py``
------------

The ``setup.py`` file used to be where project metadata was defined, before the
advent of ``setup.cfg`` and then PEP621 and PEP517 (``pyproject.toml``).
It is no longer necessary to include a ``setup.py`` file in your project,
The ``setup.py`` file used to be where project metadata was defined, before the
advent of ``setup.cfg`` and then PEP621 and PEP517 (``pyproject.toml``).
It is no longer necessary to include a ``setup.py`` file in your project,
unless you are building C extensions in your code.
However, it can increase compatibility with old versions of pip and other packaging tools.

Expand All @@ -233,7 +233,7 @@ The minimal ``setup.py`` file is very simple:
.. code-block:: python
from setuptools import setup
setup()
.. _manifest:
Expand Down
8 changes: 4 additions & 4 deletions docs/releasing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ The source distribution is a tarball of all the files needed by your package,
which includes everything in your ``my_package`` directory as well as everything
specified in your :ref:`manifest` file.

As we have setup a package with a :ref:`pyproject` file, we recommend you use the
`build <https://pypa-build.readthedocs.io/en/latest/>`__ package to build your
source distribution in the isolated environment specified in :ref:`pyproject`.
As we have setup a package with a :ref:`pyproject` file, we recommend you use the
`build <https://pypa-build.readthedocs.io/en/latest/>`__ package to build your
source distribution in the isolated environment specified in :ref:`pyproject`.
You can do this with:

.. code-block:: console
$ pip install build
$ python -m build --sdist --outdir dist .
This is equivalent to running the legacy ``python setup.py sdist`` but ensures
This is equivalent to running the legacy ``python setup.py sdist`` but ensures
that the state of your local environment does not affect the generated package.

Publishing to PyPI
Expand Down
2 changes: 1 addition & 1 deletion docs/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Defining default pytest options

If you regularly need to run tests with the same command-line flags for your
package, or if you want to set options that are required for certain pytest
plugins, you can control these by adding a ``[tool.pytest.ini_options]`` section
plugins, you can control these by adding a ``[tool.pytest.ini_options]`` section
to your ``pyproject.toml`` file; for example

.. code-block:: toml
Expand Down
2 changes: 1 addition & 1 deletion docs/tox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ specify in the tox file (unless they are later overridden), here we default
the ``commands =`` option to run pytest. The ``{posargs}`` is a tox
`substitution
<https://tox.readthedocs.io/en/latest/config.html#substitutions>`__ which
passes extra arguments through to ``pytest``.
passes extra arguments through to ``pytest``.
The ``extras = test`` line tells tox to install the ``optional-dependencies`` section
listed in ``pyproject.toml`` for running your test suite; this should include ``pytest``.

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist =
envlist =
test
build-docs

Expand All @@ -17,7 +17,7 @@ commands =

[testenv:build_docs]
description = invoke sphinx-build to build the HTML docs
change_dir =
change_dir =
docs
deps =
sphinx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ jobs:
run: |
CHANGES=0
if [ -f .cruft.json ]; then
if ! cruft check; then
if ! cruft check; then
CHANGES=1
fi
else
echo "No .cruft.json file"
fi
echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT"
- name: Run update if available
if: steps.check.outputs.has_changes == '1'
run: |
git config --global user.email "[email protected]"
git config --global user.name "Gromit"
cruft update --skip-apply-ask --refresh-private-variables
git restore --staged
Expand All @@ -76,5 +76,4 @@ jobs:
title: ${{ matrix.title }}
body: |
This is an autogenerated PR. ${{ matrix.body }}
[Cruft](https://cruft.github.io/cruft/) has detected updates from the Package Template
[Cruft](https://cruft.github.io/cruft/) has detected updates from the Package Template
2 changes: 1 addition & 1 deletion {{ cookiecutter.package_name }}/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ global-exclude *.pyc *.o
# This subpackage is only used in development checkouts
# and should not be included in built tarballs
prune {{ cookiecutter.module_name }}/_dev
{% endif -%}
{% endif -%}
6 changes: 3 additions & 3 deletions {{ cookiecutter.package_name }}/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ["_static"]

# By default, when rendering docstrings for classes, sphinx.ext.autodoc will
# make docs with the class-level docstring and the class-method docstrings,
# but not the __init__ docstring, which often contains the parameters to
# By default, when rendering docstrings for classes, sphinx.ext.autodoc will
# make docs with the class-level docstring and the class-method docstrings,
# but not the __init__ docstring, which often contains the parameters to
# class constructors across the scientific Python ecosystem. The option below
# will append the __init__ docstring to the class-level docstring when rendering
# the docs. For more options, see:
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.package_name }}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ exclude_lines = [
# Ignore branches that don't pertain to this version of Python
"pragma: py{ignore_python_version}",
# Don't complain about IPython completion helper
"def _ipython_key_completions_",
"def _ipython_key_completions_",
]

0 comments on commit 3790c38

Please sign in to comment.