Skip to content

Commit

Permalink
Move setup.cfg to pyproject.toml (astropy#15247)
Browse files Browse the repository at this point in the history
* Move setup.cfg to pyproject.toml

* Fix docs build

* Update github CI for astropy-iers-data updates

* Update code mentions of setup.cfg to pyproject.toml

* Add changelog

* Change how license is specified
  • Loading branch information
WilliamJamieson authored Sep 21, 2023
1 parent 7ca3366 commit 98710e2
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 250 deletions.
31 changes: 31 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[flake8]
max-line-length = 88
select = E,F,W
exclude = extern,*parsetab.py,*lextab.py
extend-ignore = E203,E501,E711,E721,E731,E741,F403,F841,W5
per-file-ignores =
__init__.py:F401,F403,E402
test_*.py:E402
astropy/io/fits/card.py:E131
astropy/io/registry/compat.py:F822
astropy/convolution/convolve.py:E241
astropy/modeling/functional_models.py:E226,E241
astropy/modeling/models.py:F401,F403,F405
astropy/modeling/tests/test_constraints.py:E241
astropy/stats/tests/test_histogram.py:E241
astropy/stats/tests/test_sigma_clipping.py:E126,E131,E241
astropy/units/__init__.py:F401,F821
astropy/units/astrophys.py:F821
astropy/units/cgs.py:F821
astropy/units/imperial.py:F821
astropy/units/misc.py:F821
astropy/units/photometric.py:F821
astropy/units/si.py:F821
astropy/units/tests/test_quantity_decorator.py:F821
astropy/units/tests/test_quantity_typing.py:F821
astropy/wcs/wcs.py:F821
astropy/wcs/wcsapi/fitswcs.py:F821
astropy/wcs/wcsapi/utils.py:E127,E128
docs/conf.py:F401
examples/*.py:E1,E2,E402
*/examples/*.py:E1,E2,E402
11 changes: 6 additions & 5 deletions .github/workflows/update_astropy_iers_data_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
).json()

last_version = metadata["info"]["version"]
project_file = "pyproject.toml"

with open("setup.cfg") as f:
with open(project_file) as f:
lines = f.readlines()

changed_lines = 0

for iline in range(len(lines)):
if "astropy-iers-data" in lines[iline]:
changed_lines += 1
lines[iline] = f" astropy-iers-data>={last_version}\n"
lines[iline] = f' "astropy-iers-data>={last_version}",\n'

if changed_lines == 0:
print("No line found containing astropy-iers-data in setup.cfg")
print(f"No line found containing astropy-iers-data in {project_file}")
sys.exit(1)
elif changed_lines > 1:
print("More than one line found containing astropy-iers-data in setup.cfg")
print(f"More than one line found containing astropy-iers-data in {project_file}")
sys.exit(1)


with open("setup.cfg", "w") as f:
with open(project_file, "w") as f:
f.writelines(lines)
4 changes: 2 additions & 2 deletions .github/workflows/update_astropy_iers_data_pin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Regularly update the minimum version of astropy-iers-data in setup.cfg,
# Regularly update the minimum version of astropy-iers-data in pyproject.toml,
# to ensure that if users update astropy, astropy-iers-data will also get
# updated to a recent version.

Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
run: |
git config user.name github-actions
git config user.email [email protected]
git add setup.cfg
git add pyproject.toml
if ! git diff --cached --exit-code; then
git commit -m "Update minimum required version of astropy-iers-data"
fi
Expand Down
3 changes: 3 additions & 0 deletions .pycodestyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pycodestyle]
max-line-length = 88
exclude = extern,*parsetab.py,*lextab.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ def test_earth_orientation_table(monkeypatch):
with warnings.catch_warnings():
# Server occasionally blocks IERS download in CI.
warnings.filterwarnings("ignore", message=r".*using local IERS-B.*")
# This also captures unclosed socket warning that is ignored in setup.cfg
# This also captures unclosed socket warning that is ignored in pyproject.toml
warnings.filterwarnings("ignore", message=r".*unclosed.*")
altaz_auto = sc.transform_to(altaz)
else:
Expand Down
2 changes: 1 addition & 1 deletion astropy/tests/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _build_temp_install(self):
shutil.copytree(self.docs_path, new_docs_path)
self.docs_path = new_docs_path

shutil.copy("setup.cfg", self.testing_path)
shutil.copy("pyproject.toml", self.testing_path)

def _change_permissions_testing_path(self, writable=False):
if writable:
Expand Down
2 changes: 1 addition & 1 deletion astropy/utils/compat/optional_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import warnings

# First, the top-level packages:
# TODO: This list is a duplicate of the dependencies in setup.cfg "all", but
# TODO: This list is a duplicate of the dependencies in pyproject.toml "all", but
# some of the package names are different from the pip-install name (e.g.,
# beautifulsoup4 -> bs4).
_optional_deps = [
Expand Down
2 changes: 1 addition & 1 deletion astropy/visualization/wcsaxes/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_no_numpy_warnings(ignore_matplotlibrc, tmp_path, grid_type):
# (since this is normal).
# BUT our own catch_warning was ignoring some warnings before, so now we
# have to catch it. Otherwise, the pytest filterwarnings=error
# setting in setup.cfg will fail this test.
# setting in pyproject.toml will fail this test.
# There are actually multiple warnings but they are all similar.
with warnings.catch_warnings():
warnings.filterwarnings(
Expand Down
4 changes: 2 additions & 2 deletions astropy/wcs/setup_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ def get_extensions():

# Copy over header files from WCSLIB into the installed version of Astropy
# so that other Python packages can write extensions that link to it. We
# do the copying here then include the data in [options.package_data] in
# the setup.cfg file
# do the copying here then include the data in [tools.setuptools.package_data]
# in the pyproject.toml file

wcslib_headers = [
"cel.h",
Expand Down
1 change: 1 addition & 0 deletions docs/changes/15247.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch from using ``setup.cfg`` for project configuration to using ``pyproject.toml``.
16 changes: 11 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@
# be accessible, and the documentation will not build correctly.
# See sphinx_astropy.conf for which values are set there.

import configparser
import doctest
import os
import sys
from datetime import datetime, timezone
from importlib import metadata
from pathlib import Path

from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib

# -- Check for missing dependencies -------------------------------------------
missing_requirements = {}
for line in metadata.requires("astropy"):
Expand Down Expand Up @@ -127,10 +132,11 @@

extensions += ["sphinx_changelog", "sphinx_design"]

# Grab minversion from setup.cfg
setup_cfg = configparser.ConfigParser()
setup_cfg.read(os.path.join(os.path.pardir, "setup.cfg"))
__minimum_python_version__ = setup_cfg["options"]["python_requires"].replace(">=", "")
# Grab minversion from pyproject.toml
with (Path(__file__).parents[1] / "pyproject.toml").open("rb") as f:
pyproject = tomllib.load(f)

__minimum_python_version__ = pyproject["project"]["requires-python"].replace(">=", "")

min_versions = {}
for line in metadata.requires("astropy"):
Expand Down
8 changes: 4 additions & 4 deletions docs/development/ccython.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ you probably want to install its header files along side the Python module.
1) Create an ``include`` directory inside of your package for
all of the header files.

2) Use the ``[options.package_data]`` section in your ``setup.cfg``
2) Use the ``[tool.setuptools.package_data]`` section in your ``pyproject.toml``
file to include those header files in the package. For example, the
`astropy.wcs` package has the following entries in the
``[options.package_data]`` section::
``[tool.setuptools.package_data]`` section::

[options.package_data]
[tool.setuptools.package_data]
...
astropy.wcs = include/*/*.h
"astropy.wcs" = ["include/*/*.h"]
...

Preventing importing at build time
Expand Down
6 changes: 3 additions & 3 deletions docs/development/codeguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Interface and Dependencies
==========================

* All code must be compatible with the versions of Python indicated by the
``python_requires`` key in the `setup.cfg
<https://github.com/astropy/astropy/blob/main/setup.cfg>`_ file of the
``requires-python`` key under ``[project]`` in the `pyproject.toml
<https://github.com/astropy/astropy/blob/main/pyproject.toml>`_ file of the
core package.

* Usage of ``six``, ``__future__``, and ``2to3`` is no longer acceptable.
Expand All @@ -36,7 +36,7 @@ Interface and Dependencies
methods, the optional dependency should use a normal ``import``
statement, which will raise an ``ImportError`` if the dependency is
not available. In the astropy core package, such optional dependencies should
be recorded in the ``setup.cfg`` file in the ``extras_require``
be recorded in the ``pyproject.toml`` file in the ``[project.optional-dependencies]``
entry, under ``all`` (or ``test_all`` if the dependency is only
needed for testing).

Expand Down
4 changes: 2 additions & 2 deletions docs/development/docguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ the standard Astropy docstring format.
particular module or class.

* Any external package dependencies must be explicitly mentioned in the
documentation. They should also be recorded in the ``setup.cfg`` file in the
root of the astropy repository using an entry in ``extras_require``,
documentation. They should also be recorded in the ``pyproject.toml`` file in the
root of the astropy repository using an entry in ``[project.optional-dependencies]``,
under ``all``.

* Configuration options using the :mod:`astropy.config` mechanisms must be
Expand Down
7 changes: 3 additions & 4 deletions docs/development/scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ Contents of ``/astropy/somepackage/somemod.py`` ::

do_something(res.stuff,res.op)

Then add the script to the ``setup.cfg`` under this section::
Then add the script to the ``pyproject.toml`` under this section::

[options.entry_points]
console_scripts =
somescript = astropy.somepackage.somemod:main
[project.scripts]
somescript = "astropy.somepackage.somemod:main"
31 changes: 16 additions & 15 deletions docs/development/testguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ dependency itself, in addition to several ``pytest`` plugins that are used by
Astropy, and will also be of general use to other packages.

Since the testing dependencies are not actually required to install or use
Astropy, they are not included in ``install_requires`` in ``setup.cfg``.
Instead, they are listed in an ``extras_require`` section called ``test`` in
``setup.cfg``. Developers who want to run the test suite will need to either
install pytest-astropy directly::
Astropy, in the ``pyproject.toml`` file they are not included under the
``[project]`` section in ``dependencies``. Instead, they are listed under the
``[project.optional-dependences]`` section called ``test``. Developers who want
to run the test suite will need to either install pytest-astropy directly::

pip install pytest-astropy

or install the core package in 'editable' mode specifying the ``[test]``
option::

pip install -e .[test]
pip install -e ".[test]"

A detailed description of the plugins can be found in the :ref:`pytest-plugins`
section.
Expand Down Expand Up @@ -214,10 +214,11 @@ Test-running options
Testing for open files
----------------------

There is a configuration inside the ``setup.cfg`` file that converts all
unhandled warnings to errors during a test run. As a result, any open file(s)
that throw ``ResourceWarning`` (except the specific ones already ignored)
would fail the affected test(s).
The ``filterwarnings`` settings under ``[tool.pytest.ini_options]`` in the
``pyproject.toml`` file has an option which converts all unhandled warnings to
errors during a test run. As a result, any open file(s) that throw
``ResourceWarning`` (except the specific ones already ignored) would fail the
affected test(s).

Test coverage reports
---------------------
Expand Down Expand Up @@ -652,12 +653,12 @@ These variables should exist for all of Astropy's optional dependencies; a
complete list of supported flags can be found in
``astropy.utils.compat.optional_deps``.

Any new optional dependencies should be added to that file, as well as to
relevant entries in ``setup.cfg`` under ``options.extras_require``:
typically, under ``all`` for dependencies used in user-facing code
(e.g., ``h5py``, which is used to write tables to HDF5 format),
and in ``test_all`` for dependencies only used in tests (e.g.,
``skyfield``, which is used to cross-check the accuracy of coordinate
Any new optional dependencies should be added to that file, as well as to the
relevant entries in the ``pyproject.toml`` file in the
``[project.optional-dependencies]`` section; typically, under ``all`` for
dependencies used in user-facing code (e.g., ``h5py``, which is used to write
tables to HDF5 format), and in ``test_all`` for dependencies only used in tests
(e.g., ``skyfield``, which is used to cross-check the accuracy of coordinate
transforms).

Using pytest helper functions
Expand Down
Loading

0 comments on commit 98710e2

Please sign in to comment.