Midnighter / structurizr-python

A Python 3 port of Simon Brown's Structurizr diagrams-as-code architecture description tool.
https://structurizr.com/
Apache License 2.0
65 stars 16 forks source link

How do I get data into or out of an existing workspace? #44

Closed mrchrisadams closed 3 years ago

mrchrisadams commented 3 years ago

Checklist

Question

If you have started sketching out a workspace in structurisr.com, how do you pull down an existing project, to work on locally?

Conversely, once you've made changes, how do you push it back up? I was expecting to see a put or get method, based on the web API docs for structurizr.

Some code examples for this would be really helpful.

yt-ms commented 3 years ago

One way to interact with Structurizr is through the structurizr.api.StructurizrClient class which allows you to pull workspaces through get_workspace() and push through put_workspace() (you'll need to create a StructurizrClientSettings with the URL and your API key/secret details).

Another way is to export the workspace as JSON from the web interface, and then load from file with Workspace.load(). To then resave the workspace after modifying it you can do something like (we should probably wrap this into a save() method on Workspace:

with open("my-workspace.json", "w") as f:
    f.write(WorkspaceIO.from_orm(workspace).json(indent=2))
Midnighter commented 3 years ago

One way to interact with Structurizr is through the structurizr.api.StructurizrClient class which allows you to pull workspaces through get_workspace() and push through put_workspace() (you'll need to create a StructurizrClientSettings with the URL and your API key/secret details).

We had some contact on the Structurizr Slack already. Sorry that I didn't comment sooner here.

we should probably wrap this into a save() method on Workspace

Yes, just recently had a need for this myself but didn't do it yet because when you call StructurizrClient.get_workspace() it automatically stores a copy of the workspace in the local directory as compressed JSON. Still, much better to add a proper save method.

mrchrisadams commented 3 years ago

Thanks foilks. I think I'm getting a better idea of how this works.

One really embarassing qn tho - how are you setting up, so there's sensible way to have the dependencies installed for local development?

Previously, I've used pipenv, or pipenv, or poetry to start work on projects, but I'm unable to use poetry. Here's what I see:

poetry install                                                                                                                                                                                                

[RuntimeError]
[tool.poetry] section not found in pyproject.toml

I'm okay with using pip, but the only requirements file I see is in docs.

I know how to make virtual environments, and I've had a read of the code now, but I've only ever worked on projects with a Pipfile (so I can run pipenv install) or a pyproject usable by poetry (so I can run poetry install).

Even using pip I can't see how I'd do somethig like the below:

python -m venv .venv
source .venv/bin/activate
pip install PATH_TO_FILE

Where should I look to understand how to set up so I can execute the code locally in the project?

I see the tox file, which I understand to manage checking in a matrix of versions, and I see the setup.cfg file, but I assumed those are for packaging up an distirbuting the files, not setting to work on.

If let me know, I can implement that separate save method in the PR I opened 👍🏽

mrchrisadams commented 3 years ago

Oh hang on. I've just seen this in the slack:

pip install .

So, it looks like this stanza does the job:

python -m venv .venv
source .venv/bin/activate
pip install .
Midnighter commented 3 years ago

A virtualenv with and then I personally use pip install -e . because that creates links rather than copies the files. Thus any changes you make during local development are automatically in your environment's package without having to run installation again. You may still need to reload the package or restart session, of course.

Midnighter commented 3 years ago

Poetry and Pipenv will only work to install the package from PyPI at this point.