Skip to content

Commit a29ddb4

Browse files
authored
Merge pull request #81 from ismrmrd/naegelejd/update-pipeline
Update build pipeline and switch to pytest
2 parents b93bc1b + 684b40a commit a29ddb4

File tree

16 files changed

+298
-515
lines changed

16 files changed

+298
-515
lines changed

.github/workflows/ismrmrd_python_conda.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
on:
2+
push:
3+
branches: [master]
4+
tags: ["v*.*.*"]
25
pull_request:
3-
branches:
4-
- master
5-
release:
6-
types:
7-
- created
6+
branches: [master]
7+
workflow_dispatch:
88

99
jobs:
1010
build-conda-packages:
@@ -13,12 +13,13 @@ jobs:
1313
os: [ubuntu-latest, macos-latest]
1414
runs-on: ${{ matrix.os }}
1515
steps:
16-
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
17-
- uses: conda-incubator/setup-miniconda@e81abac10ce2c37423b54eae5af93aa3b4d3475c
16+
- uses: actions/checkout@v5
17+
- uses: conda-incubator/setup-miniconda@v3
1818
with:
19+
miniforge-version: latest
1920
activate-environment: ismrmrd-python-build
2021
environment-file: conda/environment.yml
21-
python-version: 3.9
22+
python-version: 3.12
2223
auto-activate-base: false
2324
- name: Build conda package
2425
shell: bash -l {0}

.github/workflows/python-publish.yml

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,53 @@
11
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
22

3-
on:
4-
release:
5-
types:
6-
- created
3+
on:
4+
push:
5+
branches: [master]
6+
tags: ["v*.*.*"]
7+
pull_request:
8+
branches: [master]
79
workflow_dispatch:
810

911
jobs:
1012
build:
1113
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
12-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
1315
steps:
14-
- uses: actions/checkout@master
15-
- name: Set up Python 3.9
16-
uses: actions/setup-python@v1
16+
- uses: actions/checkout@v5
17+
- name: Set up Python 3.x
18+
uses: actions/setup-python@v5
1719
with:
18-
python-version: 3.9
20+
python-version: 3.12
21+
- name: Install runtime dependencies
22+
run: python -m pip install -r requirements.txt --user
23+
- name: Perform editable installation to generate the schema subpackage
24+
run: python -m pip install -e .
25+
- name: Run all tests
26+
run: python -m pytest
1927
- name: Install pypa/build
20-
run: >-
21-
python -m
22-
pip install
23-
build
24-
--user
28+
run: python -m pip install build --user
2529
- name: Build a binary wheel and a source tarball
26-
run: >-
27-
python -m
28-
build
29-
--sdist
30-
--wheel
31-
--outdir dist/
32-
.
30+
run: python -m build --sdist --wheel --outdir dist/ .
3331
- name: Store the distribution packages
34-
uses: actions/upload-artifact@v3
32+
uses: actions/upload-artifact@v4
3533
with:
3634
name: python-package-distributions
3735
path: dist/
3836

3937
publish-to-pypi:
40-
name: >-
41-
Publish Python 🐍 distribution 📦 to PyPI
42-
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' # only publish to PyPI on tag pushes or manual trigger
38+
name: Publish Python 🐍 distribution 📦 to PyPI
39+
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
4340
needs:
4441
- build
4542
runs-on: ubuntu-latest
4643
environment:
4744
name: pypi
48-
url: https://pypi.org/p/ismrmrmd
45+
url: https://pypi.org/p/ismrmrmd
4946
permissions:
5047
id-token: write
5148
steps:
5249
- name: Download all the dists
53-
uses: actions/download-artifact@v3
50+
uses: actions/download-artifact@v5
5451
with:
5552
name: python-package-distributions
5653
path: dist/

README renamed to README.md

File renamed without changes.

conda/conda_build_config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
python:
2-
- 3.9
3-
- 3.10
2+
- 3.10
3+
- 3.12

