Skip to content

Commit

Permalink
Fix Py Extensions & Install .pyi Files
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
ax3l committed May 17, 2024
1 parent 1cf07c2 commit df83ca3
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 126 deletions.
20 changes: 3 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,17 @@ 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)

# 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):
Expand Down
69 changes: 0 additions & 69 deletions src/python/impactx/ImpactXParIter.pyi

This file was deleted.

38 changes: 0 additions & 38 deletions src/python/impactx/ImpactXParticleContainer.pyi

This file was deleted.

6 changes: 4 additions & 2 deletions src/python/impactx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
File renamed without changes.
Empty file.

0 comments on commit df83ca3

Please sign in to comment.