-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(init): add a subcommand to create an example config
- Loading branch information
Showing
9 changed files
with
100 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:orphan: | ||
|
||
Initialize Universum | ||
-------------------- | ||
|
||
If you have Universum installed via ``pip3.7 install -U universum`` or downloaded it from GitHub and changed | ||
working directory to project root, run ``python3.7 -m universum init`` to create an example configuration file, | ||
that can be :doc:`updated according to your project needs <configuring>` later. | ||
|
||
Running this command will not only create a configuration file, but will also provide you with a command line to | ||
execute it with Universum. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pathlib import Path | ||
import subprocess | ||
|
||
|
||
def test_create_config(): | ||
result = subprocess.run(["python3.7", "-m", "universum", "init"], capture_output=True, check=True) | ||
new_command = '' | ||
for line in result.stdout.splitlines(): | ||
if line.startswith(b'$ '): # result.stdout is a byte string | ||
new_command = line.lstrip(b'$ ') | ||
new_result = subprocess.run(new_command.split(), capture_output=True, check=True) | ||
Path(".universum.py").unlink() | ||
artifacts = Path("artifacts") | ||
artifacts.joinpath("CONFIGS_DUMP.txt").unlink() | ||
artifacts.rmdir() | ||
assert 'Hello world' in str(new_result.stdout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from pathlib import Path | ||
|
||
from .modules.output.output import MinimalOut | ||
from .lib.gravity import Module | ||
__all__ = ["ConfigCreator"] | ||
|
||
|
||
class ConfigCreator(Module): | ||
description: str = "Create a dummy project" | ||
|
||
def __init__(self, *args, **kwargs) -> None: | ||
super().__init__(*args, **kwargs) | ||
self.out = MinimalOut() | ||
|
||
def execute(self) -> None: | ||
config_name = ".universum.py" | ||
self.out.log(f"Creating an example configuration file '{config_name}'") | ||
|
||
config = Path(config_name) | ||
config.write_text("""#!/usr/bin/env python3.7 | ||
from universum.configuration_support import Variations | ||
configs = Variations([dict(name='Show directory contents', command=['ls', '-la']), | ||
dict(name='Print a line', command=['bash', '-c', 'echo Hello world'])]) | ||
if __name__ == '__main__': | ||
print(configs.dump()) | ||
""") | ||
self.out.log("To run with Universum, execute the following command:\n" | ||
"$ python3.7 -m universum nonci --launcher-config-path={}".format(config_name)) | ||
|
||
def finalize(self) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters