This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch tristan/mirror-plugins in repository https://gitbox.apache.org/repos/asf/buildstream-plugins.git
commit 39dbab61fc4690a9cf920017bd530d69c1c3a249 Author: Tristan van Berkom <[email protected]> AuthorDate: Mon Oct 14 18:24:15 2024 +0900 Adding simple_mirror source mirror plugin Since we've added the SourceMirror feature in BuildStream 2.2, it makes sense to add this mirror plugin upstream. This is especially helpful as we can rely on loading stable buildstream-plugins via the `pip` plugin origin for loading source mirror plugins, avoiding a cyclic dependency issue if you want to use mirror plugins to load plugins via the `junction` plugin origin. --- doc/Makefile | 3 ++ doc/source/index.rst | 6 +++ project.conf | 5 +++ setup.py | 3 ++ .../sourcemirrors/simple_mirror.py | 46 ++++++++++++++++++++++ 5 files changed, 63 insertions(+) diff --git a/doc/Makefile b/doc/Makefile index eae1340..8f03dff 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -74,10 +74,12 @@ templates: mkdir -p source/sources $(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream_plugins,elements) $(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream_plugins,sources) + $(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream_plugins,sourcemirrors) templates-clean: rm -rf source/elements rm -rf source/sources + rm -rf source/sourcemirrors # Targets which generate docs with sphinx build # @@ -89,6 +91,7 @@ html devhelp: templates $(wildcard source/*.rst) \ $(wildcard source/elements/*.rst) \ $(wildcard source/sources/*.rst) + $(wildcard source/sourcemirrors/*.rst) @echo @echo "Build of $@ finished, output: $(CURDIR)/$(BUILDDIR)/$@" diff --git a/doc/source/index.rst b/doc/source/index.rst index 7aec4ea..95b6f8c 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -42,3 +42,9 @@ To these plugins in your project, follow the sources/git sources/patch sources/pip + +.. toctree:: + :maxdepth: 1 + :caption: Source Mirror Plugins + + sourcemirrors/simple_mirror diff --git a/project.conf b/project.conf index a685d47..301bb08 100644 --- a/project.conf +++ b/project.conf @@ -39,3 +39,8 @@ plugins: - git - patch - pip + +- origin: local + path: src/buildstream_plugins/sourcemirrors + source-mirrors: + - simple_mirror diff --git a/setup.py b/setup.py index b5dad20..b7de25b 100755 --- a/setup.py +++ b/setup.py @@ -92,6 +92,9 @@ setup( "pip = buildstream_plugins.sources.pip", "zip = buildstream_plugins.sources.zip", ], + "buildstream.plugins.sourcemirrors": [ + "simple_mirror = buildstream_plugins.sourcemirrors.simple_mirror", + ], }, extras_require={ "cargo": ['tomli; python_version < "3.11"'], diff --git a/src/buildstream_plugins/sourcemirrors/simple_mirror.py b/src/buildstream_plugins/sourcemirrors/simple_mirror.py new file mode 100644 index 0000000..1312faf --- /dev/null +++ b/src/buildstream_plugins/sourcemirrors/simple_mirror.py @@ -0,0 +1,46 @@ +""" +simple_mirror - plugin for simplifying mirror definitions +========================================================= + +.. note:: + + The ``simple_mirror`` plugin is available *Since 2.4.0* + +**Usage:** + +.. code:: yaml + +- name: my-mirror + kind: simple_mirror + config: + url: https://example.com/mirrors/{alias}/ + aliases: + - my-alias + - another-alias + +This plugin simplifies defining mirrors for projects where the mirrors follow +a predictable URL format that only varies with the alias name. +""" + +from posixpath import join +from buildstream import SourceMirror + + +class SimpleMirror(SourceMirror): + BST_MIN_VERSION = "2.2" + + def configure(self, node): + node.validate_keys(["url", "aliases"]) + self.set_supported_aliases(node.get_str_list("aliases")) + + self.url = node.get_str("url") + + def translate_url(self, alias, alias_url, source_url, extra_data): + base_url = self.url.format(alias=alias) + translated_url = join(base_url, source_url) + + return translated_url + + +def setup(): + return SimpleMirror
