Skip to content

Commit

Permalink
fix(groups): change groups to accept dict instead of list && improve …
Browse files Browse the repository at this point in the history
…help cmd (#28)

* fix(groups): change groups to accept dict instead of list && improve help cmd

* linter

* Changes requests in the review

* Update __main__.py
  • Loading branch information
luabida committed Mar 18, 2023
1 parent c2fd959 commit a6b1672
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .makim.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 1.0.0
groups:
- name: default
default:
targets:
clean:
help: Clean unnecessary temporary files
Expand All @@ -18,7 +18,7 @@ groups:
rm -fr htmlcov/
rm -fr .pytest_cache
- name: docs
docs:
env-file: .env
targets:
build:
Expand All @@ -30,7 +30,7 @@ groups:
help: Preview documentation page locally
run: mkdocs serve --watch docs --config-file docs/mkdocs.yaml

- name: release
release:
env-file: .env
vars:
app: |
Expand All @@ -54,7 +54,7 @@ groups:
help: Run semantic release in dry-run mode
run: {{ app }} '--dry-run'

- name: tests
tests:
targets:
lint:
help: Run linter tools
Expand Down
16 changes: 7 additions & 9 deletions makim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def _get_args():
add_help=False,
formatter_class=CustomHelpFormatter,
)

parser.add_argument(
'--help',
'-h',
Expand Down Expand Up @@ -93,14 +92,12 @@ def _get_args():
makim_file = makim_file_default

makim.load(makim_file)

target_help = []

for group in makim.config_data['groups']:
for target_name, target_data in group['targets'].items():
target_name_qualified = f"{group['name']}.{target_name}"
groups = makim.config_data.get('groups', [])
for group in groups:
for target_name, target_data in groups[group]['targets'].items():
target_name_qualified = f'{group}.{target_name}'
help_text = target_data['help'] if 'help' in target_data else ''

target_help.append(f' {target_name_qualified} => {help_text}')

if 'args' in target_data:
Expand All @@ -111,7 +108,6 @@ def _get_args():
f' --{arg_name}: ({arg_data["type"]}) '
f'{arg_data["help"]}'
)

target_help.append("NOTE: 'default.' prefix is optional.")

parser.add_argument(
Expand Down Expand Up @@ -180,6 +176,9 @@ def app():
args_parser = _get_args()
args = args_parser.parse_args()

if not args.target or args.help:
return args_parser.print_help()

if args.help:
return args_parser.print_help()

Expand All @@ -188,7 +187,6 @@ def app():

makim.load(args.makim_file)
makim_args.update(dict(args._get_kwargs()))

return makim.run(makim_args)


Expand Down
16 changes: 6 additions & 10 deletions makim/makim.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,19 @@ def _change_group_data(self, group_name=None):

if group_name is not None:
self.group_name = group_name

shell_app_default = self.config_data.get('shell', 'xonsh')

if self.group_name == 'default' and len(groups) == 1:
self.group_data = groups[0]
self.group_name = groups[0]['name']
group = list(groups)[0]
self.group_data = groups[group]

shell_app = self.group_data.get('shell', shell_app_default)
self._load_shell_app(shell_app)
return

for g in groups:
if g['name'] == self.group_name:
self.group_data = g
shell_app = g.get('shell', shell_app_default)
for group in groups:
if group == self.group_name:
self.group_data = groups[group]
shell_app = groups[group].get('shell', shell_app_default)
self._load_shell_app(shell_app)
return

Expand All @@ -162,7 +160,6 @@ def _load_shell_args(self):
def _run_dependencies(self, args: dict):
if not self.target_data.get('dependencies'):
return

makim_dep = deepcopy(self)
args_dep_original = {
'makim_file': args['makim_file'],
Expand Down Expand Up @@ -222,7 +219,6 @@ def _run_dependencies(self, args: dict):

def _run_command(self, args: dict):
cmd = self.target_data.get('run', '').strip()

if 'vars' not in self.group_data:
self.group_data['vars'] = {}

Expand Down
4 changes: 2 additions & 2 deletions tests/.makim-bash-group-scope.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1.0.0
env-file: .env
groups:
- name: group-scope
group-scope:
shell: bash
targets:
test:
Expand All @@ -17,7 +17,7 @@ groups:
export MAKIM_TEST=$(pwd)
echo ${MAKIM_TEST}
- name: group-deps
group-deps:
targets:
dep:
help: dependency using xonsh
Expand Down
2 changes: 1 addition & 1 deletion tests/.makim-bash-main-scope.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 1.0.0
env-file: .env
shell: bash
groups:
- name: main-scope
main-scope:
targets:
test:
help: Test bash defined in the main scope
Expand Down
2 changes: 1 addition & 1 deletion tests/.makim-bash-target-scope.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1.0.0
env-file: .env
groups:
- name: target-scope
target-scope:
targets:
dep:
help: dependency using xonsh
Expand Down
18 changes: 9 additions & 9 deletions tests/.makim-complex.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: 1.0.0
env-file: .env
groups:
- name: default
default:
targets:
lint:
help: Run linter tools
run: echo "[II] Run linter"

- name: build
build:
targets:
clean-gcda:
help: Remove temporary gcda files
Expand Down Expand Up @@ -71,19 +71,19 @@ groups:
clean: {{ args.clean }}
asan-options: "fast_unwind_on_malloc=0"

- name: env
env:
targets:
create-file:
help: Create a dot env file
run: echo "[II] Create a dot env file"

- name: conda
conda:
targets:
build:
help: Create the conda package
run: echo "[II] Create the conda package"

- name: release
release:
vars:
app: echo
targets:
Expand All @@ -95,7 +95,7 @@ groups:
help: Run semantic-release on CI for tests in dry-run mode.
run: {{ app }} --dry-run

- name: docs
docs:
targets:
api:
help: Build API docs
Expand All @@ -119,7 +119,7 @@ groups:
- target: docs.api
run: echo "[II] Preview documentation result locally"

- name: tests
tests:
targets:
sanitizer:
help: Run sanitizer tests
Expand Down Expand Up @@ -154,13 +154,13 @@ groups:
- target: tests.sanitizer
- target: tests.examples

- name: debug
debug:
targets:
fibonacci:
help: Debug package via an example file (fibonacci)
run: echo "[II] Debug package via an example file"

- name: print
print:
targets:
local-env-vars:
help: Print environment variables
Expand Down
2 changes: 1 addition & 1 deletion tests/.makim-simple.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1.0.0
env-file: .env
groups:
- name: default
default:
targets:
clean:
help: Use this target to clean up temporary files
Expand Down
2 changes: 1 addition & 1 deletion tests/.makim-unittest.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 1.0.0
env-file: .env
groups:
- name: tests
tests:
targets:
test-1:
help: test-1 args `all` should be false
Expand Down

0 comments on commit a6b1672

Please sign in to comment.