Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#59: Change from --import to --imports for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Nov 23, 2020
1 parent a5935a7 commit e7a637b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
7 changes: 7 additions & 0 deletions docs/source/usage/importing-tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ Tasks could be imported also in shell, for quick check, handy scripts, or for em
RKD_IMPORTS="rkt_utils.docker" rkd :docker:tag
RKD_IMPORTS="rkt_utils.docker:rkt_ciutils.boatci:rkd_python" rkd :tasks
# via commandline switch "--imports"
rkd --imports "rkt_utils.docker:rkt_ciutils.boatci:rkd_python" :tasks
*Note: The significant difference between environment variable and commandline switch is that the environment variable
will be inherited into subshells of RKD, commandline argument not.*


For more information about this environment variable check it's documentation page: :ref:`RKD_IMPORTS`

Expand Down
2 changes: 1 addition & 1 deletion src/rkd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def main(self, argv: list):

except ParsingException as e:
io.silent = False
io.error_msg('Cannot import tasks/module from RKD_IMPORTS environment variable or --import switch. '
io.error_msg('Cannot import tasks/module from RKD_IMPORTS environment variable or --imports switch. '
'Details: {}'.format(str(e)))
sys.exit(1)

Expand Down
4 changes: 2 additions & 2 deletions src/rkd/argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ def preparse_args(args: List[str]):
limited_args.append(arg)

argparse = ArgumentParser(add_help=False)
argparse.add_argument('--import', '-ri')
argparse.add_argument('--imports', '-ri')

parsed = vars(argparse.parse_known_args(args=limited_args)[0])

return {
'imports': list(filter(None,
os.getenv('RKD_IMPORT', parsed['import'] if parsed['import'] else '').split(':')
os.getenv('RKD_IMPORTS', parsed['imports'] if parsed['imports'] else '').split(':')
))
}

Expand Down
6 changes: 3 additions & 3 deletions src/rkd/standardlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ def get_declared_envs(self) -> Dict[str, str]:
'RKD_ALIAS_GROUPS': '', # supported by core, here only for documentation in CLI
'RKD_UI': 'true',
'RKD_SYS_LOG_LEVEL': 'info', # supported by core, here only for documentation in CLI
'RKD_IMPORT': '' # supported by core, here only for documentation in CLI
'RKD_IMPORTS': '' # supported by core, here only for documentation in CLI
}

def configure_argparse(self, parser: ArgumentParser):
parser.add_argument('--no-ui', '-n', action='store_true',
help='Do not display RKD interface (similar to --silent, ' +
'but does not inherit --silent into next tasks)')

parser.add_argument('--import', '-ri',
parser.add_argument('--imports', '-ri',
help='Imports a task or list of tasks separated by ":". '
'Example: "rkt_utils.docker:rkt_ciutils.boatci:rkd_python". '
'Instead of switch there could be also environment variable "RKD_IMPORT" used')
'Instead of switch there could be also environment variable "RKD_IMPORTS" used')

def execute(self, context: ExecutionContext) -> bool:
"""
Expand Down
8 changes: 4 additions & 4 deletions test/test_argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_preparse_args_tolerates_not_recognized_args(self):
then it works
"""

args = CommandlineParsingHelper.preparse_args(['--import', 'rkd_python', ':sh'])
args = CommandlineParsingHelper.preparse_args(['--imports', 'rkd_python', ':sh'])

self.assertIn('imports', args)
self.assertEqual(['rkd_python'], args['imports'])
Expand All @@ -144,7 +144,7 @@ def test_preparse_ignores_arguments_after_tasks(self):
Arguments that could be preparsed should be placed behind any task
"""

args = CommandlineParsingHelper.preparse_args([':sh', '--import', 'rkd_python'])
args = CommandlineParsingHelper.preparse_args([':sh', '--imports', 'rkd_python'])

self.assertEqual([], args['imports'])

Expand All @@ -162,8 +162,8 @@ def test_has_any_task(self):
with self.subTest(':task --test'):
self.assertTrue(CommandlineParsingHelper.has_any_task([':task', '--test']))

with self.subTest('--import rkd_python --help'):
self.assertFalse(CommandlineParsingHelper.has_any_task(['--import', 'rkd_python', '--help']))
with self.subTest('--imports rkd_python --help'):
self.assertFalse(CommandlineParsingHelper.has_any_task(['--imports', 'rkd_python', '--help']))

def test_was_help_used(self):
"""
Expand Down
6 changes: 3 additions & 3 deletions test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def test_help_shows_imports_switch_only_behind_tasks(self):

with self.subTest('Behind tasks'):
full_output, exit_code = self.run_and_capture_output(['--help'])
self.assertIn('--import', full_output)
self.assertIn('--imports', full_output)

with self.subTest('--help of a task'):
full_output, exit_code = self.run_and_capture_output([':sh', '--help'])
self.assertNotIn('--import', full_output)
self.assertNotIn('--imports', full_output)

with self.subTest('Behind tasks, but task defined'):
full_output, exit_code = self.run_and_capture_output(['--help', ':sh'])
self.assertIn('--import', full_output)
self.assertIn('--imports', full_output)

0 comments on commit e7a637b

Please sign in to comment.