MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getFilesForName

Function getFilesForName

tools/python-3.11.9-amd64/Tools/i18n/pygettext.py:265–306  ·  view source on GitHub ↗

Get a list of module files for a filename, a module or package name, or a directory.

(name)

Source from the content-addressed store, hash-verified

263
264
265def getFilesForName(name):
266 """Get a list of module files for a filename, a module or package name,
267 or a directory.
268 """
269 if not os.path.exists(name):
270 # check for glob chars
271 if containsAny(name, "*?[]"):
272 files = glob.glob(name)
273 list = []
274 for file in files:
275 list.extend(getFilesForName(file))
276 return list
277
278 # try to find module or package
279 try:
280 spec = importlib.util.find_spec(name)
281 name = spec.origin
282 except ImportError:
283 name = None
284 if not name:
285 return []
286
287 if os.path.isdir(name):
288 # find all python files in directory
289 list = []
290 # get extension for python source files
291 _py_ext = importlib.machinery.SOURCE_SUFFIXES[0]
292 for root, dirs, files in os.walk(name):
293 # don't recurse into CVS directories
294 if 'CVS' in dirs:
295 dirs.remove('CVS')
296 # add all *.py files to list
297 list.extend(
298 [os.path.join(root, file) for file in files
299 if os.path.splitext(file)[1] == _py_ext]
300 )
301 return list
302 elif os.path.exists(name):
303 # a single file
304 return [name]
305
306 return []
307
308
309class TokenEater:

Callers 1

mainFunction · 0.85

Calls 9

containsAnyFunction · 0.85
splitextMethod · 0.80
existsMethod · 0.45
globMethod · 0.45
extendMethod · 0.45
find_specMethod · 0.45
isdirMethod · 0.45
removeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected