Skip to content

Commit

Permalink
Update Spine requirements, master project
Browse files Browse the repository at this point in the history
We now require latest version of spinetoolbox. The project modification
script was moved to its own template file and updated accordingly.

Also, pulled the latest master project submodule.

Re #11
  • Loading branch information
soininen committed Nov 8, 2022
1 parent cec6fa2 commit 30d2e68
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
29 changes: 5 additions & 24 deletions flextool3/executions_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,33 +268,14 @@ def _make_mod_script(scenarios):
tuple: temporary directory containing the script file and path to the file
"""
quoted_scenarios = (f"'{s}'" for s in scenarios)
script_contents = [
"from spinedb_api import DatabaseMapping\n",
"from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE\n",
"from spinedb_api.filters.tool_filter import TOOL_FILTER_TYPE\n",
"importer = project.find_item('Import_results')\n",
"importer['purge_before_writing'] = False\n",
"db_path = project.project_dir / 'Input_data.sqlite'\n",
"db_url = 'sqlite:///' + str(db_path)\n",
"db_map = DatabaseMapping(db_url)\n",
f"active_scenarios = {{{', '.join(quoted_scenarios)}}}\n",
"try:\n",
" connection = project.find_connection('Input_data', 'Export_to_CSV')\n",
" available_scenarios = [r.name for r in db_map.query(db_map.scenario_sq)]\n",
" for name in available_scenarios:\n",
" enabled = name in active_scenarios\n",
" connection.set_filter_enabled('db_url@Input_data', SCENARIO_FILTER_TYPE, name, enabled)\n",
" available_tools = [r.name for r in db_map.query(db_map.tool_sq)]\n",
" for name in available_tools:\n",
" enabled = name == 'FlexTool3'\n",
" connection.set_filter_enabled('db_url@Input_data', TOOL_FILTER_TYPE, name, enabled)\n",
"finally:\n",
" db_map.connection.close()\n",
]
template_path = Path(__file__).parent / "project_modification_script_template.py"
with open(template_path) as template_file:
template = template_file.read()
script_contents = template.format(scenarios=", ".join(quoted_scenarios))
temp_dir = TemporaryDirectory() # pylint: disable=consider-using-with
script_path = Path(temp_dir.name) / _MOD_SCRIPT_NAME
with open(script_path, "w", encoding="utf-8") as script_file:
script_file.writelines(script_contents)
script_file.write(script_contents)
return temp_dir, script_path


Expand Down
21 changes: 21 additions & 0 deletions flextool3/project_modification_script_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from spinedb_api import DatabaseMapping
from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE
from spinedb_api.filters.tool_filter import TOOL_FILTER_TYPE
connection = project.find_connection("Import_results", "Results")
connection.options["purge_before_writing"] = False
db_path = project.project_dir / "Input_data.sqlite"
db_url = "sqlite:///" + str(db_path)
db_map = DatabaseMapping(db_url)
active_scenarios = {{{scenarios}}}
try:
connection = project.find_connection("Input_data", "Export_to_CSV")
available_scenarios = [r.name for r in db_map.query(db_map.scenario_sq)]
for name in available_scenarios:
enabled = name in active_scenarios
connection.set_filter_enabled("db_url@Input_data", SCENARIO_FILTER_TYPE, name, enabled)
available_tools = [r.name for r in db_map.query(db_map.tool_sq)]
for name in available_tools:
enabled = name == "FlexTool3"
connection.set_filter_enabled("db_url@Input_data", TOOL_FILTER_TYPE, name, enabled)
finally:
db_map.connection.close()
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
django[argon2]
spinetoolbox>=0.6.12
spinedb-api>=0.22.0
spinetoolbox>=0.6.13

0 comments on commit 30d2e68

Please sign in to comment.