-
Notifications
You must be signed in to change notification settings - Fork 120
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
Normalize path before comparison #261
Conversation
I'm wondering if it makes sense to test both cases:
Is the patch with only the normed variant equivalent? I.e. are all of the following false?
Will the above be false on any platform? I think the answer is yes, but if you could double check these cases. It looks like there is always a windows CI failure, not sure if its on my side or not yet. |
I don't think it is necessary to check both cases.
For the first two: import os
os.path.normpath("<ipython-input-")
Out[3]: '<ipython-input-'
import tempfile
tempfile.gettempdir()
Out[5]: 'C:\\Users\\USER~1\\AppData\\Local\\Temp'
os.path.normpath(tempfile.gettempdir())
Out[6]: 'C:\\Users\\USER~1\\AppData\\Local\\Temp' For the latter, the docs will take a directory from an environment variable, so I checked whether (line-profiler-bug-py3.9) C:\Users\USER\dev\line_profiler_bug\line_profiler>set TMPDIR=C:/tmpdir
(line-profiler-bug-py3.9) C:\Users\USER\dev\line_profiler_bug\line_profiler>echo %TMPDIR%
C:/tmpdir
(line-profiler-bug-py3.9) C:\Users\USER\dev\line_profiler_bug\line_profiler>python
Python 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import tempfile
>>> tempfile.gettempdir()
'C:\\tmpdir'
>>> os.path.normpath(tempfile.gettempdir())
'C:\\tmpdir'
>>>
The docs for os.path.normpath mention that "string manipulation may change the meaning of a path that contains symbolic links". So, I did a test with a file,
and USER@P1-PF3HX471:~$ echo "hello world" > hello
USER@P1-PF3HX471:~$ ln -s hello world
USER@P1-PF3HX471:~$ cat hello
hello world
USER@P1-PF3HX471:~$ cat world
hello world
USER@P1-PF3HX471:~$ python3
>>> import os
>>> os.path.normpath("./hello")
'hello'
>>> os.path.normpath("./world")
'world'
>>> os.getcwd()
'/home/USER
>>> os.path.join(os.getcwd(), "hello")
'/home/USER/hello'
>>> os.path.join(os.getcwd(), "world")
'/home/USER/world'
>>> os.path.normpath(os.path.join(os.getcwd(), "hello"))
'/home/USER/hello' So, the behavior looks to be the same. Since the fix is mainly to normalize path separators, if you prefer, we can use os.path.normcase instead of |
Thank you for the analysis (and the PR!). Normcase seems safer to me. I've been burned by normpath corner cases in the past. My intuition is that either is probably fine, but I err on the side of caution when making changes to this library given that it's widely used. It looks like the CI error is happening on my latest branch as well. I'll want to get that fixed before merging in anything, but overall switching to normcase looks good to me (if you want to accelerate merger of this branch, any help with debugging the CI error would be appreciated, but if not I will get to it eventually). |
Looks like this is fixed in a later version: |
Thoughts, @Erotemic? I think if you approve the workflow change that it will pass the build. |
Looks like CI needs fixes. Almost certainly they are unreleated to this, but I'm reluctant to merge until I see a green dashboard. |
Looks like a few more bugs were fixed with |
Okay, so looks like this issue is occurring in other PRs, too: #256 |
I will eventually look into this if nobody else does. This is one of many open source projects I maintain, so I have less time to delve into details than I would like. Perhaps I can summon @joerick and ask if this pytest error is familiar?
|
I don't recognise it, sorry! |
I've started to look into the CI issue. I think it is an issue in pytest, which I've noted here: pytest-dev/pytest#11904 |
I think I fixed (worked around) the issue by pinning pytest to 7.4.4 in cibuildwheel tests. The tests outside of cibuildwheel still use the latest pytest, but they don't seem to cause issues outside of cibuildwheel. If you rebase on main the tests will likely pass. |
I attempted to rebase this branch, but somehow I ended up clobbering it and causing it to close. I opened a new PR #264 with the correct rebased version |
Fixes issue #152
The
is_ipython_kernel_cell
was failing on my local machine because my path was:and
os.path.join(tempfile.gettempdir(), 'ipykernel_')
was returning:With this change paths will now be normalized.