Skip to content

Commit 2064cf3

Browse files
Make types._SourceProvenance public
This is needed for plugins to provide their source provenance info in their own way instead of the top level source info that is used by default. This is necessary for multi-source source plugins to provide source info per source
1 parent f462439 commit 2064cf3

File tree

3 files changed

+57
-43
lines changed

3 files changed

+57
-43
lines changed

src/buildstream/element.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
from .sandbox import _SandboxFlags, SandboxCommandError
9191
from .sandbox._config import SandboxConfig
9292
from .sandbox._sandboxremote import SandboxRemote
93-
from .types import _Scope, _CacheBuildTrees, _KeyStrength, OverlapAction, _DisplayKey, _SourceProvenance
93+
from .types import _Scope, _CacheBuildTrees, _KeyStrength, OverlapAction, _DisplayKey, SourceProvenance
9494
from ._artifact import Artifact
9595
from ._elementproxy import ElementProxy
9696
from ._elementsources import ElementSources
@@ -2639,7 +2639,7 @@ def __load_sources(self, load_element):
26392639
provenance = None
26402640
if provenance_node:
26412641
del source[Symbol.PROVENANCE]
2642-
provenance = _SourceProvenance.new_from_node(provenance_node)
2642+
provenance = SourceProvenance.new_from_node(provenance_node)
26432643

26442644
meta_source = MetaSource(
26452645
self.name,

src/buildstream/source.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@
378378
from .node import MappingNode
379379
from .plugin import Plugin
380380
from .sourcemirror import SourceMirror
381-
from .types import SourceRef, CoreWarnings, FastEnum, _SourceProvenance
381+
from .types import SourceRef, CoreWarnings, FastEnum, SourceProvenance
382382
from ._exceptions import BstError, ImplError, PluginError
383383
from .exceptions import ErrorDomain
384384
from ._loader.metasource import MetaSource
@@ -825,8 +825,8 @@ def __init__(
825825
self._directory = meta.directory # Staging relative directory
826826
self.__variables = variables # The variables used to resolve the source's config
827827
self.__provenance: Optional[
828-
_SourceProvenance
829-
] = meta.provenance # The _SourceProvenance for general user provided SourceInfo
828+
SourceProvenance
829+
] = meta.provenance # The SourceProvenance for general user provided SourceInfo
830830

831831
self.__key = None # Cache key for source
832832

@@ -1367,7 +1367,7 @@ def create_source_info(
13671367
version: str,
13681368
*,
13691369
version_guess: Optional[str] = None,
1370-
source_provenance_attrs: Optional[_SourceProvenance] = None,
1370+
source_provenance_attrs: Optional[SourceProvenance] = None,
13711371
extra_data: Optional[Dict[str, str]] = None,
13721372
) -> SourceInfo:
13731373
"""Create a :class:`.SourceInfo` object

src/buildstream/types.py

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,54 @@ class OverlapAction(FastEnum):
164164
"""
165165

166166

167+
# SourceProvenance()
168+
#
169+
# A simple object describing user provided source provenance information
170+
#
171+
# Args:
172+
# homepage: The source's homepage URL
173+
# issue_tracker: The source's issue reporting URL
174+
#
175+
class SourceProvenance:
176+
def __init__(
177+
self,
178+
homepage: Optional[str],
179+
issue_tracker: Optional[str],
180+
):
181+
self.homepage: Optional[str] = homepage
182+
self.issue_tracker: Optional[str] = issue_tracker
183+
184+
# new_from_node():
185+
#
186+
# Creates a SourceProvenance() from a YAML loaded node.
187+
#
188+
# Args:
189+
# node: The configuration node describing the spec.
190+
#
191+
# Returns:
192+
# The described SourceProvenance instance.
193+
#
194+
# Raises:
195+
# LoadError: If the node is malformed.
196+
#
197+
@classmethod
198+
def new_from_node(cls, node: MappingNode) -> "SourceProvenance":
199+
node.validate_keys(
200+
[
201+
"homepage",
202+
"issue-tracker",
203+
]
204+
)
205+
206+
homepage: Optional[str] = node.get_str("homepage", None)
207+
issue_tracker: Optional[str] = node.get_str("issue-tracker", None)
208+
209+
return cls(
210+
homepage,
211+
issue_tracker,
212+
)
213+
214+
167215
# _Scope():
168216
#
169217
# Defines the scope of dependencies to include for a given element
@@ -324,7 +372,9 @@ def __str__(self):
324372
class _ProjectInformation:
325373
def __init__(self, project, provenance_node, duplicates, internal):
326374
self.project = project
327-
self.provenance = provenance_node.get_provenance() if provenance_node else None
375+
self.provenance = (
376+
provenance_node.get_provenance() if provenance_node else None
377+
)
328378
self.duplicates = duplicates
329379
self.internal = internal
330380

@@ -390,42 +440,6 @@ def new_from_node(cls, node: MappingNode) -> "_SourceMirror":
390440
return cls(name, aliases)
391441

392442

393-
# _SourceProvenance()
394-
#
395-
# A simple object describing user provided source provenance information
396-
#
397-
# Args:
398-
# homepage: The project homepage URL
399-
# issue_tracker: The project issue reporting URL
400-
#
401-
class _SourceProvenance:
402-
def __init__(self, homepage: Optional[str], issue_tracker: Optional[str]):
403-
self.homepage: Optional[str] = homepage
404-
self.issue_tracker: Optional[str] = issue_tracker
405-
406-
# new_from_node():
407-
#
408-
# Creates a _SourceProvenance() from a YAML loaded node.
409-
#
410-
# Args:
411-
# node: The configuration node describing the spec.
412-
#
413-
# Returns:
414-
# The described _SourceProvenance instance.
415-
#
416-
# Raises:
417-
# LoadError: If the node is malformed.
418-
#
419-
@classmethod
420-
def new_from_node(cls, node: MappingNode) -> "_SourceProvenance":
421-
node.validate_keys(["homepage", "issue-tracker"])
422-
423-
homepage: Optional[str] = node.get_str("homepage", None)
424-
issue_tracker: Optional[str] = node.get_str("issue-tracker", None)
425-
426-
return cls(homepage, issue_tracker)
427-
428-
429443
########################################
430444
# Type aliases #
431445
########################################

0 commit comments

Comments
 (0)