Skip to content

Commit 7683116

Browse files
authored
Merge pull request #42 from himanshugoel2797/master
Enable automated PyPI deploymenets
2 parents 06b4ff2 + ea16ff7 commit 7683116

27 files changed

+334
-50
lines changed

.github/workflows/pypi_publish.yml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: PyPI Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-n-publish:
12+
# pull requests are a duplicate of a branch push if within the same repo.
13+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
14+
15+
name: ${{ matrix.host-os }} / Python ${{ matrix.python-version }} / OpenMP ${{ matrix.openmp }}
16+
runs-on: ${{ matrix.host-os }}
17+
strategy:
18+
matrix:
19+
host-os: ["ubuntu-latest", "macos-latest", "windows-latest"]
20+
python-version: ["3.8", "3.9", "3.10", "3.11"]
21+
openmp: ["off"]
22+
fail-fast: false
23+
24+
defaults:
25+
run:
26+
shell: bash -l {0}
27+
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Set OpenMP mode
32+
if: matrix.openmp == 'on'
33+
run: |
34+
export MODE="omp"
35+
echo "MODE=${MODE}" >> $GITHUB_ENV
36+
37+
- name: Set MacOS Deployment Target
38+
if: runner.os == 'macOS'
39+
run: |
40+
export MACOSX_DEPLOYMENT_TARGET="10.15"
41+
echo "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" >> $GITHUB_ENV
42+
43+
- uses: conda-incubator/setup-miniconda@v2
44+
with:
45+
activate-environment: testenv
46+
allow-softlinks: true
47+
auto-activate-base: false
48+
auto-update-conda: true
49+
channel-priority: flexible
50+
channels: conda-forge
51+
miniconda-version: "latest"
52+
python-version: ${{ matrix.python-version }}
53+
show-channel-urls: true
54+
use-only-tar-bz2: false
55+
56+
- name: Set up Visual Studio shell
57+
if: runner.os == 'Windows'
58+
uses: egor-tensin/vs-shell@v2
59+
with:
60+
arch: x64
61+
62+
- name: Install build requirements with conda
63+
if: runner.os != 'Linux'
64+
run: |
65+
set -vxeuo pipefail
66+
conda install -y cmake
67+
68+
- name: Install OpenMP for macOS with conda
69+
if: runner.os == 'macOS' && matrix.openmp == 'on'
70+
run: |
71+
set -vxeuo pipefail
72+
conda install -y -c conda-forge llvm-openmp
73+
74+
# NOTE: This step is not needed for fast tests.
75+
# - name: Install mpi4py for Unix with conda
76+
# if: runner.os != 'Windows'
77+
# run: |
78+
# set -vxeuo pipefail
79+
# conda install -y -c conda-forge mpi4py openmpi
80+
81+
- name: Copy over README.md
82+
run: |
83+
set -vxeuo pipefail
84+
cp README.md env/python
85+
86+
- name: Install cibuildwheel on Linux
87+
if: runner.os == 'Linux'
88+
run: |
89+
set -vxeuo pipefail
90+
python -m pip install --upgrade pip
91+
python -m pip install cibuildwheel
92+
echo "CIBW_BEFORE_ALL=pip install cmake" >> $GITHUB_ENV
93+
PYTH_VER=${{ matrix.python-version }}
94+
PYTH_VER=${PYTH_VER//.}
95+
echo "CIBW_BUILD="cp$PYTH_VER-manylinux*"" >> $GITHUB_ENV
96+
97+
- name: Build wheel on Linux
98+
if: runner.os == 'Linux'
99+
run: |
100+
set -vxeuo pipefail
101+
python -VV
102+
python -m cibuildwheel --output-dir dist env/python
103+
ls -la dist/*
104+
105+
- name: Build wheel on Windows/Mac
106+
if: runner.os != 'Linux'
107+
run: |
108+
set -vxeuo pipefail
109+
cd env/python
110+
python -VV
111+
python setup.py bdist_wheel
112+
ls -la dist/*
113+
mkdir -p ../../dist
114+
cp dist/*.whl ../../dist/
115+
116+
# - name: Build sdist on Windows (for Python 3.11)
117+
# if: runner.os == 'Windows' && matrix.python-version == '3.11'
118+
# run: |
119+
# set -vxeuo pipefail
120+
# cd env/python
121+
# python -VV
122+
# python setup.py sdist
123+
# ls -la dist/*
124+
# mkdir -p ../../dist
125+
# cp dist/*.tar.gz ../../dist/
126+
127+
- name: Publish wheels to GitHub artifacts
128+
uses: actions/upload-artifact@v3
129+
with:
130+
name: wheels
131+
path: dist/*
132+
133+
- name: Install the package and test requirements
134+
run: |
135+
set -vxeuo pipefail
136+
pip install -v dist/*64.whl
137+
138+
# Smoke import test:
139+
python -c "import srwpy; import srwpy.srwlpy"
140+
141+
python -m pip install -r env/python/requirements-dev.txt
142+
python -m pip list
143+
144+
- name: Run fast tests
145+
run: |
146+
set -vxeuo pipefail
147+
cd env/python
148+
pytest -k fast
149+
150+
publish-to-pypi:
151+
# Hints from:
152+
# - https://github.com/pypa/gh-action-pypi-publish/discussions/28
153+
# - https://github.com/Lightning-AI/lightning/blob/master/.github/workflows/release-pypi.yml
154+
if: github.event_name == 'release'
155+
name: Publish to PyPI
156+
needs: build-n-publish
157+
runs-on: ubuntu-latest
158+
permissions:
159+
id-token: write
160+
161+
steps:
162+
- uses: actions/checkout@v3
163+
164+
- name: Download wheels from GitHub artifacts
165+
uses: actions/download-artifact@v3
166+
with:
167+
name: wheels
168+
path: dist/
169+
170+
- name: Publish wheels to PyPI
171+
uses: pypa/gh-action-pypi-publish@release/v1
172+
with:
173+
packages-dir: ./dist/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ docs/build/
1919
# Compiled libraries
2020
*.a
2121
*.so
22+
*.pyd
2223

24+
.vscode/
2325
__srwl_logs__/
2426
uti_plot*.png

cpp/cmake/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ set(srw_clients_c_source_files
215215
../src/clients/c/srwlclient.cpp
216216
)
217217

218-
add_executable(srwlclient ${srw_clients_c_source_files})
218+
add_library(srwlclient STATIC ${srw_clients_c_source_files})
219219

220220
target_link_libraries(srwlclient srw)
221221

@@ -227,10 +227,8 @@ install(TARGETS srwlclient RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
227227

228228
# python
229229
# for testing we will need the python interpreter
230-
find_package(PythonInterp REQUIRED)
231-
232230
# we require python development headers
233-
find_package(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT REQUIRED)
231+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
234232

235233

236234
set(srw_clients_python_source_files
@@ -239,7 +237,7 @@ set(srw_clients_python_source_files
239237

240238
add_library(srwlpy SHARED ${srw_clients_python_source_files})
241239

242-
target_include_directories(srwlpy PUBLIC ${PYTHON_INCLUDE_DIRS})
240+
target_include_directories(srwlpy PUBLIC ${Python_INCLUDE_DIRS})
243241

244242
target_include_directories(srwlpy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src/clients/python>)
245243

@@ -263,7 +261,7 @@ if(APPLE)
263261
endif()
264262

265263
if(WIN32)
266-
target_link_libraries(srwlpy srw ${PYTHON_LIBRARIES})
264+
target_link_libraries(srwlpy srw ${Python_LIBRARIES})
267265
set_target_properties(srwlpy PROPERTIES SUFFIX ".pyd")
268266
endif()
269267

env/python/MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ include srwpy/*.so
88

99
# If including data files in the package, add them like:
1010
# include path/to/data_file
11+
12+
graft srwpy/examples/data_example_*
13+
14+
include README.md
15+
include requirements.txt
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mpi4py
2+
oasys_srw
3+
primme
4+
pykern
5+
mpld3
6+
scikit-image

env/python/setup.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def build_extension(self, ext):
5050
'-DBUILD_CLIENT_PYTHON=ON',
5151
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
5252
'-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=' + extdir,
53-
'-DPYTHON_EXECUTABLE=' + sys.executable]
53+
'-DPython_EXECUTABLE=' + sys.executable]
5454
env = os.environ.copy()
5555
if 'MODE' in env:
5656
if env['MODE'] == 'omp':
@@ -77,6 +77,9 @@ def build_extension(self, ext):
7777
base_dir = os.path.dirname(os.path.realpath(__file__))
7878
original_src_dir = os.path.join(base_dir, '../..')
7979

80+
#Read README.md for long_description
81+
long_description = open(os.path.join(base_dir, 'README.md')).read()
82+
8083
with open(os.path.join(base_dir, 'requirements.txt')) as requirements_file:
8184
# Parse requirements.txt, ignoring any commented-out lines.
8285
requirements = [line for line in requirements_file.read().splitlines()
@@ -88,10 +91,10 @@ def build_extension(self, ext):
8891
author='O. Chubar et al.',
8992
author_email='[email protected]',
9093
url='http://github.com/ochubar/SRW',
91-
long_description='''
92-
This is SRW for Python.
93-
''',
94+
long_description=long_description,
95+
long_description_content_type='text/markdown',
9496
packages=find_packages(exclude=['docs', 'tests']),
97+
package_data={'srwpy': ['examples/data_example_**/*']},
9598
install_requires=requirements,
9699
zip_safe=False,
97100
ext_modules=[CMakeExtension('srwlpy', original_src_dir, 'srwpy')],

env/python/srwpy/SRWLIB_ExampleViewDataFile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
#############################################################################
77

88
from __future__ import print_function #Python 2.7 compatibility
9-
from uti_plot import *
9+
try: #OC16112022
10+
from .uti_plot import *
11+
except:
12+
from uti_plot import *
13+
14+
#from uti_plot import *
1015
import optparse
1116
import os
1217

env/python/srwpy/__init__.py

Whitespace-only changes.

env/python/srwpy/examples/__init__.py

Whitespace-only changes.

env/python/srwpy/srwl_bl.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@
99
#############################################################################
1010

1111
from __future__ import print_function #Python 2.7 compatibility
12-
from srwlib import *
13-
from srwl_uti_mag import *
14-
from srwl_uti_und import *
15-
from uti_plot import *
16-
import uti_math
17-
import uti_io
12+
13+
try: #OC15112022
14+
from .srwlib import *
15+
from .srwl_uti_mag import *
16+
from .srwl_uti_und import *
17+
from .uti_plot import *
18+
from . import uti_math
19+
from . import uti_io
20+
except:
21+
from srwlib import *
22+
from srwl_uti_mag import *
23+
from srwl_uti_und import *
24+
from uti_plot import *
25+
import uti_math
26+
import uti_io
27+
#from .srwlib import *
28+
#from .srwl_uti_mag import *
29+
#from .srwl_uti_und import *
30+
#from .uti_plot import *
31+
#from . import uti_math
32+
#from . import uti_io
33+
1834
#import optparse #MR081032016 #Consider placing import argparse here
1935
import time
2036
import re #OC23052020
@@ -2528,7 +2544,10 @@ def calc_all(self, _v, _op=None): #16122018
25282544
#---perform optimization of beamline and possibly source parameters (this should be processed before any other things)
25292545
if(_v.om): #since the optimization modifies params in _v and calls calc_all, it goes first
25302546
try: #16122018
2531-
import uti_math_opt
2547+
try:
2548+
from . import uti_math_opt
2549+
except:
2550+
import uti_math_opt
25322551
self.uti_math_opt = uti_math_opt
25332552

25342553
except:

0 commit comments

Comments
 (0)