spaceodyssey 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ name: Publish to PyPI
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ name: Build distribution
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v6
12
+ - name: Set up Python
13
+ uses: actions/setup-python@v6
14
+ with:
15
+ python-version: "3.x"
16
+ - name: Install pypa/build
17
+ run: >-
18
+ python3 -m
19
+ pip install
20
+ build
21
+ --user
22
+ - name: Build a binary wheel and a source tarball
23
+ run: python3 -m build
24
+ - name: Store the distribution packages
25
+ uses: actions/upload-artifact@v7
26
+ with:
27
+ name: python-package-distributions
28
+ path: dist/
29
+
30
+ publish-to-pypi:
31
+ name: >-
32
+ Publish Python distribution to PyPI
33
+ if: startsWith(github.ref, 'refs/tags/')
34
+ needs:
35
+ - build
36
+ runs-on: ubuntu-latest
37
+ environment:
38
+ name: pypi
39
+ url: https://pypi.org/p/spaceodyssey
40
+ permissions:
41
+ id-token: write
42
+
43
+ steps:
44
+ - name: Download all the dists
45
+ uses: actions/download-artifact@v8
46
+ with:
47
+ name: python-package-distributions
48
+ path: dist/
49
+ - name: Publish distribution to PyPI
50
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,23 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - main
5
+ workflow_dispatch:
6
+
7
+ permissions:
8
+ contents: write
9
+ pull-requests: write
10
+
11
+ name: release-please
12
+
13
+ jobs:
14
+ release-please:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: googleapis/release-please-action@v5
18
+ with:
19
+ # Personal access token stored as an action secret; the default
20
+ # GITHUB_TOKEN cannot be used because tags it pushes do not
21
+ # trigger the publish-to-pypi workflow.
22
+ token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
23
+ release-type: simple
@@ -0,0 +1,37 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ test:
12
+ name: Test py${{ matrix.python-version }} on ${{ matrix.platform }}
13
+ runs-on: ${{ matrix.platform }}
14
+ strategy:
15
+ matrix:
16
+ python-version: ["3.12"]
17
+ platform: [ubuntu-latest]
18
+ steps:
19
+ - uses: actions/checkout@v6
20
+ with:
21
+ fetch-depth: 0
22
+
23
+ - name: Install uv
24
+ uses: astral-sh/setup-uv@v7
25
+ with:
26
+ enable-cache: true
27
+
28
+ - name: Create venv
29
+ run: uv venv .venv --python ${{ matrix.python-version }}
30
+
31
+ - name: Install package with test dependencies
32
+ run: uv pip install -e ".[test]"
33
+ env:
34
+ VIRTUAL_ENV: ${{ github.workspace }}/.venv
35
+
36
+ - name: Run tests
37
+ run: .venv/bin/pytest tests/ -v --tb=short
@@ -0,0 +1,224 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
219
+
220
+ # hatch-vcs generated version file
221
+ *_version.py
222
+
223
+ # uv lockfile (not committed for this library; see comment above)
224
+ uv.lock
@@ -0,0 +1,28 @@
1
+ repos:
2
+ - repo: local
3
+ hooks:
4
+ - id: no-internal-refs
5
+ name: no internal research references
6
+ entry: python3 tools/check_internal_refs.py
7
+ language: system
8
+ types: [text]
9
+ exclude: ^(CHANGELOG\.md|tools/check_internal_refs\.py)$
10
+ - repo: https://github.com/pre-commit/pre-commit-hooks
11
+ rev: "v6.0.0"
12
+ hooks:
13
+ - id: trailing-whitespace
14
+ - id: name-tests-test
15
+ args: [--pytest-test-first]
16
+ - id: end-of-file-fixer
17
+ - repo: https://github.com/astral-sh/ruff-pre-commit
18
+ rev: v0.15.2
19
+ hooks:
20
+ - id: ruff-check
21
+ args: [--fix]
22
+ - id: ruff-format
23
+ - repo: https://github.com/compilerla/conventional-pre-commit
24
+ rev: v4.3.0
25
+ hooks:
26
+ - id: conventional-pre-commit
27
+ stages: [commit-msg]
28
+ args: []
@@ -0,0 +1,17 @@
1
+ # Required
2
+ version: 2
3
+
4
+ build:
5
+ os: ubuntu-22.04
6
+ tools:
7
+ python: "3.12"
8
+
9
+ python:
10
+ install:
11
+ - method: pip
12
+ path: .
13
+ extra_requirements:
14
+ - docs
15
+
16
+ sphinx:
17
+ configuration: docs/conf.py
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1 (2026-09-16)
4
+
5
+
6
+ ### Features
7
+
8
+ * scaffold the spaceodyssey package ([b746a98](https://github.com/CoreySpohn/spaceodyssey/commit/b746a982768ca2f8cf020f5d3438e27423984d9f))
9
+
10
+
11
+ ### Miscellaneous Chores
12
+
13
+ * release 0.0.1 ([a3e18b0](https://github.com/CoreySpohn/spaceodyssey/commit/a3e18b047598118ba2cd01053aa68c28b673445d))
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Corey Spohn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.5
2
+ Name: spaceodyssey
3
+ Version: 0.0.1
4
+ Summary: Astronomical analysis and observing campaigns: multi-visit observing programs with inference in the loop
5
+ Project-URL: Repository, https://github.com/CoreySpohn/spaceodyssey
6
+ Project-URL: Documentation, https://spaceodyssey.readthedocs.io
7
+ Author-email: Corey Spohn <corey.a.spohn@nasa.gov>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 Corey Spohn
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Classifier: Development Status :: 2 - Pre-Alpha
31
+ Classifier: Intended Audience :: Science/Research
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
35
+ Requires-Python: >=3.11
36
+ Provides-Extra: dev
37
+ Requires-Dist: pre-commit; extra == 'dev'
38
+ Provides-Extra: docs
39
+ Requires-Dist: myst-nb; extra == 'docs'
40
+ Requires-Dist: sphinx-autoapi; extra == 'docs'
41
+ Requires-Dist: sphinx-book-theme; extra == 'docs'
42
+ Provides-Extra: test
43
+ Requires-Dist: pytest; extra == 'test'
44
+ Description-Content-Type: text/markdown
45
+
46
+ # spaceodyssey
47
+
48
+ Astronomical analysis and observing campaigns.
49
+
50
+ spaceodyssey runs multi-visit observing programs with inference in the loop.
51
+ An analysis session fits the observations already in hand for a target. A
52
+ campaign adds a time horizon, an observatory, a policy for choosing the next
53
+ visit, and an execution model that turns admitted visits into new records. An
54
+ ensemble repeats a campaign over many simulated worlds and aggregates the
55
+ outcomes. The simulated world and the model used to reason about it are
56
+ separate by construction, so a campaign can be scored against a truth it never
57
+ saw.
58
+
59
+ The first physical profile is exoplanet direct imaging with the Habitable
60
+ Worlds Observatory. The physics comes from the libraries that own it (orbits,
61
+ scenes, optics, exposure times, post-processing, inference); this package
62
+ composes them and keeps the causal record of what was observed, when, and what
63
+ was known at the time.
64
+
65
+ ## Status
66
+
67
+ Pre-alpha. The public interface is not yet published.
68
+
69
+ ## Installation
70
+
71
+ ```bash
72
+ pip install spaceodyssey
73
+ ```
74
+
75
+ ## License
76
+
77
+ MIT
@@ -0,0 +1,32 @@
1
+ # spaceodyssey
2
+
3
+ Astronomical analysis and observing campaigns.
4
+
5
+ spaceodyssey runs multi-visit observing programs with inference in the loop.
6
+ An analysis session fits the observations already in hand for a target. A
7
+ campaign adds a time horizon, an observatory, a policy for choosing the next
8
+ visit, and an execution model that turns admitted visits into new records. An
9
+ ensemble repeats a campaign over many simulated worlds and aggregates the
10
+ outcomes. The simulated world and the model used to reason about it are
11
+ separate by construction, so a campaign can be scored against a truth it never
12
+ saw.
13
+
14
+ The first physical profile is exoplanet direct imaging with the Habitable
15
+ Worlds Observatory. The physics comes from the libraries that own it (orbits,
16
+ scenes, optics, exposure times, post-processing, inference); this package
17
+ composes them and keeps the causal record of what was observed, when, and what
18
+ was known at the time.
19
+
20
+ ## Status
21
+
22
+ Pre-alpha. The public interface is not yet published.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install spaceodyssey
28
+ ```
29
+
30
+ ## License
31
+
32
+ MIT
@@ -0,0 +1,28 @@
1
+ """Sphinx configuration."""
2
+
3
+ from importlib.metadata import version as get_version
4
+
5
+ project = "spaceodyssey"
6
+ release = get_version("spaceodyssey")
7
+ version = ".".join(release.split(".")[:2])
8
+
9
+ extensions = [
10
+ "myst_nb",
11
+ "autoapi.extension",
12
+ "sphinx.ext.autodoc",
13
+ "sphinx.ext.napoleon",
14
+ "sphinx.ext.viewcode",
15
+ "sphinx.ext.mathjax",
16
+ ]
17
+
18
+ autoapi_dirs = ["../src"]
19
+ autoapi_ignore = ["**/*version.py"]
20
+ myst_enable_extensions = ["amsmath", "dollarmath"]
21
+
22
+ html_theme = "sphinx_book_theme"
23
+ html_context = {"default_mode": "dark"}
24
+ source_suffix = {".rst": "restructuredtext", ".md": "myst-nb"}
25
+
26
+ nb_execution_mode = "auto"
27
+ nb_execution_timeout = 120
28
+ nb_execution_raise_on_error = True
@@ -0,0 +1,13 @@
1
+ # spaceodyssey
2
+
3
+ Astronomical analysis and observing campaigns.
4
+
5
+ spaceodyssey runs multi-visit observing programs with inference in the loop.
6
+ An analysis session fits the observations already in hand for a target. A
7
+ campaign adds a time horizon, an observatory, a policy for choosing the next
8
+ visit, and an execution model that turns admitted visits into new records. An
9
+ ensemble repeats a campaign over many simulated worlds and aggregates the
10
+ outcomes. The simulated world and the model used to reason about it are
11
+ separate by construction.
12
+
13
+ Pre-alpha. The public interface is not yet published.
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "spaceodyssey"
7
+ dynamic = ["version"]
8
+ description = "Astronomical analysis and observing campaigns: multi-visit observing programs with inference in the loop"
9
+ authors = [{ name = "Corey Spohn", email = "corey.a.spohn@nasa.gov" }]
10
+ readme = "README.md"
11
+ requires-python = ">=3.11"
12
+ license = { file = "LICENSE" }
13
+ classifiers = [
14
+ "Development Status :: 2 - Pre-Alpha",
15
+ "Intended Audience :: Science/Research",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: Scientific/Engineering :: Astronomy",
19
+ ]
20
+ dependencies = []
21
+
22
+ [project.urls]
23
+ Repository = "https://github.com/CoreySpohn/spaceodyssey"
24
+ Documentation = "https://spaceodyssey.readthedocs.io"
25
+
26
+ [project.optional-dependencies]
27
+ dev = ["pre-commit"]
28
+ test = ["pytest"]
29
+ docs = ["myst-nb", "sphinx-autoapi", "sphinx-book-theme"]
30
+
31
+ [tool.ruff.lint]
32
+ select = ["B", "D", "E", "F", "I", "UP", "RUF"]
33
+
34
+ [tool.ruff.lint.pydocstyle]
35
+ convention = "google"
36
+
37
+ [tool.ruff.lint.per-file-ignores]
38
+ "tests/**" = ["D"]
39
+
40
+ [tool.hatch.version]
41
+ source = "vcs"
42
+
43
+ [tool.hatch.build.hooks.vcs]
44
+ version-file = "src/spaceodyssey/_version.py"
45
+
46
+ [tool.hatch.build.targets.wheel]
47
+ packages = ["src/spaceodyssey"]
48
+
49
+ [tool.pytest.ini_options]
50
+ testpaths = ["tests"]
@@ -0,0 +1,10 @@
1
+ """Astronomical analysis and observing campaigns.
2
+
3
+ Multi-visit observing programs with inference in the loop: an analysis session
4
+ fits existing observations, a campaign chooses and executes new visits against
5
+ a private simulated world, and an ensemble repeats a campaign over many worlds.
6
+ """
7
+
8
+ from spaceodyssey._version import __version__
9
+
10
+ __all__ = ["__version__"]
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.0.1'
22
+ __version_tuple__ = version_tuple = (0, 0, 1)
23
+
24
+ __commit_id__ = commit_id = None
@@ -0,0 +1,6 @@
1
+ import spaceodyssey
2
+
3
+
4
+ def test_version_is_a_string():
5
+ assert isinstance(spaceodyssey.__version__, str)
6
+ assert spaceodyssey.__version__
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env python3
2
+ """Commit guard: block internal research references in library files.
3
+
4
+ Library code is public and self-contained; pointers into the private research
5
+ workspace (project brain documents, decision-history vocabulary, working-note
6
+ paths) do not belong in it. This script scans the given files line by line
7
+ against a small pattern list and exits nonzero on any hit, so it can run as a
8
+ pre-commit hook (see .pre-commit-config.yaml) and as a pytest.
9
+
10
+ A line that must legitimately contain such a string (e.g. a development-only
11
+ data fallback path in test fixtures) can be waived by appending the comment
12
+ ``internal-ref-ok`` to that line.
13
+
14
+ Usage: check_internal_refs.py FILE [FILE ...]
15
+ """
16
+
17
+ import re
18
+ import sys
19
+ from pathlib import Path
20
+
21
+ WAIVER = "internal-ref-ok"
22
+
23
+ PATTERNS = [
24
+ # Research-workspace paths and project homes.
25
+ r"mission-control",
26
+ r"research-brain",
27
+ r"hwosim-(?:paper|build)",
28
+ r"\bbrain/",
29
+ r"deep-thoughts",
30
+ # Underscored ALL-CAPS markdown names are internal working documents.
31
+ r"\b[A-Z0-9]+(?:_[A-Z0-9]+)+\.md\b",
32
+ ]
33
+
34
+ COMPILED = [(pattern, re.compile(pattern)) for pattern in PATTERNS]
35
+
36
+
37
+ def scan_file(path):
38
+ """Return (lineno, pattern, line) hits for one file."""
39
+ hits = []
40
+ try:
41
+ text = path.read_text(encoding="utf-8", errors="ignore")
42
+ except OSError as err:
43
+ print(f"{path}: unreadable ({err})")
44
+ return [(0, "<unreadable>", "")]
45
+ for lineno, line in enumerate(text.splitlines(), start=1):
46
+ if WAIVER in line:
47
+ continue
48
+ for pattern, regex in COMPILED:
49
+ if regex.search(line):
50
+ hits.append((lineno, pattern, line.strip()))
51
+ return hits
52
+
53
+
54
+ def main(argv):
55
+ """Scan every argument path; report hits; exit 1 on any."""
56
+ self_path = Path(__file__).resolve()
57
+ failed = False
58
+ for arg in argv:
59
+ path = Path(arg)
60
+ if path.resolve() == self_path:
61
+ continue
62
+ for lineno, pattern, line in scan_file(path):
63
+ failed = True
64
+ print(f"{path}:{lineno}: matches {pattern!r}: {line}")
65
+ if failed:
66
+ print(
67
+ "\nInternal research references do not belong in library code. "
68
+ f"Rephrase self-contained, or append '{WAIVER}' to a "
69
+ "deliberately functional line."
70
+ )
71
+ return 1
72
+ return 0
73
+
74
+
75
+ if __name__ == "__main__":
76
+ sys.exit(main(sys.argv[1:]))