-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsetup.py
81 lines (64 loc) · 2.46 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
from setuptools import setup, find_packages
from distutils.command.build import build
from distutils.command.build_py import build_py
import logging
import shutil
from pathlib import Path
import re
logging.basicConfig()
log_ = logging.getLogger(__name__)
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)
def fix_init_file(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()
def generate_schema(schema_filename, config_filename, outloc ):
def to_uri(filename):
return Path(filename).absolute().as_uri()
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)
this_directory = Path(__file__).parent
long_description = (this_directory / "README").read_text()
setup(
name='ismrmrd',
version='1.14.1',
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}
)