Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion .github/workflows/publish-prices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ jobs:
with:
python-version: "3.14"

# Editable, so the package that builds the release runs from this
# checkout and its manifest can name the commit. Installed as a wheel
# it ran from site-packages, outside any checkout, and every release
# through prices-2026-11-20 says source_commit "". The tests job holds
# the tree to the fixtures, the wheel job holds the wheel to the tree.
- name: Install and test
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install ".[test]"
python -m pip install -e ".[test]"
python -m pytest -q

- name: Build and gate the release
Expand All @@ -73,6 +78,12 @@ jobs:
python -c "import json; print(json.load(open('dist/manifest.json'))['release_tag'])" > tag.txt
echo "TAG=$(cat tag.txt)" >> "$GITHUB_ENV"

# check-release cannot know which commit ran; this step can.
- name: The manifest names this commit, clean
shell: bash
run: |
python -c "import json, os, sys; m = json.load(open('dist/manifest.json')); got = (m.get('source_commit'), m.get('source_dirty')); want = (os.environ['GITHUB_SHA'], False); print('source', got); sys.exit(0 if got == want else 'manifest names %r, expected %r' % (got, want))"

# A release whose tables are committed as test fixtures must be those
# bytes. Today that is the seed, prices-2026-10-07.
- name: Compare with committed fixtures, where there are any
Expand Down
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,46 @@ code.

## Package releases

### 0.8.8 - 2026-12-01

A manifest's `source_commit` names the commit that built it. Every release
through `prices-2026-11-20` says `""` there: the publish workflow installed
the package as a wheel, so the build ran from site-packages, outside any
checkout. The workflow now installs it editable, and a new step fails the
run unless the manifest names `$GITHUB_SHA` with a clean tree. A commit is
recorded only when the checkout's top level holds the package, so a copy
installed in another project's `.venv` no longer reports that project's
HEAD. Both manifests (`release` and `build`) gain `source_dirty`: true when
tracked files differ from the commit, null when there is no checkout. The
published releases keep their manifests; `package_version` (0.7.0 and 0.8.7,
both tagged) is what traces them.

A live quote that is not a finite price above zero is skipped with a WARN,
the rule spacecost already holds a recorded snapshot to. Before, a metals.dev
payload of gold `0` priced gold at $0/kg, platinum `-5` priced it below zero,
and silver `"NaN"` left the reference price under a `metals.dev:silver`
label, all with the run ending "COMPLETE"; a yfinance close took the same
path. The reference row now prices that metal. No snapshot can hold such a
close, so no table built from one moves.

`check-release` also fails a table for a destination the package does not
price; it checked only that none was missing. The README no longer says
every destination has the same columns: `earth_surface` has none of the seven
in-space ones (`value_route` among them), and a test now holds the list.
`apply_delivery_destination`'s platinum example is the seed build's figures.

`spacevalue build --live` and `show --live` exit 1, with a FAIL line on
stderr, when no live quote came back; the table is still written. Before, a
machine without yfinance got exit 0 and, under `-q`, no word at all, and the
build manifest said `"live_quotes": true` over reference prices only. That
manifest now also carries `quoted_rows`, the rows a quote priced: what came
back, beside what was asked. The library is unchanged: a pipeline stage
still carries on with reference prices and says so in its banner. The
README's install lines pin `v0.8.7`; they named `v0.5.0`, data contract
1.19.0.
Data contract unchanged at 1.22.1; no value moves. Rebuilt from
`metals-2026-10-07`, all eight tables equal `prices-2026-11-20` byte for byte.

### 0.8.7 - 2026-11-20

