diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 71e0fa7..6d5ecf6 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -108,6 +108,9 @@ jobs: if: ${{ matrix.os != 'macos' }} run: makim smoke-tests.containers + - name: Run smoke tests using different interpreters + run: makim smoke-tests.shell-app + - name: Run smoke tests using unittest makim file run: makim smoke-tests.unittest diff --git a/.makim.yaml b/.makim.yaml index b33674e..94c2ad4 100644 --- a/.makim.yaml +++ b/.makim.yaml @@ -167,6 +167,21 @@ groups: cd ./tests/ makim $VERBOSE_FLAG --file $MAKIM_FILE containers.run + shell-app: + help: Test makim with working-directory for global no-path and its various combinations with group and target working-directory + args: + verbose-mode: + help: Run the all the tests in verbose mode + type: bool + action: store_true + env: + MAKIM_FILE: tests/.makim-interpreters.yaml + shell: bash + run: | + export VERBOSE_FLAG='{{ "--verbose" if args.verbose_mode else "" }}' + export MAKIM_FILE="$(pwd)/${MAKIM_FILE}" + makim $VERBOSE_FLAG --file $MAKIM_FILE main.all + unittest: help: Test makim using a unittest makimfile args: diff --git a/conda/dev.yaml b/conda/dev.yaml index 37f7eb9..91a4d3d 100644 --- a/conda/dev.yaml +++ b/conda/dev.yaml @@ -3,5 +3,14 @@ channels: - nodefaults - conda-forge dependencies: + - bash - python 3.8.1 # min version supported - poetry >=1.5 + - nodejs + - perl + - r-base + - sh + - pip + - pip: + # note: workaround ci issue for macos + - setuptools >= 40.8.0 diff --git a/src/makim/core.py b/src/makim/core.py index 15a9d4a..144d8ba 100644 --- a/src/makim/core.py +++ b/src/makim/core.py @@ -5,6 +5,8 @@ the way to define targets and dependencies. Instead of using the `Makefile` format, it uses `yaml` format. """ +from __future__ import annotations + import io import os import pprint @@ -14,7 +16,7 @@ from copy import deepcopy from pathlib import Path -from typing import Dict, Optional, Tuple, Union +from typing import Optional, Union import dotenv import sh @@ -30,6 +32,12 @@ SCOPE_TARGET = 2 +KNOWN_SHELL_APP_ARGS = { + 'bash': ['-e'], + 'php': ['-f'], +} + + def escape_template_tag(v: str) -> str: """Escape template tag when processing the template config file.""" return v.replace('{{', r'\{\{').replace('}}', r'\}\}') @@ -61,6 +69,7 @@ class Makim(PrintPlugin): verbose: bool = False global_data: dict = {} shell_app: sh.Command = sh.xonsh + shell_args: list[str] = [] # temporary variables env: dict = {} # initial env @@ -84,6 +93,7 @@ def __init__(self): self.file = '.makim.yaml' self.dry_run = False self.verbose = False + self.shell_args: list[str] = [] def _call_shell_app(self, cmd): fd, filepath = tempfile.mkstemp(suffix='.makim', text=True) @@ -228,10 +238,17 @@ def update_working_directory( return working_dir - def _load_shell_app(self, shell_app: str = ''): + def _load_shell_app(self, shell_app: str = '') -> None: if not shell_app: shell_app = self.global_data.get('shell', 'xonsh') - self.shell_app = getattr(sh, shell_app) + return + + cmd = shell_app.split(' ') + cmd_name = cmd[0] + self.shell_app = getattr(sh, cmd_name) + + args: list[str] = KNOWN_SHELL_APP_ARGS.get(cmd_name, []) + self.shell_args = args + cmd[1:] def _load_dotenv(self, data_scope: dict) -> dict: env_file = data_scope.get('env-file') @@ -251,7 +268,7 @@ def _load_dotenv(self, data_scope: dict) -> dict: def _load_scoped_data( self, scope: str - ) -> Tuple[Dict[str, str], Dict[str, str]]: + ) -> tuple[dict[str, str], dict[str, str]]: scope_options = ('global', 'group', 'target') if scope not in scope_options: raise Exception(f'The given scope `{scope}` is not valid.') @@ -332,13 +349,6 @@ def _load_target_args(self): default if default is not None else False if is_bool else None ) - @property - def shell_args(self): - """Return the arguments for the defined shell app.""" - if self.shell_app.__dict__['__name__'].endswith('bash'): - return ['-e'] - return [] - # run commands def _run_dependencies(self, args: dict): diff --git a/tests/.makim-interpreters.yaml b/tests/.makim-interpreters.yaml new file mode 100644 index 0000000..c8114c9 --- /dev/null +++ b/tests/.makim-interpreters.yaml @@ -0,0 +1,43 @@ +version: 1.0 +env-file: .env +groups: + main: + targets: + node: + help: Test using nodejs + shell: node + run: console.log("Hello, World!"); + perl: + help: Test using perl + shell: perl + run: print "Hello, World!\n"; + + php: + help: Test using php + shell: php + run: print "Hello, World!\n"; + + python: + help: Test using php + shell: python + run: print("Hello, World!") + + r: + help: Test using R + shell: Rscript + run: print("Hello World!") + + sh: + help: Test using sh + shell: sh + run: echo "Hello, World!" + + all: + dependencies: + - target: node + - target: perl + # note: php from conda-forge has conflicts with r-base + # - target: php + - target: python + - target: r + - target: sh