# Chapter 7: Files, Paths, Projects, and Reproducibility
# Fundamentals of Python for Financial Econometrics - Files, Paths, Projects, and Reproducibility
# Dataset: Ceteris Lab teaching sample

# Files, Paths, Projects, and Reproducibility
#
# **Opening question:** How can a project find its data tomorrow, on another computer, and after being uploaded to a website?

# %% Cell 2
from pathlib import Path

root = Path.cwd()
figure_path = root / "figures" / "example.png"
print(figure_path.suffix)
print(figure_path.parent.name)

# **Interpretation check:** Interpretation. The path expresses the file type and project role without assuming an operating system.

# %% Cell 4
import json
from pathlib import Path

metadata = {
    "provider": "Bank of Canada",
    "series": "FXUSDCAD",
    "retrieved": "2026-08-15",
}
path = Path("data/metadata/example.json")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(metadata, indent=2), encoding="utf-8")
print(path.exists())

# **Interpretation check:** Interpretation. Metadata becomes a first-class project artifact rather than a memory held by one analyst.

# %% Cell 6
from pathlib import Path
root = Path.cwd()
print(figure_path.suffix)
print(figure_path.parent.name)
import json
from pathlib import Path

# Verified source output
#
# ```text
# .png figures
# ```
#
# ```text
# True
# ```
#
# ```text
# .png
# figures
# ```
