mirror of
https://github.com/PR0M3TH3AN/python_charts.git
synced 2026-10-27 17:00:41 +00:00
Add Makefile and update startup.sh for improved environment setup
- Introduce a Makefile to define standard targets for installation, data preparation, plotting, testing, and cleaning. - Update `startup.sh` to enhance clarity and functionality, including better command handling and virtual environment management. - Document changes in `repo-context.txt` to reflect the addition of the Makefile.
This commit is contained in:
1 parent
3c097cc847
commit
1d6f38fedd
3 files changed
+162
-24
No files matched your search
@@ -0,0 +1,65 @@
|
||||
# AGENTS.md — Guidance for OpenAI Codex
|
||||
|
||||
## Project Overview
|
||||
|
||||
This repository, **python\_charts**, provides a framework for fetching economic time series from FRED, storing them locally, and producing custom matplotlib charts with configurable parameters. The core components are:
|
||||
|
||||
* **`startup.sh`**: Single-entrypoint script to bootstrap a Python venv, install dependencies, fetch data, and run specified commands under the venv interpreter.
|
||||
* **`Makefile`**: Convenient high-level targets (`install`, `data`, `plot`, `plot-custom`, `test`, `clean`) that funnel through `startup.sh` for reproducible builds.
|
||||
* **`scripts/refresh_data.py`**: Downloads UNRATE and DCOILWTICO series into `data/fred.db`.
|
||||
* **`scripts/lagged_oil_unrate_chart_styled.py`**: Generates the lagged oil vs. unemployment chart with fixed axes styling and log scale.
|
||||
|
||||
Future extensions will add additional custom chart scripts under `scripts/`, all driven by the same bootstrapping and command conventions.
|
||||
|
||||
## Usage Conventions
|
||||
|
||||
### Primary Commands
|
||||
|
||||
* **Bootstrap & default plot**: `./startup.sh` or `make plot` — runs the lagged-oil chart with an 18‑month offset.
|
||||
* **Custom plot**: `./startup.sh --offset 12 --end 2025-05-31 --extend-years 5` or `make plot-custom ARGS="--offset 12 --end 2025-05-31 --extend-years 5"`.
|
||||
* **Data refresh**: `./startup.sh scripts/refresh_data.py` or `make data`.
|
||||
* **Run tests**: `./startup.sh pytest -q` or `make test`.
|
||||
|
||||
### Argument Rules
|
||||
|
||||
* Arguments beginning with `--` are forwarded to the default chart script.
|
||||
* If the first token is a `.py` script or executable, it is invoked under the venv’s Python.
|
||||
* Otherwise, commands are executed directly (e.g. linters, test frameworks).
|
||||
|
||||
## Coding Standards
|
||||
|
||||
* **Python**: Target version 3.12. Use type hints for all function signatures. Follow PEP8 with **Black** formatting.
|
||||
* **Bash**: `startup.sh` must use `set -euo pipefail` and always call `$VENV_DIR/bin/python` to avoid system‑Python mismatches.
|
||||
* **Makefile**: Use tab‑indented commands. All tasks should funnel to `startup.sh`.
|
||||
|
||||
## Testing & Validation
|
||||
|
||||
* **Automated tests**: No current tests; add pytest modules under `tests/` following the pattern `test_*.py`.
|
||||
* **Data mocking**: For new chart scripts, mock FRED downloads via monkeypatching `pandas_datareader.data.DataReader`.
|
||||
|
||||
## Extending with New Charts
|
||||
|
||||
1. **Create a new script** under `scripts/`, for example `scripts/custom_chart.py`.
|
||||
2. **Implement** a `main()` accepting `--start`, `--end`, `--offset` or custom args using `argparse`.
|
||||
3. **Leverage** `startup.sh` invocation: add usage example in your script’s docstring.
|
||||
4. **Update** the `Makefile` if you need a dedicated target, otherwise users can call:
|
||||
|
||||
```bash
|
||||
./startup.sh python scripts/custom_chart.py --your-args
|
||||
```
|
||||
|
||||
## CI / Codex Integration
|
||||
|
||||
* In Codex cloud or CLI tasks, set the **Setup Script** to `./startup.sh install data` to ensure dependencies and data are ready.
|
||||
* **Task Commands** should call `make plot` or `make test`, which delegates to `startup.sh`.
|
||||
* **AGENTS.md** is automatically loaded by Codex to understand structure and commands.
|
||||
|
||||
## PR & Commit Guidelines
|
||||
|
||||
* Prefix branches/PRs with `feature/` or `fix/`.
|
||||
* Commit messages: `<type>(<scope>): <description>` (e.g. `feat(charts): add custom inflation plot`).
|
||||
* Include screenshots or saved chart outputs under `outputs/` for visual verification.
|
||||
|
||||
---
|
||||
|
||||
*End of AGENTS.md — tailored for python\_charts repo*
|
||||
@@ -0,0 +1,29 @@
|
||||
# Makefile for python_charts
|
||||
# Defines standard targets for Codex/CI to use startup.sh
|
||||
|
||||
.PHONY: install data plot test clean
|
||||
|
||||
# Install dependencies into venv and prepare data
|
||||
install:
|
||||
./startup.sh pip install
|
||||
|
||||
# Download FRED data (if needed)
|
||||
data:
|
||||
./startup.sh scripts/refresh_data.py
|
||||
|
||||
# Generate the default chart (18-month lag)
|
||||
plot:
|
||||
./startup.sh
|
||||
|
||||
# Generate a custom chart
|
||||
# Usage: make plot ARGS="--offset 12 --end 2025-05-31 --extend-years 5"
|
||||
plot-custom:
|
||||
./startup.sh $(ARGS)
|
||||
|
||||
# Run test suite
|
||||
test:
|
||||
./startup.sh pytest -q
|
||||
|
||||
# Remove virtual environment and outputs
|
||||
clean:
|
||||
rm -rf venv data outputs
|
||||
+68
-24
@@ -12,6 +12,7 @@ Generated on: 2025-05-30
|
||||
├── lagged_oil_unrate_chart_styled.py
|
||||
├── pyproject.toml
|
||||
├── refresh_data.py
|
||||
├── Makefile
|
||||
├── README.md
|
||||
├── requirements.txt
|
||||
├── startup.sh
|
||||
@@ -176,15 +177,13 @@ python-dateutil>=2.8.1
|
||||
```
|
||||
#!/usr/bin/env bash
|
||||
# -------------------------------------------------------------------
|
||||
# startup.sh — prepare Python env, ensure dependencies, FRED data,
|
||||
# and run a command inside the venv
|
||||
# startup.sh — prepare Python env, ensure deps & data, then run.
|
||||
# Usage:
|
||||
# ./startup.sh [command…]
|
||||
# Automatically:
|
||||
# - Upgrades pip & setuptools (ensuring distutils on Python 3.12+)
|
||||
# - Creates venv if missing
|
||||
# - Installs requirements
|
||||
# - Downloads data/fred.db if missing
|
||||
# ./startup.sh [options] # passes options to default plot script
|
||||
# ./startup.sh [script or cmd] # runs specified script/command
|
||||
# Examples:
|
||||
# ./startup.sh --offset 12 --end 2025-05-31 --extend-years 5
|
||||
# ./startup.sh pytest -q
|
||||
# -------------------------------------------------------------------
|
||||
set -euo pipefail
|
||||
|
||||
@@ -192,49 +191,94 @@ VENV_DIR="venv"
|
||||
REQ_FILE="requirements.txt"
|
||||
WHEELHOUSE="wheelhouse"
|
||||
DATA_DB="data/fred.db"
|
||||
PYTHON="$VENV_DIR/bin/python"
|
||||
DEFAULT_SCRIPT="scripts/lagged_oil_unrate_chart_styled.py"
|
||||
|
||||
# 1) Create or reuse venv
|
||||
if [[ ! -d "$VENV_DIR" ]]; then
|
||||
echo "🔧 Creating virtual-env…"
|
||||
python3 -m venv "$VENV_DIR"
|
||||
fi
|
||||
# Activate
|
||||
|
||||
# 2) Activate venv
|
||||
# shellcheck disable=SC1090
|
||||
source "$VENV_DIR/bin/activate"
|
||||
|
||||
# 2) Upgrade pip & setuptools (to provide distutils on Py3.12+)
|
||||
# 3) Upgrade pip & setuptools
|
||||
echo "🛠 Upgrading pip & setuptools…"
|
||||
pip install --upgrade pip setuptools
|
||||
$PYTHON -m pip install --upgrade pip setuptools
|
||||
|
||||
# 3) Install project dependencies
|
||||
# 4) Install dependencies
|
||||
PIP_OPTS=(install --upgrade --no-input)
|
||||
if [[ -d "$WHEELHOUSE" ]]; then
|
||||
echo "📦 Installing from wheelhouse…"
|
||||
pip "${PIP_OPTS[@]}" --no-index --find-links="$WHEELHOUSE" -r "$REQ_FILE" \
|
||||
|| { echo "⚠️ Wheelhouse failed—falling back to PyPI…"; \
|
||||
pip "${PIP_OPTS[@]}" -r "$REQ_FILE"; }
|
||||
$PYTHON -m pip "${PIP_OPTS[@]}" --no-index --find-links="$WHEELHOUSE" -r "$REQ_FILE" \
|
||||
|| { echo "⚠️ Wheelhouse failed—falling back…"; \
|
||||
$PYTHON -m pip "${PIP_OPTS[@]}" -r "$REQ_FILE"; }
|
||||
else
|
||||
echo "🌐 Installing from PyPI…"
|
||||
pip "${PIP_OPTS[@]}" -r "$REQ_FILE"
|
||||
$PYTHON -m pip "${PIP_OPTS[@]}" -r "$REQ_FILE"
|
||||
fi
|
||||
|
||||
echo "✅ Virtual-env ready ($(python -V))"
|
||||
echo "✅ Virtual-env ready ($($PYTHON -V))"
|
||||
|
||||
# 4) Ensure data/fred.db exists
|
||||
# 5) Ensure data exists
|
||||
if [[ ! -f "$DATA_DB" ]]; then
|
||||
echo "🔄 $DATA_DB not found—downloading FRED series…"
|
||||
python scripts/refresh_data.py
|
||||
echo "🔄 Data not found—downloading FRED series…"
|
||||
$PYTHON scripts/refresh_data.py
|
||||
fi
|
||||
|
||||
# 5) Decide what to run
|
||||
if [[ $# -gt 0 ]]; then
|
||||
CMD=("$@")
|
||||
# 6) Build command
|
||||
if [[ $# -eq 0 ]]; then
|
||||
CMD=("$PYTHON" "$DEFAULT_SCRIPT" --offset 18)
|
||||
elif [[ "$1" == --* ]]; then
|
||||
CMD=("$PYTHON" "$DEFAULT_SCRIPT" "$@")
|
||||
else
|
||||
CMD=(python scripts/lagged_oil_unrate_chart_styled.py --offset 18)
|
||||
if [[ -f "$1" || "$1" == *.py ]]; then
|
||||
CMD=("$PYTHON" "$@")
|
||||
else
|
||||
CMD=("$@")
|
||||
fi
|
||||
fi
|
||||
|
||||
# 7) Execute
|
||||
echo "🚀 Executing: ${CMD[*]}"
|
||||
exec "${CMD[@]}"
|
||||
|
||||
```
|
||||
|
||||
## python_charts/Makefile
|
||||
```
|
||||
# Makefile for python_charts
|
||||
# Defines standard targets for Codex/CI to use startup.sh
|
||||
|
||||
.PHONY: install data plot test clean
|
||||
|
||||
# Install dependencies into venv and prepare data
|
||||
install:
|
||||
./startup.sh pip install
|
||||
|
||||
# Download FRED data (if needed)
|
||||
data:
|
||||
./startup.sh scripts/refresh_data.py
|
||||
|
||||
# Generate the default chart (18-month lag)
|
||||
plot:
|
||||
./startup.sh
|
||||
|
||||
# Generate a custom chart
|
||||
# Usage: make plot ARGS="--offset 12 --end 2025-05-31 --extend-years 5"
|
||||
plot-custom:
|
||||
./startup.sh $(ARGS)
|
||||
|
||||
# Run test suite
|
||||
test:
|
||||
./startup.sh pytest -q
|
||||
|
||||
# Remove virtual environment and outputs
|
||||
clean:
|
||||
rm -rf venv data outputs
|
||||
|
||||
```
|
||||
|
||||
## scripts/refresh_data.py
|
||||
|
||||
Reference in new issue
Block a user