sci-bots / conda-helpers

Helper functions, etc. for Conda environments
BSD 3-Clause "New" or "Revised" License
0 stars 3 forks source link

Error calling `package_version(...)` with multiple package names #2

Closed cfobel closed 7 years ago

cfobel commented 7 years ago

The package_version(...) function MUST accept either a single package name or a list of package names. However, as of ac3eed5ef083de6a387dbb9a0d916a7854c67632, passing a list of package names to package_version causes the following error (at least on Windows):

RuntimeError: 'path_helpers)$' is not recognized as an internal or external command,
operable program or batch file.

Cause

When a list of package names is passed to package_version, the package names are joined into a regular expression string using the | character (i.e., the "or" operator). However, the | character is also used as a ["pipe" operator][1] on the command line. Therefore, the regular expression string must be quoted.

Unfortunately, at least on Windows, there does not seem to be a way to force the subprocess.* commands to force quoting an argument (see subprocess.list2cmdline to try converting a list of args to the corresponding argument string).

Workaround

This issue can be worked around by explicitly adding a space into the regular expression, which causes the argument to be quoted.