-
Notifications
You must be signed in to change notification settings - Fork 92
Split Vensim views in separate Python files #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split Vensim views in separate Python files #279
Conversation
…eaf/pysd-internal-dev into building_split_model_merge
…eaf/pysd-internal-dev into building_split_model_merge
Hello @rogersamso! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-07-07 07:11:31 UTC |
Other changes included in this PR:
|
Sorry about this. I think a good solution for it would be to move all grammars into a separate file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few quesetions - looks good otherwise. =) Nice formatting changes, that'll make it a lot easier to read.
docs/installation.rst
Outdated
Installing with conda | ||
--------------------- | ||
To install PySD with conda into a conda environment, use the following command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worth mentioning that this doesn't use the standard conda channel, which is why we have the -c conda-forge
. It's not important, but may save a few questions down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :)
def get_header(cls, outfile): | ||
def get_header(cls, outfile, root=False): | ||
""" | ||
Returns the importing information to print in the model file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the root
argument here something that only takes a true/false value, or could it also take a path? looks like it's only used in the boolean sense, but if that's the long-term plan for it, might make sense to give it a different name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update the name with force_root
and add the documentation to the method. If this argument is True the _root
is added in the model. If the parameter is false, the _root
will be added only if the model has External
objects.
pysd/py_backend/vensim/vensim2py.py
Outdated
-------- | ||
>>> get_file_sections(r'a~b~c| d~e~f| g~h~i|') | ||
[{'returns': [], 'params': [], 'name': 'main', 'string': 'a~b~c| d~e~f| g~h~i|'}] | ||
[{'returns': [], 'params': [], 'name': 'main', 'string': 'a~b~c| d~e~f| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does doctests handle this linebreak?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is not. I am recovering the previous version and improving some functions docs.
This pull requests gives the user the option to get a translated model file organised by Vensim views. In the translated model, Vensim views can be seen as Python modules.
This option is controlled by the
split_modules
argument in theread_vensim
function.By default, the argument is set to False; hence, unless explicitly modified, the user gets the usual behaviour.
This new functionality has been added by adding a new grammar to parse the necessary bits from the Vensim sketch.
The option to split the model in views is particularly interesting for large models with tens of views. Translating those models into a single file may make the resulting Python model difficult to read and maintain.
In a Vensim model with three separate views (e.g.
view_1
,view_2
andview_3
), settingsplit_modules
to True would create the following tree inside the directory where the.mdl
model is located:| main-folder
| ├── modules_many_views_model
| │ ├── _modules.json
| │ ├── view_1.py
| │ ├── view_2.py
| │ └── view_3.py
| ├── _namespace_many_views_model.json
| ├── _subscripts_dict_many_views_model.json
| ├── many_views_model.py
|
|
If macros are present, they will be self-contained in files named as the macro itself. The macro inner variables will be placed inside the module that corresponds with the view in which they were defined.