Skip to content

Commit 1861392

Browse files
authored
Python packaging (#346)
* Updated packaging * use extras_require for optional dependencies * Add python 3.10 in tests * Add python 3.10 in tests * Ensure a c99 compliant C compiler * separate C anc C++ extensions
1 parent 25802a3 commit 1861392

File tree

12 files changed

+188
-104
lines changed

12 files changed

+188
-104
lines changed

.github/workflows/build-python-wheels.yml

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
push:
77
tags:
88
- pyat-*
9+
workflow_dispatch:
910

1011
defaults:
1112
run:
@@ -20,41 +21,52 @@ jobs:
2021

2122
steps:
2223
- uses: actions/checkout@v2
23-
24-
- uses: actions/setup-python@v2
25-
name: Install Python
2624
with:
27-
python-version: '3.7'
28-
29-
- name: Install cibuildwheel
30-
run: python -m pip install cibuildwheel
25+
# Necessary to fetch tags and allow setuptools_scm
26+
# see: https://github.com/pypa/setuptools_scm/issues/480
27+
fetch-depth: 0
3128

32-
- name: Prepare source
33-
run: |
34-
pip install -e .
29+
- name: Install Python
30+
uses: actions/setup-python@v2
31+
with:
32+
python-version: '3.9'
3533

36-
- name: Remove built files
37-
if: (! contains(matrix.os, 'windows'))
38-
run: rm -rf build
34+
- name: Set build configuration
35+
run: cp githubproject.toml pyproject.toml
3936

4037
- name: Build wheels
41-
run: python -m cibuildwheel --output-dir wheelhouse
42-
env:
43-
# We don't yet support Python 3.10.
44-
# Pypy does not have Scipy so we cannot support it.
45-
CIBW_SKIP: cp310* pp*
46-
CIBW_BUILD_VERBOSITY: 1
47-
48-
- name: Build sdist
49-
run: python setup.py sdist
38+
uses: pypa/[email protected]
39+
with:
40+
package-dir: pyat
5041

5142
- name: Upload wheels
5243
uses: actions/upload-artifact@v2
5344
with:
5445
name: wheels
55-
path: ./pyat/wheelhouse/*.whl
46+
path: ./wheelhouse/*.whl
5647
if-no-files-found: error
5748

49+
build_sdist:
50+
runs-on: ubuntu-18.04
51+
52+
steps:
53+
- uses: actions/checkout@v2
54+
with:
55+
# Necessary to fetch tags and allow setuptools_scm
56+
# see: https://github.com/pypa/setuptools_scm/issues/480
57+
fetch-depth: 0
58+
59+
- name: Install Python
60+
uses: actions/setup-python@v2
61+
with:
62+
python-version: '3.9'
63+
64+
- name: Install build tools
65+
run: python -m pip install build
66+
67+
- name: Build sdist
68+
run: python -m build --sdist
69+
5870
- name: Upload sdist
5971
uses: actions/upload-artifact@v2
6072
with:

.github/workflows/python-tests.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
strategy:
2121
matrix:
22-
python-version: ['3.6', '3.7', '3.8', '3.9']
22+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
2323
os: [macos-latest, ubuntu-latest, windows-latest]
2424

2525
steps:
@@ -31,15 +31,8 @@ jobs:
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333

34-
- name: Install dependencies
35-
run: |
36-
python -m pip install --upgrade pip
37-
python -m pip install flake8
38-
python -m pip install -r requirements.txt
39-
python -m pip install pytest-cov
40-
41-
- name: Build and install at
42-
run: python -m pip install -e .
34+
- name: Build and install at with tests
35+
run: python -m pip install -e ".[dev]"
4336

4437
- name: Lint with flake8
4538
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pyat/dist
2424
pyat/at.egg-info
2525
pyat/prefix
2626
pyat/integrator-src
27+
pyat/at/_version.py
2728
*.egg-info
2829
.pytest_cache
2930
.coverage

jupyter/at.dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ RUN git clone --depth 1 -b $AT_BRANCH $AT_REPO /home/$USERNAME/at \
4242
&& octave --eval 'bootstrap(:,true);savepath'
4343

4444
RUN cd /home/$USERNAME/at/pyat \
45-
&& pip3 install -r requirements.txt \
4645
&& pip3 install matplotlib \
46+
&& pip3 install numpy \
47+
&& pip3 install scipy \
4748
&& python3 setup.py install --user
4849

4950
WORKDIR $DOCKER_NOTEBOOK_DIR

pyat/MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
recursive-include integrator-src *.c *.h
2+
global-include *.c *.h *.cc

pyat/at/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
"""Python port of the Accelerator Toolbox"""
22

3-
# Make all functions visible in the at namespace:
43
import sys
4+
if sys.version_info.minor < 8:
5+
from importlib_metadata import version, PackageNotFoundError
6+
else:
7+
from importlib.metadata import version, PackageNotFoundError
8+
try:
9+
__version__ = version('accelerator-toolbox')
10+
except PackageNotFoundError:
11+
__version__ = "0.0.0"
12+
# from ._version import version as __version__
13+
# Make all functions visible in the at namespace:
514
from .lattice import *
615
from .tracking import *
716
from .physics import *

pyat/developers.rst

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Install the Python development package for your OS. For example, using yum:
1919

2020
* ``sudo yum install python3-devel``
2121

22+
Source download
23+
---------------
24+
Download the latest version of AT:
25+
``$ git clone https://github.com/atcollab/at.git``
26+
27+
2228
Installation (all platforms)
2329
----------------------------
2430

@@ -30,9 +36,18 @@ It is easiest to do this using a virtualenv. inside pyat:
3036

3137
Then:
3238

33-
* ``source venv/bin/activate # or venv\Scripts\activate on Windows``
34-
* ``pip install -r requirements.txt``
35-
* ``pip install -e .``
39+
* activate the virtual environment:
40+
41+
``source venv/bin/activate # or venv\Scripts\activate on Windows``
42+
* make sure you have a recent pip installer:
43+
44+
``pip install --upgrade pip``
45+
* Go to the pyat root directory:
46+
47+
``cd <atroot>/pyat``
48+
* install AT:
49+
50+
``pip install -e .``
3651

3752
Finally, you should be able to run the tests:
3853

@@ -58,17 +73,17 @@ recompiled. To force recompilation, remove the build directory:
5873
Any changes to .py files are automatically reinstalled in the build, but to
5974
ensure any changes to .c files are reinstalled rerun:
6075

61-
* ``python setup.py develop``
76+
* ``pip install -e .``
6277

63-
If you get strange behaviour even after running setup.py develop again, then
78+
If you get strange behaviour even after running pip install develop again, then
6479
running the following, inside pyat, should fix it:
6580

6681
* ``rm -rf build``
6782
* ``find at -name "*.pyc" -exec rm '{}' \;``
6883
* ``find at -name "*.so" -exec rm '{}' \;``
69-
* ``python setup.py develop``
84+
* ``pip install -e .``
7085

71-
N.B. setup.py develop needs to be run with the same version of Python (and
86+
N.B. ``pip install -e .`` needs to be run with the same version of Python (and
7287
numpy) that you are using to run pyAT.
7388

7489
Releasing a version to PyPI
@@ -91,12 +106,10 @@ For testing any version that you have installed, the simple snippet in
91106
``README.rst`` is sufficient.
92107

93108
* Decide the Python versions that should be supported in the release
94-
* Set these Python versions in setup.py
95-
* Set at least these Python versions as python-version in .github/workflows/python-tests.yml
109+
* Set these Python versions in ``python_requires`` in ``setup.cfg``
110+
* Set at least these Python versions as ``python-version`` in ``.github/workflows/python-tests.yml``
96111
* Determine the minimum Numpy version that is required for those Python versions
97-
* Set this numpy version in install_requires in setup.py
98-
* Set this numpy version in requirements.txt
99-
* Update the pyat version in setup.py to x.y.z
112+
* Set this numpy version in ``install_requires`` in ``setup.cfg``
100113
* Push a tag ``pyat-x.y.z`` to Github
101114

102115
If all goes well, there will be a build of "Build and upload wheels and sdist"

pyat/githubproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build-system]
2+
requires = [
3+
"numpy == 1.16.6;python_version<'3.10'",
4+
"numpy == 1.21.5;python_version>='3.10'",
5+
"setuptools >= 45",
6+
"setuptools_scm>=6.2",
7+
"wheel",
8+
]
9+
build-backend = "setuptools.build_meta"
10+
11+
[tool.cibuildwheel]
12+
# Pypy does not have Scipy so we cannot support it.
13+
build = ["cp3{6,7,8,9,10}*"]
14+
build-verbosity = "1"
15+
# "build" frontend fails on windows
16+
# build-frontend = "build"
17+
18+
[tool.cibuildwheel.macos]
19+
archs = ["x86_64", "arm64"]
20+
21+
[tool.setuptools_scm]
22+
root = ".."
23+
# write_to = "pyat/at/_version.py"
24+
git_describe_command = "git describe --tags --long --match pyat-[0-9]* HEAD"
25+
fallback_version = "0.0.0"

pyat/pyproject.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
[build-system]
22
requires = [
3-
"numpy == 1.16.6",
4-
"setuptools >= 40.9.0",
3+
"numpy >= 1.16.6;python_version<'3.10'",
4+
"numpy >= 1.21.5;python_version>='3.10'",
5+
"setuptools >= 45",
6+
"setuptools_scm>=6.2",
57
"wheel",
68
]
79
build-backend = "setuptools.build_meta"
10+
11+
[tool.cibuildwheel]
12+
# Pypy does not have Scipy so we cannot support it.
13+
build = ["cp3{6,7,8,9}*", "cp310*"]
14+
build-verbosity = "1"
15+
# "build" frontend fails on windows
16+
# build-frontend = "build"
17+
18+
[tool.cibuildwheel.macos]
19+
archs = ["x86_64", "arm64"]
20+
21+
[tool.setuptools_scm]
22+
root = ".."
23+
# write_to = "pyat/at/_version.py"
24+
git_describe_command = "git describe --dirty --tags --long --match pyat-[0-9]*"
25+
fallback_version = "0.0.0"

pyat/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)