-
Notifications
You must be signed in to change notification settings - Fork 29
Update build pipeline and switch to pytest #81
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| python: | ||
| - 3.9 | ||
| - 3.10 | ||
| - 3.10 | ||
| - 3.12 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,4 @@ | |
|
|
||
| set -euo pipefail | ||
|
|
||
| cd tests | ||
| nosetests | ||
|
|
||
| pytest | ||
| 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 * |
| 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" |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,81 +1,75 @@ | ||
| 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) | ||
| print(f"JOE: Moved {subpackage_name} to {destination}") | ||
naegelejd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| setup( | ||
| name='ismrmrd', | ||
| version='1.14.1', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the version be bumped?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.