FAILED [ 84%]
tests/integration/plugins/test_scons.py:9 (test_scons_plugin)
self = <craft_parts.plugins.scons_plugin.SConsPluginEnvironmentValidator object at 0x7f57e615f2b0>
dependency = 'scons', plugin_name = 'scons', part_dependencies = []
argument = '--version'
def validate_dependency(
self,
dependency: str,
plugin_name: str,
part_dependencies: Optional[List[str]],
argument: str = "--version",
) -> str:
"""Validate that the environment has a required dependency.
`<dependency-name> --version` is executed to confirm the dependency is valid.
:param dependency: name of the dependency to validate.
:param plugin_name: used to generate the part name that would satisfy
the dependency.
:param part_dependencies: A list of the parts this part depends on.
:param argument: argument to call with the dependency. Default is `--version`.
:raises PluginEnvironmentValidationError: If the environment is invalid.
:return: output from executed dependency
"""
try:
command = f"{dependency} {argument}"
> output = self._execute(command).strip()
/home/lengau/Work/Code/craft-parts/craft_parts/plugins/validator.py:100:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <craft_parts.plugins.scons_plugin.SConsPluginEnvironmentValidator object at 0x7f57e615f2b0>
cmd = 'scons --version'
def _execute(self, cmd: str) -> str:
"""Execute a command in a build environment shell.
:param cmd: The command to execute.
:return: The command output or error message.
"""
logger.debug("plugin validation environment: %s", self._env)
logger.debug("plugin validation command: %r", cmd)
with tempfile.NamedTemporaryFile(mode="w+") as env_file:
print(self._env, file=env_file)
print(cmd, file=env_file)
env_file.flush()
> proc = subprocess.run(
["/bin/bash", env_file.name],
check=True,
capture_output=True,
universal_newlines=True,
)
/home/lengau/Work/Code/craft-parts/craft_parts/plugins/validator.py:143:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
input = None, capture_output = True, timeout = None, check = True
popenargs = (['/bin/bash', '/tmp/tmpk2u9crjk'],)
kwargs = {'stderr': -1, 'stdout': -1, 'universal_newlines': True}
process = <Popen: returncode: 127 args: ['/bin/bash', '/tmp/tmpk2u9crjk']>
stdout = '', stderr = '/tmp/tmpk2u9crjk: line 22: scons: command not found\n'
retcode = 127
def run(*popenargs,
input=None, capture_output=False, timeout=None, check=False, **kwargs):
"""Run command with arguments and return a CompletedProcess instance.
The returned instance will have attributes args, returncode, stdout and
stderr. By default, stdout and stderr are not captured, and those attributes
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
If check is True and the exit code was non-zero, it raises a
CalledProcessError. The CalledProcessError object will have the return code
in the returncode attribute, and output & stderr attributes if those streams
were captured.
If timeout is given, and the process takes too long, a TimeoutExpired
exception will be raised.
There is an optional argument "input", allowing you to
pass bytes or a string to the subprocess's stdin. If you use this argument
you may not also use the Popen constructor's "stdin" argument, as
it will be used internally.
By default, all communication is in bytes, and therefore any "input" should
be bytes, and the stdout and stderr will be bytes. If in text mode, any
"input" should be a string, and stdout and stderr will be strings decoded
according to locale encoding, or by "encoding" if set. Text mode is
triggered by setting any of text, encoding, errors or universal_newlines.
The other arguments are the same as for the Popen constructor.
"""
if input is not None:
if kwargs.get('stdin') is not None:
raise ValueError('stdin and input arguments may not both be used.')
kwargs['stdin'] = PIPE
if capture_output:
if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
raise ValueError('stdout and stderr arguments may not be used '
'with capture_output.')
kwargs['stdout'] = PIPE
kwargs['stderr'] = PIPE
with Popen(*popenargs, **kwargs) as process:
try:
stdout, stderr = process.communicate(input, timeout=timeout)
except TimeoutExpired as exc:
process.kill()
if _mswindows:
# Windows accumulates the output in a single blocking
# read() call run on child threads, with the timeout
# being done in a join() on those threads. communicate()
# _after_ kill() is required to collect that and add it
# to the exception.
exc.stdout, exc.stderr = process.communicate()
else:
# POSIX _communicate already populated the output so
# far into the TimeoutExpired exception.
process.wait()
raise
except: # Including KeyboardInterrupt, communicate handled that.
process.kill()
# We don't call process.wait() as .__exit__ does that for us.
raise
retcode = process.poll()
if check and retcode:
> raise CalledProcessError(retcode, process.args,
output=stdout, stderr=stderr)
E subprocess.CalledProcessError: Command '['/bin/bash', '/tmp/tmpk2u9crjk']' returned non-zero exit status 127.
/usr/lib/python3.10/subprocess.py:524: CalledProcessError
The above exception was the direct cause of the following exception:
new_dir = local('/tmp/pytest-of-lengau/pytest-33/test_scons_plugin0')
def test_scons_plugin(new_dir):
"""Test builds with the scons plugin"""
source_location = Path(__file__).parent / "test_scons"
parts_yaml = textwrap.dedent(
f"""
parts:
foo:
plugin: scons
source: {source_location}
scons-parameters:
- greeting=Hello
- person-name=craft-parts
"""
)
parts = yaml.safe_load(parts_yaml)
lf = LifecycleManager(
parts, application_name="test_scons", cache_dir=new_dir, work_dir=new_dir
)
actions = lf.plan(Step.PRIME)
> with lf.action_executor() as ctx:
/home/lengau/Work/Code/craft-parts/tests/integration/plugins/test_scons.py:31:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/lengau/Work/Code/craft-parts/craft_parts/executor/executor.py:284: in __enter__
self._executor.prologue()
/home/lengau/Work/Code/craft-parts/craft_parts/executor/executor.py:92: in prologue
self._verify_plugin_environment()
/home/lengau/Work/Code/craft-parts/craft_parts/executor/executor.py:270: in _verify_plugin_environment
validator.validate_environment(part_dependencies=part.dependencies)
/home/lengau/Work/Code/craft-parts/craft_parts/plugins/scons_plugin.py:72: in validate_environment
version = self.validate_dependency(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <craft_parts.plugins.scons_plugin.SConsPluginEnvironmentValidator object at 0x7f57e615f2b0>
dependency = 'scons', plugin_name = 'scons', part_dependencies = []
argument = '--version'
def validate_dependency(
self,
dependency: str,
plugin_name: str,
part_dependencies: Optional[List[str]],
argument: str = "--version",
) -> str:
"""Validate that the environment has a required dependency.
`<dependency-name> --version` is executed to confirm the dependency is valid.
:param dependency: name of the dependency to validate.
:param plugin_name: used to generate the part name that would satisfy
the dependency.
:param part_dependencies: A list of the parts this part depends on.
:param argument: argument to call with the dependency. Default is `--version`.
:raises PluginEnvironmentValidationError: If the environment is invalid.
:return: output from executed dependency
"""
try:
command = f"{dependency} {argument}"
output = self._execute(command).strip()
logger.debug("executed %s with output %s", command, output)
return output
except subprocess.CalledProcessError as err:
if err.returncode != COMMAND_NOT_FOUND:
raise errors.PluginEnvironmentValidationError(
part_name=self._part_name,
reason=f"{dependency!r} failed with error code {err.returncode}",
) from err
if part_dependencies is None:
raise errors.PluginEnvironmentValidationError(
part_name=self._part_name,
reason=f"{dependency!r} not found",
) from err
part_dependency = f"{plugin_name}-deps"
if part_dependency not in part_dependencies:
> raise errors.PluginEnvironmentValidationError(
part_name=self._part_name,
reason=(
f"{dependency!r} not found and part {self._part_name!r} "
f"does not depend on a part named {part_dependency!r} "
"that would satisfy the dependency"
),
) from err
E craft_parts.errors.PluginEnvironmentValidationError: Environment validation failed for part 'foo': 'scons' not found and part 'foo' does not depend on a part named 'scons-deps' that would satisfy the dependency.
/home/lengau/Work/Code/craft-parts/craft_parts/plugins/validator.py:118: PluginEnvironmentValidationError