Skip to content

Commit

Permalink
feat: juypter notebook support
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Nov 24, 2024
1 parent 0f0b1a1 commit 3ffe2d9
Show file tree
Hide file tree
Showing 5 changed files with 474 additions and 5 deletions.
30 changes: 30 additions & 0 deletions docs/source/how-tos/juypter_notebooks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Juypter Notebooks (IPython)
###########################

If you want to run a Jupyter notebook with all the setup a script has (named contracts, ``sys.path`` adjustments, etc), you can use the following code:

.. code-block:: python
from moccasin import setup_notebook
setup_notebook()
Then, you can work with the notebook as you would normally.

.. code-block:: python
from moccasin.config import get_active_network
active_network = get_active_network()
eth_usd = active_network.manifest_named("eth_usd_price_feed")
If you update your config while the notebook is running, you can reload the config with:

.. code-block:: python
from moccasin.config import get_config
config = get_config()
# This command
config.reload()
1 change: 1 addition & 0 deletions docs/source/toctree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Moccasin
Contract Verification <how-tos/verify_contracts.rst>
Stateless Fuzzing <how-tos/stateless_fuzzing.rst>
Stateful Fuzzing <how-tos/stateful_fuzzing.rst>
how-tos/juypter_notebooks.rst


.. toctree::
Expand Down
3 changes: 3 additions & 0 deletions moccasin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,9 @@ def _load_config(self, config_path: Path, pyproject_path: Path | None = None):
def _load_env_file(self):
load_dotenv(dotenv_path=self.project_root.joinpath(self.dot_env))

def reload(self):
self.__init__(self.project_root)

def get_config_path(self) -> Path:
return self.config_path

Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "moccasin"
version = "0.3.4"
version = "0.3.5"
description = "Pythonic smart contract development framework using Titanoboa"
authors = [
{ name = "PatrickAlphac", email = "54278053+PatrickAlphaC@users.noreply.github.com" },
Expand All @@ -11,12 +11,14 @@ dependencies = [
"python-dotenv>=1.0.1",
"titanoboa-zksync>=0.2.8",
"tqdm>=4.66.5",
"tomlkit>=0.13.2", # For preserving comments when writing to toml
"tomlkit>=0.13.2",
# For preserving comments when writing to toml
"tomli-w>=1.0.0",
"pytest-cov>=5.0.0",
"uv>=0.4.15",
"pytest-xdist>=3.6.1",
"vyper==0.4.0", # We will want to get rid of this hard-coded dependency in 0.3.4 of moccasin
"vyper>=0.4.0",
"ipykernel>=6.29.5",
]
readme = "README.md"
requires-python = ">= 3.11, <= 3.13"
Expand Down
Loading

0 comments on commit 3ffe2d9

Please sign in to comment.