Skip to content

Commit

Permalink
Convert setup.cfg to pyproject.toml (PlasmaPy#1758)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Closes PlasmaPy#1680
Closes PlasmaPy#1276
  • Loading branch information
StanczakDominik authored Dec 13, 2022
1 parent b11560f commit f5ff8e6
Show file tree
Hide file tree
Showing 29 changed files with 442 additions and 698 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ jobs:
python: 3.8
toxenv: py38-all

- name: Python 3.9
- name: Python 3.9, develop mode
os: ubuntu-latest
python: 3.9
toxenv: py39
toxargs: --develop

steps:
- name: Checkout code
Expand Down Expand Up @@ -180,16 +181,14 @@ jobs:
python-version: 3.8
- name: Install requirements
run: |
pip install --progress-bar off --upgrade pip
pip install --progress-bar off setuptools numpy wheel setuptools_scm twine
- name: Build a binary wheel
run: python setup.py bdist_wheel
pip install --progress-bar off setuptools numpy wheel setuptools_scm twine build pip
- name: Build a source tarball
run: python setup.py sdist
run: python -m build --sdist --outdir dist/
- name: Build a binary wheel
run: python -m build --wheel --outdir dist/
- name: Twine check
run: twine check dist/*
- name: Install PlasmaPy in all variants
run: |
pip install --progress-bar off .[all,dev]
pip install --progress-bar off -e .[all,dev]
python setup.py develop
pip install --progress-bar off .[dev]
pip install --progress-bar off -e .[dev]
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ untitled*
auto_examples

# Version file
plasmapy/version.py
plasmapy/_version.py
tags
docs/notebooks/*.md
16 changes: 12 additions & 4 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ version: 2
formats:
- htmlzip

build:
os: ubuntu-20.04
tools:
python: '3.10'
jobs:
pre_create_environment:
- python -m pip install --upgrade setuptools pip


# Optionally set the version of Python and requirements required to build your docs
python:
version: '3.8'
install:
- requirements: requirements/install.txt
- requirements: requirements/docs.txt
- method: setuptools
- method: pip
path: .
extra_requirements:
- docs
system_packages: true
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
include README.md
include LICENSE.md
include setup.py
include pyproject.toml

include setup.cfg
include plasmapy/tests/coveragerc
include CITATION.cff

recursive-include plasmapy *.json *.npy
recursive-include docs *
recursive-include licenses *

# Only for editable installs
prune plasmapy/_dev

prune build
prune docs/_build
prune docs/api
Expand Down
4 changes: 1 addition & 3 deletions binder/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-r ../requirements/build.txt
-r ../requirements/install.txt
-r ../requirements/extras.txt
.
..
jupytext
3 changes: 3 additions & 0 deletions changelog/1758.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Transferred most of the contents of :file:`setup.py` and :file:`setup.cfg` to
|pyproject.toml|_ (see :pep:`518` and :pep:`621`). Simplified ``extras``
requirements (``pip install plasmapy[all]`` and ``[extras]`` are gone).
2 changes: 1 addition & 1 deletion changelog/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ to the top-level directory of your local clone of PlasmaPy and run:

.. code-block:: shell
pip install -r requirements.txt
pip install -e .[dev]
Configuration files for towncrier_ are in :file:`pyproject.toml`.

Expand Down
12 changes: 0 additions & 12 deletions docs/common_links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,6 @@
.. _`pyproject.toml`: https://github.com/PlasmaPy/PlasmaPy/blob/main/pyproject.toml
.. |pyproject.toml| replace:: :file:`pyproject.toml`

.. _`requirements`: https://github.com/PlasmaPy/PlasmaPy/tree/main/requirements
.. |requirements| replace:: :file:`requirements`

.. _`requirements/build.txt`: https://github.com/PlasmaPy/PlasmaPy/blob/main/requirements/build.txt
.. |requirements/build.txt| replace:: :file:`requirements/build.txt`

.. _`requirements/environment.yml`: https://github.com/PlasmaPy/PlasmaPy/blob/main/requirements/environment.yml
.. |requirements/environment.yml| replace:: :file:`requirements/environment.yml`

.. _`setup.cfg`: https://github.com/PlasmaPy/PlasmaPy/blob/main/setup.cfg
.. |setup.cfg| replace:: :file:`setup.cfg`

.. _`sphinxcontrib-bibtex`: https://sphinxcontrib-bibtex.readthedocs.io
.. |sphinxcontrib-bibtex| replace:: `sphinxcontrib-bibtex`

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
# a new role, and the corresponding tuple contains the base url and the
# caption. For example, we can now do :orcid:`0000-0000-0000-0000` and
# have a link create to the corresponding ORCID page. New roles should
# be added to rst-roles in setup.cfg to avoid being caught by
# be added to rst-roles in tox.ini to avoid being caught by
# flake8-rst-docstrings.

extlinks = {
Expand Down
22 changes: 2 additions & 20 deletions docs/contributing/coding_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,8 @@ Imports
Requirements
============

* Package requirements are specified in multiple locations that need to
be updated simultaneously.

- The |requirements|_ directory contains multiple text files that
contain build, installation, testing, documentation, and extra
requirements.

- The ``build-system.requires`` section of |pyproject.toml|_ includes
the requirements for building PlasmaPy. This section must mirror
|requirements/build.txt|_.

- |setup.cfg|_ includes sections for the install, docs, tests, and
extra requirements that must mirror the corresponding files in
the |requirements|_ directory.

- |requirements/environment.yml|_ contains a Conda_ environment
for PlasmaPy.

- |tox.ini|_ contains a testing environment for the minimal
dependencies.
* Package requirements are specified in |pyproject.toml|_. |tox.ini|_
also contains a testing environment for the minimal dependencies.

* Each release of PlasmaPy should support all minor versions of
Python that have been released in the prior 42 months, and all minor
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing/doc_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ and run:

.. code-block:: bash
pip install -r requirements.txt
pip install -e .[dev]
It may also be necessary to install the following software:

Expand Down Expand Up @@ -395,7 +395,7 @@ value in |docs/conf.py|_.

When an extension contains new |roles| or |directives|, it may be
necessary to add them to ``rst-roles`` and ``rst-directives`` in the
``[flake8]`` section of |setup.cfg|_ to avoid linter errors during
``[flake8]`` section of |tox.ini|_ to avoid linter errors during
continuous integration tests in pull requests.

.. _external-references:
Expand Down
7 changes: 3 additions & 4 deletions docs/contributing/install_dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ following:

.. code-block:: bash
conda env create -f requirements/environment.yml
conda create -n plasmapy python=3.10
You may now enter the environment via

Expand Down Expand Up @@ -171,7 +171,7 @@ dependencies. One way to do this is to do
Next, setup the development version of PlasmaPy which you just cloned
by moving into the root directory of the cloned repo and running the
setup.py script there:
following there:

.. code-block:: bash
Expand Down Expand Up @@ -204,11 +204,10 @@ Installing your own dev version
===============================

To be able to import PlasmaPy from your source version, enter the
repository root and use one of
repository root and use

.. code-block:: bash
python setup.py develop
pip install -e .
.. note::
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing/testing_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ The following checks are performed with each pull request.

* Occasionally codespell_ will report false positives. Please add
false positives to ``ignore-words-list`` under ``codespell`` in
:file:`setup.cfg`.
:file:`pyproject.toml`.

.. note::

Expand All @@ -200,7 +200,7 @@ To install the packages necessary to run tests on your local computer

.. code-block:: shell
pip install -r requirements.txt
pip install -e .[tests]
To run PlasmaPy's tests from the command line, go to a directory within
PlasmaPy's repository and run:
Expand Down
4 changes: 2 additions & 2 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ If you expect to occasionally edit the source code, instead run:

.. code:: bash
pip install -e .[developer]
pip install -e ".[dev]"
The ``-e`` flag makes the installation editable and ``[developer]``
The ``-e`` flag makes the installation editable and ``[dev]``
indicates that all of the dependencies needed for developing PlasmaPy
will be installed.

Expand Down
58 changes: 17 additions & 41 deletions plasmapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Packages may add whatever they like to this file, but
# should keep this content at the top.
# ----------------------------------------------------------------------------
from importlib.metadata import PackageNotFoundError, version
from importlib.metadata import PackageNotFoundError

from plasmapy import (
analysis,
Expand All @@ -43,46 +43,22 @@

# define version
try:
# this places a runtime dependency on setuptools
#
# note: if there's any distribution metadata in your source files, then this
# will find a version based on those files. Keep distribution metadata
# out of your repository unless you've intentionally installed the package
# as editable (e.g. `pip install -e {plasmapy_directory_root}`),
# but then __version__ will not be updated with each commit, it is
# frozen to the version at time of install.
#
#: PlasmaPy version string
__version__ = version("plasmapy")
except PackageNotFoundError:
# package is not installed
fallback_version = "unknown"
try:
# code most likely being used from source
# if setuptools_scm is installed then generate a version
from setuptools_scm import get_version

__version__ = get_version(
root="..", relative_to=__file__, fallback_version=fallback_version
)
del get_version
warn_add = "setuptools_scm failed to detect the version"
except ModuleNotFoundError:
# setuptools_scm is not installed
__version__ = fallback_version
warn_add = "setuptools_scm is not installed"

if __version__ == fallback_version:
from warnings import warn

warn(
f"plasmapy.__version__ not generated (set to 'unknown'), PlasmaPy is "
f"not an installed package and {warn_add}.",
RuntimeWarning,
)

del warn
del fallback_version, warn_add
from plasmapy._dev.scm_version import version as __version__
except ImportError:
from plasmapy._version import version as __version__
except Exception: # coverage: ignore
# package is not installed
__version__ = "0.0.0"

from warnings import warn

warn(
"plasmapy.__version__ not generated (set to '0.0.0'). It looks like "
"the installation's broken. Ask on Element!",
)

del warn

# ----------------------------------------------------------------------------
#: PlasmaPy citation instructions
Expand All @@ -92,7 +68,7 @@
)


def online_help(query: str):
def online_help(query: str): # coverage: ignore
"""
Open a webpage containing a search page in `PlasmaPy's documentation`_,
or another page that contains relevant online help.
Expand Down
8 changes: 8 additions & 0 deletions plasmapy/_dev/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
This subpackage is only used with an editable install of PlasmaPy.
It ensures that setuptools-scm gets the right version. This is helpful,
for example, with documentation builds.
Its implementation follows the setup of https://github.com/astropy/astropy/pull/10774.
"""
10 changes: 10 additions & 0 deletions plasmapy/_dev/scm_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Try to use setuptools_scm to get the current version; this is only used
# in development installations from the git repository.
import os.path as pth

try:
from setuptools_scm import get_version

version = get_version(root=pth.join("..", ".."), relative_to=__file__)
except Exception as e:
raise ImportError("setuptools_scm broken or not installed") from e
Loading

0 comments on commit f5ff8e6

Please sign in to comment.