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

running script with pipenv run will fail if args contains special characters on Windows #4935

Closed
pinfort opened this issue Jan 28, 2022 · 5 comments
Labels
Category: CLI Issue relates to the CLI OS: Windows This issue affects the Windows Operating System.

Comments

@pinfort
Copy link
Contributor

pinfort commented Jan 28, 2022

Issue description

After updating pipenv, my scripts fail with exception. I don't know if there are any configurations to fix this problem, please tell me if it exists.

When

This problem happens when the following conditions are met

  • on Windows
  • pipenv version >= 2021.11.5
  • Args are invalid format for glob.glob python standard function.

Cause

version 2021.11.5 has updating dependency click from 7.1.2 to 8.0.1.

click 8.0 has new feature like below. see: https://palletsprojects.com/blog/flask-2-0-released/

Command line arguments on Windows support glob patterns like *.txt and ~/config.json, since the Windows terminal does not support this automatically.

FYI: pallets/click#1096

Due to the above feature, All arguments are passed for glob.glob function and throws exception because the arguments are not for glob function for my script. [3-1] in my example is invalid as glob format.

Latest pipenv has same issue.

IMO, windows_expand_args=False should be set.
see: pallets/click#2135

Expected result

print Hello world!

Actual result

throws Exception

Traceback (most recent call last):
  File "C:\Python\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python\Scripts\pipenv.exe\__main__.py", line 7, in <module>
  File "C:\Python\lib\site-packages\pipenv\vendor\click\core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "C:\Python\lib\site-packages\pipenv\vendor\click\core.py", line 1049, in main
    args = _expand_args(args)
  File "C:\Python\lib\site-packages\pipenv\vendor\click\utils.py", line 572, in _expand_args
    matches = glob(arg, recursive=glob_recursive)
  File "C:\Python\lib\glob.py", line 24, in glob
    return list(iglob(pathname, root_dir=root_dir, dir_fd=dir_fd, recursive=recursive))
  File "C:\Python\lib\glob.py", line 69, in _iglob
    yield from _glob1(root_dir, basename, dir_fd, dironly)
  File "C:\Python\lib\glob.py", line 97, in _glob1
    return fnmatch.filter(names, pattern)
  File "C:\Python\lib\fnmatch.py", line 58, in filter
    match = _compile_pattern(pat)
  File "C:\Python\lib\fnmatch.py", line 52, in _compile_pattern
    return re.compile(res).match
  File "C:\Python\lib\re.py", line 251, in compile
    return _compile(pattern, flags)
  File "C:\Python\lib\re.py", line 303, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Python\lib\sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "C:\Python\lib\sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "C:\Python\lib\sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "C:\Python\lib\sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "C:\Python\lib\sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "C:\Python\lib\sre_parse.py", line 598, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range 3-1 at position 5

Steps to replicate

building below Dockerfiles and running it on Windows.

Dockerfile_success with pipenv version 2021.5.29 will success with printing Hello world!.
Dockerfile_fail with pipenv version 2021.11.5 will fail with throwing Exception.

Dockerfile_success

FROM python:3-windowsservercore-1809

WORKDIR /app

COPY . .

RUN pip install pipenv==2021.5.29

RUN pipenv --python 3

CMD ["pipenv", "run", "python", "main.py", "[3-1]"]

Dockerfile_fail

FROM python:3-windowsservercore-1809

WORKDIR /app

COPY . .

RUN pip install pipenv==2021.11.5

RUN pipenv --python 3

CMD ["pipenv", "run", "python", "main.py", "[3-1]"]

main.py

print("Hello world!")

Please run $ pipenv --support, and paste the results here. Don't put backticks (`) around it! The output already contains Markdown formatting.

If you're on macOS, run the following:

$ pipenv --support | pbcopy

If you're on Windows, run the following:

> pipenv --support | clip

If you're on Linux, run the following:

$ pipenv --support | xclip
@pinfort pinfort changed the title running script with pipenv run will fail if args contains special characters running script with pipenv run will fail if args contains special characters on Windows Jan 28, 2022
@oz123 oz123 added Category: CLI Issue relates to the CLI OS: Windows This issue affects the Windows Operating System. labels Jan 28, 2022
@oz123
Copy link
Contributor

oz123 commented Jan 28, 2022

Thanks for the detailed issue report. I guess we need to wait for upstream here.

@pinfort
Copy link
Contributor Author

pinfort commented Jan 29, 2022

Thanks for your response.

I think this feature is strange. However, upstream project already have an option to disable it. Therefore, it is the user's responsibility to take advantage and disadvantage of this feature.

For this reason I think we need to change the settings for click used in this project at our own risk.

@oz123
Copy link
Contributor

oz123 commented Jan 29, 2022

If this is something we can control, I think a PR can be merged. Not having a windows will make it hard to for me to test. If can, you are welcome to submit a PR.

@pinfort
Copy link
Contributor Author

pinfort commented Jan 29, 2022

Thanks. I created a PR to fix it.

@oz123
Copy link
Contributor

oz123 commented Jan 30, 2022

Fixed in b60d37a

@oz123 oz123 closed this as completed Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: CLI Issue relates to the CLI OS: Windows This issue affects the Windows Operating System.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants