-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unify generation code for consistent imports
- Loading branch information
Showing
3 changed files
with
49 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import importlib | ||
import json | ||
import sys | ||
|
||
import click | ||
|
||
|
||
@click.command() | ||
@click.option('--view', prompt='Your view file (e.g. example.componentview)', | ||
help='The view file to generate.') | ||
def dump(view: str): | ||
try: | ||
initial_modules = set(sys.modules.keys()) | ||
module = importlib.import_module(view) | ||
imported_modules = set(sys.modules.keys()) - initial_modules | ||
code = module.workspace.dump() | ||
print(json.dumps({ | ||
"code": code, | ||
"imported_modules": list(imported_modules) | ||
})) | ||
except ModuleNotFoundError: | ||
# pylint: disable=raise-missing-from | ||
raise click.BadParameter("Invalid view name. Make sure you don't include the .py file extension.") | ||
except AttributeError: | ||
# pylint: disable=raise-missing-from | ||
raise click.BadParameter("Non-compliant view file: make sure it exports the PyStructurizr workspace.") | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
pass | ||
|
||
|
||
cli.add_command(dump) | ||
|
||
if __name__ == '__main__': | ||
cli() |