[Notes] [Git][BuildStream/buildstream][Qinusty/597-non-alias-url-fix] 2 commits: source.py: Take first part of url split for alias



Title: GitLab

Qinusty pushed to branch Qinusty/597-non-alias-url-fix at BuildStream / buildstream

Commits:

3 changed files:

Changes:

  • buildstream/plugin.py
    ... ... @@ -757,6 +757,16 @@ class CoreWarnings():
    757 757
         which is found to be invalid based on the configured track
    
    758 758
         """
    
    759 759
     
    
    760
    +    URL_WITHOUT_ALIAS = "url-without-alias"
    
    761
    +    """
    
    762
    +    This warning will be produced when a source is configured with a url which does not contain an alias.
    
    763
    +    """
    
    764
    +
    
    765
    +    UNKNOWN_ALIAS = "unknown-alias"
    
    766
    +    """
    
    767
    +    This warning will be produced when a source is configured with a url which does not contain an alias.
    
    768
    +    """
    
    769
    +
    
    760 770
     
    
    761 771
     __CORE_WARNINGS = [
    
    762 772
         value
    

  • buildstream/source.py
    ... ... @@ -137,6 +137,7 @@ from . import Plugin
    137 137
     from . import _yaml, utils
    
    138 138
     from ._exceptions import BstError, ImplError, ErrorDomain
    
    139 139
     from ._projectrefs import ProjectRefStorage
    
    140
    +from .plugin import CoreWarnings
    
    140 141
     
    
    141 142
     
    
    142 143
     class Consistency():
    
    ... ... @@ -219,9 +220,9 @@ class SourceFetcher():
    219 220
             Args:
    
    220 221
                url (str): The url used to download.
    
    221 222
             """
    
    222
    -        # Not guaranteed to be a valid alias yet.
    
    223
    -        # Ensuring it's a valid alias currently happens in Project.get_alias_uris
    
    224
    -        alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    223
    +        # NOTE: This takes advantage of _get_alias() checking against project aliases.
    
    224
    +        # This will consider `http://foo.com`` to have an alias of `http`.
    
    225
    +        alias = url.split(utils._ALIAS_SEPARATOR, 1)[0]
    
    225 226
             self.__alias = alias
    
    226 227
     
    
    227 228
         #############################################################
    
    ... ... @@ -459,9 +460,23 @@ class Source(Plugin):
    459 460
     
    
    460 461
             *Since: 1.2*
    
    461 462
             """
    
    462
    -        alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    463
    +        # NOTE: This takes advantage of _get_alias() checking against project aliases.
    
    464
    +        # This will consider `http://foo.com`` to have an alias of `http`.
    
    465
    +        url_parts = url.split(utils._ALIAS_SEPARATOR, 1)
    
    466
    +        alias = url_parts[0]
    
    463 467
             self.__expected_alias = alias
    
    464 468
     
    
    469
    +        # Check and warn when detecting no valid alias.
    
    470
    +        project = self._get_project()
    
    471
    +        if alias.lower() in utils._URI_SCHEMES:
    
    472
    +            self.warn("{}: The use of an alias in urls is strongly advised.".format(self._get_provenance()),
    
    473
    +                      detail="See https://buildstream.gitlab.io/buildstream/format_project.html#source-aliases",
    
    474
    +                      warning_token=CoreWarnings.URL_WITHOUT_ALIAS)
    
    475
    +
    
    476
    +        elif not project.get_alias_uri(alias, first_pass=self.__first_pass) and len(url_parts) > 1:
    
    477
    +            self.warn("{}: Unknown alias '{}' in url".format(self._get_provenance(), alias),
    
    478
    +                      warning_token=CoreWarnings.UNKNOWN_ALIAS)
    
    479
    +
    
    465 480
         def get_source_fetchers(self):
    
    466 481
             """Get the objects that are used for fetching
    
    467 482
     
    
    ... ... @@ -525,7 +540,7 @@ class Source(Plugin):
    525 540
             else:
    
    526 541
                 # Sneakily store the alias if it hasn't already been stored
    
    527 542
                 if not self.__expected_alias and url and utils._ALIAS_SEPARATOR in url:
    
    528
    -                url_alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    543
    +                url_alias = url.split(utils._ALIAS_SEPARATOR, 1)[0]
    
    529 544
                     self.__expected_alias = url_alias
    
    530 545
     
    
    531 546
                 project = self._get_project()
    

  • buildstream/utils.py
    ... ... @@ -47,6 +47,7 @@ _magic_timestamp = calendar.timegm([2011, 11, 11, 11, 11, 11])
    47 47
     
    
    48 48
     # The separator we use for user specified aliases
    
    49 49
     _ALIAS_SEPARATOR = ':'
    
    50
    +_URI_SCHEMES = ["http", "https", "ftp", "file", "git", "sftp", "ssh"]
    
    50 51
     
    
    51 52
     
    
    52 53
     class UtilError(BstError):
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]