codeimprint 0.5.0a23__tar.gz → 0.5.0a24__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.
Files changed (26) hide show
  1. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/CHANGELOG.md +19 -0
  2. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/PKG-INFO +1 -1
  3. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/pyproject.toml +1 -1
  4. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/__init__.py +1 -1
  5. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/chainseal.py +36 -4
  6. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/cli.py +10 -0
  7. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/.gitignore +0 -0
  8. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/LICENSE +0 -0
  9. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/NOTICE +0 -0
  10. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/README.pypi.md +0 -0
  11. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint/__init__.py +0 -0
  12. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint/__main__.py +0 -0
  13. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/__main__.py +0 -0
  14. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/api.py +0 -0
  15. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/config.py +0 -0
  16. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/gitrepo.py +0 -0
  17. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/imprint_file.py +0 -0
  18. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/linecount.py +0 -0
  19. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/ownership.py +0 -0
  20. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/project.py +0 -0
  21. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/receipt.py +0 -0
  22. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/records.py +0 -0
  23. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/timestamp.py +0 -0
  24. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/transparency.py +0 -0
  25. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/trust.py +0 -0
  26. {codeimprint-0.5.0a23 → codeimprint-0.5.0a24}/src/codeimprint_cli/tsa_roots.py +0 -0
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0a24 — Empty seals are refused; a tip to name a project [CIM-BE-37-v1]
4
+
5
+ For engine 0.7.0a28. Older engines still work.
6
+
7
+ - **Changed: `imprint seal` refuses a seal that would cover no file.** "Nothing to seal: no
8
+ files matched. Check .gitignore, the exclude list in .imprint/config.json, and that you
9
+ are in the project folder." The exit code is 2; nothing is sent beyond the plan and
10
+ nothing is logged. With engine 0.7.0a28 the server refuses it (`422 nothing_to_seal`); for
11
+ an older server the client stops when the plan counts no file. When files matched but
12
+ hold nothing to seal, the server's own sentence is shown ("Nothing to seal: the files that
13
+ matched contain no code to seal."). When the repository has
14
+ files but none is a Python file, the message adds that CodeImprint seals Python source
15
+ files at present. **In an automated build** (GitHub Actions, GitLab CI, Bitbucket
16
+ Pipelines) it is a warning and the build goes on, as with every seal that cannot be made.
17
+ The Git hook skips such a commit instead of queueing it.
18
+ - **New: a tip after sealing** when the project has no name: "Tip: name this project in the
19
+ hub (or run `imprint project rename <name>`)". Shown only when the server says so.
20
+ - No engine or algorithm code. Tests: `tests/test_empty_seal.py`.
21
+
3
22
  ## 0.5.0a23 — `imprint verify` says VERIFIED [CIM-BE-36-v2]
4
23
 
