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

Using BioMASS without Graphviz #161

Closed
2 tasks done
himoto opened this issue Jul 25, 2022 Discussed in #158 · 6 comments · Fixed by #162
Closed
2 tasks done

Using BioMASS without Graphviz #161

himoto opened this issue Jul 25, 2022 Discussed in #158 · 6 comments · Fixed by #162
Assignees
Labels
graph Graph visualization

Comments

@himoto
Copy link
Contributor

himoto commented Jul 25, 2022

Discussed in #158

Originally posted by himoto July 23, 2022
BioMass requires users to manually install Graphviz for graph visualization but some packages derived from biomass, e.g., pasmpy, do not need it. Currently if we run import biomass without Graphviz, it will raise an ImportError.
I would like to make this optional so that biomass-derived packages can be run without error even if Graphviz is not installed.

Ideas:

  • Move pygraphviz and pyvis from requirements.txt to extras_require in setup.py
  • Modify graph.py as follows:
def to_graph(self):
    try:
        import pygraphviz as pgv
    except ImportError:
        print("pygraphviz is required to run this function.")
    ...

def dynamic_plot(self, ...):
    try:
        from pyvis.network import Network
    except ImportError:
        print("pyvis is required to run this function.")

@formersbach
I would be grateful if you could give me comments on this. I have a branch working on this and if it's ok, I will send a PR.

@himoto himoto added the graph Graph visualization label Jul 25, 2022
@himoto himoto self-assigned this Jul 25, 2022
@formersbach
Copy link
Contributor

I agree with the changes!
Have you checked whether import pygraphviz raises an ImportError when graphviz is not installed? I suspect it might be able to import pygraphviz, but fail further down the line.

@himoto
Copy link
Contributor Author

himoto commented Jul 26, 2022

Hi @formersbach, thanks for your reply. I am sorry but I was wrong. When you run import biomass without Graphviz, it will not raise ImportError but show different error message. Please refer to https://github.com/pasmopy/pasmopy/actions/runs/2742861321.

@formersbach
Copy link
Contributor

Hey @himoto, So it already fails during the installation...
I found this code which allows to install a package inside a script:

import subprocess
import sys
def install(package):
    subprocess.check_call([sys.executable, "-m", "pip", "install", package])

We could replace

try:
    import pygraphviz as pgv 

with

try:
    install("pygraphviz") #install being the function defined above
    import pygraphviz

Note that subprocess.check_call will raise a CalledProcessError if installation fails.

@himoto
Copy link
Contributor Author

himoto commented Jul 27, 2022

@formersbach
Sorry for confusing you but the error message above is raised before updating the code.
It works as I expected after the update.

@formersbach
Copy link
Contributor

Aah I see, I did notice the attached pull request. Changes look good!

P.S.: Why are you working at 3 in the mornign? 😄

@himoto
Copy link
Contributor Author

himoto commented Jul 27, 2022

Because coding is above sleeping 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
graph Graph visualization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants