Skip to content

Commit

Permalink
Tolerate and escape globbing characters in sys.path (#5956)
Browse files Browse the repository at this point in the history
If your build environment uses literal globbing characters, Cython 3.0
might fail, because `find_versioned_file` in `Utils.py` was slapping a
`*` in the path and expecting it to properly glob. This fails in
certain large build environments that use, for example, brackets in
system paths. Escape paths from sys.path and other sources before
looking for different versions of collateral files.

Closes GitHub issue [#5942](#5942)
  • Loading branch information
eewanco committed Feb 18, 2024
1 parent a501021 commit e286742
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cython/Utils.py
Expand Up @@ -305,7 +305,7 @@ def find_versioned_file(directory, filename, suffix,
assert not suffix or suffix[:1] == '.'
path_prefix = os.path.join(directory, filename)

matching_files = glob.glob(path_prefix + ".cython-*" + suffix)
matching_files = glob.glob(glob.escape(path_prefix) + ".cython-*" + suffix)
path = path_prefix + suffix
if not os.path.exists(path):
path = None
Expand Down
27 changes: 27 additions & 0 deletions tests/run/sys_path_globbed.srctree
@@ -0,0 +1,27 @@
# tag: gh5942

PYTHON setup.py build_ext --inplace
PYTHON -c "from tglob import mytest; mytest()"

######## tglob.pyx ########
def mytest():
assert True

######## setup.py ########
import sys

from Cython.Build.Dependencies import cythonize
from distutils.core import setup, Extension

sys.path.append("[Hello-World]*?")

try:
from __builtin__ import reload
except ImportError:
from importlib import reload
reload(sys) # Required to make Python use updated sys.path

setup(
ext_modules=cythonize(["tglob.pyx"], language_level="3"),
)

0 comments on commit e286742

Please sign in to comment.