pycollect — pycollect 0.2.2 documentation

### Navigation

- ☰
- pycollect-0.2.2 »
- Reference »

Fork me on GitHub

# pycollect

class `pycollect.` `PythonFileCollector`(use_regex_patterns: bool = False, additional_file_exclusion_patterns: Iterable[str] = None, additional_dir_exclusion_patterns: Iterable[str] = None)

  PythonFileCollector provides method “collect” to collect files while applying exclusion patterns to files and directories.

  Exclusion patterns are in respect to file and directory names only, NOT taking into account the absolute nor the relative file or directory path.

  When not using regex patterns, a single wildcard, “*”, can be used anywhere in a pattern to filter names “starting with” and/or “ending with”. Also, a single exclamation mark, “!”, can be used at the beginning of the pattern to negate it. These only applies when :param use_regex_patterns: is False.

  Notice that using regex patterns may be slower.

  Parameters

    - use_regex_patterns – (default: False) flag to indicate whether or not to use regex to match patterns. When this flag it set to False the PythonFileCollector._WILDCARD (default: “*”) character is interpreted as wildcard and patterns starting with the PythonFileCollector._NEGATION (default: “!”) character are negated.

    - additional_file_exclusion_patterns – (default: None) additional patterns to filter out of collection files. In addition to the PythonFileCollector._DEFAULT_FILE_EXCLUSION_PATTERNS or PythonFileCollector._DEFAULT_FILE_EXCLUSION_REGEX_PATTERNS any file that matches these patterns will be excluded from collection.

    - additional_dir_exclusion_patterns – (default: None) additional patterns to filter out of collection directories. In addition to the PythonFileCollector._DEFAULT_DIR_EXCLUSION_PATTERNS or PythonFileCollector._DEFAULT_DIR_EXCLUSION_REGEX_PATTERNS any directory that matches these patterns will be excluded from collection.

  `collect`(search_path: Optional[str] = None, recursion_limit: Optional[int] = None, follow_symlinks: bool = True) → Set[posix.DirEntry]

    Method to perform Python files collection in the specified search path, respecting exclusion patterns set to the class object.

    Parameters

      - search_path – (default: uses the caller’s path) absolute or relative path from which to search for when collecting Python files. This is expected to be a directory.

      - recursion_limit – (default: None) directory recursion limit. The directory indicated by the :param search_path: is considered level 0 of recursion.

      - follow_symlinks – (default: True) boolean indicating whether or not to follow symbolic links when collecting Python files.

    Returns

      A set of DirEntry instances referring to each collected file is returned.

`pycollect.` `find_module_name`(filepath: Union[posix.DirEntry, str], innermost: bool = False) → Optional[str]

  Utility function to find the Python module name of a python file.

  Parameters

    - filepath – The absolute filepath as a DirEntry object or path string.

    - innermost – (default: False) By default the outermost possible module name is returned. When this flag is set to True, the first found, innermost possible module name is then returned without further looking.

  Returns

    The module name string or None if no module was found for the specified filepath.

### Navigation

- index
- modules |
- next |
- previous |