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

fix: glob characters in local paths #552

Merged
merged 4 commits into from Nov 23, 2021
Merged

Conversation

wtanksleyjr
Copy link
Contributor

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.

@henryiii
Copy link
Collaborator

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.

@wtanksleyjr
Copy link
Contributor Author

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 python3.8 -m pip install pytest, but I don't see where to take it from there; simply running pytest obviously isn't enough:

ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --cov-config=setup.cfg
  inifile: /home/william/plumbum/setup.cfg
  rootdir: /home/william/plumbum

@henryiii
Copy link
Collaborator

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).

@henryiii
Copy link
Collaborator

You can see the test requirements under the dev extra in setup.cfg, if you are curious, BTW.

@henryiii
Copy link
Collaborator

And -v adds more verbosity to the tests, and can be stacked, like -vv (hope I remember correctly and it's not -V).

@wtanksleyjr
Copy link
Contributor Author

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

python -m install .[dev]

That doesn't look like a valid Bash command -- the non-quoted .[dev] string doesn't match anything and won't run. When I try to quote it, it tells me I don't have an "install" module.

@henryiii
Copy link
Collaborator

Sorry, python -m pip install ".[dev]" , and the quotes are optional on bash and most other shells except Windows, IIRC. I can try to be more help later.

@wtanksleyjr
Copy link
Contributor Author

wtanksleyjr commented Aug 18, 2021 via email

@henryiii
Copy link
Collaborator

"." 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.

@AndydeCleyre
Copy link
Contributor

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, that was added in 3.4.

@henryiii
Copy link
Collaborator

henryiii commented Oct 6, 2021

Python 2 will get dropped at some point before or on Jan 1, 2022, so if you just want to wait. :)

@wtanksleyjr
Copy link
Contributor Author

wtanksleyjr commented Oct 6, 2021 via email

@henryiii
Copy link
Collaborator

henryiii commented Oct 7, 2021

4: you can now run nox -s tests-3.9 (or whatever version you want). No environment setup except to install nox. (And, if you are a pipx user, then pipx run nox -s tests-3.9 and no nox install needed either). The remote/sudo tests are off by default.

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.

@henryiii
Copy link
Collaborator

How about root_dir? Sounds perfect!

Changed in version 3.10: Added the root_dir and dir_fd parameters.

Noooooo 😭

@henryiii
Copy link
Collaborator

The contents of glob.escape look pretty easy, actually:

https://github.com/python/cpython/blob/024209401ebc8a011f242af00efdd8ecece6953d/Lib/glob.py#L205-L234

(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.

@henryiii
Copy link
Collaborator

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?

@henryiii
Copy link
Collaborator

I came up with a working test, let's see.

@coveralls
Copy link

coveralls commented Nov 23, 2021

Coverage Status

Coverage remained the same at 82.268% when pulling d289941 on wtanksleyjr:master into e388030 on tomerfiliba:master.

@henryiii henryiii changed the title Prototype fix for glob characters in local paths. fix: glob characters in local paths Nov 23, 2021
@henryiii henryiii merged commit 6cc4b98 into tomerfiliba:master Nov 23, 2021
@henryiii
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants