Skip to content

Commit

Permalink
Allow spaces in filenames in registry files (#315)
Browse files Browse the repository at this point in the history
Previously, the tokenization would not use this. 
Introduce shlex.split as a tokenizer that is aware of quotes and escapes.
  • Loading branch information
dokempf committed Jul 21, 2022
1 parent 9a59ff3 commit 65d74c9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ order by last name) and are considered "The Pooch Developers":
* [Mark Harfouche](https://github.com/hmaarrfk) - Ramona Optics Inc. - [0000-0002-4657-4603](https://orcid.org/0000-0002-4657-4603)
* [Danilo Horta](https://github.com/horta) - EMBL-EBI, UK
* [Hugo van Kemenade](https://github.com/hugovk) - Independent (Non-affiliated) (ORCID: [0000-0001-5715-8632](https://www.orcid.org/0000-0001-5715-8632))
* [Dominic Kempf](https://github.com/dokempf) - Scientific Software Center, Heidelberg University, Germany (ORCID: [0000-0002-6140-2332](https://www.orcid.org/0000-0002-6140-2332))
* [Kacper Kowalik](https://github.com/Xarthisius) - National Center for Supercomputing Applications, University of Illinois at Urbana-Champaign, USA (ORCID: [0000-0003-1709-3744](https://www.orcid.org/0000-0003-1709-3744))
* [John Leeman](https://github.com/jrleeman)
* [Daniel McCloy](https://github.com/drammock) - University of Washington, USA (ORCID: [0000-0002-7572-3241](https://orcid.org/0000-0002-7572-3241))
Expand Down
3 changes: 2 additions & 1 deletion pooch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time
import contextlib
from pathlib import Path
import shlex
import shutil
import ftplib

Expand Down Expand Up @@ -656,7 +657,7 @@ def load_registry(self, fname):
if line.startswith("#"):
continue

elements = line.split()
elements = shlex.split(line)
if not len(elements) in [0, 2, 3]:
raise OSError(
f"Invalid entry in Pooch registry file '{fname}': "
Expand Down
2 changes: 2 additions & 0 deletions pooch/tests/data/registry-spaces.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"file with spaces.txt" baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2d
other\ with\ spaces.txt baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2d
8 changes: 8 additions & 0 deletions pooch/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,14 @@ def test_pooch_load_registry_invalid_line():
pup.load_registry(os.path.join(DATA_DIR, "registry-invalid.txt"))


def test_pooch_load_registry_with_spaces():
"Should check that spaces in filenames are allowed in registry files"
pup = Pooch(path="", base_url="")
pup.load_registry(os.path.join(DATA_DIR, "registry-spaces.txt"))
assert "file with spaces.txt" in pup.registry
assert "other with spaces.txt" in pup.registry


@pytest.mark.network
def test_check_availability():
"Should correctly check availability of existing and non existing files"
Expand Down

0 comments on commit 65d74c9

Please sign in to comment.