From 7cbff9625259ae46dcf74f3c98db1b5995eb851b Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Fri, 21 Jul 2023 19:08:44 -0700 Subject: [PATCH] fix sdist build error ValueError: 'chgnet/graph/cygraph.pyx' doesn't match any files File "/tmp/build-env-d_rbfy8m/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 119, in nonempty raise ValueError(error_msg) ValueError: 'chgnet/graph/cygraph.pyx' doesn't match any files ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel --- .github/workflows/test.yml | 2 ++ setup.py | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b730b31f..90dbaf78 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,6 +36,8 @@ jobs: - name: Install dependencies run: | + pip install cython + python setup.py build_ext --inplace pip install -e .[test] - name: Run Tests diff --git a/setup.py b/setup.py index 49d04efa..3715b9f6 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,22 @@ from __future__ import annotations -from Cython.Build import cythonize from setuptools import Extension, setup +from setuptools.command.build_ext import build_ext -extensions = cythonize( - [Extension("chgnet.graph.cygraph", ["chgnet/graph/cygraph.pyx"])] -) -setup(ext_modules=extensions) +class BuildExt(build_ext): + """Custom build extension.""" + + def finalize_options(self): + """Override finalize_options to ensure we don't run cythonize when making + a source distribution. + """ + import Cython.Build + + self.distribution.ext_modules = Cython.Build.cythonize( + [Extension("chgnet.graph.cygraph", ["chgnet/graph/cygraph.pyx"])] + ) + super().finalize_options() + + +setup(cmdclass={"build_ext": BuildExt})