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

bpo-38347: find Python scripts whose name contain a '-' #16536

Merged
merged 19 commits into from Oct 11, 2019

Conversation

Copy link
Contributor

@rpluem rpluem commented Oct 2, 2019

Allow Python scripts to contain a '-' in their filename when working
recursively.

https://bugs.python.org/issue38347

@the-knights-who-say-ni
Copy link

@the-knights-who-say-ni the-knights-who-say-ni commented Oct 2, 2019

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@rpluem

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Member

@vstinner vstinner left a comment

Would you mind to add a test to Lib/test/test_tools/test_pathfix.py?

@rpluem
Copy link
Author

@rpluem rpluem commented Oct 2, 2019

Would you mind to add a test to Lib/test/test_tools/test_pathfix.py?

This requires a bigger amount of work since the ability of pathfix.py to recursively search a directory is not tested at all currently. But the issue only happens in this case. If you specify an explicit filename on command line with '-' in the name things work fine.

@vstinner
Copy link

@vstinner vstinner commented Oct 2, 2019

This requires a bigger amount of work since the ability of pathfix.py to recursively search a directory is not tested at all currently. But the issue only happens in this case.

It sounds like a nice enhancement to write a test for this code path.

By the way, I don't see the point of using a regex to match the filename. Why not only checking for the ".py" suffix?

@rpluem
Copy link
Author

@rpluem rpluem commented Oct 2, 2019

This requires a bigger amount of work since the ability of pathfix.py to recursively search a directory is not tested at all currently. But the issue only happens in this case.

It sounds like a nice enhancement to write a test for this code path.

By the way, I don't see the point of using a regex to match the filename. Why not only checking for the ".py" suffix?

I tried to keep the changes to a minimum. Of course it can be changed to allow all filenames that just have the .py suffix. I can adjust this. Whatever preference you have :-)

@vstinner
Copy link

@vstinner vstinner commented Oct 2, 2019

The regex is quite old:

commit 9af22a037fc961b51651324bdd17a43567a688fd
Author: Guido van Rossum <guido@python.org>
Date:   Fri Aug 19 15:02:57 1994 +0000

    newslist.py: Added search for .newslistrc.py;
    pindent.py: use /usr/local/bin/python;
    pathfix.py: new script to fix #! lines in a group of scripts.

(...)

+ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
+def ispython(name):
+       return ispythonprog.match(name) >= 0
+

(...)

I don't see any rationale for rejecting filenames which don't match '^[a-zA-Z0-9_]+.py$', I suggest to only check for the suffix.

@vstinner
Copy link

@vstinner vstinner commented Oct 2, 2019

By the way, please add a NEWS entry using the Python tool "blurb" ("python3 -m pip install --user blurb" then run "blurb").

@rpluem
Copy link
Author

@rpluem rpluem commented Oct 2, 2019

By the way, please add a NEWS entry using the Python tool "blurb" ("python3 -m pip install --user blurb" then run "blurb").

I already did: 7aa6c09
Looks like the check status is outdated.

@rpluem
Copy link
Author

@rpluem rpluem commented Oct 2, 2019

This requires a bigger amount of work since the ability of pathfix.py to recursively search a directory is not tested at all currently. But the issue only happens in this case.

It sounds like a nice enhancement to write a test for this code path.

Test case created (05f15f8). I hope the code is not too weird.

@rpluem
Copy link
Author

@rpluem rpluem commented Oct 2, 2019

I don't see any rationale for rejecting filenames which don't match '^[a-zA-Z0-9_]+.py$', I suggest to only check for the suffix.

Done in 0c1e65c

rpluem and others added 6 commits Oct 2, 2019
Allow Python scripts to contain a '-' in their filename when working
recursively.
Assume all files that end on '.py' are Python scripts when working
recursively.
Add a test case for the recursive search including filenames with
a '-'.
Fix a test failure on Windows by using os.sep instead of the Unix
specific '/' as path separator.
Lib/test/test_tools/test_pathfix.py Outdated Show resolved Hide resolved
Lib/test/test_tools/test_pathfix.py Outdated Show resolved Hide resolved
Lib/test/test_tools/test_pathfix.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 2, 2019

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Member

@vstinner vstinner left a comment

I see that you updated your PR, but setUp() still creates a temporary directory (I asked to move that into the test_recursive() method), there is still "**kwargs", and now test_recursive() inspects self to call other functions... I don't understand what you are trying to do.

My expectation is that test_recursive() creates a temporary directory which contains one ".py" file which has a shebang, you can pathfix on the directory, and then you check that the .py file shebang is updated.

Please don't try to magically make other test methods work on a temporary directory. I prefer simple tests.

@rpluem
Copy link
Author

@rpluem rpluem commented Oct 8, 2019

After reverting the previous changes to test_pathfix.py I hope that 92384a5 now addresses your concerns.

@rpluem rpluem requested a review from vstinner Oct 8, 2019
Lib/test/test_tools/test_pathfix.py Outdated Show resolved Hide resolved
Lib/test/test_tools/test_pathfix.py Outdated Show resolved Hide resolved
Use local variables with better names instead of class attributes.
@rpluem rpluem requested a review from vstinner Oct 10, 2019
Lib/test/test_tools/test_pathfix.py Outdated Show resolved Hide resolved
Lib/test/test_tools/test_pathfix.py Show resolved Hide resolved
@rpluem
Copy link
Author

@rpluem rpluem commented Oct 11, 2019

The Azure failure seems to be caused by the inability to download OpenSSL sources for the Ubuntu tests. Maybe a temporary network issue on Azure / Openssl side. I would like to reexecute the Azure pipeline, but I don't know how.

@vstinner vstinner closed this Oct 11, 2019
@vstinner vstinner reopened this Oct 11, 2019
@vstinner
Copy link

@vstinner vstinner commented Oct 11, 2019

I closed/reopened the PR to schedule a new Azure Pipelines run.

Copy link
Member

@vstinner vstinner left a comment

LGTM, but please fix the typo. It seems like I'm not allowed to push into your branch.

Lib/test/test_tools/test_pathfix.py Outdated Show resolved Hide resolved
Co-Authored-By: Victor Stinner <vstinner@python.org>
@vstinner vstinner merged commit 2b7dc40 into python:master Oct 11, 2019
4 checks passed
@miss-islington
Copy link

@miss-islington miss-islington commented Oct 11, 2019

Thanks @rpluem for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 11, 2019
…ythonGH-16536)

 pathfix.py: Assume all files that end on '.py' are Python scripts when working recursively.
(cherry picked from commit 2b7dc40)

Co-authored-by: Ruediger Pluem <r.pluem@gmx.de>
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 11, 2019

GH-16718 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this issue Oct 11, 2019
…H-16536)

 pathfix.py: Assume all files that end on '.py' are Python scripts when working recursively.
(cherry picked from commit 2b7dc40)

Co-authored-by: Ruediger Pluem <r.pluem@gmx.de>
vstinner added a commit that referenced this issue Oct 11, 2019
…H-16536) (GH-16719)

pathfix.py: Assume all files that end on '.py' are Python scripts when working recursively.

(cherry picked from commit 2b7dc40)
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this issue Dec 5, 2019
…ythonGH-16536)

 pathfix.py: Assume all files that end on '.py' are Python scripts when working recursively.
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.

None yet

5 participants