New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow cythonize to recompile .py file when .pxd file has changed #4063
Allow cythonize to recompile .py file when .pxd file has changed #4063
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
It'd be nice to have a test for this feature. Unfortunately I don't think there's an existing test file to add it to (which is probably why it's broken right now).
Maybe a file similar to https://github.com/cython/cython/blob/474573b324fdd4e2e113043efe326971e652769b/Cython/Build/Tests/TestCyCache.py that creates a bunch of pyx, py and matching pxd files and tests that it's found the correct dependencies?
Co-authored-by: da-woods <dw-git@d-woods.co.uk>
So like a new TestPxdDeps.py test file? Or a more general TestDependencies.py? |
If you were able to do it then the more general TestDependencies.py would be good - I'd think that doing both (py and pyx) would only be slightly longer than doing both. I'm slightly surprised that we don't have a test for this already, but I really can't find one. (I don't know the build system hugely well though) |
Ok, I will try writing tests for dependencies. |
Cython/Build/Dependencies.py
Outdated
if filename[-4:] == '.pyx' and path_exists(filename[:-4] + '.pxd'): | ||
pxd_list = [filename[:-4] + '.pxd'] | ||
elif filename[-3:] == '.py' and path_exists(filename[:-3] + '.pxd'): | ||
pxd_list = [filename[:-3] + '.pxd'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified by first using os.path.splitext()
.
Cython/Build/Dependencies.py
Outdated
@@ -597,10 +597,16 @@ def find_pxd(self, module, filename=None): | |||
|
|||
@cached_method | |||
def cimported_files(self, filename): | |||
<<<<<<< HEAD |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Implementation looks good, test missing. |
Add test to check recythonization after pxd has changed
The dependency tree now additionally searches for dependency pxd files are relative to the dependent file path. Possibly fixing #1718 |
Cython/Build/Dependencies.py
Outdated
@@ -534,7 +535,7 @@ def included_files(self, filename): | |||
for include in self.parse_dependencies(filename)[1]: | |||
include_path = join_path(os.path.dirname(filename), include) | |||
if not path_exists(include_path): | |||
include_path = self.context.find_include_file(include, None) | |||
include_path = self.context.find_include_file(include, (FileSourceDescriptor(filename),)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm… I'd rather not create a fake code position tuple here. I'll see what I can do about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I boldly pushed a change to the master branch that makes this unnecessary.
finally: | ||
shutil.rmtree(temp_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a typical use case for setUp()
and tearDown()
.
The tests fail on Xenial, but not OS. I am not familiar with Xenial, but my guess is that I need to supply the full path direction to dependency files somewhere in the code. Is there something else I should look at? |
This is a guess, but I wonder if the timestamps that it's using to check for changes are too coarse and it isn't spotting that the file has been modified. I'd try putting a 2s pause before changing the files. I may be wrong here, of course. |
# The number of dependencies should be 2: "a.pxd" and "a.pyx" | ||
self.assertEqual(2, len(dep_tree.all_dependencies(a_pyx))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, why not check for the two file names instead of just their count?
a_c_contents2 = f.read() | ||
|
||
|
||
self.assertNotEqual(a_c_contents1, a_c_contents2, 'C file not changed!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this produces tons of uselessly unreadable output on failure, I'd rather compare them separately, (properly) print the file on failure (or, preferably, only a relevant part of it), then just assertTrue(False)
.
Actually, you can also assertIn("cdef int value", …)
and assertIn("cdef double value", …)
or something like that. Maybe both assertIn()
and assertNotIn()
.
It sound be possible to make a PR against goldenrockfeller/cython recythonize-pxd-for-py branch. Then he'd accept it and it would become part of this PR. I'm not sure exactly what you need to click to do it, but I've managed to do it before. If you can get that to work, that's probably the easiest thing to do. |
As far as I understood, the branch was deleted. Now it exists, it is already better.
I have no idea how to do this. I cannot open PR there from my fork. Also, I can't open a fork from a @goldenrockefeller fork. |
…into recythonize-pxd-for-py
…kefeller/cython into recythonize-pxd-for-py
Thanks! |
Adds the complementary .pxd file to the dependency tree if it exists. Fixes #1428