Skip to content

Remove trailing os.sep to avoid false negatives #5293

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

Merged
merged 2 commits into from
Apr 20, 2018
Merged

Remove trailing os.sep to avoid false negatives #5293

merged 2 commits into from
Apr 20, 2018

Conversation

andresdelfino
Copy link
Contributor

@andresdelfino andresdelfino commented Apr 19, 2018

When we look the dirs in PATH, we don't remove the trailing os.sep, and since we are using a set to do the checking, we get false negatives.

Example:

image

@pradyunsg pradyunsg added the type: enhancement Improvements to functionality label Apr 19, 2018
@cjerdonek
Copy link
Member

There is no test for this?

@andresdelfino
Copy link
Contributor Author

No, there isn't, sorry. Please let me know if you want me to write it.

@cjerdonek
Copy link
Member

As a simpler step, rather than only trying to test message_about_scripts_not_on_PATH() (which is a function with a lot of complexity), I would create and test a simpler and more easily testable helper function (e.g. make_not_warn_dirs() or however it should best be called).

@pradyunsg
Copy link
Member

Please let me know if you want me to write it.

Yes, please do. :)

@andresdelfino
Copy link
Contributor Author

I have created the test on #5325

pradyunsg pushed a commit that referenced this pull request Apr 23, 2018
* Test that trailing os.sep are ignored while searching PATH
* Simplify paths list creation
@florisla
Copy link

florisla commented Jul 12, 2018

Note: if it is at all possible to install scripts in the root folder of a file system, this might break.
Then the trailing separator is stripped from / on Linux or C:\\ on Windows, where it is also the root separator.

Using os.path.normpath() instead on the entries of PATH works equally well in my case, but I'm not sure if that introduces other undesired effects.

@andresdelfino
Copy link
Contributor Author

andresdelfino commented Jul 12, 2018

The documentation does mention an issue with symbolic paths in Unix. Perhaps we should only remove the trailing os.sep in Windows and if not os.path.normpath(i).endswith(os.sep) ? This won't remove it in "C:\".

florisla added a commit to florisla/pip that referenced this pull request Jul 12, 2018
@florisla
Copy link

florisla commented Jul 12, 2018

I like that!

This seems to work:
florisla@b756eed

I'm not doing the endswith(os.sep) since that check is already built into rstrip(os.sep).

@florisla
Copy link

florisla commented Jul 17, 2018

I can add unit tests for this if you want. I would need some pointers on how to get the unit tests rolling though (currently getting ImportError: attempted relative import with no known parent package).

@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants