craft_parts.sources.sources module¶
Source handle utilities.
Unless the part plugin overrides this behaviour, a part can use these ‘source’ keys in its definition. They tell Craft Parts where to pull source code for that part, and how to unpack it if necessary.
source: url-or-path
A URL or path to some source tree to build. It can be local (‘./src/foo’) or remote (’https://foo.org/…’), and can refer to a directory tree or a tarball or a revision control repository (‘git:…’).
source-type: git, tar, deb, rpm, or zip
In some cases the source string is not enough to identify the version control system or compression algorithm. The source-type key can tell Craft Parts exactly how to treat that content.
source-checksum: <algorithm>/<digest>
Craft Parts will use the digest specified to verify the integrity of the source. The source-type needs to be a file (tar, zip, deb or rpm) and the algorithm either md5, sha1, sha224, sha256, sha384, sha512, sha3_256, sha3_384 or sha3_512.
source-depth: <integer>
By default clones or branches with full history, specifying a depth will truncate the history to the specified number of commits.
source-branch: <branch-name>
Craft Parts will checkout a specific branch from the source tree. This only works on multi-branch repositories from git and hg (mercurial).
source-commit: <commit>
Craft Parts will checkout the specific commit from the source tree revision control system.
source-tag: <tag>
Craft Parts will checkout the specific tag from the source tree revision control system.
source-subdir: path
When building, Snapcraft will set the working directory to be this subdirectory within the source.
source-submodules: <list-of-submodules>
Configure which submodules to fetch from the source tree. If source-submodules in defined and empty, no submodules are fetched. If source-submodules is not defined, all submodules are fetched (default behavior).
Note that plugins might well define their own semantics for the ‘source’ keywords, because they handle specific build systems, and many languages have their own built-in packaging systems (think CPAN, PyPI, NPM). In those cases you want to refer to the documentation for the specific plugin.
- craft_parts.sources.sources.get_source_handler(cache_dir, part, project_dirs, ignore_patterns=None)[source]¶
Return the appropriate handler for the given source.
- Parameters:
application_name – The name of the application using Craft Parts.
part (
Part
) – The part to get a source handler for.project_dirs (
ProjectDirs
) – The project’s work directories.cache_dir (
Path
)ignore_patterns (
Optional
[list
[str
]])
- Return type:
SourceHandler
|None
- craft_parts.sources.sources.get_source_type_from_uri(source, ignore_errors=False)[source]¶
Return the source type based on the given source URI.
- Parameters:
source (
str
) – The source specification.ignore_errors (
bool
) – Don’t raise InvalidSourceType if the source type could not be determined.
- Return type:
str
- Returns:
a string matching the registered source type.
- Raises:
InvalidSourceType – If the source type is unknown.
- craft_parts.sources.sources.register(source, /)[source]¶
Register source handlers.
- Parameters:
source (
type
[SourceHandler
]) – a SourceHandler class to register.- Raises:
ValueError if the source handler overrides a built-in source type.
- Return type:
None