conda/meta.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ source:
1010
requirements:
1111
build:
1212
- python {{ python }}
13-
- xsdata >=24.0
13+
- xsdata>=24.0
1414
- setuptools
15-
- wheel
16-
- jinja2 >=2.11.0
1715
- pip
18-
16+
1917
run:
2018
- python
2119
- numpy>=1.22.0
@@ -29,10 +27,10 @@ test:
2927
- tests
3028
commands:
3129
- pip check
32-
- nosetests
30+
- pytest
3331
requires:
3432
- pip
35-
- nose
33+
- pytest
3634

3735
about:
3836
home: https://github.com/ismrmrd/ismrmrd-python

conda/run_test.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
set -euo pipefail
44

5-
cd tests
6-
nosetests
7-
5+
pytest

ismrmrd/xsd/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .pyxb_compat import (CreateFromDocument, ToXML, ToDOM)
2-
from .ismrmrdschema import *
1+
from .pyxb_compat import CreateFromDocument, ToXML, ToDOM
2+
from .ismrmrdschema import *

pyproject.toml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
[build-system]
2-
requires = ["setuptools","wheel","xsdata[cli]","jinja2 >= 2.11.0"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["setuptools", "xsdata[cli]"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "ismrmrd"
7+
dynamic = ["version"]
8+
dependencies = ["h5py>=2.3", "numpy>=1.22.0", "xsdata>=22.12"]
9+
requires-python = ">=3.9"
10+
11+
authors = [{name = "ISMRMRD Developers"}]
12+
13+
description = "Python implementation of ISMRMRD"
14+
readme = "README.md"
15+
license-files = ["LICENSE"]
16+
license = "LicenseRef-IsmrmrdSoftwareLicense"
17+
keywords = ["ismrmrd"]
18+
classifiers = [
19+
"Development Status :: 5 - Production/Stable",
20+
"Programming Language :: Python :: 3",
21+
"Operating System :: OS Independent",
22+
"Intended Audience :: Science/Research",
23+
"Topic :: Scientific/Engineering :: Medical Science Apps."
24+
]
25+
26+
[project.urls]
27+
Homepage = "https://github.com/ismrmrd/ismrmrd-python"
28+
Documentation = "https://github.com/ismrmrd/ismrmrd-python"
29+
Repository = "https://github.com/ismrmrd/ismrmrd-python"

requirements.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
h5py==2.9.0
2-
nose==1.3.7
3-
numpy==1.22.0
4-
PyXB==1.2.6
5-
six==1.12.0
6-
xsdata==24.4
1+
h5py==3.14.0
2+
pytest==8.4.1
3+
numpy==2.3.2
4+
xsdata==25.7

setup.py

Lines changed: 51 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,74 @@
11
import os
2-
from setuptools import setup, find_packages
3-
from distutils.command.build import build
4-
from distutils.command.build_py import build_py
2+
from setuptools import setup, find_packages, Command
53

6-
import logging
74
import shutil
85
from pathlib import Path
9-
import re
10-
11-
logging.basicConfig()
12-
log_ = logging.getLogger(__name__)
6+
import re
137

148
schema_file = os.path.join('schema','ismrmrd.xsd')
159
config_file = os.path.join('schema','.xsdata.xml')
1610

17-
class my_build_py(build_py):
18-
def run(self):
19-
# honor the --dry-run flag
20-
if not self.dry_run:
21-
outloc = self.build_lib
22-
outloc = os.path.join(outloc,'ismrmrd/xsd/ismrmrdschema')
2311

24-
25-
generate_schema(schema_file, config_file, outloc)
26-
# distutils uses old-style classes, so no super()
27-
build_py.run(self)
12+
import setuptools.command.build
13+
setuptools.command.build.build.sub_commands.append(("generate_schema", None))
2814

15+
class GenerateSchemaCommand(Command):
16+
description = "Generate Python code from ISMRMRD XML schema using xsdata"
17+
user_options = []
2918

30-
def fix_init_file(package_name,filepath):
19+
def __init__(self, *args, **kwargs):
20+
super().__init__(*args, **kwargs)
21+
self.build_lib = None
22+
self.editable_mode = False
3123

32-
with open(filepath,'r+') as f:
33-
text = f.read()
34-
text = re.sub(f'from {package_name}.ismrmrd', 'from .ismrmrd',text)
35-
f.seek(0)
36-
f.write(text)
37-
f.truncate()
24+
def initialize_options(self):
25+
pass
3826

27+
def finalize_options(self):
28+
# Set build_lib for non-editable installs
29+
self.set_undefined_options("build_py", ("build_lib", "build_lib"))
3930

31+
def run(self):
32+
# Use editable_mode if present (PEP 660)
33+
if self.editable_mode:
34+
outdir = 'ismrmrd/xsd/'
35+
else:
36+
outdir = os.path.join(self.build_lib, 'ismrmrd/xsd/')
37+
self.announce(f'Generating schema to {outdir} (editable_mode={self.editable_mode})', level=3)
38+
self.generate_schema(schema_file, config_file, 'ismrmrdschema', outdir)
4039

40+
def get_source_files(self):
41+
return [schema_file, config_file]
4142

42-
def generate_schema(schema_filename, config_filename, outloc ):
43-
def to_uri(filename):
44-
return Path(filename).absolute().as_uri()
43+
def get_outputs(self):
44+
return [
45+
"{build_lib}/ismrmrd/xsd/ismrmrdschema/__init__.py",
46+
"{build_lib}/ismrmrd/xsd/ismrmrdschema/ismrmrd.py"
47+
]
4548

46-
import sys
47-
import subprocess
48-
49-
subpackage_name = 'ismrmrdschema'
50-
args = [sys.executable,'-m','xsdata', str(schema_filename), '--config',str(config_filename), '--package',subpackage_name]
51-
subprocess.run(args)
52-
fix_init_file(subpackage_name,f"{subpackage_name}/__init__.py")
53-
shutil.rmtree(os.path.join(outloc,subpackage_name),ignore_errors=True)
54-
shutil.move(subpackage_name,outloc)
49+
def fix_init_file(self, package_name,filepath):
50+
with open(filepath,'r+') as f:
51+
text = f.read()
52+
text = re.sub(f'from {package_name}.ismrmrd', 'from .ismrmrd',text)
53+
f.seek(0)
54+
f.write(text)
55+
f.truncate()
5556

56-
this_directory = Path(__file__).parent
57-
long_description = (this_directory / "README").read_text()
57+
def generate_schema(self, schema_filename, config_filename, subpackage_name, outdir):
58+
import sys
59+
import subprocess
60+
# subpackage_name = 'ismrmrdschema'
61+
args = [sys.executable, '-m', 'xsdata', str(schema_filename), '--config', str(config_filename), '--package', subpackage_name]
62+
subprocess.run(args)
63+
self.fix_init_file(subpackage_name, f"{subpackage_name}/__init__.py")
64+
destination = os.path.join(outdir, subpackage_name)
65+
shutil.rmtree(destination, ignore_errors=True)
66+
shutil.move(subpackage_name, destination)
5867

5968
setup(
60-
name='ismrmrd',
6169
version='1.14.1',
62-
author='ISMRMRD Developers',
63-
description='Python implementation of the ISMRMRD',
64-
license='Public Domain',
65-
keywords='ismrmrd',
66-
url='https://ismrmrd.github.io',
67-
long_description = long_description,
68-
long_description_content_type='text/markdown',
6970
packages=find_packages(),
70-
classifiers=[
71-
'Development Status :: 5 - Production/Stable',
72-
'Intended Audience :: Science/Research',
73-
'License :: Public Domain',
74-
'Operating System :: OS Independent',
75-
'Topic :: Scientific/Engineering :: Medical Science Apps.'
76-
],
77-
install_requires=['xsdata>=22.12', 'numpy>=1.22.0', 'h5py>=2.3'],
78-
setup_requires=['nose>=1.0', 'xsdata[cli]>=22.12', 'jinja2 >= 2.11'],
79-
test_suite='nose.collector',
80-
cmdclass={'build_py':my_build_py}
71+
cmdclass={
72+
'generate_schema': GenerateSchemaCommand
73+
}
8174
)

0 commit comments

Comments
 (0)