Skip to content
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

Merged
merged 22 commits into from Jun 28, 2021

Conversation

goldenrockefeller
Copy link
Contributor

Adds the complementary .pxd file to the dependency tree if it exists. Fixes #1428

Copy link
Contributor

@da-woods da-woods left a 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?

Cython/Build/Dependencies.py Outdated Show resolved Hide resolved
Co-authored-by: da-woods <dw-git@d-woods.co.uk>
@goldenrockefeller
Copy link
Contributor Author

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?

So like a new TestPxdDeps.py test file? Or a more general TestDependencies.py?

@da-woods
Copy link
Contributor

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)

@goldenrockefeller
Copy link
Contributor Author

Ok, I will try writing tests for dependencies.

Comment on lines 600 to 603
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']
Copy link
Contributor

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().

@@ -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.

@scoder
Copy link
Contributor

scoder commented Mar 26, 2021

Implementation looks good, test missing.

@goldenrockefeller
Copy link
Contributor Author

The dependency tree now additionally searches for dependency pxd files are relative to the dependent file path. Possibly fixing #1718

@@ -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),))
Copy link
Contributor

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.

Copy link
Contributor

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.

Comment on lines 61 to 62
finally:
shutil.rmtree(temp_dir)
Copy link
Contributor

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().

@goldenrockefeller
Copy link
Contributor Author

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?

@da-woods
Copy link
Contributor

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.

Cython/Build/Dependencies.py Outdated Show resolved Hide resolved
Cython/Build/Dependencies.py Outdated Show resolved Hide resolved
Cython/Build/Dependencies.py Outdated Show resolved Hide resolved
Comment on lines 46 to 47
# The number of dependencies should be 2: "a.pxd" and "a.pyx"
self.assertEqual(2, len(dep_tree.all_dependencies(a_pyx)))
Copy link
Contributor

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!')
Copy link
Contributor

@scoder scoder Apr 26, 2021

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().

@0dminnimda
Copy link
Contributor

0dminnimda commented Jun 21, 2021

@da-woods @scoder I found a problem due to which this PR does not pass the tests, but the author, unfortunately, is inactive, should I create my PR based on this, where would I fix all the problems?

@goldenrockefeller
Copy link
Contributor Author

@da-woods @scoder I found a problem due to which this PR does not pass the tests, but the author, unfortunately, is inactive, should I create my PR based on this, where would I fix all the problems?

Is it a quick fix, I can get to it this weekend.

@0dminnimda
Copy link
Contributor

Is it a quick fix, I can get to it this weekend.

The point is that I have already fixed it and also added more test cases.
Well, I don't know what to do in this case. Anyway, I've added enough changes for a separate PR.
@da-woods @scoder

@da-woods
Copy link
Contributor

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.

@0dminnimda
Copy link
Contributor

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.

As far as I understood, the branch was deleted. Now it exists, it is already better.

If you can get that to work, that's probably the easiest thing to do.

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.

@0dminnimda
Copy link
Contributor

Well, we are waiting for @scoder, he can run workflow.

I don't know if he will merge this PR right away, or wait until #4241 meets all the requirements.

@scoder scoder merged commit 304b822 into cython:master Jun 28, 2021
@scoder scoder added this to the 3.0 milestone Jun 28, 2021
@scoder
Copy link
Contributor

scoder commented Jun 28, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cythonize doesn’t recompile when only the pxd has changed in pure python mode
4 participants