diff options
author | Chandan Singh <csingh43@bloomberg.net> | 2019-11-05 13:00:30 +0000 |
---|---|---|
committer | Chandan Singh <csingh43@bloomberg.net> | 2019-11-05 13:00:30 +0000 |
commit | e06c2295b063245dbdb2397e5bd8c4d0a79ba10d (patch) | |
tree | 224a111e1daee5a7d450e7d5e0c31fd94c1e19c6 /src/buildstream/sandbox/_sandboxbuildbox.py | |
parent | c1f423f8653c5a9e3e72283879e8cecabf25ed3f (diff) | |
download | buildstream-e06c2295b063245dbdb2397e5bd8c4d0a79ba10d.tar.gz |
Blacken codebase
Diffstat (limited to 'src/buildstream/sandbox/_sandboxbuildbox.py')
-rw-r--r-- | src/buildstream/sandbox/_sandboxbuildbox.py | 84 |
1 files changed, 51 insertions, 33 deletions
diff --git a/src/buildstream/sandbox/_sandboxbuildbox.py b/src/buildstream/sandbox/_sandboxbuildbox.py index 4258ee26d..15e45a4df 100644 --- a/src/buildstream/sandbox/_sandboxbuildbox.py +++ b/src/buildstream/sandbox/_sandboxbuildbox.py @@ -34,22 +34,22 @@ from .._exceptions import SandboxError # BuildBox-based sandbox implementation. # class SandboxBuildBox(Sandbox): - def __init__(self, context, project, directory, **kwargs): - if kwargs.get('allow_real_directory'): + if kwargs.get("allow_real_directory"): raise SandboxError("BuildBox does not support real directories") - kwargs['allow_real_directory'] = False + kwargs["allow_real_directory"] = False super().__init__(context, project, directory, **kwargs) @classmethod def check_available(cls): try: - utils.get_host_tool('buildbox') + utils.get_host_tool("buildbox") except utils.ProgramNotFoundError as Error: cls._dummy_reasons += ["buildbox not found"] - raise SandboxError(" and ".join(cls._dummy_reasons), - reason="unavailable-local-sandbox") from Error + raise SandboxError( + " and ".join(cls._dummy_reasons), reason="unavailable-local-sandbox" + ) from Error @classmethod def check_sandbox_config(cls, platform, config): @@ -73,42 +73,48 @@ class SandboxBuildBox(Sandbox): scratch_directory = self._get_scratch_directory() if not self._has_command(command[0], env): - raise SandboxCommandError("Staged artifacts do not provide command " - "'{}'".format(command[0]), - reason='missing-command') + raise SandboxCommandError( + "Staged artifacts do not provide command " "'{}'".format(command[0]), + reason="missing-command", + ) # Grab the full path of the buildbox binary try: - buildbox_command = [utils.get_host_tool('buildbox')] + buildbox_command = [utils.get_host_tool("buildbox")] except ProgramNotFoundError as Err: - raise SandboxError(("BuildBox not on path, you are using the BuildBox sandbox because " - "BST_FORCE_SANDBOX=buildbox")) from Err + raise SandboxError( + ( + "BuildBox not on path, you are using the BuildBox sandbox because " + "BST_FORCE_SANDBOX=buildbox" + ) + ) from Err for mark in self._get_marked_directories(): - path = mark['directory'] - assert path.startswith('/') and len(path) > 1 + path = mark["directory"] + assert path.startswith("/") and len(path) > 1 root_directory.descend(*path[1:].split(os.path.sep), create=True) digest = root_directory._get_digest() - with open(os.path.join(scratch_directory, 'in'), 'wb') as input_digest_file: + with open(os.path.join(scratch_directory, "in"), "wb") as input_digest_file: input_digest_file.write(digest.SerializeToString()) buildbox_command += ["--local=" + root_directory.cas_cache.casdir] buildbox_command += ["--input-digest=in"] buildbox_command += ["--output-digest=out"] - common_details = ("BuildBox is a experimental sandbox and does not support the requested feature.\n" - "You are using this feature because BST_FORCE_SANDBOX=buildbox.") + common_details = ( + "BuildBox is a experimental sandbox and does not support the requested feature.\n" + "You are using this feature because BST_FORCE_SANDBOX=buildbox." + ) if not flags & SandboxFlags.NETWORK_ENABLED: # TODO self._issue_warning( - "BuildBox sandbox does not have Networking yet", - detail=common_details + "BuildBox sandbox does not have Networking yet", detail=common_details ) if cwd is not None: - buildbox_command += ['--chdir=' + cwd] + buildbox_command += ["--chdir=" + cwd] # In interactive mode, we want a complete devpts inside # the container, so there is a /dev/console and such. In @@ -119,14 +125,14 @@ class SandboxBuildBox(Sandbox): # TODO self._issue_warning( "BuildBox sandbox does not fully support BuildStream shells yet", - detail=common_details + detail=common_details, ) if flags & SandboxFlags.ROOT_READ_ONLY: # TODO self._issue_warning( "BuildBox sandbox does not fully support BuildStream `Read only Root`", - detail=common_details + detail=common_details, ) # Set UID and GID @@ -134,11 +140,11 @@ class SandboxBuildBox(Sandbox): # TODO self._issue_warning( "BuildBox sandbox does not fully support BuildStream Inherit UID", - detail=common_details + detail=common_details, ) - os.makedirs(os.path.join(scratch_directory, 'mnt'), exist_ok=True) - buildbox_command += ['mnt'] + os.makedirs(os.path.join(scratch_directory, "mnt"), exist_ok=True) + buildbox_command += ["mnt"] # Add the command buildbox_command += command @@ -150,7 +156,7 @@ class SandboxBuildBox(Sandbox): with ExitStack() as stack: # Ensure the cwd exists if cwd is not None and len(cwd) > 1: - assert cwd.startswith('/') + assert cwd.startswith("/") root_directory.descend(*cwd[1:].split(os.path.sep), create=True) # If we're interactive, we want to inherit our stdin, @@ -162,15 +168,25 @@ class SandboxBuildBox(Sandbox): stdin = stack.enter_context(open(os.devnull, "r")) # Run buildbox ! - exit_code = self.run_buildbox(buildbox_command, stdin, stdout, stderr, env, - interactive=(flags & SandboxFlags.INTERACTIVE), - cwd=scratch_directory) + exit_code = self.run_buildbox( + buildbox_command, + stdin, + stdout, + stderr, + env, + interactive=(flags & SandboxFlags.INTERACTIVE), + cwd=scratch_directory, + ) if exit_code == 0: - with open(os.path.join(scratch_directory, 'out'), 'rb') as output_digest_file: + with open( + os.path.join(scratch_directory, "out"), "rb" + ) as output_digest_file: output_digest = remote_execution_pb2.Digest() output_digest.ParseFromString(output_digest_file.read()) - self._vdir = CasBasedDirectory(root_directory.cas_cache, digest=output_digest) + self._vdir = CasBasedDirectory( + root_directory.cas_cache, digest=output_digest + ) return exit_code @@ -194,7 +210,9 @@ class SandboxBuildBox(Sandbox): group_id = os.getpgid(process.pid) os.killpg(group_id, signal.SIGCONT) - with _signals.suspendable(suspend_proc, resume_proc), _signals.terminator(kill_proc): + with _signals.suspendable(suspend_proc, resume_proc), _signals.terminator( + kill_proc + ): process = subprocess.Popen( argv, close_fds=True, @@ -203,7 +221,7 @@ class SandboxBuildBox(Sandbox): stdout=stdout, stderr=stderr, cwd=cwd, - start_new_session=interactive + start_new_session=interactive, ) # Wait for the child process to finish, ensuring that |