Skip to content

Commit

Permalink
Ensure external.py is generated at the right time
Browse files Browse the repository at this point in the history
build_ext is called after build_py, and only the files in build_py
are picked in the package. Since we generate external.py during cmake
configuration, move this step inside the build_py step
  • Loading branch information
Luthaf committed Aug 29, 2022
1 parent 8e411bd commit 6bba669
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rm -rf .coverage
rm -rf src/chemfiles.egg-info
rm -rf doc/_build

rm -rf chemfiles/*.dylib
rm -rf chemfiles/*.so
rm -rf chemfiles/*.dll
rm -rf chemfiles/external.py
rm -rf src/chemfiles/*.dylib
rm -rf src/chemfiles/*.so
rm -rf src/chemfiles/*.dll
rm -rf src/chemfiles/external.py
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from setuptools import Extension, setup
from wheel.bdist_wheel import bdist_wheel

from distutils.command.build_py import build_py # type: ignore isort: skip
from distutils.command.build_ext import build_ext # type: ignore isort: skip
from distutils.command.install import install as distutils_install # type: ignore isort: skip

Expand Down Expand Up @@ -44,10 +45,8 @@ def get_tag(self):
return ("py2.py3", "none") + tag[2:]


class cmake_ext(build_ext):
"""
Build the native library using cmake
"""
class cmake_configure(build_py):
"""configure cmake to build chemfiles and generate external.py"""

def run(self):
source_dir = ROOT
Expand Down Expand Up @@ -80,6 +79,17 @@ def run(self):
cwd=build_dir,
check=True,
)

return super().run()


class cmake_build(build_ext):
"""build and install chemfiles with cmake"""

def run(self):
source_dir = ROOT
build_dir = os.path.join(ROOT, "build", "cmake-build")

subprocess.run(
[CMAKE_EXECUTABLE, "--build", build_dir, "--target", "install"],
check=True,
Expand Down Expand Up @@ -112,7 +122,8 @@ def _get_lib_ext():
Extension(name="chemfiles", sources=[]),
],
cmdclass={
"build_ext": cmake_ext,
"build_py": cmake_configure,
"build_ext": cmake_build,
"bdist_wheel": universal_wheel,
# HACK: do not use the new setuptools install implementation, it tries
# to install the package with `easy_install`, which fails to resolve the
Expand Down

0 comments on commit 6bba669

Please sign in to comment.