spacecost repinned from `v0.17.1` to `v0.19.0` (its data contract 1.28.0:
Expand Down
3 changes: 2 additions & 1 deletion CITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,5 @@ Cite the release you used, by its tag (`prices-YYYY-MM-DD` for the tables,
`vX.Y.Z` for the code), and the data contract stamped in its rows. A table
from `spacevalue build` is not a release: its `<table>.manifest.json` gives
the package version, data contract, quote snapshot and source commit to cite
instead (General_Research rc-776).
instead (General_Research rc-776). If its `source_dirty` is true, the table
came from uncommitted code and the commit alone does not rebuild it.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ orbit, because every kilogram already up there is a kilogram nobody has to
launch.

```bash
pip install git+https://github.com/loggger101/spacevalue@v0.5.0
pip install git+https://github.com/loggger101/spacevalue@v0.8.7
```

```python
Expand Down Expand Up @@ -105,7 +105,7 @@ its iron and sulfur. The yields are in `yields_json` on every row.
## What a row holds

One row per mineral or element in the reference table, and the same columns
at every destination. The ones you will read most:
at every destination in space. The ones you will read most:

| column | what it holds |
|---|---|
Expand All @@ -125,6 +125,12 @@ at every destination. The ones you will read most:
`pipeline_version` and `delivery_destination` are stamped on every row, so a
table that has lost its filename still says what it is.

Nothing is repriced at `earth_surface`, so its table has no in-space
columns: `terrestrial_price_usd_per_kg`, `in_space_utility`,
`downleg_cost_usd_per_kg`, `in_space_processing_usd_per_kg`,
`refining_kwh_per_kg`, `price_before_processing_usd_per_kg` and
`value_route` are absent there, and `price_usd_per_kg` is the Earth price.

## What a hold is worth

The tables price a kilogram of one mineral. `spacevalue.cargo` prices a
Expand Down Expand Up @@ -170,7 +176,7 @@ column says where it came from.

Live prices are still there, opt-in, for anyone who wants today's and accepts
that it cannot be repeated: `use_yfinance=True` or `spacevalue build --live`,
with the extra `pip install "spacevalue[live] @ git+https://github.com/loggger101/spacevalue@v0.5.0"`.
with the extra `pip install "spacevalue[live] @ git+https://github.com/loggger101/spacevalue@v0.8.7"`.
Asking for live and recorded quotes at once is refused.

The snapshot code is [spacecost's](https://github.com/loggger101/spacecost)
Expand All @@ -186,7 +192,8 @@ holding this package at the same tag can rebuild it and get the same bytes.
The publish workflow builds it on Windows, runs `spacevalue check-release`,
and uploads nothing unless the gate passes. The gate checks:

- every destination has a table, and every byte matches the manifest
- every destination has a table, no table names anything else, and every
byte matches the manifest
- the manifest's quotes are the snapshot's, record for record (ticker, source,
close, unit and close date, each once), and its date is the snapshot's
- every table is CRLF, has one row per reference entry, and carries one data
Expand Down
2 changes: 1 addition & 1 deletion spacevalue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# The PACKAGE release. Not the data contract: that is
# `MineralValueConfig.pipeline_version`, stamped into every row.
__version__ = "0.8.7"
__version__ = "0.8.8"

# Each public name, and the submodule that defines it.
_LAZY = {name: "catalog" for name in (
Expand Down
46 changes: 34 additions & 12 deletions spacevalue/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"""

import json
import math
import os
import sys
from dataclasses import dataclass
from datetime import datetime
from typing import Dict, List, Optional, Tuple
Expand Down Expand Up @@ -510,7 +510,7 @@ def _build_destination_table() -> Dict[str, dict]:
# all and it can only be sold by flying it down.
#
# THESE ARE ENGINEERING JUDGEMENTS, NOT MEASUREMENTS. Unlike the price
# above, which is derived from the rocket equation and a real launch price,
# above, which is derived from the rocket equation and a real launch price,
# no market exists yet to calibrate these against. They are the single
# biggest soft assumption in the in-space case, so they live here as one
# obvious table rather than being buried per-entry.
Expand Down Expand Up @@ -799,7 +799,7 @@ def _build_destination_table() -> Dict[str, dict]:
"olivine": 0.03, "pyroxene": 0.03, "orthopyroxene": 0.03,
"enstatite": 0.03, "plagioclase": 0.03, "spinel": 0.03,
"phyllosilicates": 0.03, "oxides": 0.03, "silicates": 0.03,
# Carbon is one of the genuinely scarce elements on the Moon;
# Carbon is one of the genuinely scarce elements on the Moon;
# solar-wind implantation leaves it at ~100 ppm, which is not a
# resource. No discount. v1.11.0: nor for CO2 or ammonia, the
# volatiles of carbon and nitrogen, which are scarcer still.
Expand Down Expand Up @@ -961,7 +961,7 @@ def in_space_utility(name: str, destination: str) -> float:
# Prices in this pipeline were static at the point of sale: a mission could
# return any quantity of platinum and still sell every kilogram at spot. That
# is the one remaining assumption that flatters the model in a direction
# nothing else corrects, because the whole "just fly more missions" lever;
# nothing else corrects, because the whole "just fly more missions" lever;
# nre_amortization_missions, has no natural stopping point without it.
#
# Terrestrial figures are USGS Mineral Commodity Summaries annual primary
Expand Down Expand Up @@ -2370,6 +2370,22 @@ def _new_mineral(name: str, formula: str, density: float,
# live. The fetch itself is spacecost's `quotes.fetch_closes`, the same loop
# for fuel and for metals: five days of history, the last non-blank close.

def _usable_close(value) -> Optional[float]:
"""`value` as a price if it is a finite number above zero, else None.

The rule spacecost's `row_problems` holds a recorded snapshot to, applied
to the live paths too: before 0.8.8 a live quote of 0 priced gold at
$0/kg, a negative one priced platinum below zero, and "NaN" left the
reference price standing under a live source's label. A quote that fails
is skipped, so the reference row prices that metal and the build says so.
"""
try:
close = float(value)
except (TypeError, ValueError):
return None
return close if math.isfinite(close) and close > 0 else None


def metal_tickers() -> Dict[str, str]:
"""Ticker -> quote unit, for every reference row yfinance prices."""
return {e["yfinance_ticker"]: e["yfinance_unit"] for e in MINERAL_REFERENCE
Expand All @@ -2392,8 +2408,12 @@ def metal_prices_from_quotes(quotes: Dict[str, "_quotes.Quote"]) -> pd.DataFrame
f"{q.unit!r}, converted per {unit!r}; skipped")
continue

last_close = q.close
last_close = _usable_close(q.close)
last_date = q.close_date
if last_close is None:
say(f" WARN {entry['name']:11s} ({ticker}) - close {q.close!r} "
f"is not a price; skipped")
continue

if unit == "troy_oz":
price_kg = _per_troy_oz_to_per_kg(last_close)
Expand Down Expand Up @@ -2528,11 +2548,12 @@ def fetch_metals_dev(config: MineralValueConfig) -> pd.DataFrame:
if not key or key not in quotes:
continue

try:
usd_per_toz = float(quotes[key])
price_kg = _per_troy_oz_to_per_kg(usd_per_toz)
except (TypeError, ValueError):
usd_per_toz = _usable_close(quotes[key])
if usd_per_toz is None:
say(f" WARN {entry['name']:11s} (metals.dev:{key}) - quote "
f"{quotes[key]!r} is not a price; skipped")
continue
price_kg = _per_troy_oz_to_per_kg(usd_per_toz)

rows.append({
"name": entry["name"],
Expand Down Expand Up @@ -2639,8 +2660,9 @@ def apply_delivery_destination(
already in orbit is a kilogram nobody has to launch.
• Precious metals lose their in-space premium but keep their value.
Nobody in orbit wants platinum, so it is priced by shipping it down:
terrestrial price less the downleg. ~$31,700/kg in LEO against
$57,074 on the ground, a real discount, not a wipeout.
terrestrial price less the downleg. ~$29,700/kg in LEO against
$55,087 on the ground (the metals-2026-10-07 close), a real
discount, not a wipeout.

Applied after merge_sources so it overrides live quotes as well as
reference ones.
Expand Down Expand Up @@ -2849,7 +2871,7 @@ def validate(catalog: pd.DataFrame) -> pd.DataFrame:
if unknown:
say(f" WARN {r['name']}: yields reference unknown elements {sorted(unknown)}")

say(f" OK Validation complete")
say(" OK Validation complete")
return catalog


Expand Down
34 changes: 30 additions & 4 deletions spacevalue/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,33 @@

from . import __version__
from . import catalog as _catalog
from .release import _sha256, _source_commit, build_release, check_release
from .release import _sha256, _source_state, build_release, check_release

_PREVIEW = ["name", "kind", "price_usd_per_kg", "price_basis", "value_route",
"live_price_source", "annual_market_kg"]


def _quoted_rows(table) -> int:
"""Rows priced from a quote (live or recorded), not a reference row."""
if "live_price_source" not in table.columns:
return 0
return int(table["live_price_source"].notna().sum())


def _live_quoted_nothing(args, table) -> bool:
"""True, and said on stderr, when `--live` was asked and nothing quoted.

The library carries on with reference prices and warns in its banner
(a pipeline stage should not die with a market feed), but `-q` hides the
banner, and someone who typed `--live` asked for live prices.
"""
if not args.live or _quoted_rows(table):
return False
print("FAIL --live quoted nothing: every price is a reference row "
"(is spacevalue[live] installed?)", file=sys.stderr)
return True


def write_build_manifest(cfg, table) -> str:
"""Write `<table>.manifest.json` beside a standalone build's CSV.

Expand All @@ -48,6 +69,7 @@ def write_build_manifest(cfg, table) -> str:
csv_path = os.path.join(out_dir, cfg.catalog_filename)
stem = os.path.splitext(cfg.catalog_filename)[0]
path = os.path.join(out_dir, stem + ".manifest.json")
commit, dirty = _source_state()
manifest = {
"release_tag": None,
"release_tag_note": "a standalone build, not a published release",
Expand All @@ -57,7 +79,10 @@ def write_build_manifest(cfg, table) -> str:
"delivery_destination": cfg.delivery_destination,
"quote_snapshot": cfg.quote_snapshot or None,
"live_quotes": bool(cfg.use_yfinance),
"source_commit": _source_commit() or None,
# What was asked is `live_quotes`; what came back is this.
"quoted_rows": _quoted_rows(table),
"source_commit": commit or None,
"source_dirty": dirty,
"file": {"name": cfg.catalog_filename, "rows": int(len(table)),
"sha256": _sha256(csv_path)},
}
Expand Down Expand Up @@ -135,10 +160,11 @@ def main(argv=None) -> int:
table = _catalog.build_mineral_value_catalog(
_config(args, output_dir=tmp))
cols = [c for c in _PREVIEW if c in table.columns]
failed = _live_quoted_nothing(args, table) # the whole table, not -n
if args.rows:
table = table.head(args.rows)
print(table[cols].to_string(index=False))
return 0
return 1 if failed else 0

if args.command == "build":
set_verbose(not args.quiet)
Expand All @@ -148,7 +174,7 @@ def main(argv=None) -> int:
write_build_manifest(cfg, table)
if args.quiet:
print(os.path.join(cfg.resolved_output_dir(), cfg.catalog_filename))
return 0
return 1 if _live_quoted_nothing(args, table) else 0

if args.command == "release":
set_verbose(True)
Expand Down
Loading
Loading