The embedded 40250 script layer needs its own interpreter on five platforms. 2.7 is end-of-life, so nothing can be fetched from the target SDKs and the source is vendored (official 2.7.18 tarball, trimmed to 25MB; Lib/ stays for step 3's python27.zip). cpython-2.7.18/CMakeLists.txt builds one `mtpython` static library from exactly the 133 objects the reference libpython2.7.a contains, off by default behind -DMTGODOT_EMBED_PYTHON=ON. The source list and the built-in module table (config/config.c, 39 entries) are shared; pyconfig.h is a probe result and is not, so each platform keeps its own under config/<platform>/, regenerated by tools/py_embed/gen_pyconfig.sh and checked against the shared table. Three vendor patches, documented in docs/THIRD-PARTY.md: configure/configure.ac learn arm64 on macOS, and posixmodule.c undefines the process-control calls it hard-defines past pyconfig.h when building for iOS. macOS (ctest python.embed: every builtin imports, codecs and pickle work off the vendored Lib/), Android arm64 and iOS arm64 build. Linux needs a Linux host and Windows needs a MinGW-vs-MSVC decision; both are noted for step 4. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
"""Filename globbing utility."""
|
|
|
|
import sys
|
|
import os
|
|
import re
|
|
import fnmatch
|
|
|
|
try:
|
|
_unicode = unicode
|
|
except NameError:
|
|
# If Python is built without Unicode support, the unicode type
|
|
# will not exist. Fake one.
|
|
class _unicode(object):
|
|
pass
|
|
|
|
__all__ = ["glob", "iglob"]
|
|
|
|
def glob(pathname):
|
|
"""Return a list of paths matching a pathname pattern.
|
|
|
|
The pattern may contain simple shell-style wildcards a la
|
|
fnmatch. However, unlike fnmatch, filenames starting with a
|
|
dot are special cases that are not matched by '*' and '?'
|
|
patterns.
|
|
|
|
"""
|
|
return list(iglob(pathname))
|
|
|
|
def iglob(pathname):
|
|
"""Return an iterator which yields the paths matching a pathname pattern.
|
|
|
|
The pattern may contain simple shell-style wildcards a la
|
|
fnmatch. However, unlike fnmatch, filenames starting with a
|
|
dot are special cases that are not matched by '*' and '?'
|
|
patterns.
|
|
|
|
"""
|
|
dirname, basename = os.path.split(pathname)
|
|
if not has_magic(pathname):
|
|
if basename:
|
|
if os.path.lexists(pathname):
|
|
yield pathname
|
|
else:
|
|
# Patterns ending with a slash should match only directories
|
|
if os.path.isdir(dirname):
|
|
yield pathname
|
|
return
|
|
if not dirname:
|
|
for name in glob1(os.curdir, basename):
|
|
yield name
|
|
return
|
|
# `os.path.split()` returns the argument itself as a dirname if it is a
|
|
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
|
|
# contains magic characters (i.e. r'\\?\C:').
|
|
if dirname != pathname and has_magic(dirname):
|
|
dirs = iglob(dirname)
|
|
else:
|
|
dirs = [dirname]
|
|
if has_magic(basename):
|
|
glob_in_dir = glob1
|
|
else:
|
|
glob_in_dir = glob0
|
|
for dirname in dirs:
|
|
for name in glob_in_dir(dirname, basename):
|
|
yield os.path.join(dirname, name)
|
|
|
|
# These 2 helper functions non-recursively glob inside a literal directory.
|
|
# They return a list of basenames. `glob1` accepts a pattern while `glob0`
|
|
# takes a literal basename (so it only has to check for its existence).
|
|
|
|
def glob1(dirname, pattern):
|
|
if not dirname:
|
|
dirname = os.curdir
|
|
if isinstance(pattern, _unicode) and not isinstance(dirname, unicode):
|
|
dirname = unicode(dirname, sys.getfilesystemencoding() or
|
|
sys.getdefaultencoding())
|
|
try:
|
|
names = os.listdir(dirname)
|
|
except os.error:
|
|
return []
|
|
if pattern[0] != '.':
|
|
names = filter(lambda x: x[0] != '.', names)
|
|
return fnmatch.filter(names, pattern)
|
|
|
|
def glob0(dirname, basename):
|
|
if basename == '':
|
|
# `os.path.split()` returns an empty basename for paths ending with a
|
|
# directory separator. 'q*x/' should match only directories.
|
|
if os.path.isdir(dirname):
|
|
return [basename]
|
|
else:
|
|
if os.path.lexists(os.path.join(dirname, basename)):
|
|
return [basename]
|
|
return []
|
|
|
|
|
|
magic_check = re.compile('[*?[]')
|
|
|
|
def has_magic(s):
|
|
return magic_check.search(s) is not None
|