MCPcopy Index your code
hub / github.com/python/cpython / getFilesForName

Function getFilesForName

Tools/i18n/pygettext.py:238–279  ·  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

236
237
238def getFilesForName(name):
239 """Get a list of module files for a filename, a module or package name,
240 or a directory.
241 """
242 if not os.path.exists(name):
243 # check for glob chars
244 if containsAny(name, "*?[]"):
245 files = glob.glob(name)
246 list = []
247 for file in files:
248 list.extend(getFilesForName(file))
249 return list
250
251 # try to find module or package
252 try:
253 spec = importlib.util.find_spec(name)
254 name = spec.origin
255 except ImportError:
256 name = None
257 if not name:
258 return []
259
260 if os.path.isdir(name):
261 # find all python files in directory
262 list = []
263 # get extension for python source files
264 _py_ext = importlib.machinery.SOURCE_SUFFIXES[0]
265 for root, dirs, files in os.walk(name):
266 # don't recurse into CVS directories
267 if 'CVS' in dirs:
268 dirs.remove('CVS')
269 # add all *.py files to list
270 list.extend(
271 [os.path.join(root, file) for file in files
272 if os.path.splitext(file)[1] == _py_ext]
273 )
274 return list
275 elif os.path.exists(name):
276 # a single file
277 return [name]
278
279 return []
280
281
282# Key is the function name, value is a dictionary mapping argument positions to the

Callers 1

mainFunction · 0.85

Calls 10

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…