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
Do not verify destdir argument to compileall #69091
Comments
In compileall.py's main, we verify that the provided destdir (-d) exists at build time. But destdir will commonly be used to override the build time path with a runtime path. That runtime path will usually not exist at build time. Note that this logic was changed when compileall.py was migrated to argparse. I think the old logic accidentally avoided the isdir() check at build time. With the attached patch, behavior is made consistent with python 2.7, intended or otherwise. |
That line isn't checking the existence of destdir, but rather of the (single, because we have only one destdir to use) directory to compile. What bug are you actually seeing? |
Thanks for the response and sorry for the mis-read. In 2.7, I did something like: But in 3.4, I get: I'm doing this during a build. Then we package the pyc file into a runtime image. Let me know if I can further help (or confuse). |
So, given that that does something useful, it appears that the error message (which is what is in 2.7 as well) is wrong to refer to 'directory argument', and we should just eliminate the isdir check (and fix the error message). The patch will need a test. |
Actually, it looks like it is a bit more potentially complex than that. The original code would issue the error only if there were more than one argument and the first one was not a directory. So it would in fact compile more than one argument as long as the first one was a dir. It's not clear what purpose that check was supposed to serve. |
I agree. I couldn't find a use for the check, so I removed it entirely in the provided patch. I'm running that way now with success, but of course I'm covering just one use case. Digging back a bit further, the isdir() check came in here: And even further, near the beginning of time, we find the original check: Speculation: In the context of the original code, "directory" in the error message makes more sense and that word should have been dropped when single file support was added. However, given that we loop over the args, I don't see how -d was limited to a single arg. With my patch in place, I tested compileall.py with multiple args and the -d. It works as expected and contains the -d path. I'm happy to craft a new patch. How would you like it? |
OK, so I think the goal was to prevent more than one *directory* from being specified, since as I said earlier that wouldn't make sense given we have only a single destdir path. However, for backward compatibility reasons we should probably not restrict it, but rather invoke the python "consenting adults" rule and let you shoot yourself in the foot that way if you want to. It only affects error messages, after all. So yeah, if you can build a new patch including some tests that would be great. Best way is to check out the repository, switch to the 3.4 branch, edit the files, and use 'hg diff' to generate the patch. Doing it that way makes it easy to test your changes. But whatever method of coming up with a context diff that you care to use is also fine. More detailed information about the normal workflow is in docs.python.org/devguide. Note that in addition to the central repository at hg.python.org, there are also bitbucket and github mirrors, which should both be mentioned in the devguide (if they aren't, that's a bug in the devguide :) |
Updated patch. Same as before, but updates tests. Sorry I went MIA on this issue. |
New changeset b63fd82a8528 by R David Murray in branch '3.4': New changeset c65e135df1dc by R David Murray in branch '3.5': New changeset 1e5aacddb67d by R David Murray in branch 'default': |
Thanks, Jake. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: