Skip to content

refactor: name each module for its mechanism, not for the scheme - #132

Merged
skishchampi merged 2 commits into
masterfrom
refactor/name-modules-for-mechanics
Aug 17, 2026
Merged

refactor: name each module for its mechanism, not for the scheme#132
skishchampi merged 2 commits into
masterfrom
refactor/name-modules-for-mechanics

Conversation

@skishchampi

Copy link
Copy Markdown
Contributor

A module name must tell a developer what to implement. It must not name the
policy, the scheme, the department or the state. That context belongs in the
docstring, beside the host and the vintage.

The audit

47 modules were read. Three classes came out of it.

Already correct (21). http_client, url_safety, browser, wayback,
textparse, base, corpus, records, validate, runlog, resolver,
entities, evidence, stats, topics, dspace, nada. The convention
existed. It was applied inconsistently.

Renamed (21). Listed below.

Duplication the naming hid. indiacode and dspace both define
parse_browse_page, and indiacode's own docstring says it is a legacy DSpace
install. doe and niti are one mechanism, and niti's docstring says so.
Consolidating them changes behaviour, so it is not in this PR. The names now
make the duplication visible.

The renames

old new
sansad parliament_qa_api
questions_list question_list_api
committees committee_report_api
debates verbatim_pdf_api
attendance attendance_json_api
bills bill_catalog_api
prs drupal_publication_index
cag audit_pdf_index
ddg ministry_pdf_index
doe pay_report_index
niti annual_report_index
census ogd_resource_api
dchb_town ogd_town_release
mospi rest_dataset_api
indiacode statute_dspace
abhilekh_patal catalogue_search_api
myneta affidavit_pages
courts case_law_api
neva assembly_portal
neva_portals assembly_portal_registry
neva_text two_column_pdf_qa

Nothing breaks

Every old path stays as a shim. The shim binds the SAME module object, so both
of these still reach the code that runs:

from commoner_probe.sansad import SansadProbe
monkeypatch.setattr("commoner_probe.sansad.extract_pdf_text", fake)

Re-exporting a copy would hand a patcher one object and the running code
another. tests/test_module_aliases.py asserts the identity, the deprecation
warning, and the exact module paths five sibling repos import today.

Verified from a built wheel in a clean venv, not only from the source tree.
All eleven consumer import paths resolve, and the CLI runs.

The CLI is untouched. Subcommand names are the operator's interface and
name the source an operator asks for. Renaming them buys a developer nothing.

The boundary that makes this safe

Data identifiers do not move. Manifest kinds, schema filenames, record fields,
corpus filenames and the extractor provenance string are written into corpora
already on disk.

The first pass rewrote two of them: the corpus filename questions_list.jsonl
and the extractor value recorded in every question row. The tests caught
both. Both are restored, with a comment saying why they keep their original
spelling.

Verification

1,305 passed, ruff clean. test_pyproject_version_matches_package_version
fails here and on untouched master, because the venv is an editable install
of a different worktree.

Not in this PR

The two consolidations, and the two open PRs (#130, #131) which will need a
rebase onto these names.

A module name must tell a developer what to implement. It must not name the
policy, the scheme, the department or the state. That context belongs in the
docstring beside the host and the vintage.

21 modules move. Each new name states the transport and the artefact:

  sansad          -> parliament_qa_api
  questions_list  -> question_list_api
  committees      -> committee_report_api
  debates         -> verbatim_pdf_api
  attendance      -> attendance_json_api
  bills           -> bill_catalog_api
  prs             -> drupal_publication_index
  cag             -> audit_pdf_index
  ddg             -> ministry_pdf_index
  doe             -> pay_report_index
  niti            -> annual_report_index
  census          -> ogd_resource_api
  dchb_town       -> ogd_town_release
  mospi           -> rest_dataset_api
  indiacode       -> statute_dspace
  abhilekh_patal  -> catalogue_search_api
  myneta          -> affidavit_pages
  courts          -> case_law_api
  neva            -> assembly_portal
  neva_portals    -> assembly_portal_registry
  neva_text       -> two_column_pdf_qa

Nothing breaks. Every old path stays as a shim that binds the SAME module
object, so `from commoner_probe.sansad import SansadProbe` and
`monkeypatch.setattr("commoner_probe.sansad.f", ...)` both still reach the code
that runs. Re-exporting a copy would hand a patcher one object and the running
code another. tests/test_module_aliases.py asserts the identity, the warning,
and the exact module paths five sibling repos import today. Verified from a
built wheel in a clean venv, not only from the source tree.

The CLI is untouched. Subcommand names are the operator's interface and name
the source the operator wants; renaming them buys a developer nothing.

Data identifiers are untouched, and that boundary is what makes this safe.
Manifest kinds, schema filenames, record fields, corpus filenames and the
`extractor` provenance string are written into corpora already on disk. The
first pass rewrote two of them; the tests caught it, and both are restored with
a comment saying why they keep their original spelling.
… it is

The module name states the mechanism. The docstring must state the rest, or
the context is lost rather than moved.

Every renamed module now opens with one line of mechanism and a CONTEXT block.
The block names the operator, the host, the scheme and the access constraint.

  ogd_resource_api    ORGI produces the data. NIC operates the API. The API
                      needs a key, and the published sample key returns one
                      demo row.
  drupal_publication_index  PRS is a private body. The pages carry an All
                      Rights Reserved footer and no usable terms.
  case_law_api        Indian Kanoon is a private service. The reference client
                      is MIT, so this repo reimplements its wire contract.
  assembly_portal     NeVA is a Ministry programme. Each State runs its own
                      deployment at <state>.neva.gov.in.

parliament_qa_api had no module docstring at all. It has one now.

The blocks follow ASD-STE100: one idea per sentence, active voice, simple
tenses, and the same word for the same thing.
@skishchampi
skishchampi merged commit 9f7c109 into master Aug 17, 2026
9 checks passed
@skishchampi
skishchampi deleted the refactor/name-modules-for-mechanics branch August 17, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant