Skip to content
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

Provide ability to call gaphor console externally #2821

Open
hulsed opened this issue Nov 8, 2023 · 10 comments
Open

Provide ability to call gaphor console externally #2821

hulsed opened this issue Nov 8, 2023 · 10 comments
Assignees
Labels
feature A new feature

Comments

@hulsed
Copy link
Contributor

hulsed commented Nov 8, 2023

Is your feature request related to a problem?

I am a researcher who would like to build some tools simulation tools connected to gaphor. One thing I would like to be able to do is call Gaphor's console from an external console (python instance, powershell, jupyter).

Currently, this is impossible without a development installation, which may be difficult or impossible to setup without administrative privileges. Preferably, it gaphor's console should be possible to call from a fully packaged version so you don't need to build gtk to interact with it. This would make it a lot easier to develop scripts which interact with gaphor's data model.

Describe the solution you'd like

Something along the lines of:

  • Provide a .exe for the gaphor python console
  • Provide some documentation of working with it (e.g., using it as a kernel in jupyter, setting it as a sphinx plugin)

Describe alternatives you've considered

  • Package a standalone version of command-line gaphor packages for interacting with/rendering the data model without having to install the gtk/UI pieces (if possible).
@danyeaw
Copy link
Member

danyeaw commented Nov 9, 2023

Hi @hulsed, to summarize this feature request, you are looking for these types of scripting capabilities like described here: https://docs.gaphor.org/en/latest/scripting.html, except you want to use it from a fully packaged version of Gaphor, is that right?

@hulsed
Copy link
Contributor Author

hulsed commented Nov 9, 2023

I am referencing the scripting capabilities, yes, but I'm not necessarily tied to "calling fully packaged version" as a solution.

I think the key functionality would be being able to interact with gaphor command-line services without needing to build gtk.

There are different ways of accomplishing that:

  1. If I could call a packaged version of gaphor (and call its console), ostensibly there would be a decent glide path to interacting with the underlying data model from an external shell (python, etc). I put this up as there but I'm not sure it's really the most elegant approach and could mean anyone who is scripting has to write needless glue code. But it may (?) be easier to implement in terms of not changing much in the back-end.

  2. Right now, if I clone gaphor and run from gaphor.core.modeling import ElementFactory from a script in the repository, in loading all the modules it will say I need gaphas (because it is being imported in gaphor.core.modeling.diagram). This puts me in a pickle--if I run a pip install gaphas, I then need to build gtk, even though it's not really necessary for the functionality I want to interact with. So my problem would be solved if elements of the library would be refactored so gui libraries are only loaded when needed. Potentially, this could be a more elegant solution, because then the user would be working in a single consistent python environment, but I'm not sure what would need to actually be done--it could be as little as changing some imports or as much as creating a separate repo/package for the data model.

@amolenaar
Copy link
Member

@hulsed If you install Gaphor as a dependency in your own project, you should not need GTK per se. The scripting and Jupyter examples in the docs are executed that way.

You do need PyGObject, Pango (for text rendering), Cairo and Pycairo.

@hulsed
Copy link
Contributor Author

hulsed commented Nov 9, 2023

Yes, I was grouping PyGObject and gtk there, since both are installed using gvsbuild on windows. It would be nice not to have to go through that process just to call a library that (I imagine?) doesn't actually need it for my use-case.

@hulsed
Copy link
Contributor Author

hulsed commented Nov 9, 2023

Okay so there is a secret third way to solve my problem and that is installing dependencies via anaconda, which I have now figured out how to do.

I'd recommend adding some instructions for installing dependencies with anaconda in windows:


Creating a development environment for gaphor in anaconda.

(1) Create new anaconda profile e.g., 'gaphor'

(2) Update anaconda in the environment

(3) Install packages

conda install -c conda-forge gobject-introspection gtk4 pygobject pycairo hicolor-icon-theme adwaita-icon-theme

Note: gtksourceview5, libadwaita are not available as anaconda packages. So you may (?) not be able to build/run the program in this environment.

(4) Set up your IDE(s)

conda install ipython ipykernel

(a) VSCode should work out-of-the box if it is already installed. Just set 'gaphor' as the kernel in your VSCode Profile or notebook

(b) Spyder may not be able to install under this environment (conda install spyder will reveal conflicts).

Instead, you can do the following

conda install spyder-kernels=2.4

Then open spyder and set 'gaphor' as your python interpreter

@amolenaar
Copy link
Member

amolenaar commented Nov 10, 2023

Yes, I was grouping PyGObject and gtk there, since both are installed using gvsbuild on windows. It would be nice not to have to go through that process just to call a library that (I imagine?) doesn't actually need it for my use-case.

Indeed it would certainly be nice to have PyGObject as an optional dependency altogether. I was not able to achieve this when I wanted to make Gaphor (as a library) work on readthedocs without GTK. We need Pango for text rendering still, and Pango is also provided via PyGObject.

We do still need Cairo, though. Not sure if you can install that on windows without building it.

@amolenaar
Copy link
Member

Th Conda way is interesting as well. With a tool like Pixi we should be able to provide everything needed to run Gaphor with Jupyter.

@danyeaw
Copy link
Member

danyeaw commented Nov 27, 2023

@hulsed Would you be willing to add Anaconda Windows instructions to the docs? That would be an awesome contribution!

@amolenaar
Copy link
Member

BTW. Gaphor also supports running scripts from the CLI:

$ gaphor exec --help
usage: gaphor exec [-v | -q] [--profiler] [-h] script

Execute a python script from within Gaphor.

positional arguments:
  script         execute a script file and exit

options:
  -v, --verbose  enable verbose logging
  -q, --quiet    only show warning and error logging
  --profiler     run in profiler (cProfile)
  -h, --help     show this help message and exit

@hulsed
Copy link
Contributor Author

hulsed commented Dec 5, 2023

@danyeaw I could do that, but not sure about time-frame since I would want to refine/double-check the approach (and I have a few things on my plate right now). Feel free to assign this to me in the mean-time so I can keep track of it.

@amolenaar amolenaar added the feature A new feature label Apr 25, 2024
hulsed added a commit to hulsed/gaphor that referenced this issue May 17, 2024
- Docs page added for anaconda installation
- See: gaphor#2821
0lione pushed a commit to 0lione/gaphor that referenced this issue May 27, 2024
- Docs page added for anaconda installation
- See: gaphor#2821
0lione pushed a commit to 0lione/gaphor that referenced this issue May 27, 2024
- Docs page added for anaconda installation
- See: gaphor#2821
0lione pushed a commit to 0lione/gaphor that referenced this issue May 27, 2024
- Docs page added for anaconda installation
- See: gaphor#2821
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

No branches or pull requests

3 participants