Skip to content
Merged
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
17 changes: 9 additions & 8 deletions .github/workflows/ismrmrd_python_conda.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
on:
push:
branches: [master]
tags: ["v*.*.*"]
pull_request:
branches:
- master
release:
types:
- created
branches: [master]
workflow_dispatch:

jobs:
build-conda-packages:
Expand All @@ -13,12 +13,13 @@ jobs:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- uses: conda-incubator/setup-miniconda@e81abac10ce2c37423b54eae5af93aa3b4d3475c
- uses: actions/checkout@v5
- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
activate-environment: ismrmrd-python-build
environment-file: conda/environment.yml
python-version: 3.9
python-version: 3.12
auto-activate-base: false
- name: Build conda package
shell: bash -l {0}
Expand Down
51 changes: 24 additions & 27 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
release:
types:
- created
on:
push:
branches: [master]
tags: ["v*.*.*"]
pull_request:
branches: [master]
workflow_dispatch:

jobs:
build:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.9
uses: actions/setup-python@v1
- uses: actions/checkout@v5
- name: Set up Python 3.x
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- name: Install runtime dependencies
run: python -m pip install -r requirements.txt --user
- name: Perform editable installation to generate the schema subpackage
run: python -m pip install -e .
- name: Run all tests
run: python -m pytest
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
run: python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
run: python -m build --sdist --wheel --outdir dist/ .
- name: Store the distribution packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' # only publish to PyPI on tag pushes or manual trigger
name: Publish Python 🐍 distribution 📦 to PyPI
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/ismrmrmd
url: https://pypi.org/p/ismrmrmd
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v5
with:
name: python-package-distributions
path: dist/
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions conda/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
python:
- 3.9
- 3.10
- 3.10
- 3.12
10 changes: 4 additions & 6 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ source:
requirements:
build:
- python {{ python }}
- xsdata >=24.0
- xsdata>=24.0
- setuptools
- wheel
- jinja2 >=2.11.0
- pip

run:
- python
- numpy>=1.22.0
Expand All @@ -29,10 +27,10 @@ test:
- tests
commands:
- pip check
- nosetests
- pytest
requires:
- pip
- nose
- pytest

about:
home: https://github.com/ismrmrd/ismrmrd-python
Expand Down
4 changes: 1 addition & 3 deletions conda/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

set -euo pipefail

cd tests
nosetests

pytest
4 changes: 2 additions & 2 deletions ismrmrd/xsd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .pyxb_compat import (CreateFromDocument, ToXML, ToDOM)
from .ismrmrdschema import *
from .pyxb_compat import CreateFromDocument, ToXML, ToDOM
from .ismrmrdschema import *
30 changes: 28 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
[build-system]
requires = ["setuptools","wheel","xsdata[cli]","jinja2 >= 2.11.0"]
build-backend = "setuptools.build_meta"
requires = ["setuptools", "xsdata[cli]"]
build-backend = "setuptools.build_meta"

[project]
name = "ismrmrd"
dynamic = ["version"]
dependencies = ["h5py>=2.3", "numpy>=1.22.0", "xsdata>=22.12"]
requires-python = ">=3.9"

authors = [{name = "ISMRMRD Developers"}]

description = "Python implementation of ISMRMRD"
readme = "README.md"
license-files = ["LICENSE"]
license = "LicenseRef-IsmrmrdSoftwareLicense"
keywords = ["ismrmrd"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Medical Science Apps."
]

[project.urls]
Homepage = "https://github.com/ismrmrd/ismrmrd-python"
Documentation = "https://github.com/ismrmrd/ismrmrd-python"
Repository = "https://github.com/ismrmrd/ismrmrd-python"
10 changes: 4 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
h5py==2.9.0
nose==1.3.7
numpy==1.22.0
PyXB==1.2.6
six==1.12.0
xsdata==24.4
h5py==3.14.0
pytest==8.4.1
numpy==2.3.2
xsdata==25.7
109 changes: 51 additions & 58 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,74 @@
import os
from setuptools import setup, find_packages
from distutils.command.build import build
from distutils.command.build_py import build_py
from setuptools import setup, find_packages, Command

import logging
import shutil
from pathlib import Path
import re

logging.basicConfig()
log_ = logging.getLogger(__name__)
import re

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

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


generate_schema(schema_file, config_file, outloc)
# distutils uses old-style classes, so no super()
build_py.run(self)
import setuptools.command.build
setuptools.command.build.build.sub_commands.append(("generate_schema", None))

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

def fix_init_file(package_name,filepath):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.build_lib = None
self.editable_mode = False

with open(filepath,'r+') as f:
text = f.read()
text = re.sub(f'from {package_name}.ismrmrd', 'from .ismrmrd',text)
f.seek(0)
f.write(text)
f.truncate()
def initialize_options(self):
pass

def finalize_options(self):
# Set build_lib for non-editable installs
self.set_undefined_options("build_py", ("build_lib", "build_lib"))

def run(self):
# Use editable_mode if present (PEP 660)
if self.editable_mode:
outdir = 'ismrmrd/xsd/'
else:
outdir = os.path.join(self.build_lib, 'ismrmrd/xsd/')
self.announce(f'Generating schema to {outdir} (editable_mode={self.editable_mode})', level=3)
self.generate_schema(schema_file, config_file, 'ismrmrdschema', outdir)

def get_source_files(self):
return [schema_file, config_file]

def generate_schema(schema_filename, config_filename, outloc ):
def to_uri(filename):
return Path(filename).absolute().as_uri()
def get_outputs(self):
return [
"{build_lib}/ismrmrd/xsd/ismrmrdschema/__init__.py",
"{build_lib}/ismrmrd/xsd/ismrmrdschema/ismrmrd.py"
]

import sys
import subprocess

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

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

setup(
name='ismrmrd',
version='1.14.1',

Choose a reason for hiding this comment

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

Shouldn't the version be bumped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally, yes, but this project's version has historically followed the version of the main C++ implementation.

So, the version will bump to 1.14.2 in the next PR when I add the ProtocolSerializer, bringing the API to feature parity with the C++ library.

author='ISMRMRD Developers',
description='Python implementation of the ISMRMRD',
license='Public Domain',
keywords='ismrmrd',
url='https://ismrmrd.github.io',
long_description = long_description,
long_description_content_type='text/markdown',
packages=find_packages(),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: Public Domain',
'Operating System :: OS Independent',
'Topic :: Scientific/Engineering :: Medical Science Apps.'
],
install_requires=['xsdata>=22.12', 'numpy>=1.22.0', 'h5py>=2.3'],
setup_requires=['nose>=1.0', 'xsdata[cli]>=22.12', 'jinja2 >= 2.11'],
test_suite='nose.collector',
cmdclass={'build_py':my_build_py}
cmdclass={
'generate_schema': GenerateSchemaCommand
}
)
Loading
Loading