spine-tools / Spine-Toolbox

Spine Toolbox is an open source Python package to manage data, scenarios and workflows for modelling and simulation. You can have your local workflow, but work as a team through version control and SQL databases.
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
72 stars 17 forks source link

Separating git content from non-git content in project.json #1238

Closed jkiviluo closed 2 days ago

jkiviluo commented 3 years ago

It's really handy to be able to share Spine Toolbox projects through a git repo. There has also been good progress to eliminate absolute paths. However, project.json contains stuff where changes shouldn't be reflected in the git repo and it's not nice to be pushing and pulling those. This includes at least the x/y positions of items (connections should be in the repo though) and what scenarios are selected. Possibly also whether to execute in work or source directory.

The main solution is to make a separate .gitignored file(s) for local data like the x/y positions of icons and what scenarios are selected.

The challenge is that when someone pulls a repo for the first time without those informations, they need to be generated somehow. In the discussion below, @manuelma suggests to use an algorithm (used in graph view) to generate icon positions if they don't exist (i.e. the local file is not contained). @soininen suggests to make a folder for the local changes so that more can be added there in future and they would be managed by the same .gitignore. Some of the other local data items might work through a default choice that would be hard-coded (e.g. no scenarios chosen) or in the tool specification.

I think doing those would be sufficient to address the issue. At first we would put x/y positions there, but we could expand that when needed.

manuelma commented 3 years ago

One idea is to use the graph view algorithm to place items nicely in case no positions are given in the project.json file. And then find a way to save the project file without the positions, before putting it into version control.

soininen commented 3 years ago

We could add a special directory for storing local/GUI settings like item positions. Adding the directory in .gitignore would then exclude that content.

ptsavol commented 3 years ago

We could add a special directory for storing local/GUI settings like item positions. Adding the directory in .gitignore would then exclude that content.

Does it need to be a directory? Could this be done in memory?

If I understand this issue correctly it is just that we need to make better checks to has anything really changed when saving the project. For example, if I remove a connection and then put the same connection back, the connection part in project.json should not change.

manuelma commented 3 years ago

For example, if I remove a connection and then put the same connection back, the connection part in project.json should not change.

Does it change at the moment? I believe it doesn't. Our undo/redo implementation is not smart enough and still considers the project dirty, so it just enables the 'save' action and writes the project.json file if the user activates it... but the file will end up with the same content... I think

I believe the problem here is moving items around. Their x and y coordinates go to version control, which seems to be undesirable...

manuelma commented 3 years ago

I believe @soininen 's idea works. We save the x and y coordinates to a different file that we gitignore.

When another user clones the project for the first time, they won't have that file with the positions so we need to place the items nicely. I was suggesting to use the graph view algorithm for that.

soininen commented 3 years ago

but the file will end up with the same content... I think

The project file content will change in the general case as we currently store the connections internally as a Python list. Readding a connection appends to the list potentially changing the connection's position within that list. Dumping the list to the .proj file will then change the file. This could (and I guess should) be fixed by e.g. sorting the connection list at project save.

soininen commented 3 years ago

I suggested an entire directory for saving local changes because that way we can later add more 'local' stuff there. Caches for undo stacks, for example if we ever want undo/redo functionality that persists over Toolbox sessions.

jkiviluo commented 3 years ago

I updated the issue description based on the comments here.

soininen commented 2 years ago

Since 78aa488 there is now <project dir>/.spinetoolbox/local/ that should be used to store 'local' content, i.e. project data that is system or user specific.

jkiviluo commented 2 days ago

Closing due to newer issue #2509