-
Notifications
You must be signed in to change notification settings - Fork 187
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
fix: glob characters in local paths #552
Conversation
Great to see work on this! Most importantly, can you add a test for the fix? I can probably do the remote part if there's a test. I can probably add a test instead, but it's unlikely to be before SciPy is over (next week) at the earliest. |
Sorry to be dumb... but I'm really not sure what to do here. This is the first time I've submitted a pull request. I don't know what I need to do to see these test results. The results given in these failure reports are absurdly truncated to the point of being useless. (Why on earth would they do that truncation on a failure?) Is there a way to access a more complete transcript? Definitely I should run the tests on my own machine ... but how? I installed pytest (obviously) using
|
Sorry, didn't mean it to be hard. I'll add a noxfile at some point so you'll be able to run it with nox without any other setup. The remote tests will likely never run easily on a local machine due to requiring being able to SSH into localhost. Probably should make the coverage non-mandatory. 🤦 You should be able to do (showing my favorite formula, using bash): python -m venv .venv
source .venv/bin/activate
python -m install .[dev]
pytest We should have a Mostly I wanted the contents of a test (like setting up a glob example that would normally fail but now passes), I can help with the plumbing (no pun intended... well, maybe). |
You can see the test requirements under the dev extra in setup.cfg, if you are curious, BTW. |
And |
I'm sorry, I've been distracted; I've got some more time, but I still can't figure out how to make the tests run. You gave me a sequence of commands, and they stop working for me at
That doesn't look like a valid Bash command -- the non-quoted |
Sorry, |
Oh, now that makes sense. But it doesn't quite work --
```
ERROR: Directory '.[dev]' is not installable. Neither 'setup.py' nor
'pyproject.toml' found.
```
I'm thinking I might be in the wrong folder ... I'm in `plumbum/tests`. But
I can't find a folder named `.[dev]` anywhere else either. Maybe I'm not
using the right commands, it's really hard to deal with folders with
wildcards in their names (ironically the whole purpose of this fix).
…On Sun, Jul 11, 2021 at 8:31 PM Henry Schreiner ***@***.***> wrote:
Sorry, didn't mean it to be hard. I'll add a noxfile at some point so
you'll be able to run it with nox without any other setup. The remote tests
will likely never run easily on a local machine due to requiring being able
to SSH into localhost. Probably should make the coverage non-mandatory. 🤦
You should be able to do (showing my favorite formula, using bash):
python -m venv .venv
source .venv/bin/activate
python -m install .[dev]
pytest
We should have a [test] extra at some point, currently we only have [dev],
but that's basically what I'd normally call test.
Mostly I wanted the contents of a test (like setting up a glob example
that would normally fail but now passes), I can help with the plumbing (no
pun intended... well, maybe).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#552 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7H6KOLCDJEOREDW3MX3TTXJOZVANCNFSM5AETQDMQ>
.
|
"." refers to the current directory, so it needs to be in the root folder of the project. I'll probably try to add a noxfile at some point to make this easier to run without as much setup. |
Python 2 will get dropped at some point before or on Jan 1, 2022, so if you just want to wait. :) |
Wow, that's a very good point (the 3.4+ specific function), I should have
checked that!
Some thoughts:
0. This is not a problem for Windows, which doesn't allow wildcard
characters to be included in path names. That plausibly makes the task a
bit easier.
1. Of course we COULD simply decree no more 2.x support. I ... dunno if you
want to do that. I don't think I would if I were in your place.
2. Implementing 2.x support for this exact code might be unduly hard;
escapes aren't always as simple as they seem, edge cases can kill you and
we also have to consider multiplatform support. Remember that this is
essentially a data vulnerability, not anything that can be solved by
careful coding -- that is, it depends on all of the filenames in the path,
including path components that the programmer might not be able to
standardize.
3. The "best" way to solve this (and the reason I called my code a
"prototype") would be to change the implementation so that wildcard
expansion is only done on the actual wildcard, not on the concatenated path
-- so in a sense, the wildcard is relative to the base path, rather than
being an absolute wildcard. Since this is concordant both with normal
expectation and with the documentation's claim that the wildcard matches
"under" the path it's applied to, it's a net win. Unfortunately doing this
is a little more complicated than the method I chose.
4. I can't run the tests at all, sorry. No idea why.
…On Tue, Sep 28, 2021 at 9:51 AM Andy Kluger ***@***.***> wrote:
If you check the logs from CI, we're getting this on Python 2.7:
AttributeError: 'module' object has no attribute 'escape'
. . . where module is glob. Looking at the docs
<https://docs.python.org/3/library/glob.html#glob.escape>, that was added
<https://github.com/python/cpython/blob/fe7746c61a73f58f0cf905ad1378be884d479b5b/Lib/glob.py#L168>
in 3.4.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#552 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7H6J4QHZTVKX4G5LB3UTUEHXCRANCNFSM5AETQDMQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
4: you can now run 2: 2.x support will be removed at the end of the year. So one option is to wait. Another option would be to leave the old behavior on 2.x and just fix it in 3.x. |
How about
Noooooo 😭 |
The contents of glob.escape look pretty easy, actually: (ignore the functions in the middle, not used) It could be backported in plumbum.six if you wanted to get this in before Jan 1. |
magic_check = re.compile(u'([*?[])')
magic_check_bytes = re.compile(b'([*?[])')
def escape(pathname):
drive, pathname = os.path.splitdrive(pathname)
if isinstance(pathname, bytes):
pathname = magic_check_bytes.sub(br'[\1]', pathname)
else:
pathname = magic_check.sub(ur'[\1]', pathname)
return drive + pathname Something like this. If I add this, could you add a test? |
I came up with a working test, let's see. |
Thanks! |
Addresses only the local part of #481 with minimal changes and no new dependencies. I haven't worked with the remote parts of plumbum, sorry.