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

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

commit 8c0271a8ff3cb999f9894291c6f9b55cd8e3701c
Author: Tristan van Berkom <[email protected]>
AuthorDate: Fri Feb 5 16:05:30 2021 +0900

    Moving HostMount from _project.py -> types.py
    
    Putting simple types here helps avoid circular imports, and allows
    us to remove a nested import statement from the CLI.
---
 src/buildstream/_frontend/cli.py |  6 ++----
 src/buildstream/_project.py      | 31 +++++--------------------------
 src/buildstream/types.py         | 22 +++++++++++++++++++++-
 3 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index e1d84a7..fbe16d3 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -7,7 +7,7 @@ import click
 from .. import _yaml
 from .._exceptions import BstError, LoadError, AppError
 from .complete import main_bashcomplete, complete_path, CompleteUnhandled
-from ..types import _CacheBuildTrees, _SchedulerErrorAction, _PipelineSelection
+from ..types import _CacheBuildTrees, _SchedulerErrorAction, 
_PipelineSelection, _HostMount, _Scope
 from ..utils import UtilError
 
 
@@ -611,8 +611,6 @@ def shell(app, element, mount, isolate, build_, 
cli_buildtree, pull_, command):
     If no COMMAND is specified, the default is to attempt
     to run an interactive shell.
     """
-    from ..element import _Scope
-    from .._project import HostMount
 
     # Buildtree can only be used with build shells
     if cli_buildtree:
@@ -626,7 +624,7 @@ def shell(app, element, mount, isolate, build_, 
cli_buildtree, pull_, command):
             if not element:
                 raise AppError('Missing argument "ELEMENT".')
 
-        mounts = [HostMount(path, host_path) for host_path, path in mount]
+        mounts = [_HostMount(path, host_path) for host_path, path in mount]
 
         try:
             exitcode = app.stream.shell(
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index c8d8e5c..b54139c 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -35,7 +35,7 @@ from .exceptions import LoadErrorReason
 from ._options import OptionPool
 from .node import ScalarNode, SequenceNode, MappingNode, 
ProvenanceInformation, _assert_symbol_name
 from ._pluginfactory import ElementFactory, SourceFactory, load_plugin_origin
-from .types import CoreWarnings
+from .types import CoreWarnings, _HostMount
 from ._projectrefs import ProjectRefs, ProjectRefStorage
 from ._loader import Loader, LoadContext
 from .element import Element
@@ -52,27 +52,6 @@ if TYPE_CHECKING:
 _PROJECT_CONF_FILE = "project.conf"
 
 
-# HostMount()
-#
-# A simple object describing the behavior of
-# a host mount.
-#
-class HostMount:
-    def __init__(self, path, host_path=None, optional=False):
-
-        # Support environment variable expansion in host mounts
-        path = os.path.expandvars(path)
-        if host_path is not None:
-            host_path = os.path.expandvars(host_path)
-
-        self.path = path  # Path inside the sandbox
-        self.host_path = host_path  # Path on the host
-        self.optional = optional  # Optional mounts do not incur warnings or 
errors
-
-        if self.host_path is None:
-            self.host_path = self.path
-
-
 # Represents project configuration that can have different values for 
junctions.
 class ProjectConfig:
     def __init__(self):
@@ -159,7 +138,7 @@ class Project:
         self._fatal_warnings: List[str] = []  # A list of warnings which 
should trigger an error
         self._shell_command: List[str] = []  # The default interactive shell 
command
         self._shell_environment: Dict[str, str] = {}  # Statically set 
environment vars
-        self._shell_host_files: List[str] = []  # A list of HostMount objects
+        self._shell_host_files: List[_HostMount] = []  # A list of HostMount 
objects
 
         # This is a lookup table of lists indexed by project,
         # the child dictionaries are lists of ScalarNodes indicating
@@ -256,7 +235,7 @@ class Project:
     # Returns:
     #    (list): The shell command
     #    (dict): The shell environment
-    #    (list): The list of HostMount objects
+    #    (list): The list of _HostMount objects
     #
     def get_shell_config(self):
         return (self._shell_command, self._shell_environment, 
self._shell_host_files)
@@ -915,7 +894,7 @@ class Project:
         host_files = shell_options.get_sequence("host-files", default=[])
         for host_file in host_files:
             if isinstance(host_file, ScalarNode):
-                mount = HostMount(host_file.as_str())
+                mount = _HostMount(host_file.as_str())
             else:
                 # Some validation
                 host_file.validate_keys(["path", "host_path", "optional"])
@@ -924,7 +903,7 @@ class Project:
                 path = host_file.get_str("path")
                 host_path = host_file.get_str("host_path", default=None)
                 optional = host_file.get_bool("optional", default=False)
-                mount = HostMount(path, host_path, optional)
+                mount = _HostMount(path, host_path, optional)
 
             self._shell_host_files.append(mount)
 
diff --git a/src/buildstream/types.py b/src/buildstream/types.py
index 67383f8..4d9effc 100644
--- a/src/buildstream/types.py
+++ b/src/buildstream/types.py
@@ -25,7 +25,8 @@ Foundation types
 
 """
 
-from typing import Any, Dict, List, Union
+from typing import Any, Dict, List, Union, Optional
+import os
 
 from ._types import MetaFastEnum
 
@@ -310,6 +311,25 @@ class _ProjectInformation:
         self.internal = internal
 
 
+# _HostMount()
+#
+# A simple object describing the behavior of a host mount.
+#
+class _HostMount:
+    def __init__(self, path: str, host_path: Optional[str] = None, optional: 
bool = False) -> None:
+
+        # Support environment variable expansion in host mounts
+        path = os.path.expandvars(path)
+        if host_path is None:
+            host_path = path
+        else:
+            host_path = os.path.expandvars(host_path)
+
+        self.path: str = path  # Path inside the sandbox
+        self.host_path: str = host_path  # Path on the host
+        self.optional: bool = optional  # Optional mounts do not incur 
warnings or errors
+
+
 ########################################
 #           Type aliases               #
 ########################################

Reply via email to