From 467098e671f3310106dd3a451befe1e1ae21820b Mon Sep 17 00:00:00 2001 From: Vincent Pinon Date: Fri, 20 Aug 2021 16:59:17 +0200 Subject: [PATCH 1/2] Install and develop XDM as a standard python module one can install with `python3 setup.py install [--user]` or develop with `python3 -m pip install -e . [--user] [--no-clean]` --- .gitignore | 5 +++++ setup.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ src/python/xdm.py.in | 15 ++++++++------ 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 3afa929..533609f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,8 @@ build/ # ignore CLion builds cmake-build-*/ + +xdm_bdl.egg-info +*.so +src/python/xdm_bdl.py +dist diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f18a3cb --- /dev/null +++ b/setup.py @@ -0,0 +1,49 @@ +from setuptools import setup, Extension, find_packages +import setuptools.command.build_py +import os + +XDM_VERSION = "2.4.0" + +class config_build(setuptools.command.build_py.build_py): + def run(self): + source_file = os.path.join(os.path.dirname(__file__), + "src", "python", "xdm.py.in") + with open(source_file, 'r') as fi: + src_data = fi.read() + target_file = os.path.join(os.path.dirname(__file__), + "src", "python", "xdm_bdl.py") + with open(target_file, 'w') as fo: + fo.write(src_data.replace( + "@XDM_MAJOR_VERSION@.@XDM_MINOR_VERSION@.@XDM_PATCH_VERSION@", + XDM_VERSION)) + setuptools.command.build_py.build_py.run(self) + +setup( name = 'xdm_bdl', + version = XDM_VERSION, + description = 'Xyce(TM) XDM Netlist Translator', + author = 'National Technology & Engineering Solutions of Sandia, LLC', + ext_modules = [ + Extension('XdmRapidXmlReader', + include_dirs = ['src/c_boost/xml/rapidxml/rapidxml-1.13'], + libraries = ['boost_python3-mt'], + sources = ['src/c_boost/xml/xdm_rapid.cpp']), + Extension('SpiritExprCommon', + libraries = ['boost_python3-mt'], + sources = ['src/c_boost/expr/expr_parser_interface.cpp', + 'src/c_boost/expr/hspice_expr_parser_interface.cpp', + 'src/c_boost/expr/spectre_expr_parser_interface.cpp']), + Extension('SpiritCommon', + libraries = ['boost_python3-mt'], + sources = ['src/c_boost/xyce/parser_interface.cpp', + 'src/c_boost/xyce/xyce_parser_interface.cpp', + 'src/c_boost/xyce/hspice_parser_interface.cpp', + 'src/c_boost/xyce/spectre_parser_interface.cpp', + 'src/c_boost/xyce/pspice_parser_interface.cpp', + 'src/c_boost/xyce/tspice_parser_interface.cpp']) + ], + package_dir={'': 'src/python'}, + packages=find_packages(where='src/python'), + package_data={'': ['schema/*.xml'],}, + scripts=['src/python/xdm_bdl.py'], + cmdclass={'build_py': config_build,}, + ) diff --git a/src/python/xdm.py.in b/src/python/xdm.py.in index 713e80f..a06b6eb 100644 --- a/src/python/xdm.py.in +++ b/src/python/xdm.py.in @@ -35,6 +35,7 @@ import types # from copy import deepcopy # from collections import OrderedDict # from pprint import pformat +import xdm from xdm.errorHandling.CallCount import CallCount from xdm.index.DEVICES_INDEX import DEVICES_INDEX from xdm.index.SRC_LINE_INDEX import SRC_LINE_INDEX @@ -120,7 +121,7 @@ def get_value(current_device): return 'Unknown' -base_path = execDirName +base_path = os.path.dirname(xdm.__file__) xdm_mod_date = str(modification_date(sys.executable)) parser = argparse.ArgumentParser( @@ -214,12 +215,14 @@ origin_combine_off_dict = { 'spectre': True } +xml_path = os.path.join(os.path.dirname(xdm.inout.xml.__file__), "schema/") + xml_files = { - 'xyce': os.path.join(base_path, "xyce.xml"), - 'pspice': os.path.join(base_path, "pspice.xml"), - 'hspice': os.path.join(base_path, "hspice.xml"), - 'tspice': os.path.join(base_path, "tspice.xml"), - 'spectre': os.path.join(base_path, "spectre.xml") + 'xyce': os.path.join(xml_path, "xyce.xml"), + 'pspice': os.path.join(xml_path, "pspice.xml"), + 'hspice': os.path.join(xml_path, "hspice.xml"), + 'tspice': os.path.join(xml_path, "tspice.xml"), + 'spectre': os.path.join(xml_path, "spectre.xml") } pspice_xml = xml_files['pspice'] From a884b41915775e7dda2f339e4a7acae2c2e14959 Mon Sep 17 00:00:00 2001 From: Vincent Pinon Date: Sun, 27 Mar 2022 21:21:42 +0200 Subject: [PATCH 2/2] fix script patching step --- setup.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index f18a3cb..f462fb6 100644 --- a/setup.py +++ b/setup.py @@ -1,22 +1,31 @@ from setuptools import setup, Extension, find_packages -import setuptools.command.build_py +from setuptools.command.install_scripts import install_scripts +from setuptools.command.develop import develop import os XDM_VERSION = "2.4.0" -class config_build(setuptools.command.build_py.build_py): +def set_xdm_version(): + source_file = os.path.join(os.path.dirname(__file__), + "src", "python", "xdm.py.in") + with open(source_file, 'r') as fi: + src_data = fi.read() + target_file = os.path.join(os.path.dirname(__file__), + "src", "python", "xdm_bdl.py") + with open(target_file, 'w') as fo: + fo.write(src_data.replace( + "@XDM_MAJOR_VERSION@.@XDM_MINOR_VERSION@.@XDM_PATCH_VERSION@", + XDM_VERSION)) + +class install_xdm(install_scripts): + def run(self): + set_xdm_version() + install_scripts.run(self) + +class develop_xdm(develop): def run(self): - source_file = os.path.join(os.path.dirname(__file__), - "src", "python", "xdm.py.in") - with open(source_file, 'r') as fi: - src_data = fi.read() - target_file = os.path.join(os.path.dirname(__file__), - "src", "python", "xdm_bdl.py") - with open(target_file, 'w') as fo: - fo.write(src_data.replace( - "@XDM_MAJOR_VERSION@.@XDM_MINOR_VERSION@.@XDM_PATCH_VERSION@", - XDM_VERSION)) - setuptools.command.build_py.build_py.run(self) + set_xdm_version() + develop.run(self) setup( name = 'xdm_bdl', version = XDM_VERSION, @@ -45,5 +54,5 @@ def run(self): packages=find_packages(where='src/python'), package_data={'': ['schema/*.xml'],}, scripts=['src/python/xdm_bdl.py'], - cmdclass={'build_py': config_build,}, + cmdclass={'install_scripts': install_xdm, 'develop': develop_xdm}, )