Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and upload to pypa #203

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e2b47b0
Debugging git workflow to replace travis
vetlewi Jan 16, 2023
00613a7
Updates to workflow
vetlewi Jan 16, 2023
867794b
Debugging...
vetlewi Jan 16, 2023
0ffe6ed
Fixed a small bug
vetlewi Jan 16, 2023
471f964
Added a macOS test as well
vetlewi Jan 16, 2023
36d4856
Debugging
vetlewi Jan 16, 2023
3347489
Slight error...
vetlewi Jan 16, 2023
e742de5
Updated workflow
vetlewi Jan 16, 2023
3f8c8dc
Publish workflow
vetlewi Jan 16, 2023
c5d8bf9
Merging stats.cpp and erfinv.hpp
vetlewi Jan 16, 2023
64de29c
Modified setup file
vetlewi Jan 16, 2023
76385f9
Fixing a syntax error
vetlewi Jan 16, 2023
6b66f77
Update to use a different image
vetlewi Jan 16, 2023
74e31ef
More adjustments to the workflow...
vetlewi Jan 16, 2023
4be9550
More fixes...
vetlewi Jan 16, 2023
c7e8dae
Okei, this should be it!
vetlewi Jan 16, 2023
31de276
Additional changes
vetlewi Jan 16, 2023
fa13edd
A little more debugging...
vetlewi Jan 17, 2023
77d4b9d
Testing the cibuildwheel solution
vetlewi Jan 17, 2023
96d031d
Working on determining where stuff ends up...
vetlewi Jan 17, 2023
594daf6
Update main.yml
vetlewi Jan 17, 2023
3e6e861
Added test step
vetlewi Jan 17, 2023
84db009
Missing &&
vetlewi Jan 17, 2023
e1be6b8
Moved configuration to pyproject
vetlewi Jan 17, 2023
ed1c511
Modification to the example code
vetlewi Jan 17, 2023
7e2b5fd
Build and test both macOS and linux
vetlewi Jan 17, 2023
dd41a0f
Updates to the build settings
vetlewi Jan 17, 2023
127cde4
Added missing environmental variable FC
vetlewi Jan 17, 2023
b1da15a
Added the example matrix files
vetlewi Jan 17, 2023
d37b764
No install because of issues while installing
vetlewi Jan 17, 2023
e52e797
Removed some compiler flags that does not work on apple silicon
vetlewi Jan 17, 2023
c32815c
Test deployment too
vetlewi Jan 17, 2023
caa0a6d
Testing with ubuntu only...
vetlewi Jan 17, 2023
28d7af5
Removed the upload job. Will add once I know that the test release works
vetlewi Jan 17, 2023
8c31a92
Added python tag
vetlewi Jan 17, 2023
978a186
Stupid errors...
vetlewi Jan 17, 2023
dfd52a4
Added missing upload
vetlewi Jan 17, 2023
b248640
Workflow (#96)
vetlewi Jan 17, 2023
6eb352a
'hopefully' final version of the workflow
vetlewi Jan 17, 2023
22885f3
Stupid indentation error!
vetlewi Jan 17, 2023
26e3302
Merge branch 'test_release' into workflow
vetlewi Jan 17, 2023
8a2bb8a
Removed `publish-to-pypi` script and set the correct triggers for the…
vetlewi Jan 17, 2023
4917fe5
Merge branch 'master' into workflow
vetlewi Apr 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: main


# Automatically cancel a previous run.
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true


on:
push:
branches:
- master
pull_request:
branches:
- master
release:
types: [published]

jobs:

build_sdist:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build SDist
run: pipx run build --sdist

- name: Check metadata
run: pipx run twine check dist/*

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

build_wheel:
name: Build wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest', 'macos-latest']
steps:
- uses: actions/checkout@v3

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: x86_64 arm64

- uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl


upload_test:
name: Upload if test release
needs: [build_sdist, build_wheel]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/test_release'
steps:
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/[email protected]
with:
name: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/

upload:
name: Upload if new release
needs: [build_sdist, build_wheel]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'

steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.pypi_password }}
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include LICENSE.md
include README.md
include ompy/decomposition.pyx
include ompy/rebin.pyx
include ompy/gauss_smoothing.pyx
include ompy/stats/stats.cpp
include ompy/stats/erfinv.hpp
include ompy/examples/Dy164_raw.m
include ompy/examples/Si28_raw_matrix_compressed.m
Binary file added ompy/examples/Dy164_raw.m
Binary file not shown.
Binary file added ompy/examples/Si28_raw_matrix_compressed.m
Binary file not shown.
7 changes: 4 additions & 3 deletions ompy/examples.py → ompy/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
from typing import Tuple, List
from .matrix import Matrix
from ..matrix import Matrix
import numpy as np

EXAMPLES = {'dy164': {'raw': "../../example_data/Dy164_raw.m",

EXAMPLES = {'dy164': {'raw': "../Dy164_raw.m",
# 'response': "../../data/Dy164_response_matrix.m"
},
'si28': {'raw': "../../example_data/Si28_raw_matrix_compressed.m"}
'si28': {'raw': "../Si28_raw_matrix_compressed.m"}
}
DATAPATH = os.path.abspath(__file__)

Expand Down
2 changes: 1 addition & 1 deletion ompy/spinfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def gDisc_and_EB05(self, mass: int, NLDa: float, Eshift: float, Sn: float,
sigma2_Sn = self.gEB05(mass, NLDa, Eshift, Ex=Sn)
sigma2_EB05 = lambda Ex: self.gEB05(mass, NLDa, Eshift, Ex=Ex) # noqa
x = [sigma2_disc[0], Sn]
y = [sigma2_disc[1], sigma2_EB05(Sn)]
y = [sigma2_disc[1], float(sigma2_EB05(Sn))]
sigma2 = interp1d(x, y,
bounds_error=False,
fill_value=(sigma2_disc[1], sigma2_Sn))
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions src/stats.cpp → ompy/stats/stats.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <cmath>

#include "erfinv.hpp"



namespace py = pybind11;
constexpr double sqrt2 = 1.41421356237309504880168872420969807856967187;

Expand Down
75 changes: 69 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,71 @@
[build-system]
requires = [
"setuptools",
"numpy>=1.20.0",
"cython",
"pybind11>=2.6.0",
"wheel"]
requires = ["setuptools", "numpy>=1.20.0", "cython", "pybind11>=2.6.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "OMpy"
version = "1.1.0"
authors = [
{name="Jørgen Eriksson Midtbø", email="[email protected]"},
{name="Fabio Zeiser", email="[email protected]"},
{name="Erlend Lima", email="[email protected]"}
]
maintainers = [
{name="Erlend Lima", email="[email protected]"},
{name="Vetle Wegner Ingeberg", email="[email protected]"}
]

dependencies = [
"cython", "numpy>=1.20.0", "pandas", "matplotlib", "termtables",
"pymultinest", "scipy", "uncertainties>=3.0.3", "tqdm", "pathos", "pybind11>=2.6.0"]

description = "A python implementation of the Oslo method"
readme = "README.md"
requires-python = ">=3.8"
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Physics",
]

[project.urls]
"Homepage" = "https://github.com/oslocyclotronlab/ompy"
"Bug Tracker" = "https://github.com/oslocyclotronlab/ompy/issues"

[tool.cibuildwheel]
build = ["cp310-manylinux_x86_64",
"cp311-manylinux_x86_64",
"cp310-macosx_x86_64",
"cp311-macosx_x86_64",
"cp310-macosx_arm64",
"cp311-macosx_arm64"]

skip = ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "*-musllinux-*", "pp*"]
test-requires = "pytest"
test-command = "pytest {project}/tests"
test-skip = ["*-macosx_arm64, *-macosx_universal2:arm64", "*-*linux_{aarch64,ppc64le,s390x}"]

[tool.cibuildwheel.macos]
before-all = [
"git clone https://github.com/JohannesBuchner/MultiNest",
"cd MultiNest/build",
"cmake ..",
"make"
]
environment = {LD_LIBRARY_PATH="/home/runner/work/ompy/ompy/MultiNest/lib", MACOSX_DEPLOYMENT_TARGET="10.14", FC="/usr/local/bin/gfortran-11"}

[tool.cibuildwheel.linux]
before-all = [
"yum -y install blas-devel lapack-devel",
"git clone https://github.com/JohannesBuchner/MultiNest",
"cd MultiNest/build",
"cmake ..",
"make install"
]
environment = {LD_LIBRARY_PATH="/usr/local/lib"}
2 changes: 2 additions & 0 deletions release_note.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Changed:
- Fixed a bug where the `std` attribute of `Vector` was not saved to file.
- Reimplemented PPF for normal distribution and truncated normal distribution in C++ for improved performance (about 300% faster than the SciPy implementation!).
- Fixed a potential bug where `units` attribute is set erroniously when reading the discrete level density from file (`load_levels_discrete` and `load_levels_discrete_smooth`).
- Moved example data to the source folder such that they are distributed with the package and avalible regardless of if OMpy is installed with `-e` option or not.
- Source code for the `ompy.stats` sublibrary now lives in the `ompy` folder.

Deprecated:
- `shape` argument of Matrix for creation of a matrix filled with zeros. Use `ZerosMatrix` instead.
Expand Down
50 changes: 41 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from ctypes.util import find_library
from pybind11.setup_helpers import Pybind11Extension

try:
import wheel.bdist_wheel
except ImportError:
wheel = None

try:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
Expand Down Expand Up @@ -108,10 +113,15 @@ def write_version_py(filename='ompy/version_setup.py'):
'git_revision': GIT_REVISION})
finally:
a.close()
write_version_py()
try:
write_version_py()
except:
pass

# If macOS, use ctypes.util.find_library to determine if OpenMP is avalible.
openmp = os.getenv("ompy_OpenMP")
if wheel is not None: # We do not build with OpenMP if wheel
openmp = False
if openmp is None and platform.system() == 'Darwin': # Check if macOS
if find_library("omp") != None:
openmp = True
Expand All @@ -131,7 +141,7 @@ def write_version_py(filename='ompy/version_setup.py'):
if os.path.exists(fname):
os.remove(fname)

extra_compile_args = ["-O3", "-ffast-math", "-march=native"]
extra_compile_args = ["-O3"]
extra_link_args = []
if openmp and platform.system() == 'Darwin':
extra_compile_args.insert(-1, "-Xpreprocessor -fopenmp")
Expand All @@ -144,8 +154,8 @@ def write_version_py(filename='ompy/version_setup.py'):
Extension("ompy.decomposition",
["ompy/decomposition.pyx"],
# on MacOS the clang compiler pretends not to support OpenMP, but in fact it does so
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
#extra_compile_args=extra_compile_args,
#extra_link_args=extra_link_args,
include_dirs=[numpy.get_include()]
),
Extension("ompy.rebin", ["ompy/rebin.pyx"], include_dirs=[numpy.get_include()]),
Expand All @@ -154,7 +164,7 @@ def write_version_py(filename='ompy/version_setup.py'):

ext_modules_pybind11 = [
Pybind11Extension("ompy.stats",
["src/stats.cpp"],
["ompy/stats/stats.cpp"],
cxx_std=20,
extra_compile_args=["-O3"]),
Pybind11Extension("ompy.rhosigchi",
Expand All @@ -177,20 +187,42 @@ def write_version_py(filename='ompy/version_setup.py'):
"pybind11>=2.6.0"
]

setup(name='OMpy',
version=get_version_info()[0],
def read_version():
try:
with open("ompy/version_setup.py") as f:
ns = {}
exec(f.read(), ns)
version = ns["full_version"]
return version
except FileNotFoundError:
return VERSION

try:
version = get_version_info()[0]
except:
version = read_version()


setup(name='ompy',
version=version,
author="Jørgen Eriksson Midtbø, Fabio Zeiser, Erlend Lima",
author_email=("[email protected], "
"[email protected], "
"[email protected]"),
url="https://github.com/oslocyclotronlab/ompy",
packages=find_packages(),
python_requires=">= 3.8",
packages=['ompy', 'ompy.examples', 'ompy.stats', 'ompy.introspection'],
package_data={
"ompy": ["decomposition.pyx", "rebin.pyx", "gauss_smoothing.pyx"],
"ompy.stats": ['*.hpp'],
"ompy.examples": ['*.m']
},
ext_modules=cythonize(ext_modules,
compiler_directives={'language_level': "3",
'embedsignature': True},
compile_time_env={"OPENMP": openmp}
)+ext_modules_pybind11,
zip_safe=False,
install_requires=install_requires
setup_requires=["cython", "numpy>=1.20.0", "pybind11>=2.6.0"]
)