From df83ca3da8c309cd0f53ad14aab2a3553ee04447 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 16 May 2024 22:51:13 -0700 Subject: [PATCH] Fix Py Extensions & Install `.pyi` Files - The python runtime extension files did shadow the actual pybind classes we declare for `ImpactXParIter` and a few others, because the module name was the same. - `.pyi` stub files were not yet installed. --- setup.py | 20 +----- src/python/impactx/ImpactXParIter.pyi | 69 ------------------- .../impactx/ImpactXParticleContainer.pyi | 38 ---------- src/python/impactx/__init__.py | 6 +- .../{ => extensions}/ImpactXParIter.py | 0 .../ImpactXParticleContainer.py | 0 src/python/impactx/extensions/__init__.py | 0 7 files changed, 7 insertions(+), 126 deletions(-) delete mode 100644 src/python/impactx/ImpactXParIter.pyi delete mode 100644 src/python/impactx/ImpactXParticleContainer.pyi rename src/python/impactx/{ => extensions}/ImpactXParIter.py (100%) rename src/python/impactx/{ => extensions}/ImpactXParticleContainer.py (100%) create mode 100644 src/python/impactx/extensions/__init__.py diff --git a/setup.py b/setup.py index 1e4f11898..306ca79a3 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def initialize_options(self): def run(self): # remove existing build directory # by default, this stays around. we want to make sure generated - # files like libwarpx.(2d|3d|rz).(so|pyd) are always only the + # files like libimpactx.(so|pyd) are always only the # ones we want to package and not ones from an earlier wheel's stage if os.path.exists(self.build_base): shutil.rmtree(self.build_base) @@ -37,23 +37,9 @@ def run(self): # call superclass build.run(self) - # matches: impactx_pybind.*.(so|pyd) - re_libprefix = re.compile(r"impactx_pybind\..*\.(?:so|pyd)") - libs_found = [] - for lib_name in os.listdir(PYIMPACTX_libdir): - if re_libprefix.match(lib_name): - lib_path = os.path.join(PYIMPACTX_libdir, lib_name) - libs_found.append(lib_path) - if len(libs_found) == 0: - raise RuntimeError( - "Error: no pre-build pyImpactX libraries found in " - "PYIMPACTX_libdir='{}'".format(PYIMPACTX_libdir) - ) - - # copy external libs into collection of files in a temporary build dir + # copy Python module artifacts and sources dst_path = os.path.join(self.build_lib, "impactx") - for lib_path in libs_found: - shutil.copy(lib_path, dst_path) + shutil.copytree(PYIMPACTX_libdir, dst_path, dirs_exist_ok=True) class CMakeExtension(Extension): diff --git a/src/python/impactx/ImpactXParIter.pyi b/src/python/impactx/ImpactXParIter.pyi deleted file mode 100644 index 5757d68dd..000000000 --- a/src/python/impactx/ImpactXParIter.pyi +++ /dev/null @@ -1,69 +0,0 @@ -""" - -This file is part of ImpactX - -Copyright 2023 ImpactX contributors -Authors: Axel Huebl -License: BSD-3-Clause-LBNL -""" - -from __future__ import annotations - -__all__ = [ - "register_ImpactXParIter_extension", - "soa", - "soa_int_comps", - "soa_real_comps", -] - -def register_ImpactXParIter_extension(impactx_pybind): - """ - ImpactXParIter helper methods - """ - -def soa(self): - """ - Get the StructOfArrays on the current tile - - Parameters - ---------- - self : ImpactXParIter or ImpactXParConstIter - used to query particle container component names - - """ - -def soa_int_comps(pti, num_comps): - """ - - Name the ImpactX int components in SoA. - - Parameters - ---------- - pti : ImpactXParIter or ImpactXParConstIter - used to query particle container component names - num_comps : int - number of components to generate names for. - - Returns - ------- - A list of length num_comps with values. - - """ - -def soa_real_comps(pti, num_comps): - """ - - Name the ImpactX ParticleReal components in SoA. - - Parameters - ---------- - pti : ImpactXParIter or ImpactXParConstIter - used to query particle container component names - num_comps : int - number of components to generate names for. - - Returns - ------- - A list of length num_comps with values. - - """ diff --git a/src/python/impactx/ImpactXParticleContainer.pyi b/src/python/impactx/ImpactXParticleContainer.pyi deleted file mode 100644 index dfb5ebefa..000000000 --- a/src/python/impactx/ImpactXParticleContainer.pyi +++ /dev/null @@ -1,38 +0,0 @@ -""" - -This file is part of ImpactX - -Copyright 2023 ImpactX contributors -Authors: Axel Huebl -License: BSD-3-Clause-LBNL -""" - -from __future__ import annotations - -__all__ = ["ix_pc_plot_mpl_phasespace", "register_ImpactXParticleContainer_extension"] - -def ix_pc_plot_mpl_phasespace(self, num_bins=50, root_rank=0): - """ - - Plot the longitudinal and transverse phase space projections with matplotlib. - - Parameters - ---------- - self : ImpactXParticleContainer_* - The particle container class in ImpactX - num_bins : int, default=50 - The number of bins for spatial and momentum directions per plot axis. - root_rank : int, default=0 - MPI root rank to reduce to in parallel runs. - - Returns - ------- - A matplotlib figure with containing the plot. - For MPI-parallel ranks, the figure is only created on the root_rank. - - """ - -def register_ImpactXParticleContainer_extension(ixpc): - """ - ImpactXParticleContainer helper methods - """ diff --git a/src/python/impactx/__init__.py b/src/python/impactx/__init__.py index 777be3cd0..420de40ce 100644 --- a/src/python/impactx/__init__.py +++ b/src/python/impactx/__init__.py @@ -18,9 +18,11 @@ # import core bindings to C++ from . import impactx_pybind as cxx +from .extensions.ImpactXParIter import register_ImpactXParIter_extension +from .extensions.ImpactXParticleContainer import ( + register_ImpactXParticleContainer_extension, +) from .impactx_pybind import * # noqa -from .ImpactXParIter import register_ImpactXParIter_extension -from .ImpactXParticleContainer import register_ImpactXParticleContainer_extension from .madx_to_impactx import read_beam, read_lattice # noqa __version__ = cxx.__version__ diff --git a/src/python/impactx/ImpactXParIter.py b/src/python/impactx/extensions/ImpactXParIter.py similarity index 100% rename from src/python/impactx/ImpactXParIter.py rename to src/python/impactx/extensions/ImpactXParIter.py diff --git a/src/python/impactx/ImpactXParticleContainer.py b/src/python/impactx/extensions/ImpactXParticleContainer.py similarity index 100% rename from src/python/impactx/ImpactXParticleContainer.py rename to src/python/impactx/extensions/ImpactXParticleContainer.py diff --git a/src/python/impactx/extensions/__init__.py b/src/python/impactx/extensions/__init__.py new file mode 100644 index 000000000..e69de29bb