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

Include examples in readthedocs #2382

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
d90b0f7
further updates
quaquel Jan 21, 2024
9586490
Update benchmarks/WolfSheep/__init__.py
quaquel Jan 21, 2024
4aaa35d
Merge remote-tracking branch 'upstream/main'
quaquel Feb 21, 2024
d31478c
Merge remote-tracking branch 'upstream/main'
quaquel Apr 22, 2024
6e4c72e
Merge remote-tracking branch 'upstream/main'
quaquel Aug 14, 2024
70fbaf5
Merge remote-tracking branch 'upstream/main'
quaquel Aug 18, 2024
724c8db
Merge remote-tracking branch 'upstream/main'
quaquel Aug 21, 2024
45184a4
Merge remote-tracking branch 'upstream/main'
quaquel Aug 22, 2024
3d75d30
Merge remote-tracking branch 'upstream/main'
quaquel Aug 27, 2024
2759244
Update __init__.py
quaquel Aug 27, 2024
fc8aaea
Merge remote-tracking branch 'upstream/main'
quaquel Aug 28, 2024
1ba465d
Merge remote-tracking branch 'upstream/main'
quaquel Aug 30, 2024
2b5e822
Merge remote-tracking branch 'upstream/main'
quaquel Sep 2, 2024
3847799
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
301d80e
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
fe3d655
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
7d18880
Merge remote-tracking branch 'upstream/main'
quaquel Sep 5, 2024
6b49a3b
Merge remote-tracking branch 'upstream/main'
quaquel Sep 5, 2024
b9909e6
Merge remote-tracking branch 'upstream/main'
quaquel Sep 9, 2024
8ce3d83
Merge remote-tracking branch 'upstream/main'
quaquel Sep 10, 2024
88fbf74
Merge remote-tracking branch 'upstream/main'
quaquel Sep 13, 2024
077aca5
Merge remote-tracking branch 'upstream/main'
quaquel Sep 16, 2024
c771e3b
Merge remote-tracking branch 'upstream/main'
quaquel Sep 18, 2024
3fa0c27
Merge remote-tracking branch 'upstream/main'
quaquel Sep 18, 2024
8fdcf5c
Merge remote-tracking branch 'upstream/main'
quaquel Sep 21, 2024
475b060
Merge remote-tracking branch 'upstream/main'
quaquel Sep 21, 2024
fb93261
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
86f2f0c
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
dc1d843
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
9857ef1
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
afdd836
Merge remote-tracking branch 'upstream/main'
quaquel Sep 29, 2024
46c3d13
Merge remote-tracking branch 'upstream/main'
quaquel Sep 30, 2024
a5205eb
Merge remote-tracking branch 'upstream/main'
quaquel Oct 7, 2024
59a0413
Merge remote-tracking branch 'upstream/main'
quaquel Oct 12, 2024
56f00af
Merge remote-tracking branch 'upstream/main'
quaquel Oct 12, 2024
135c978
Merge remote-tracking branch 'upstream/main'
quaquel Oct 14, 2024
bd4ca35
Merge remote-tracking branch 'upstream/main'
quaquel Oct 15, 2024
5a69aee
Merge remote-tracking branch 'upstream/main'
quaquel Oct 15, 2024
98c4616
Merge remote-tracking branch 'upstream/main'
quaquel Oct 16, 2024
2aa5326
Merge remote-tracking branch 'upstream/main'
quaquel Oct 16, 2024
91e6c0f
Merge remote-tracking branch 'upstream/main'
quaquel Oct 16, 2024
5976962
Merge remote-tracking branch 'upstream/main'
quaquel Oct 17, 2024
95da9b7
Merge remote-tracking branch 'upstream/main'
quaquel Oct 17, 2024
66b70eb
Merge remote-tracking branch 'upstream/main'
quaquel Oct 18, 2024
2d1d391
first test of examples in docs
quaquel Oct 17, 2024
dc84b97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2024
25837e2
Update conf.py
quaquel Oct 17, 2024
6c132d1
Update pyproject.toml
quaquel Oct 17, 2024
1251297
Update conf.py
quaquel Oct 17, 2024
6cb510d
filename updates
quaquel Oct 17, 2024
8f41c33
Update conf.py
quaquel Oct 17, 2024
8bbdb1d
fixes
quaquel Oct 17, 2024
962e794
further updates
quaquel Oct 17, 2024
ee662b1
Update examples_overview_template.txt
quaquel Oct 17, 2024
fd4bfaa
Update example_template.txt
quaquel Oct 18, 2024
3f0c3e6
add app.py into docs
quaquel Oct 18, 2024
1515f29
Update app.py
quaquel Oct 18, 2024
5759cb3
remove inits from api docs
quaquel Oct 18, 2024
f5070b7
updates
quaquel Oct 18, 2024
b65fa0a
hacky fix
quaquel Oct 18, 2024
6ec9687
Update visualization_tutorial.ipynb
quaquel Oct 18, 2024
4bbf000
cleanup
quaquel Oct 18, 2024
962c0cc
updated files
quaquel Oct 18, 2024
6ce1e0a
updates
quaquel Oct 18, 2024
14f7104
automated detection of updates to example files
quaquel Oct 18, 2024
2ef80f8
Update conf.py
quaquel Oct 18, 2024
ed764f8
Improve Mesa 3.0 beta 1 release notes (#2384)
EwoutH Oct 18, 2024
ed43d5c
refactor: Simplify Schelling code (#2353)
rht Oct 18, 2024
962adce
trying to merge
quaquel Oct 18, 2024
824459f
trying to merge
quaquel Oct 18, 2024
e0ac4ba
Update index.md
quaquel Oct 19, 2024
8fa9f53
some typo fixes
quaquel Oct 19, 2024
4be7dd2
allways create md files
quaquel Oct 20, 2024
f92b37c
Update conf.py
quaquel Oct 20, 2024
5163352
Update conf.py
quaquel Oct 20, 2024
6a34561
Merge branch 'main' into docs
quaquel Oct 20, 2024
04e8763
Update conf.py
quaquel Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Docs for Mesa
=============
# Docs for Mesa

The readable version of the docs is hosted at [mesa.readthedocs.org](http://mesa.readthedocs.org/).

This folder contains the docs that build the docs for the core mesa code on readthdocs.

### How to publish updates to the docs
## How to publish updates to the docs

Updating docs can be confusing. Here are the basic setups.

##### Submit a pull request with updates
#### Submit a pull request with updates
1. Create branch (either via branching or fork of repo) -- try to use a descriptive name.
* `git checkout -b doc-updates`
1. Update the docs. Save.
Expand All @@ -23,7 +22,7 @@ Updating docs can be confusing. Here are the basic setups.
* `git push origin doc-updates`
1. From here you will want to submit a pull request to main.

##### Update read the docs
#### Update read the docs

From this point, you will need to find someone that has access to readthedocs. Currently, that is [@jackiekazil](https://github.com/jackiekazil), [@rht](https://github.com/rht), and [@tpike3](https://github.com/dmasad).

Expand Down
10 changes: 0 additions & 10 deletions docs/apis/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ This namespace contains experimental features. These are under development, and

## Cell Space

```{eval-rst}
.. automodule:: experimental.cell_space.__init__
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.cell
:members:
Expand Down Expand Up @@ -40,11 +35,6 @@ This namespace contains experimental features. These are under development, and

## Devs

```{eval-rst}
.. automodule:: experimental.devs.__init__
:members:
```

```{eval-rst}
.. automodule:: experimental.devs.eventlist
:members:
Expand Down
87 changes: 87 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
# serve to show the default.

import os
import os.path as osp
import glob
import sys
import string
from datetime import date

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
HERE = osp.abspath(osp.dirname(__file__))
sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, "../examples")
sys.path.insert(0, "../mesa")
Expand Down Expand Up @@ -289,3 +293,86 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}



def write_example_md_file(agent_filename, model_filename, readme_filename, app_filename, md_filepath, template):
with open(agent_filename) as content_file:
agent_file = content_file.read()
with open(model_filename) as content_file:
model_file = content_file.read()
with open(readme_filename) as content_file:
readme_file = content_file.read()
with open(app_filename) as content_file:
app_file = content_file.read()

with open(md_filepath, "w") as fh:
content = template.substitute(
dict(agent_file=agent_file, model_file=model_file,
readme_file=readme_file, app_file=app_file)
)
fh.write(content)

def setup_examples_pages():
# create md files for all examples
# check what examples exist
examples_folder = osp.abspath(osp.join(HERE, "..", "mesa", "examples"))
basic_examples = [f.path for f in os.scandir(osp.join(examples_folder, "basic")) if f.is_dir() ]
advanced_examples = []
# advanced_examples = [f.path for f in os.scandir(osp.join(examples_folder, "advanced")) if f.is_dir()]
examples = basic_examples + advanced_examples

# get all existing md files
md_files = glob.glob(os.path.join(HERE, "examples", "*.md"))
md_files = {os.path.basename(os.path.normpath(entry)) for entry in md_files}

# check which rst files exist
with open(os.path.join(HERE, "example_template.txt")) as fh:
template = string.Template(fh.read())

examples_md = []
for example in examples:
base_name = os.path.basename(os.path.normpath(example))

agent_filename = os.path.join(example, "agents.py")
model_filename = os.path.join(example, "model.py")
readme_filename = os.path.join(example, "Readme.md")
app_filename = os.path.join(example, "app.py")

md_filename = f"{base_name}.md"
examples_md.append(base_name)

# let's establish the latest update to the example files
timestamps = [osp.getmtime(fh) for fh in [agent_filename, model_filename, readme_filename, app_filename]]
latest_edit = max(timestamps)

md_filepath = os.path.join(HERE, "examples", md_filename)

# if the example is new or the existing example md file is older than the latest update, create a new file
if md_filename not in md_files or latest_edit > osp.getmtime(md_filepath):
write_example_md_file(agent_filename, model_filename, readme_filename, app_filename, md_filepath, template)


# check if any md files should be removed because the example is removed
outdated_md_files = md_files - {f"{entry}.md" for entry in examples_md}
for entry in outdated_md_files:
os.remove(os.path.join(HERE, "examples", entry) )

# create overview of examples.md
with open(os.path.join(HERE, "examples_overview_template.txt")) as fh:
template = string.Template(fh.read())

with open(os.path.join(HERE, "examples.md"), "w") as fh:
content = template.substitute(
dict(
examples="\n".join([f"{' '.join(base_name.split('_'))} </examples/{base_name}>" for base_name in examples_md]),
)
)
fh.write(content)

def setup(app):
setup_examples_pages()


if __name__ == "__main__":
setup_examples_pages()
22 changes: 22 additions & 0 deletions docs/example_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

$readme_file

## Agents

```python
$agent_file
```


## Model

```python
$model_file
```


## App

```python
$app_file
```
14 changes: 14 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Examples


```{toctree}
:maxdepth: 1

boid flockers </examples/boid_flockers>
virus on network </examples/virus_on_network>
conways game of life </examples/conways_game_of_life>
schelling </examples/schelling>
boltzmann wealth model </examples/boltzmann_wealth_model>

```
Loading
Loading