Skip to content

Commit d6fcf86

Browse files
author
David Miguel Susano Pinto
committed
maint: adopt pyproject.toml for build and drop setup.py
We had half of package information in pyproject.toml duplicated from setup.py. We were only using pyproject.toml to configure external tools and left the build to setup.py. We really needed setup.py because it handled the call of sphinx-apidoc before sphinx-build and our manual injection of extra files in source distribution. This commit replaces our hack to insert files into source distributions with using `MANIFEST.in` file. It replaces our call of sphinx-apidoc with the sphinx apidoc extension (configuration in doc/conf.py). So we no longer need a special setup.py and so we replace it with a more extensive pyproject.toml. Documentation on how to build documentation and prepare releases is updated accordingly.
1 parent 60a26e1 commit d6fcf86

File tree

5 files changed

+173
-223
lines changed

5 files changed

+173
-223
lines changed

MANIFEST.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# We list here all extra non-standard files to be included in source
2+
# distributions. We list *all*, even those that setuptools picks up
3+
# automatically --- at the moment setuptools picks up COPYING and
4+
# README.rst and ignores NEWS.rst and INSTALL.rst. We list them all
5+
# because 1) we never know when setuptools changes their mind on what
6+
# files to include by default; 2) we may accidentally use an older
7+
# version of setuptools; or 3) we may move away from setuptools to
8+
# another build tool.
9+
#
10+
# Note we do not use package_data from setuptools. That is for files
11+
# that will be included in the binary distribution, i.e., needed at
12+
# runtime. We only want these files in the source distribution, they
13+
# are for user information.
14+
15+
include COPYING
16+
include NEWS.rst
17+
include README.rst
18+
include INSTALL.rst
19+
20+
graft doc

doc/conf.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import unittest.mock
1515

1616

17-
sys.path.insert(0, "../microscope")
17+
sys.path.insert(0, "..")
1818

1919

2020
# autodoc imports the modules to be documented. Modules that wrap the
@@ -93,6 +93,7 @@ def sizeof_diversion(struct):
9393
"sphinx.ext.napoleon",
9494
"sphinx.ext.todo",
9595
"sphinx.ext.viewcode",
96+
"sphinxcontrib.apidoc",
9697
]
9798

9899
# Configuration for sphinx.ext.autodoc
@@ -125,6 +126,27 @@ def sizeof_diversion(struct):
125126
# Configuration for sphinx.ext.todo
126127
todo_include_todos = True
127128

129+
# Configuration for sphinxcontrib.apidoc
130+
apidoc_module_dir = '../microscope'
131+
apidoc_output_dir = 'api'
132+
apidoc_excluded_paths = [
133+
# Exclude the testsuite
134+
"microscope/testsuite/",
135+
# Exclude the wrappers to shared libraries
136+
"microscope/_wrappers/",
137+
# Exclude the deprecated devices and deviceserver that are kept
138+
# for backwards compatibility only
139+
"microscope/devices.py",
140+
"microscope/deviceserver.py",
141+
"microscope/lasers/",
142+
# Exclude these that should be moved to microscope/_wrappers
143+
"microscope/cameras/_SDK3.py",
144+
"microscope/cameras/_SDK3Cam.py",
145+
]
146+
apidoc_separate_modules = True
147+
apidoc_toc_file = "index"
148+
apidoc_module_first = True
149+
apidoc_exra_args = ["--private"]
128150

129151
#
130152
# Options for HTML output
@@ -145,3 +167,14 @@ def sizeof_diversion(struct):
145167
.. _gpl-licence: https://www.gnu.org/licenses/gpl-3.0.html
146168
.. _cockpit-link: https://github.com/MicronOxford/cockpit/
147169
"""
170+
171+
172+
#
173+
# Options for LaTeX/PDF output
174+
#
175+
# Currently this has issues because of Japanese characters in
176+
# authors.rst. But maybe it would make sense to change authors.rst or
177+
# maybe there's something smart we can do on LaTeX customisation with
178+
# latex_elements https://www.sphinx-doc.org/en/master/latex.html
179+
180+
latex_show_urls = "footnote"

doc/get-involved/maintaining.rst

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,59 +29,72 @@ relevant change should also add the entry to the NEWS file.
2929
Steps to make a release
3030
=======================
3131

32-
Because the ``NEWS`` file is supposed to always be kept up to date,
33-
there should be no need to check it.
34-
35-
#. Change version number on ``setup.py`` and date on ``NEWS``. Commit
36-
these changes only. Note that we use ``release-N`` for tag and not
37-
``v.N``. This will enable us to one day perform snapshot releases
38-
with tags such as ``snapshot-N``::
39-
40-
VERSION=$(python3 setup.py --version)
41-
sed -i "s,(upcoming),($(date +%Y/%m/%d))," NEWS.rst
42-
git commit -m "maint: release $VERSION" setup.py NEWS.rst
43-
COMMIT=$(git rev-parse HEAD | cut -c1-12)
44-
git tag -s -u $GPGKEY \
45-
-m "Added tag release-$VERSION for commit $COMMIT" release-$VERSION
46-
47-
#. Build a source distribution from a git archive export. Performing
48-
a release from a git archive will ensure that the release will not
49-
accidentally include modified or untracked files::
50-
51-
rm -rf target/
52-
git archive --format=tar --prefix="target/" HEAD | tar -x
53-
cd target/
54-
python3 setup.py sdist --formats=gztar
32+
#. Check the ``NEWS`` is up to date for the next release. Because the
33+
``NEWS`` file is supposed to be kept up to date with each commit
34+
that introduces changes worth mentioning, there should be no need
35+
to add entries now. But if so, then::
36+
37+
git commit -m "maint: update NEWS for upcoming release" NEWS.rst
38+
39+
#. Manually add date and version for next release on ``NEWS.rst``.
40+
Then change the version on ``pyproject.toml``, commit it, and tag
41+
it::
42+
43+
NEW_VERSION="X.Y.Z" # replace this with new version number
44+
OLD_VERSION=`grep '^version ' pyproject.toml | sed 's,^version = "\([0-9.]*+dev\)"$,\1,'`
45+
python3 -c "from packaging.version import parse; assert parse('$NEW_VERSION') > parse('$OLD_VERSION');"
46+
47+
sed -i 's,^version = "'$OLD_VERSION'"$,version = "'$NEW_VERSION'",' pyproject.toml
48+
git commit -m "maint: release $NEW_VERSION" pyproject.toml NEWS.rst
49+
COMMIT=$(git rev-parse HEAD | cut -c1-12)
50+
git tag -a -m "Added tag release-$NEW_VERSION for commit $COMMIT" release-$NEW_VERSION
51+
52+
Note that we use ``release-N`` for tag and not ``v.N``. This will
53+
enable us to one day perform snapshot releases with tags such as
54+
``snapshot-N``.
55+
56+
#. Build a source and wheel distribution from a git archive export::
57+
58+
rm -rf target
59+
git archive --format=tar --prefix="target/" release-$NEW_VERSION | tar -x
60+
(cd target/ ; python3 -m build)
61+
62+
Performing a release from a git archive ensures that the release
63+
does not accidentally include modified or untracked files. The
64+
wheel distribution is not for actual distribution, we only build it
65+
to ensure that a binary distribution can be built from the source
66+
distribution.
5567

5668
We should probably do this from a git clone and not an archive to
5769
ensure that we are not using a commit that has not been pushed yet.
5870

59-
#. Upload and sign distribution::
71+
#. Upload source distribution to PyPI::
6072

61-
twine upload -r pypi -s -i $GPGKEY target/dist/microscope-X.tar.gz
73+
twine upload -r pypi target/dist/microscope-$NEW_VERSION.tar.gz
6274

63-
#. Add ``+dev`` to version string and a new entry on the ``NEWS``
64-
file::
75+
#. Add ``+dev`` to version string and manually add a new entry on the
76+
``NEWS`` file for the upcoming version::
6577

66-
sed -i "s,\(^project_version = '[^+]*\)',\1+dev'," setup.py
67-
# manually add new version line on NEWS file
68-
git commit setup.py NEWS \
69-
-m "maint: set version to $VERSION+dev after $VERSION release."
70-
git push upstream master
71-
git push upstream release-$VERSION
78+
sed -i 's,^version = "'$NEW_VERSION'"$,version = "'$NEW_VERSION'+dev",' pyproject.toml
79+
# manually add new version line on NEWS.rst file
80+
git commit -m "maint: set version to $NEW_VERSION+dev after $NEW_VERSION release." pyproject.toml NEWS.rst
81+
git push upstream master
82+
git push upstream release-$NEW_VERSION
7283

7384

7485
Documentation
7586
=============
7687

77-
The documentation is generated automatically with `sphinx
78-
<https://www.sphinx-doc.org/en/master/>`_. The API section is
79-
generated from the inline docstrings and makes use of `Sphinx's
80-
Napoleon extension
81-
<http://www.sphinx-doc.org/en/stable/ext/napoleon.html>`_. It is
82-
generated with::
88+
The documentation is generated with `Sphinx
89+
<https://www.sphinx-doc.org/>`__, like so::
90+
91+
sphinx-build -b html doc/ dist/sphinx/html
92+
sphinx-build -M pdflatex doc/ dist/sphinx/pdf
8393

84-
python3 setup.py build_sphinx
94+
The API section is generated from the inline docstrings and makes use
95+
of Sphinx's `Napoleon
96+
<http://www.sphinx-doc.org/en/stable/ext/napoleon.html>`__ and `apidoc
97+
<https://github.com/sphinx-contrib/apidoc>`__ extensions.
8598

8699

87100
Versioning

pyproject.toml

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,78 @@
1+
[project]
2+
name = "microscope"
3+
version = "0.7.0+dev"
4+
description = "An interface for control of microscope devices"
5+
readme = "README.rst"
6+
license = {file = "COPYING"}
7+
8+
# Names are in alphabetical order. This is the list of active
9+
# maintainers. For the full list of people that have contributed to
10+
# the development of the project, see `doc/authors.rst`.
11+
maintainers = [
12+
{name = "David Miguel Susano Pinto"},
13+
{name = "Ian Dobbie"},
14+
{name = "Julio Mateos-Langerak"},
15+
]
16+
17+
# https://pypi.org/classifiers
18+
classifiers = [
19+
"Intended Audience :: Science/Research",
20+
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
21+
"Topic :: Scientific/Engineering",
22+
]
23+
24+
requires-python = ">=3.7"
25+
dependencies = [
26+
"Pillow",
27+
"Pyro4",
28+
"hidapi",
29+
"numpy",
30+
"pyserial",
31+
"scipy",
32+
]
33+
34+
[project.optional-dependencies]
35+
GUI = ["PySide2"]
36+
37+
[project.scripts]
38+
device-server = "microscope.device_server:_setuptools_entry_point"
39+
deviceserver = "microscope.device_server:_setuptools_entry_point"
40+
41+
[project.gui-scripts]
42+
microscope-gui = "microscope.gui:_setuptools_entry_point [GUI]"
43+
44+
[project.urls]
45+
Homepage = "https://www.python-microscope.org"
46+
Download = "https://pypi.org/project/microscope/"
47+
Documentation = "https://www.python-microscope.org/doc/"
48+
News = "https://www.python-microscope.org/doc/news.html"
49+
Source = "https://github.com/python-microscope/microscope"
50+
Tracker = "https://github.com/python-microscope/microscope"
51+
52+
153
[build-system]
2-
requires = ['setuptools']
54+
requires = ["setuptools >= 61.0"]
55+
build-backend = "setuptools.build_meta"
56+
57+
[tool.setuptools.package-dir]
58+
microscope = "microscope"
359

460

561
[tool.isort]
662
profile = "black"
763
line_length = 79
8-
lines_after_imports = 2
9-
# Despite the profile option being set to "black", there's still some
10-
# options that are not correcly set in a compatible manner. The
11-
# following are for compatibility with black style.
12-
combine_as_imports = true
13-
include_trailing_comma = true
14-
multi_line_output = 3 # multi lineoutput 3 is vert-hanging
64+
1565

1666
[tool.black]
1767
line-length = 79
18-
target-version = ['py37', 'py38']
1968

2069

2170
[tool.pylint.FORMAT]
2271
max-line-length = 79
2372

2473

2574
[tool.pytest.ini_options]
26-
testpaths = "microscope/testsuite"
75+
testpaths = ["microscope/testsuite",]
2776
# python_classes must be an empty string otherwise it defaults to all
2877
# Test* classes which then include the TestDevices imported in the
2978
# test_* modules. By using an empty value, it defaults to only
@@ -36,10 +85,15 @@ python_classes = ""
3685
[tool.tox]
3786
legacy_tox_ini = """
3887
[tox]
88+
# We need to set isolated_build because: 'pyproject.toml file found.
89+
# To use a PEP 517 build-backend you are required to configure tox to
90+
# use an isolated_build"
91+
isolated_build = True
3992
envlist = py
93+
4094
[testenv]
4195
description = run whole test suite
4296
commands = python -m unittest discover \
43-
--start-directory microscope/testsuite \
44-
--verbose
97+
--start-directory microscope/testsuite \
98+
--verbose
4599
"""

0 commit comments

Comments
 (0)