5
24
  - **Changed: the result line of `imprint verify`** reads `Result VERIFIED`, `Result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeimprint
3
- Version: 0.5.0a23
3
+ Version: 0.5.0a24
4
4
  Summary: CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline.
5
5
  Project-URL: Homepage, https://codeimprint.ai
6
6
  Project-URL: Hub, https://app.codeimprint.ai
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
  # Published on PyPI as `codeimprint`. The import package stays `codeimprint_cli` and the
7
7
  # command `imprint`.
8
8
  name = "codeimprint"
9
- version = "0.5.0a23"
9
+ version = "0.5.0a24"
10
10
  description = "CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline."
11
11
  readme = "README.pypi.md"
12
12
  license = "Apache-2.0"
@@ -5,4 +5,4 @@ A thin client for a CodeImprint server: it zips a project, asks the server to se
5
5
  it, and verifies Imprint files offline. All analysis happens on the server.
6
6
  """
7
7
 
8
- __version__ = "0.5.0a23"
8
+ __version__ = "0.5.0a24"
@@ -19,6 +19,7 @@ import time
19
19
  from pathlib import Path
20
20
 
21
21
  from . import gitrepo, linecount, trust
22
+ from .api import ApiError
22
23
  from .imprint_file import canonical
23
24
 
24
25
  PAGE = 5000 # files per plan request
@@ -148,7 +149,12 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
148
149
  pass # the seal does not depend on them
149
150
  if kind == "release" and tag:
150
151
  body.update(tag=tag, public_tag=public_tag)
151
- resp = client.plan(project, body)
152
+ try:
153
+ resp = client.plan(project, body)
154
+ except ApiError as exc:
155
+ if exc.code == "nothing_to_seal":
156
+ raise NothingToSeal(len(files), _python(files), str(exc)) from exc
157
+ raise
152
158
  if "release" in resp:
153
159
  rel = resp["release"]
154
160
  result = client.finalise(project, rel["pending_id"], public_key(key),
@@ -161,6 +167,8 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
161
167
  return {"already": seal, "released": resp.get("already_released"),
162
168
  "commit": commit, "info": info}
163
169
  plan_id = resp.get("plan_id", plan_id)
170
+ if resp.get("files") == 0: # an engine before 0.7.0a28 would seal nothing
171
+ raise NothingToSeal(len(files), _python(files))
164
172
  need = resp["need"]
165
173
  sizes = {f["blob"]: f["size"] for f in files}
166
174
  size = sum(sizes.get(b, 0) for b in need)
@@ -175,9 +183,14 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
175
183
  batch_size += len(data)
176
184
  if batch:
177
185
  client.upload_blobs(project, batch)
178
- prep = client.prepare(project, plan_id)
179
- if "job_id" in prep:
180
- prep = _wait(client, prep["job_id"])
186
+ try:
187
+ prep = client.prepare(project, plan_id)
188
+ if "job_id" in prep:
189
+ prep = _wait(client, prep["job_id"])
190
+ except ApiError as exc:
191
+ if exc.code == "nothing_to_seal":
192
+ raise NothingToSeal(said=str(exc)) from exc
193
+ raise
181
194
  result = client.finalise(project, prep["pending_id"], public_key(key),
182
195
  sign(key, prep["statement"]))
183
196
  check_lines(lines, result)
@@ -185,6 +198,21 @@ def seal_commit(client, root: Path, project: str, commit: str, kind: str, key,
185
198
  "files": resp.get("files", 0), "commit": commit, "info": info, "lines": lines}
186
199
 
187
200
 
201
+ NOTHING_TO_SEAL = ("Nothing to seal: no files matched. Check .gitignore, the exclude list in "
202
+ ".imprint/config.json, and that you are in the project folder.")
203
+ PYTHON_ONLY = " CodeImprint seals Python source files (.py) at present."
204
+
205
+
206
+ class NothingToSeal(RuntimeError):
207
+ """A seal that would cover no file is never made (engine 0.7.0a28 answers 422
208
+ nothing_to_seal; for an older engine the client stops here, before anything is sent).
209
+ ``tracked`` is the number of files Git tracks at the commit, of any kind."""
210
+
211
+ def __init__(self, tracked: int = 0, python: int = 0, said: str | None = None) -> None:
212
+ super().__init__((said or NOTHING_TO_SEAL)
213
+ + (PYTHON_ONLY if tracked and not python else ""))
214
+
215
+
188
216
  def check_lines(sent: dict, result: dict) -> None:
189
217
  """The Imprint you signed carries the count this client sent (older servers keep none)."""
190
218
  kept = (result.get("imprint") or {}).get("lines")
@@ -193,6 +221,10 @@ def check_lines(sent: dict, result: dict) -> None:
193
221
  "counted; the seal is logged, but report this")
194
222
 
195
223
 
224
+ def _python(files: list[dict]) -> int:
225
+ return sum(1 for f in files if f["path"].endswith(".py"))
226
+
227
+
196
228
  # -- local state ---------------------------------------------------------------------------
197
229
  def _state(root: Path) -> Path:
198
230
  path = gitrepo.git_dir(root) / "codeimprint"
@@ -458,6 +458,8 @@ def _other_repository(client: Client, cfg: dict, root: Path) -> None:
458
458
  def _prepare_upload(path: str, action: str, client: Client, assume_yes: bool) -> bytes:
459
459
  sel = project.select_files(path)
460
460
  if sel.count == 0:
461
+ if action == "seal": # a seal of nothing is never made
462
+ raise SealFailed(chainseal.NOTHING_TO_SEAL + chainseal.PYTHON_ONLY)
461
463
  raise Abort(f"no Python files to send under {sel.root} (check .gitignore and "
462
464
  ".imprint/config.json excludes)")
463
465
  data = project.build_zip(sel)
@@ -994,6 +996,9 @@ def _hook_run(args, root: Path) -> int:
994
996
  try:
995
997
  out = chainseal.seal_commit(client, root, cfg["project_id"], item["commit"],
996
998
  item["kind"], key, cfg.get("exclude"))
999
+ except chainseal.NothingToSeal as exc: # not queued: it would never seal
1000
+ warn(f"seal of {item['commit'][:12]} skipped: {exc}")
1001
+ continue
997
1002
  except Exception as exc: # noqa: BLE001 — a hook never blocks a commit or push
998
1003
  chainseal.save_queue(root, queue[i:])
999
1004
  return warn(f"seal of {item['commit'][:12]} queued ({len(queue) - i} waiting): "
@@ -1831,6 +1836,9 @@ def _finish(args, client: Client, root: Path, result: dict, keys: list,
1831
1836
  _verify_line(iid, hub, out))
1832
1837
  if hub:
1833
1838
  _say("", "README badge:", imprint_file.badge(iid, hub, client.url))
1839
+ if result.get("project_named") is False: # engine 0.7.0a28: the project has no name
1840
+ _say("", "Tip: name this project in the hub (or run `imprint project rename <name>`): "
1841
+ "the name appears on its seal page, badge and certificate.")
1834
1842
  _say("", SEAL_NOTE)
1835
1843
  _step_summary(iid, rec, stamps, signer, hub)
1836
1844
  return 0
@@ -1858,6 +1866,8 @@ def _seal_zip(args, client: Client, data: bytes, project_id: str | None,
1858
1866
  if lines is not None:
1859
1867
  chainseal.check_lines(lines, result)
1860
1868
  except (ApiError, NetworkError) as exc:
1869
+ if isinstance(exc, ApiError) and exc.code == "nothing_to_seal":
1870
+ raise SealFailed(str(exc) or chainseal.NOTHING_TO_SEAL) from exc
1861
1871
  raise SealFailed(_explain(client, exc, "sealing failed")) from exc
1862
1872
  except RuntimeError as exc:
1863
1873
  raise SealFailed(str(exc)) from exc
File without changes
File without changes