Skip to content

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

@pinfort

Description

@pinfort

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Category: CLIIssue relates to the CLIOS: WindowsThis issue affects the Windows Operating System.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions