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

make mesa runable without some dependencies #1950

Merged
merged 1 commit into from
Jan 9, 2024
Merged

Conversation

Corvince
Copy link
Contributor

@Corvince Corvince commented Jan 9, 2024

I was playing around with Jupyter Lite to create a first version of a Netlogo Web-like experience, where users can try out some models on a statically hosted webpage.

However, Pyodide (the underlying tech) needs either pure python packages or specialized wheels. Mesa itself is pure python, but it depends on mesa-viz-tornado, which depends on tornado, which is not yet compatible with Pyodide. I was trying to install mesa without dependencies, but the way it is currently build it requires mesa_viz_tornado to be present to import mesa.

This PR removes that hard dependency by only trying to import the module. So if users don't use the tornado backend they don't need to have that dependency installed.

I did the same for pandas, which is only used for converting the output of the datacollector and networkx, which is only used for NetworkGrid.

The other dependencies are either already only used on access or an integral part of mesa.

Copy link

codecov bot commented Jan 9, 2024

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (4471047) 79.92% compared to head (30803c1) 79.45%.
Report is 1 commits behind head on main.

Files Patch % Lines
mesa/experimental/jupyter_viz.py 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1950      +/-   ##
==========================================
- Coverage   79.92%   79.45%   -0.47%     
==========================================
  Files          15       15              
  Lines        1270     1285      +15     
  Branches      277      285       +8     
==========================================
+ Hits         1015     1021       +6     
- Misses        216      225       +9     
  Partials       39       39              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Corvince Corvince force-pushed the feat/less-dependencies branch from 757993f to 30803c1 Compare January 9, 2024 22:25
import itertools
import types
from functools import partial

import pandas as pd
with contextlib.suppress(ImportError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading https://stackoverflow.com/questions/34566806/why-use-contextlib-suppress-as-opposed-to-try-except-with-pass, I suppose that using contextlib.suppress is more concise than try-except.

@rht rht merged commit b7044de into main Jan 9, 2024
10 of 12 checks passed
@rht rht deleted the feat/less-dependencies branch January 9, 2024 23:07
@rht
Copy link
Contributor

rht commented Jan 10, 2024

It seems that the dependencies in Solara (watchdog, etc) can be optionally imported as well: widgetti/solara#449 (comment).

@rht rht added the enhancement Release notes label label Jan 10, 2024
@EwoutH EwoutH added the depedency Release notes label label Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
depedency Release notes label enhancement Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants