From 3790c389f42462b803f5150e5091339768b05dc3 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Fri, 9 Feb 2024 19:58:29 +0000 Subject: [PATCH] Add a very simple pre-commit to keep ci happy (#50) --- .pre-commit-config.yaml | 16 ++++++++++ docs/minimal.rst | 32 +++++++++---------- docs/releasing.rst | 8 ++--- docs/tests.rst | 2 +- docs/tox.rst | 2 +- tox.ini | 4 +-- .../.github/workflows/sub_package_update.yml | 9 +++--- {{ cookiecutter.package_name }}/MANIFEST.in | 2 +- {{ cookiecutter.package_name }}/docs/conf.py | 6 ++-- .../pyproject.toml | 2 +- 10 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b4a6ad5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 }}" diff --git a/docs/minimal.rst b/docs/minimal.rst index d0d3fca..59b5ca6 100644 --- a/docs/minimal.rst +++ b/docs/minimal.rst @@ -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 `_) and the ``[build-system]`` table (defined by `PEP518 `__). @@ -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 `_ 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 `_ 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): @@ -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 `_ +package in the first place. For example, the :ref:`setup_py` file +will only run correctly if `setuptools `_ 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 @@ -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 `_. ``[tool.setuptools_scm]`` @@ -213,8 +213,8 @@ The ``[tool.setuptools_scm]`` table indicates that we want to use the `setuptool `_ 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: @@ -222,9 +222,9 @@ package itself. ``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. @@ -233,7 +233,7 @@ The minimal ``setup.py`` file is very simple: .. code-block:: python from setuptools import setup - + setup() .. _manifest: diff --git a/docs/releasing.rst b/docs/releasing.rst index 038903d..7f9aab3 100644 --- a/docs/releasing.rst +++ b/docs/releasing.rst @@ -58,9 +58,9 @@ 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 `__ 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 `__ package to build your +source distribution in the isolated environment specified in :ref:`pyproject`. You can do this with: .. code-block:: console @@ -68,7 +68,7 @@ You can do this with: $ 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 diff --git a/docs/tests.rst b/docs/tests.rst index ccb553d..9291da1 100644 --- a/docs/tests.rst +++ b/docs/tests.rst @@ -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 diff --git a/docs/tox.rst b/docs/tox.rst index 720accc..d670e49 100644 --- a/docs/tox.rst +++ b/docs/tox.rst @@ -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 `__ 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``. diff --git a/tox.ini b/tox.ini index dd877ac..1e98147 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = +envlist = test build-docs @@ -17,7 +17,7 @@ commands = [testenv:build_docs] description = invoke sphinx-build to build the HTML docs -change_dir = +change_dir = docs deps = sphinx diff --git a/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml b/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml index 9946610..7f10d1b 100644 --- a/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml +++ b/{{ cookiecutter.package_name }}/.github/workflows/sub_package_update.yml @@ -45,13 +45,13 @@ 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 @@ -59,7 +59,7 @@ jobs: run: | git config --global user.email "gromit@cruft.com" git config --global user.name "Gromit" - + cruft update --skip-apply-ask --refresh-private-variables git restore --staged @@ -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 diff --git a/{{ cookiecutter.package_name }}/MANIFEST.in b/{{ cookiecutter.package_name }}/MANIFEST.in index 93b7800..cda3fc5 100644 --- a/{{ cookiecutter.package_name }}/MANIFEST.in +++ b/{{ cookiecutter.package_name }}/MANIFEST.in @@ -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 -%} \ No newline at end of file +{% endif -%} diff --git a/{{ cookiecutter.package_name }}/docs/conf.py b/{{ cookiecutter.package_name }}/docs/conf.py index 01c0d75..acbdf7c 100644 --- a/{{ cookiecutter.package_name }}/docs/conf.py +++ b/{{ cookiecutter.package_name }}/docs/conf.py @@ -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: diff --git a/{{ cookiecutter.package_name }}/pyproject.toml b/{{ cookiecutter.package_name }}/pyproject.toml index 65f11d9..ab3efcf 100644 --- a/{{ cookiecutter.package_name }}/pyproject.toml +++ b/{{ cookiecutter.package_name }}/pyproject.toml @@ -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_", ]