Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a tox.ini which is more sunpy like #24

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions {{ cookiecutter.package_name }}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ open_astronomy_package_template_example = "{{ cookiecutter.module_name }}.exampl

{% endif -%}
[project.optional-dependencies]
test = [
tests = [
"pytest",
"pytest-doctestplus",
"pytest-cov",
]
docs = [
"sphinx",
Expand Down Expand Up @@ -102,5 +103,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_",
]
68 changes: 36 additions & 32 deletions {{ cookiecutter.package_name }}/tox.ini
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
[tox]
min_version = 4.0
requires =
tox-pypi-filter>=0.14
Comment on lines +3 to +4
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CyclingNinja This is missing from core btw, we should add it.

envlist =
py{38,39,310,311}-test
py38-test-oldestdeps
py{39,310,311,312}{,-oldestdeps,-devdeps}
build_docs
isolated_build = true

[testenv]
# tox environments are constructed with so-called 'factors' (or terms)
# separated by hyphens, e.g. test-devdeps-cov. Lines below starting with factor:
# will only take effect if that factor is included in the environment name. To
# see a list of example environments that can be run, along with a description,
# run:
#
# tox -l -v
#
pypi_filter = https://raw.githubusercontent.com/sunpy/sunpy/main/.test_package_pins.txt
# Run the tests in a temporary directory to make sure that we don't import
# the package from the source tree
change_dir = .tmp/{envname}
description =
run tests
oldestdeps: with the oldest supported version of key dependencies
devdeps: with the latest developer version of key dependencies

# Pass through the following environment variables which may be needed for the CI
pass_env =
HOME
WINDIR
LC_ALL
LC_CTYPE
CC
CI
TRAVIS

# Suppress display of matplotlib plots generated during docs build
set_env =
set_env =
MPLBACKEND=agg

# Run the tests in a temporary directory to make sure that we don't import
# the package from the source tree
change_dir = .tmp/{envname}
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
# Define the base test command here to allow us to add more flags for each tox factor
PYTEST_COMMAND = pytest -vvv -r fEs --pyargs {{ cookiecutter.module_name }} --cov-report=xml --cov={{ cookiecutter.module_name }} --cov-config={toxinidir}/pyproject.toml {toxinidir}/docs

deps =
# For packages which publish nightly wheels this will pull the latest nightly
devdeps: numpy>=0.0.dev0
# Packages without nightly wheels will be built from source like this
devdeps: git+https://github.com/sunpy/sunpy
oldestdeps: minimum_dependencies
pytest-cov

# The following indicates which extras_require from setup.cfg will be installed
# The following indicates which extras_require will be installed
extras =
test
tests

commands_pre =
oldestdeps: minimum_dependencies packagename --filename requirements-min.txt
oldestdeps: pip install -r requirements-min.txt
pip freeze
pip freeze --all --no-input

commands =
pytest --pyargs packagename --cov {{ cookiecutter.module_name }} --cov-report xml:coverage.xml --cov-report term-missing {posargs}
# To run different commands for different factors exclude the factor from the default command like this
# !online: {env:PYTEST_COMMAND} {posargs}
# Then specify a specific one like this
# online: {env:PYTEST_COMMAND} --remote-data=any {posargs}
# If you have no factors which require different commands this is all you need:
{env:PYTEST_COMMAND} {posargs}

# Uncomment this once we add pre-commit
#[testenv:codestyle]
#pypi_filter =
#skip_install = true
#description = Run all style and file checks with pre-commit
#deps =
# pre-commit
#commands =
# pre-commit install-hooks
# pre-commit run --color always --all-files --show-diff-on-failure

[testenv:build_docs]
description = invoke sphinx-build to build the HTML docs
Expand Down
Loading