Skip to content

Commit

Permalink
Fix subcommand config attribute (#43)
Browse files Browse the repository at this point in the history
* [#42] Fix subcommand config attribute

* [0.2.x] Modify workflow to run on pull request
  • Loading branch information
StephaneCapponi authored Sep 21, 2023
1 parent bdb0c64 commit 53355fa
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ on:
push:
branches:
- master
- 'release/**'
paths-ignore:
- 'docs/**'

pull_request:
branches:
- master
- 'release/**'
paths-ignore:
- 'docs/**'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ on:
pull_request:
branches:
- master
- 'release/**'
paths:
- 'docs/**'
- '.github/workflows/docs.yml'
push:
branches:
- master
- 'release/**'
paths:
- 'docs/**'
- '.github/workflows/docs.yml'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ on:
push:
branches:
- master
- 'release/**'
paths-ignore:
- 'docs/**'

pull_request:
branches:
- master
- 'release/**'
paths-ignore:
- 'docs/**'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ on:
push:
branches:
- master
- 'release/**'
paths-ignore:
- 'docs/**'

pull_request:
branches:
- master
- 'release/**'
paths-ignore:
- 'docs/**'

Expand Down
10 changes: 6 additions & 4 deletions socon/core/management/subcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ def parse_args(self, argv: tuple) -> Config:
# message when we run the subcommand.
setattr(options, "subcommand", subcommand)

# Save the subcommand for later use in the handle method. This is to avoid
# to seach again for the command and initialize it with no config. #42
self.__subcommand = command

# Create a config object that will store all the options
return command.baseconfig(options, extras_args)
return command.set_config(options, extras_args)

def handle(self, config: Config):
"""Execute the subcommand"""
subcommand = config.getoption("subcommand")
command = self.get_subcommand(subcommand, self.argv)
return command.execute(config)
return self.__subcommand.execute(config)
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ class SubTwocommand(BaseCommand):

def handle(self, config: Config) -> None:
print(config.extras_args)


class SubAccessConfig(BaseCommand):
"""Subcommand to check access to sub config attribute"""

name = "sub-config"
manager = "with_subs"

def handle(self, config: Config) -> None:
assert self.config == config
6 changes: 6 additions & 0 deletions tests/admin_scripts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,3 +1419,9 @@ def test_call_main_sub_command_with_call_command(self, capsys):
assert "List of available subcommands:" in captured.out
assert "sub1" in captured.out
assert "sub2" in captured.out

def test_access_config_attribute(self, test_dir):
"""Check that we can access the config attribute. Test for #42"""
args = ["base-subcommand", "sub-config", "--project", "subcommands"]
_, err = self.run_manage(args, test_dir)
assert err == ""

0 comments on commit 53355fa

Please sign in to comment.