click_extra.config.discovery moduleΒΆ

Search for the configuration files a --config location designates.

ConfigDiscovery is the mixin ConfigOption inherits to find its files. It downloads a URL, or globs a local pattern, then walks up the parent folders until a VCS root. It also looks for a pyproject.toml from the current working directory upward.

click_extra.config.discovery.VCS_DIRS = ('.git', '.hg', '.svn', '.bzr', 'CVS', '.darcs')ΒΆ

VCS directory names used to identify version control system roots.

Includes: - .git: Git - .hg: Mercurial - .svn: Subversion - .bzr: Bazaar - CVS: CVS (note: uppercase, no leading dot) - .darcs: Darcs

class click_extra.config.discovery.ConfigDiscovery[source]ΒΆ

Bases: object

Find the configuration files a location designates.

A mixin of ConfigOption, which sets the attributes the search reads: search_pattern_flags, search_parents and stop_at. A pyproject.toml is read with the option’s own parse_conf().

search_parents: boolΒΆ
stop_at: Path | str | Literal[Sentinel.VCS] | NoneΒΆ
parent_patterns(pattern)[source]ΒΆ

Generate (root_dir, file_pattern) pairs for searching.

Each yielded pair can be passed directly to glob.iglob(file_pattern, root_dir=root_dir) so that every sub-pattern (whether from BRACE or SPLIT expansion) is correctly scoped to the same directory.

root_dir is None for entirely magic patterns that will be evaluated relative to the current working directory.

Stops when reaching the root folder, the stop_at boundary, or an inaccessible directory.

Return type:

Iterable[tuple[str | None, str]]

search_and_read_file(pattern)[source]ΒΆ

Search filesystem or URL for files matching the pattern.

If pattern is an URL, download its content. A pattern is considered an URL only if it validates as one and starts with http:// or https://. All other patterns are considered glob patterns for local filesystem search.

Returns an iterator of (location, content, media_type) triples, for each one matching the pattern. location is normalized and content raw. media_type is the bare type/subtype the server advertised in its Content-Type header, and is None for a local file, whose format is derived from its name. Only regular files are returned, directories are silently skipped. The exception is a pattern naming a character device or a named pipe, like /dev/null: it is read from that path.

This method returns the raw content of all matching patterns, without trying to parse them. If the content is empty, it is still returned as-is.

Also includes lookups into parents directories if self.search_parents is True.

Raises FileNotFoundError if no file was found after searching all locations.

Return type:

Iterable[tuple[Path | str, str, str | None]]