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:
objectFind the configuration files a location designates.
A mixin of
ConfigOption, which sets the attributes the search reads:search_pattern_flags,search_parentsandstop_at. Apyproject.tomlis read with the optionβs ownparse_conf().- 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 fromBRACEorSPLITexpansion) is correctly scoped to the same directory.root_dirisNonefor entirely magic patterns that will be evaluated relative to the current working directory.Stops when reaching the root folder, the
stop_atboundary, or an inaccessible directory.
- search_and_read_file(pattern)[source]ΒΆ
Search filesystem or URL for files matching the
pattern.If
patternis an URL, download its content. A pattern is considered an URL only if it validates as one and starts withhttp://orhttps://. 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.locationis normalized andcontentraw.media_typeis the baretype/subtypethe server advertised in itsContent-Typeheader, and isNonefor a local file, whose format is derived from its name. Only regular files are returned, directories are silently skipped. The exception is apatternnaming 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_parentsisTrue.Raises
FileNotFoundErrorif no file was found after searching all locations.