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

refactor(build): change setup.py to pyproject.toml and supress cython warning #293

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 19 additions & 10 deletions .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.6'
python-version: '3.7'

- name: Install numpy
run: |
python3 -m pip install numpy
- name: git version
run: git --version

- name: Install dependencies
- name: Install hdf5 & netcdf & numpy
run: |
python3 -m pip install -r requirements.txt
sudo apt-get update
sudo apt-get install libhdf5-dev libnetcdf-dev
# This is a build time dependency of pygacode
# that it assumes to be installed
python3 -m pip install numpy

- name: Install OMAS
- name: Build & Install OMAS
run: |
python3 -m pip install .[machine]
python3 -m pip install build
python3 -m build --sdist
# TODO do not hard code version here
python3 -m pip install "./dist/omas-0.93.0.tar.gz[machine]"

- name: Move to root and try importing OMAS
run: |
Expand All @@ -43,4 +49,7 @@ jobs:

- name: Run OMAS tests
run: |
# TODO the tests pickup omas from the python files in the directory not the installed version
# so to make that work we run an editable install to create the omas_cython lib in the right place.
python3 -m pip install -e
make test
8 changes: 0 additions & 8 deletions .github/workflows/regression_no_munittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ jobs:
with:
python-version: '3.x'

- name: Install numpy
run: |
python3 -m pip install numpy

- name: Install dependencies
run: |
python3 -m pip install -r requirements.txt

- name: Install OMAS
run: |
python3 -m pip install .[machine]
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ tag:

sdist:
rm -rf dist
python3 setup.py sdist
python3 -m build --sdist

pypi: sdist
python3 -m twine upload --repository pypi dist/omas-$(VERSION).tar.gz
Expand Down
2 changes: 1 addition & 1 deletion omas/omas_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def get2d(contour_quantity):
z = scipy.ndimage.zoom(z, sf)
value_2d = scipy.ndimage.zoom(value_2d, sf)

cs = ax.contour(r, z, value_2d, levels, **kw)
cs = ax.contour(r, z, value_2d, levels=levels, **kw)

if label_contours or ((label_contours is None) and (contour_quantity == 'q')):
ax.clabel(cs)
Expand Down
18 changes: 1 addition & 17 deletions omas/omas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from .omas_setup import *
from .omas_setup import __version__
from .omas_cython import *
import sys

# --------------------------------------------
Expand Down Expand Up @@ -864,23 +865,6 @@ def omas_global_quantities(imas_version=omas_rcparams['default_imas_version']):
return _global_quantities[imas_version]


# only attempt cython if effective user owns this copy of omas
# disabled for Windows: need to add check for file ownership under Windows
if os.name == 'nt' or os.geteuid() != os.stat(__file__).st_uid:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change the compiled version of omas_cython should be available to everyone. Also windows users.

with open(os.path.split(__file__)[0] + os.sep + 'omas_cython.pyx', 'r') as f:
exec(f.read(), globals())
else:
try:
import pyximport

pyximport.install(language_level=3)
from .omas_cython import *
except Exception as _excp:
warnings.warn('omas cython failed: ' + str(_excp))
with open(os.path.split(__file__)[0] + os.sep + 'omas_cython.pyx', 'r') as f:
exec(f.read(), globals())


