Get a list of module files for a filename, a module or package name, or a directory.
(name)
| 236 | |
| 237 | |
| 238 | def 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 |
no test coverage detected
searching dependent graphs…