Publish a completed study to GitHub - creates a repo with the analysis report as README.md, all charts, data, and a reproducibility footer linking to Expected Parrot
Publish a completed study to GitHub - creates a repo with the analysis report as README.md, all charts, data, and a reproducibility footer linking to Expected Parrot
Takes a completed study directory (containing results, an experiment design, and an analysis report) and publishes it as a GitHub repository. The analysis report becomes README.md so it renders nicely on GitHub.
If no study directory is specified, auto-detect from the current working directory by looking for directories matching YYYY-MM-DD_*.
Workflow
1. Locate the Study Directory
If a directory was provided, confirm it exists. Otherwise, find candidates:
import glob
import os
candidates = sorted(glob.glob(), key=os.path.getmtime, reverse=)
candidates = [d d candidates os.path.isdir(d)]
"./[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_*"
True
for
in
if
If zero candidates, tell the user no study directories were found.
If exactly one, use it automatically.
If multiple, use AskUserQuestion to let the user pick:
Question: "Which study do you want to publish?"
Header: "Study"
Options: [list each directory as an option with its name as label and first line of experiment_design.md as description]
2. Select the Analysis
Find analysis_N/ subdirectories that contain report.md:
import os, glob
analysis_dirs = sorted(glob.glob(f"{study_dir}/analysis_*/"))
with_reports = [d for d in analysis_dirs if os.path.isfile(os.path.join(d, "report.md"))]
If zero, tell the user to run /analyze-results first.
If exactly one, use it automatically.
If multiple, use AskUserQuestion to let the user pick which analysis to feature as the README:
Question: "Which analysis should be the primary report (README.md)?"
Header: "Analysis"
Options: [list each analysis_N with first line of its report.md as description]
3. Ensure Results Are on Expected Parrot
Check for results.json.gz in the study directory and push it to Expected Parrot so the repo can link to it for reproducibility.
from edsl import Results
results = Results.load(f"{study_dir}/results") # loads results.json.gz# Push to Expected Parrot (unlisted by default)
info = results.push(description="Results for: <study_slug>")
# Extract the UUID and URL from the push response# info is a dict with 'uuid' and 'url' keys
results_uuid = info["uuid"]
results_url = info["url"]
print(f"Results pushed: {results_url}")
print(f"UUID: {results_uuid}")
If the push fails or results.json.gz doesn't exist, warn the user but continue — the reproducibility section will note that results are not available on Expected Parrot.
4. Stage Repo Contents
Build the repository contents in a temporary directory. Copy files from the study and analysis directories:
Check for subdirectories inside the analysis directory that contain answer.md:
import glob, os, shutil
staging = "/tmp/publish-study-staging"
analysis_dir = "<analysis_dir>"
answer_dirs = [d for d in glob.glob(f"{analysis_dir}/*/")
if os.path.isfile(os.path.join(d, "answer.md"))]
for answer_dir in answer_dirs:
slug = os.path.basename(answer_dir.rstrip("/"))
dest = f"{staging}/questions/{slug}"
os.makedirs(dest, exist_ok=True)
# Copy answer.md as <slug>.md
shutil.copy2(f"{answer_dir}/answer.md", f"{staging}/questions/{slug}.md")
# Copy any PNGsfor png in glob.glob(f"{answer_dir}/*.png"):
os.makedirs(f"{dest}", exist_ok=True)
shutil.copy2(png, f"{dest}/{os.path.basename(png)}")
5. Generate README.md
Read the original report.md and apply three modifications:
import re
withopen(f"{analysis_dir}/report.md", "r") as f:
readme = f.read()
# 1. Rewrite image paths: (foo.png) -> (images/foo.png)# Match markdown image syntax 
readme = re.sub(
r'(!\[[^\]]*\])\(([^/)][^)]*\.png)\)',
r'\1(images/\2)',
readme
)
# 2. Rewrite results.csv links: (results.csv) -> (data/results.csv)
readme = readme.replace("(results.csv)", "(data/results.csv)")
# 3. Append reproducibility footer
footer = f"""
---
## Reproducibility
This study was conducted using [Expected Parrot EDSL](https://docs.expectedparrot.com/).
### Results on Expected Parrot
The full results object is available on Expected Parrot:
- **URL:** [{results_url}]({results_url})
- **UUID:** `{results_uuid}`
### Pull the Results
```python
from edsl import Results
results = Results.pull("{results_uuid}")
df = results.to_pandas()
Study Code
The full study code is available in the study/ directory, including:
with open(f"{staging}/README.md", "w") as f:
f.write(readme)
If the EP push failed (no `results_uuid`), use a simpler footer without the EP link:
```python
footer_no_ep = """
---
## Reproducibility
This study was conducted using [Expected Parrot EDSL](https://docs.expectedparrot.com/).
### Study Code
The full study code is available in the [`study/`](study/) directory, including:
- EDSL component definitions (survey, agents, models, scenarios)
- Results runner script
- Makefile for reproducibility
- Experimental design specification
### License
This study and its artifacts are released under the [MIT License](LICENSE).
---
*Generated with [Expected Parrot EDSL](https://docs.expectedparrot.com/)*
"""
6. Generate LICENSE
Write a standard MIT license file:
from datetime import datetime
year = datetime.now().year
license_text = f"""MIT License
Copyright (c) {year}
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""withopen(f"{staging}/LICENSE", "w") as f:
f.write(license_text)
7. Ask User for Repo Details
Use AskUserQuestion to confirm the repo name, visibility, and GitHub account:
Question: "What should the GitHub repo be named?"
Header: "Repo name"
Options:
1. "<study-slug>" - "Default: slug from the study directory name (without date prefix)"
2. "Custom name" - "Enter a custom repository name"
Then ask about visibility:
Question: "Should the repo be public or private?"
Header: "Visibility"
Options:
1. "Public (Recommended)" - "Anyone can see this repository"
2. "Private" - "Only you and collaborators can see this repository"
The study slug is derived from the directory name by stripping the date prefix: