Skip to content

Commit 63b8f0c

Browse files
authored
Migrate to pyproject.toml and common workflows, update for numpy 2.0 (#35)
* move to pyproject file * remove setup.py * not needed anymore * using common workflows * switch to np.nan for numpy 2.0 compatibility * and bump patch version for release * and add to changelog * membership test should be 'not in' * not fstrings * update authors metadata as discussed
1 parent 3f2364f commit 63b8f0c

File tree

14 files changed

+114
-315
lines changed

14 files changed

+114
-315
lines changed

.github/workflows/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
# Continous Integration Workflows
22

3-
This package implements different workflows for CI.
3+
This package implements different workflows for CI, based on our organisation's common workflows.
44
They are organised as follows.
55

66
### Documentation
77

88
The `documentation` workflow triggers on any push to master, builds the documentation and pushes it to the `gh-pages` branch (if the build is successful).
9-
It runs on `ubuntu-latest` and Python version, `Python 3.9`.
109

1110
### Testing Suite
1211

1312
Tests are ensured in the `tests` workflow, which triggers on all pushes.
14-
It runs on a matrix of all supported operating systems (ubuntu-20.04, ubuntu-22.04, windows-latest and macos-latest) for all supported Python versions (currently `3.7`, `3.8`, `3.9` and `3.10`).
13+
It runs on a matrix of all supported operating systems for all supported Python versions.
1514

1615
### Test Coverage
1716

1817
Test coverage is calculated in the `coverage` wokflow, which triggers on pushes to `master` and any push to a `pull request`.
19-
It runs on `ubuntu-latest` & the Python version (`Python 3.9`), and reports the coverage results of the test suite to `CodeClimate`,
18+
It reports the coverage results of the test suite to `CodeClimate`.
2019

2120
### Regular Testing
2221

2322
A `cron` workflow triggers every Monday at 3am (UTC time) and runs the full testing suite, on all available operating systems and supported Python versions.
24-
It also runs on `Python 3.x` so that newly released Python versions that would break tests are automatically detected.
23+
It also runs on `Python 3.x` so that newly released Python versions that would break tests are automatically included.
2524

2625
### Publishing
2726

28-
Publishing to `PyPI` is done through the `publish` workflow, which triggers anytime a `release` is made of the Github repository.
27+
Publishing to `PyPI` is done through the `publish` workflow, which triggers anytime a `release` is made of the GitHub repository.
2928
It builds a `wheel`, checks it, and pushes to `PyPI` if checks are successful.

.github/workflows/coverage.yml

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Runs all tests and pushes coverage report to codeclimate
22
name: Coverage
33

4-
defaults:
5-
run:
6-
shell: bash
7-
84
on: # Runs on all push events to master branch and any push related to a pull request
95
push:
106
branches:
@@ -13,60 +9,7 @@ on: # Runs on all push events to master branch and any push related to a pull r
139

1410
jobs:
1511
coverage:
16-
name: ${{ matrix.os }} / ${{ matrix.python-version }}
17-
runs-on: ${{ matrix.os }}
18-
strategy:
19-
matrix:
20-
os: [ubuntu-latest]
21-
python-version: [3.9]
22-
23-
steps:
24-
- uses: actions/checkout@v3
25-
26-
- name: Set up Python ${{ matrix.python-version }}
27-
uses: actions/setup-python@v4
28-
with:
29-
python-version: ${{ matrix.python-version }}
30-
cache: 'pip'
31-
cache-dependency-path: '**/setup.py'
32-
33-
- name: Get full Python version
34-
id: full-python-version
35-
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
36-
37-
- name: Upgrade pip, setuptools and wheel
38-
run: python -m pip install --upgrade pip setuptools wheel
39-
40-
- name: Install package
41-
run: python -m pip install '.[test]'
42-
43-
- name: Set up env for CodeClimate (push)
44-
run: |
45-
echo "GIT_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_ENV
46-
echo "GIT_COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
47-
if: github.event_name == 'push'
48-
49-
- name: Set up env for CodeClimate (pull_request)
50-
env:
51-
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
52-
run: |
53-
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
54-
echo "GIT_COMMIT_SHA=$PR_HEAD_SHA" >> $GITHUB_ENV
55-
if: github.event_name == 'pull_request'
56-
57-
- name: Prepare CodeClimate binary
58-
env:
59-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
60-
run: |
61-
curl -LSs 'https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64' >./cc-test-reporter;
62-
chmod +x ./cc-test-reporter
63-
./cc-test-reporter before-build
64-
65-
- name: Run all tests
66-
run: python -m pytest --cov-report xml --cov=optics_functions
67-
68-
- name: Push Coverage to CodeClimate
69-
if: ${{ success() }} # only if tests were successful
70-
env:
71-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
72-
run: ./cc-test-reporter after-build
12+
uses: pylhc/.github/.github/workflows/coverage.yml@master
13+
with:
14+
src-dir: optics_functions
15+
secrets: inherit

.github/workflows/cron.yml

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,11 @@
1-
# Runs all tests on master everyday at 10 am (UTC time)
1+
# Runs all tests on master on Mondays at 3 am (UTC time)
22
name: Cron Testing
33

4-
defaults:
5-
run:
6-
shell: bash
74

8-
on: # Runs on master branch on Mondays at 3am UTC time
5+
on:
96
schedule:
107
- cron: '* 3 * * mon'
118

129
jobs:
13-
tests:
14-
name: ${{ matrix.os }} / ${{ matrix.python-version }}
15-
runs-on: ${{ matrix.os }}
16-
strategy:
17-
matrix:
18-
os: [ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
19-
# Make sure to escape 3.10 with quotes so it doesn't get interpreted as float 3.1 by GA's parser
20-
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", 3.x] # crons should always run latest python hence 3.x
21-
22-
steps:
23-
- uses: actions/checkout@v3
24-
25-
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v4
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
cache: 'pip'
30-
cache-dependency-path: '**/setup.py'
31-
32-
- name: Get full Python version
33-
id: full-python-version
34-
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
35-
36-
- name: Upgrade pip, setuptools and wheel
37-
run: python -m pip install --upgrade pip setuptools wheel
38-
39-
- name: Install package
40-
run: python -m pip install '.[test]'
41-
42-
- name: Run all tests
43-
run: python -m pytest
10+
tests:
11+
uses: pylhc/.github/.github/workflows/cron.yml@master

.github/workflows/documentation.yml

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# The build is published to github pages if the triggering event is a push to the master branch (PR merge)
44
name: Build and upload documentation
55

6-
defaults:
7-
run:
8-
shell: bash
9-
106
on: # Runs on any push event in a PR or any push event to master
117
pull_request:
128
push:
@@ -15,46 +11,4 @@ on: # Runs on any push event in a PR or any push event to master
1511

1612
jobs:
1713
documentation:
18-
name: ${{ matrix.os }} / ${{ matrix.python-version }}
19-
runs-on: ${{ matrix.os }}
20-
strategy:
21-
matrix:
22-
os: [ubuntu-latest]
23-
python-version: [3.9]
24-
25-
steps:
26-
- uses: actions/checkout@v3
27-
28-
- name: Set up Python ${{ matrix.python-version }}
29-
uses: actions/setup-python@v4
30-
with:
31-
python-version: ${{ matrix.python-version }}
32-
cache: 'pip'
33-
cache-dependency-path: '**/setup.py'
34-
35-
- name: Get full Python version
36-
id: full-python-version
37-
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
38-
39-
- name: Upgrade pip, setuptools and wheel
40-
run: python -m pip install --upgrade pip setuptools wheel
41-
42-
- name: Install package
43-
run: python -m pip install '.[doc]'
44-
45-
- name: Build documentation
46-
run: python -m sphinx -b html doc ./doc_build -d ./doc_build
47-
48-
- name: Upload build artifacts # upload artifacts so reviewers can have a quick look without building documentation from the branch locally
49-
uses: actions/upload-artifact@v3
50-
if: success() && github.event_name == 'pull_request' # only for pushes in PR
51-
with:
52-
name: site-build
53-
path: doc_build
54-
retention-days: 5
55-
56-
- name: Upload documentation to gh-pages
57-
if: success() && github.ref == 'refs/heads/master' # only for pushes to master
58-
uses: JamesIves/github-pages-deploy-action@v4
59-
with:
60-
folder: doc_build
14+
uses: pylhc/.github/.github/workflows/documentation.yml@master

.github/workflows/publish.yml

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,11 @@
11
# Publishes to PyPI upon creation of a release
22
name: Upload Package to PyPI
33

4-
defaults:
5-
run:
6-
shell: bash
7-
84
on: # Runs everytime a release is added to the repository
95
release:
106
types: [created]
117

128
jobs:
139
deploy:
14-
name: ${{ matrix.os }} / ${{ matrix.python-version }}
15-
runs-on: ${{ matrix.os }}
16-
strategy:
17-
matrix:
18-
os: [ubuntu-latest]
19-
python-version: [3.9]
20-
21-
22-
steps:
23-
- uses: actions/checkout@v3
24-
25-
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v4
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
cache: 'pip'
30-
cache-dependency-path: '**/setup.py'
31-
32-
- name: Get full Python version
33-
id: full-python-version
34-
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
35-
36-
- name: Upgrade pip, setuptools, wheel, build and twine
37-
run: python -m pip install --upgrade pip setuptools wheel build twine
38-
39-
- name: Build and check build
40-
run: |
41-
python -m build
42-
twine check dist/*
43-
44-
- name: Publish
45-
if: ${{ success() }}
46-
env:
47-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
48-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
49-
run: |
50-
twine upload dist/*
10+
uses: pylhc/.github/.github/workflows/publish.yml@master
11+
secrets: inherit

.github/workflows/tests.yml

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,15 @@
1-
# Runs all tests not flagged as "extended" with a pytest marker
2-
name: Tests
1+
# Runs all tests
2+
name: All Tests
33

44
defaults:
55
run:
66
shell: bash
77

8-
on: [push] # Runs on all push events to any branch
9-
8+
on: # Runs on any push event to any branch except master (the coverage workflow takes care of that)
9+
push:
10+
branches-ignore:
11+
- 'master'
1012

1113
jobs:
1214
tests:
13-
name: ${{ matrix.os }} / ${{ matrix.python-version }}
14-
runs-on: ${{ matrix.os }}
15-
strategy:
16-
matrix:
17-
os: [ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
18-
# Make sure to escape 3.10 with quotes so it doesn't get interpreted as float 3.1 by GA's parser
19-
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
20-
21-
steps:
22-
- uses: actions/checkout@v3
23-
24-
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v4
26-
with:
27-
python-version: ${{ matrix.python-version }}
28-
cache: 'pip'
29-
cache-dependency-path: '**/setup.py'
30-
31-
- name: Get full Python version
32-
id: full-python-version
33-
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
34-
35-
- name: Upgrade pip, setuptools and wheel
36-
run: python -m pip install --upgrade pip setuptools wheel
37-
38-
- name: Install package
39-
run: python -m pip install '.[test]'
40-
41-
- name: Run basic tests
42-
run: python -m pytest
15+
uses: pylhc/.github/.github/workflows/tests.yml@master

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# optics_functions Changelog
22

3+
## Version 0.1.3
4+
5+
- Fixed use of `np.NaN` to ensure compatibility with `numpy 2.0`.
6+
37
## Version 0.1.2
48

59
- Fixed:
610
- an issue that could lead to an indexing error in the closest tune approach calculation for some of the available methods.
711

812
## Version 0.1.1
13+
914
A patch for some closest tune approach methods, and the addition of new methods.
1015

1116
- Fixed:

optics_functions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__title__ = "optics_functions"
66
__description__ = "Calculate optics parameters from TWISS outputs."
77
__url__ = "https://github.com/pylhc/optics_functions"
8-
__version__ = "0.1.2"
8+
__version__ = "0.1.3"
99
__author__ = "pylhc"
1010
__author_email__ = "pylhc@github.com"
1111
__license__ = "MIT"

optics_functions/coupling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,5 +374,5 @@ def check_resonance_relation(df: DataFrame, to_nan: bool = False) -> DataFrame:
374374
"of the data points |F1001| < |F1010|. Your closest tune "
375375
"approach estimates might not be accurate.")
376376
if to_nan:
377-
df.loc[condition_not_fulfilled, COUPLING_RDTS] = np.NaN
377+
df.loc[condition_not_fulfilled, COUPLING_RDTS] = np.nan
378378
return df

optics_functions/rdt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def generator(orders: Sequence[int], normal: bool = True,
197197
if ((order in orders) # check for order
198198
and not (x[0] == x[1] and x[2] == x[3]) # rdt index rule
199199
and ((skew and sum(x[2:4]) % 2) or (normal and not sum(x[2:4]) % 2)) # skew or normal
200-
and (complex_conj or not((x[1], x[0], x[3], x[2]) in permut[order])) # filter conj
200+
and (complex_conj or (x[1], x[0], x[3], x[2]) not in permut[order]) # filter conj
201201
):
202202
permut[order].append(x)
203203
return permut

0 commit comments

Comments
 (0)