Skip to content

Commit

Permalink
EXPERIMENT: play with cython's dependency resolution
Browse files Browse the repository at this point in the history
Patching up Cython.Build via the included cython.patch,
then running `python setup.py build_ext -i`, and walking the stack in pdb,
can get:

(Pdb) p deps.cimported_files('observable.pyx')
('observable.pxd',)
(Pdb) p deps.included_files('observable.pyx')
{'foobar.pxi'}

So that should be enough to cook up a depfile for `observable.pyx` from this?
  • Loading branch information
ev-br committed Jul 31, 2021
1 parent 4aece2a commit 818f466
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mc_lib/cython.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$ git diff
diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
index ae491c7c6..9f863b2b7 100644
--- a/Cython/Build/Dependencies.py
+++ b/Cython/Build/Dependencies.py
@@ -990,6 +990,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
deps = create_dependency_tree(ctx, quiet=quiet)
build_dir = getattr(options, 'build_dir', None)

+ import pdb; pdb.set_trace()
+
def copy_to_build_dir(filepath, root=os.getcwd()):
filepath_abs = os.path.abspath(filepath)
if os.path.isabs(filepath):

3 changes: 3 additions & 0 deletions mc_lib/foobar.pxi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def foo():
return None
2 changes: 2 additions & 0 deletions mc_lib/observable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import numpy as np
from .observable cimport ScalarObservable
from .observable cimport trampoline_mrg

include "foobar.pxi"

cdef class RealObservable():

def __cinit__(self):
Expand Down
6 changes: 6 additions & 0 deletions mc_lib/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from setuptools import setup
from Cython.Build import cythonize

setup(
ext_modules = cythonize("observable.pyx")
)

0 comments on commit 818f466

Please sign in to comment.