Example scripts in the examples/ directory used hardcoded or brittle paths that made them fail or require execution from specific working directories. This prevented users from running examples from anywhere in the filesystem or from different project locations.
Updated all Python example scripts to use relative path resolution based on the script location, following the pattern already used by some examples in the repository.
- examples/feature_store_example.py
- examples/deep_svdd_example.py
- examples/graph_validation_demo.py
All Python examples now use the following pattern at the top of the file:
import sys
from pathlib import Path
# Add the parent directory to the path to import astroml
# This allows the example to run from any working directory
script_dir = Path(__file__).parent.resolve()
repo_root = script_dir.parent
sys.path.insert(0, str(repo_root))- ✅ Examples can be run from any working directory
- ✅ Examples can be run from any location in the filesystem
- ✅ Proper module imports regardless of execution context
- ✅ Follows existing patterns in
benchmark_example.py,calibration_example.py, andquick_start.py
examples/benchmark_example.py- already had correct setupexamples/calibration_example.py- already had correct setupexamples/quick_start.py- already had correct setup- Jupyter notebooks - use relative path setup appropriate for notebooks
- All Python files pass syntax validation
- Import tests confirm astroml can be imported from any directory
- Examples follow consistent patterns across the repository
Users can now run examples like:
# From any directory
python /path/to/examples/feature_store_example.py
# From project root
python examples/feature_store_example.py
# From examples directory
python feature_store_example.py
# From completely different directory
cd /tmp && python /workspaces/astroml/examples/feature_store_example.pyAll of these will work correctly without path-related errors.