Exemple #1
0
def main_entry_point(args: Optional[List[str]] = None):
    parsed = ParsedArgs(args)

    dirs = Dirs(project_dir=get_project_dir(parsed))

    if parsed.command == Commands.create:
        main_create(dirs, parsed.python_executable)
    elif parsed.command == Commands.recreate:
        main_recreate(dirs, parsed.python_executable)  # todo .existing()?
    elif parsed.command == Commands.delete:  # todo move 'existing' check from func?
        main_delete(dirs.venv_dir)
    elif parsed.command == Commands.path:
        print(dirs.venv_dir)  # does not need to be existing
    elif parsed.command == Commands.run:
        # todo allow running commands from strings
        main_run(dirs.venv_must_exist(), parsed.run_args)
    elif parsed.command == Commands.call:

        main_call(parsed, dirs)

    elif parsed.command == Commands.shell:
        main_shell(dirs, parsed.shell_input, parsed.shell_delay)
    else:
        raise ValueError
Exemple #2
0
 def test_call_field(self):
     pd = ParsedArgs('-p a/b/c call -m myfile.py arg1 arg2'.split())
     self.assertIsNotNone(pd.call)
     self.assertEqual(pd.call.filename, "myfile.py")
     self.assertEqual(pd.call.before_filename, "-m")
Exemple #3
0
 def test_unrecoginzed(self):
     """Unrecognized arguments that are NOT after the 'call' word."""
     with self.assertRaises(SystemExit) as ce:
         ParsedArgs('-labuda call myfile.py a b c'.split())
     self.assertEqual(ce.exception.code, 2)
Exemple #4
0
 def test_p(self):
     pd = ParsedArgs('-p a/b/c call -d myfile.py a b c'.split())
     self.assertEqual(pd.args_to_python, ['-d', 'myfile.py', 'a', 'b', 'c'])
Exemple #5
0
 def test_outdated_p(self):
     pd = ParsedArgs('-p a/b/c call -p d/e/f myfile.py arg1 arg2'.split())
     self.assertEqual(pd.args_to_python, ['myfile.py', 'arg1', 'arg2'])
Exemple #6
0
 def test_call_short_both(self):
     pd = ParsedArgs('-p a/b/c call -p d/e/f myfile.py'.split())
     self.assertEqual(pd.project_dir_arg, 'd/e/f')
Exemple #7
0
 def test_call_long_left(self):
     pd = ParsedArgs('--project-dir a/b/c call myfile.py'.split())
     self.assertEqual(pd.project_dir_arg, 'a/b/c')
Exemple #8
0
 def test_input(self):
     pd = ParsedArgs(windows_too(['shell', '--input', 'cd / && ls']))
     self.assertEqual(pd.shell_input, 'cd / && ls')
Exemple #9
0
 def test_run_long_left(self):
     pd = ParsedArgs(
         windows_too('--project-dir a/b/c run python3 myfile.py'.split()))
     self.assertEqual(pd.project_dir_arg, 'a/b/c')
Exemple #10
0
 def test_windowsallargs_fails_on_posix(self):
     # is the PARAM_WINDOWS_ALL_ARGS is set, we must run windows.
     # Otherwise, AssertionError is thrown
     with self.assertRaises(AssertionError):
         ParsedArgs([ParsedArgs.PARAM_WINDOWS_ALL_ARGS, 'shell'])
Exemple #11
0
 def test_without_arg(self):
     pd = ParsedArgs(['recreate'])
     self.assertEqual(pd.command, Commands.recreate)
     self.assertEqual(pd.python_executable, None)
Exemple #12
0
 def test_with_arg(self):
     pd = ParsedArgs(['create', 'python3'])
     self.assertEqual(pd.command, Commands.create)
     self.assertEqual(pd.python_executable, "python3")
Exemple #13
0
 def test(self):
     pd = ParsedArgs(windows_too(['run', 'python3', '-OO', 'file.py']))
     self.assertEqual(pd.command, Commands.run)
     self.assertEqual(pd.run_args, ['python3', '-OO', 'file.py'])
Exemple #14
0
 def test_labuda(self):
     with self.assertRaises(SystemExit) as ce:
         pd = ParsedArgs(windows_too('shell --labuda'.split()))
     self.assertEqual(ce.exception.code, 2)
Exemple #15
0
 def test_delay(self):
     pd = ParsedArgs(windows_too('shell --delay 1.2'.split()))
     self.assertEqual(pd.shell_delay, 1.2)
Exemple #16
0
 def _gpd(self, cmd: str) -> Path:
     cmd = fix_paths(cmd)
     result = get_project_dir(ParsedArgs(windows_too(cmd.split())))
     self.assertTrue(result.is_absolute())
     return result
Exemple #17
0
 def test_call_short_right(self):
     pd = ParsedArgs('call -p a/b/c myfile.py'.split())
     self.assertEqual(pd.project_dir_arg, 'a/b/c')
Exemple #18
0
 def test_no_args(self):
     pd = ParsedArgs(windows_too('shell'.split()))
     self.assertEqual(pd.command, Commands.shell)
     self.assertEqual(pd.shell_delay, None)
     self.assertEqual(pd.shell_input, None)