def l2ut(path):
"""
Formats IMAS time lists ['bla',0,'time_slice',5,'quantity'] with universal ODS path 'bla.0.time_slice.:.quantity'
Expand Down
67 changes: 67 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[build-system]
requires = ["setuptools", "Cython"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
where = ["."]
exclude = ["sphinx*"]

[tool.setuptools.package-data]
"*" = ["*.json", "*.dat"]
"omas.samples" = ["*"]
"omas"=["*.pyx"]

[tool.setuptools.dynamic]
version = {file = "omas/version"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This automatically sets the version to what is found in omas/version


[project]
name = 'omas'
dynamic = ["version"]
description = 'Ordered Multidimensional Array Structures'
authors = [
{name = 'Orso Meneghini', email = '[email protected]'},
]
classifiers = [
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'License :: OSI Approved :: MIT License',
]
keywords = ["integrated modeling", "OMFIT", "IMAS", "ITER"]

requires-python = '>=3.7'
dependencies = [
'numpy>=1.16.1',
'uncertainties',
'pint',
'netCDF4',
'boto3',
'matplotlib',
'scipy',
'h5py',
'pymongo',
'dnspython',
'xmltodict',
'xarray',
'tqdm',
]
readme="README.md"

[project.urls]
Homepage = 'https://gafusion.github.io/omas'
Source = 'https://github.com/gafusion/omas'

[project.optional-dependencies]
machine = [
'omfit_classes',
'pexpect',
'fortranformat',
'pygacode',
]
hdc = ['pyhdc']
imas = ['imas']
uda = ['pyuda']
build_sdist = ['build']
build_structures = ['bs4']
build_documentation = ['Sphinx', 'sphinx-bootstrap-theme', 'sphinx-gallery', 'Pillow']
128 changes: 3 additions & 125 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,128 +1,6 @@
import os
import sys
import glob
import subprocess

install_requires = [
'numpy>=1.16.1',
'uncertainties',
'pint',
'netCDF4',
'boto3',
'matplotlib',
'scipy',
'h5py',
'pymongo',
'dnspython',
'xmltodict',
'xarray',
'setuptools>=41.2',
'tqdm',
'Cython',
]

extras_require = {
'machine': [
'omfit_classes',
'pexpect',
'fortranformat',
'pygacode',
],
'hdc': ['pyhdc'],
'imas': ['imas'],
'uda': ['pyuda'],
'build_structures': ['bs4'],
'build_documentation': ['Sphinx', 'sphinx-bootstrap-theme', 'sphinx-gallery', 'Pillow'],
}

# Add .json IMAS structure files to the package
here = os.path.abspath(os.path.split(__file__)[0]) + os.sep

# Automatically generate requirement.txt file if this is the OMAS repo and requirements.txt is missing
if os.path.exists(here + '.git') and not os.path.exists(here + 'requirements.txt'):
with open(here + 'requirements.txt', 'w') as f:
f.write('# Do not edit this file by hand, operate on setup.py instead\n#\n')
f.write('# usage: pip install -r requirements.txt\n\n')
for item in install_requires:
f.write(item.ljust(25) + '# required\n')
for requirement in extras_require:
f.write('\n')
for item in extras_require[requirement]:
f.write('# ' + item.ljust(25) + '# %s\n' % requirement)

packages = ['omas', 'omas.examples', 'omas.samples', 'omas.tests', 'omas.utilities']
package_data = {
'omas': ['*.py', '*.pyx', 'version'],
'omas.examples': ['*.py'],
'omas.samples': ['*'],
'omas.tests': ['*.py'],
'omas.utilities': ['*.py'],
}

machine_mappings_dir = here + os.sep + 'omas' + os.sep + 'machine_mappings'
for item in glob.glob(os.sep.join([here, 'omas', 'imas_structures', '*'])):
packages.append('omas.imas_structures.' + os.path.split(item)[1])
package_data['omas.imas_structures.' + os.path.split(item)[1]] = ['*.json']
for retry in [1, 2]:
if os.path.exists(here + '.git') and retry == 1:
try:
tmp = f'pushd {machine_mappings_dir}; git ls-files; popd'
machine_mappings_files = subprocess.check_output(tmp, shell=True).decode("utf-8").strip().split('\n')[2:-1]
machine_mappings_files = ['omas' + os.sep + 'machine_mappings' + os.sep + k for k in machine_mappings_files]
except subprocess.CalledProcessError:
pass
else:
print("setup.py machine_mappings_files based on git")
break
else:
machine_mappings_files = []
for root, subdirs, files in os.walk(machine_mappings_dir):
root = root[len(machine_mappings_dir) + 1 :]
for file in reversed(files):
machine_mappings_files.append('omas' + os.sep + 'machine_mappings' + os.sep + root + os.sep + file)
dirs = {os.path.dirname(file): [] for file in sorted(machine_mappings_files)}
for file in machine_mappings_files:
dirs[os.path.dirname(file)].append(os.path.basename(file))
for dir in dirs:
packages.append(dir.replace('/', '.'))
package_data[dir.replace('/', '.')] = dirs[dir]

long_description = '''
OMAS is a Python library designed to simplify the interface of third-party codes with the `ITER <http://iter.org>`_ Integrated Modeling and Analysis Suite (`IMAS <https://confluence.iter.org/display/IMP>`_).

* It provides a **convenient Python API**

* capable of storing data with **different file/database formats**

* in a form that is **always compatible with the IMAS data model**

Mapping the physics codes I/O to the IMAS data model is done in third party Python codes such as the `OMFIT framework <https://omfit.io>`_.
'''

print()
print('INFO: optional dependencies:')
from pprint import pprint

pprint(extras_require)
print()
print('INFO: run the `imports_check.py` script to quickly verify that all Python dependencies for OMAS are installed')
print()

from setuptools import setup
from setuptools import Extension, setup
from Cython.Build import cythonize

setup(
name='omas',
version=open(here + 'omas/version', 'r').read().strip(),
description='Ordered Multidimensional Array Structures',
url='https://gafusion.github.io/omas',
author='Orso Meneghini',
license='MIT',
classifiers=['License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3'],
keywords='integrated modeling OMFIT IMAS ITER',
long_description=long_description,
long_description_content_type='text/markdown',
packages=packages,
package_data=package_data,
install_requires=install_requires,
extras_require=extras_require,
ext_modules = cythonize("omas/omas_cython.pyx")
)
Loading