Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] add execute build commands from item yaml for specific testing #749

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from glob import iglob
import yaml
from jinja2 import Template
from sys import platform

PROJECT_ROOT = Path(__file__).parent.parent.absolute()

Expand Down Expand Up @@ -134,6 +135,46 @@ def install_requirements(
)


def execute_build_commands(
directory: str,
commands: Union[List[str], Set[str]],
):
"""
Installing requirements from a requirements list/set and from a requirements.txt file if found in directory
:param directory: The relevant directory were the requirements are installed and collected
:param commands: Requirement list/set with or without bounds
"""
build_file = str(Path(directory) / 'item.yaml')

with open(build_file, 'r') as file:
item_yaml = yaml.safe_load(file)

spec = item_yaml['spec']
item_commands = None
if 'build' in spec:
build = spec['build']
if 'commands' in build:
item_commands = build['commands']

if not item_commands and not commands.exists():
print(f"No build commands found for {directory}...")
return

if item_commands is not None:
if platform == "linux" or platform == "linux2":
print(f"running commands from {build_file}...")
for command in item_commands:
_run_subprocess(f"{command}"
, directory)
else:
print(f"cannot install commands on {platform}...")

if commands:
print(f"Installing commands [{' '.join(commands)}] for {directory}...")
_run_subprocess(
f"{commands}", directory
)

def get_item_yaml_values(
item_path: pathlib.Path, keys: Union[str, Set[str]]
) -> Dict[str, Set[str]]:
Expand Down Expand Up @@ -167,6 +208,8 @@ def get_item_yaml_values(
if values:
if isinstance(values, list):
values_set = set(values)
elif isinstance(values, dict):
values_set = values
else:
values_set.add(values)
values_dict[key] = values_set
Expand Down
2 changes: 2 additions & 0 deletions cli/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
install_pipenv,
install_python,
install_requirements,
execute_build_commands,
get_item_yaml_values,
)
from cli.path_iterator import PathIterator
Expand Down Expand Up @@ -236,6 +237,7 @@ def run(self, path: Union[str, Path]):
item_requirements = list(get_item_yaml_values(path, 'requirements')['requirements'])
mlrun_version = list(get_item_yaml_values(path, "mlrunVersion")["mlrunVersion"])[0]
install_requirements(path, ["pytest", f"mlrun=={mlrun_version}"] + item_requirements)
execute_build_commands(path,[])
click.echo(f"Running tests for {path}...")
completed_process: CompletedProcess = subprocess.run(
f"cd {path} ; pipenv run python -m pytest",
Expand Down
Loading