You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/12/07 10:44:01 UTC

[buildstream] 01/04: _project.py: Change get_alias_uri() -> alias_exists()

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/mirror-policy
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit ea4bb14aed38a3998a17a65d2435397a0242fa22
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Thu Nov 11 16:37:42 2021 +0900

    _project.py: Change get_alias_uri() -> alias_exists()
    
    This clarifies the purpose of this API, which is only used to check
    the presence of an alias.
    
      - Project.alias_exists() now checks if the alias is declared
      - Project.get_alias_uris() is the only valid way to actually expand the URIs
---
 src/buildstream/_project.py | 10 +++++-----
 src/buildstream/source.py   |  5 ++---
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 882f2c7..24783ea 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -369,7 +369,7 @@ class Project:
     def create_source(self, meta, variables):
         return self.source_factory.create(self._context, self, meta, variables)
 
-    # get_alias_uri()
+    # alias_exists()
     #
     # Returns the URI for a given alias, if it exists
     #
@@ -378,15 +378,15 @@ class Project:
     #    first_pass (bool): Whether to use first pass configuration (for junctions)
     #
     # Returns:
-    #    str: The URI for the given alias; or None: if there is no URI for
-    #         that alias.
-    def get_alias_uri(self, alias, *, first_pass=False):
+    #    bool: Whether the alias is declared in the scope of this project
+    #
+    def alias_exists(self, alias, *, first_pass=False):
         if first_pass:
             config = self.first_pass_config
         else:
             config = self.config
 
-        return config._aliases.get_str(alias, default=None)
+        return config._aliases.get_str(alias, default=None) is not None
 
     # get_alias_uris()
     #
diff --git a/src/buildstream/source.py b/src/buildstream/source.py
index fa8042c..afc2092 100644
--- a/src/buildstream/source.py
+++ b/src/buildstream/source.py
@@ -682,8 +682,7 @@ class Source(Plugin):
         # If there is an alias in use, ensure that it exists in the project
         if alias:
             project = self._get_project()
-            alias_uri = project.get_alias_uri(alias, first_pass=self.__first_pass)
-            if alias_uri is None:
+            if not project.alias_exists(alias, first_pass=self.__first_pass):
                 raise SourceError(
                     "{}: Invalid alias '{}' specified in URL: {}".format(self, alias, url),
                     reason="invalid-source-alias",
@@ -1117,7 +1116,7 @@ class Source(Plugin):
     def _get_alias(self):
         alias = self.__expected_alias
         project = self._get_project()
-        if project.get_alias_uri(alias, first_pass=self.__first_pass):
+        if project.alias_exists(alias, first_pass=self.__first_pass):
             # The alias must already be defined in the project's aliases
             # otherwise http://foo gets treated like it contains an alias
             return alias