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

Path_u doesn't support file protocol on Windows #144

Closed
RoryDungan opened this issue Jul 7, 2022 · 2 comments
Closed

Path_u doesn't support file protocol on Windows #144

RoryDungan opened this issue Jul 7, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@RoryDungan
Copy link

🐛 Bug report

I have an argument of type Path_u. When I pass a file protocol URL to a file that I know does exist I get an error saying "File does not exist". The issue only seems to happen on Windows.

To reproduce

Example code:

from jsonargparse import ArgumentParser
from jsonargparse.typing import path_type

parser = ArgumentParser()
parser.add_argument("--path", type=path_type("u"))

args = parser.parse_args()

print(f"path: {args.path}")

To run:

python example.py --path "file:///C:/Users/r_dungan/dev/test/file_protocol_test/example.py"

This resulted in the following output:

usage: example.py [-h] [--path PATH]
example.py: error: Configuration check failed :: Parser key "path": Not of type Path_u. File does not exist: /C:/Users/r_dungan/dev/test/file_protocol_test/example.py

This seems to be a result of the logic at util.py:408 that replaces file:/// with / before checking if the file exists. This works fine on Unix-like platforms but on windows it results in an extra "/" at the beginning of the path before the drive letter, which makes it invalid.

Expected behavior

The path should be picked up by JsonArgParse with no errors. On Linux, this happens as long as the file exists:

$ python3 example.py --path file:///mnt/c/Users/r_dungan/dev/test/file_protocol_test/example.py
path: file:///mnt/c/Users/r_dungan/dev/test/file_protocol_test/example.py

Environment

  • jsonargparse version: 4.10.2
  • Python version: 3.10.5, 3.9.10
  • How jsonargparse was installed: pip install jsonargparse, poetry install jsonargparse
  • OS: Windows 10 21H2
@RoryDungan RoryDungan added the bug Something isn't working label Jul 7, 2022
@mauvilsa
Copy link
Member

mauvilsa commented Jul 7, 2022

@RoryDungan would you like to create a pull request with the fix?

mauvilsa added a commit that referenced this issue Jul 13, 2022
- Enabled most Path unit tests in windows.
- For windows use jsonnet-binary as dependency.
- Use all extras in tox testenv.
@mauvilsa
Copy link
Member

Fixed in af9e6df.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants