-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
common/build-style/python3-pep517.sh: ignore tests in temp destdir #43946
Conversation
This PR fixes the first time check is run, but not the second and subsequent runs. In fact, the wheel will be installed into a different testdir each time (and not removed afterwards) and this only ignores the current one. Suggestions:
|
94eeba9
to
69ed70b
Compare
Oh, right. I'll keep it in wrksrc so that it gets auto-cleaned by |
LGTM now. Just FTR this merge confilcts with #44071 but both PR are necessary. |
Yeah I'll rebase once that's merged into master. |
This seems reasonable. Using |
Hrm, should we just remove the tmpdir after the tests are run? |
Where would you put the |
That's okay, because failing tests will already abort a build and any subsequent attempt probably ought to start from a clean masterdir for proper behavior anyway. Cleaning up at the end of |
69ed70b
to
6905c03
Compare
Oh, okay. I thought the norm was if the build is successful, one should be able to run |
Sure, it's reasonable to repeatedly run |
common/build-style/python3-pep517.sh
Outdated
${make_check_pre} pytest3 --ignore="${wrksrc}/tmp" ${testjobs} \ | ||
${make_check_args} ${make_check_target} | ||
|
||
rm -r "${wrksrc}/tmp" |
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've been thinking about this some more and believe we should be more targeted in the removal:
rm -r "${wrksrc}/tmp" | |
rm -r "${testdir}" |
Yes, this will leave tmp
around if we created it, but I suspect that won't cause any problems, and it might avoid a problem where a package actually ships a tmp
directory. What do you think?
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.
Alternatively, we could do:
rm -r "${wrksrc}/tmp" | |
rm -r "${testdir}" | |
rmdir tmp >/dev/null 2>&1 || true |
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 agree with removing only what was created in this run (i.e. just ${tmpdir}
).
Also, in terms of avoiding conflicts, maybe the tmpdir should be something more "unique". Perhaps ${wrksrc}/.xbps-tmpdir/$(data +%s)
which also has the advantage that pytest will not recurse hidden directories, so the --ignore ..
doesn't seem to be necessary.
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'm a bit confused about the need to remove the $testdir
after a successful run. What's the issue if we keep it there?
And if we are adding /.xbps-tmpdir
for uniqueness, I don't see why we also need to include another sub-directory under it. I only added the epoch subdirs for the extremely rare chance if a package actually ships a /tmp
dirrctory under $wrksrc
.
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.
Fine with me in principle. Although I'd be wary about what happens when there is an old testdir lying around from a previous check run. I don' t know if python -m installer
will do the right thing.
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 guess this is irrelevant because the wheel was already built before the tmpdir was created, and the installer should really only be unpacking the wheel. I do prefer @tornaria's suggestion to give the directory a hidden, XBPS-specific name that is extremely unlikely to conflict with package contents. Maybe try changing testdir
to .xbps-testdir
(which is more meaningful than .xbps-tempdir
) and see if that solves your problem without needing to ignore tests, and then skip the removal.
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.
After some testing, the python installer doesn't override files so moved the deletion logic at top. And removed the now redundant epoch subdir & ignore flag.
While we are at this, I was going to suggest using a venv instead of The gist of it would be something like:
This is needed to fix check for I also needed it to fix check for |
I'm not convinced we should move to a venv for testing. Half of your two test cases require further adjustment (symlinking a package into the venv) anyway. Adjusting the Python path is a supported mechanism, so the failure of those two packages probably reflects some inappropriate assumptions in those packages. |
6905c03
to
0712107
Compare
This LGTM, let's get this in, we can figure out whether switching or not to testing using a venv later (cf #44268 where I needed a venv). |
common/build-style/python3-pep517.sh
Outdated
@@ -19,7 +19,9 @@ do_check() { | |||
testjobs="-n $XBPS_MAKEJOBS" | |||
fi | |||
|
|||
local testdir="${wrksrc}/tmp/$(date +%s)" | |||
local testdir="${wrksrc}/.xbps-testdir" | |||
rm -rf "${testdir}" |
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.
The benefit of cleaning up the test directory after we've used it is that we (attempt to) restore the source tree to the state it was in when the function was first called.
The benefit of cleaning up the directory before it would normally exist seems dubious. If we agree there is no need to clean up the test after a successful run, I think changing the directory name as you've done is sufficient.
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 just ran into the reason for the cleanup: attempting to re-run a check after a failure will cause python3 -m installer
to fail unless the test directory is clean. Still, I think the idea of purging a (typically nonexistent) directory just to avoid issues with re-running tests is strange. At this point, I guess I'd rather see
local testdir="${wrksrc}/.xbps-testdir/$(date +s)"
and skip cleanup altogether. This should solve the problem of pytest
trying to traverse into tmp
without requiring a manual exclude, keeps our tests in a more-likely-unique subdirectory that should not conflict with any package contents, and avoid strange pre-clean steps. As a bonus, if you do run multiple tests to correct a failure, you can always do something like
diff -r .xbps-testdir/<failed> .xbps-testdir/<succeeeded>
after the fact to confirm what, if anything, has changed in the installed wheel.
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.
Ayyy, feels like I'm running in circles 😆 This should be the Final.Final.Final.patch
a16895d
to
01717cb
Compare
This prevents pytest from collecting tests multiple times when they are bundled in the wheel itself alongside the source tree.
01717cb
to
62db149
Compare
This prevents pytest from collecting tests multiple times when they are bundled in the wheel itself alongside the source tree. Closes: void-linux#43946 [via git-merge-pr]
This prevents pytest from collecting tests multiple times when they are bundled in the wheel itself alongside the source tree. Closes: void-linux#43946 [via git-merge-pr]
Testing the changes
An edge case I came across today. On rare cases, packages include tests in their built wheel. While testing with these wheels extracted in a temporary directory, it conflicts with the tests in the source tree as pytest cannot run testfiless with same name in different directories (ref: pytest-dev/pytest#3151).
See this run as an example. The same package passes checks correctly in this PR.