envlib 0.1.2__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: envlib
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: The environmental library
5
5
  Project-URL: Documentation, https://envlib.github.io/envlib/
6
6
  Project-URL: Source, https://github.com/envlib/envlib
@@ -10,7 +10,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
10
10
  Requires-Python: >=3.10
11
11
  Requires-Dist: booklet>=0.12.6
12
12
  Requires-Dist: cfdb>=0.9.1
13
- Requires-Dist: ebooklet>=0.10.0
13
+ Requires-Dist: ebooklet>=0.10.3
14
14
  Requires-Dist: pyproj
15
15
  Requires-Dist: shapely>=2.0
16
16
  Requires-Dist: urllib3
@@ -4,6 +4,6 @@ from envlib import vocabularies
4
4
  from envlib.catalogue import Catalogue, DatasetRef
5
5
  from envlib.metadata import Metadata, ValidationError, compute_station_id
6
6
 
7
- __version__ = '0.1.2'
7
+ __version__ = '0.1.3'
8
8
 
9
9
  __all__ = ['Catalogue', 'DatasetRef', 'Metadata', 'ValidationError', 'compute_station_id', 'vocabularies']
@@ -27,6 +27,7 @@ from envlib.metadata import (
27
27
  GENERAL_FIELDS,
28
28
  IDENTITY_FIELDS,
29
29
  Metadata,
30
+ PublishIntegrityError,
30
31
  ValidationError,
31
32
  compute_station_id,
32
33
  )
@@ -62,6 +63,34 @@ def _raise_on_push_failure(result, context: str):
62
63
  raise RuntimeError(msg)
63
64
 
64
65
 
66
+ def _verify_remote_objects(member_conn: ebooklet.S3Connection) -> None:
67
+ """Confirm the just-pushed remote's committed index matches the objects
68
+ actually in the store, BEFORE the catalogue entry is written.
69
+
70
+ A push can report success while some objects never durably landed (a
71
+ 2xx-without-persist), leaving the index referencing objects the store does
72
+ not have - a silent over-claim that only surfaces later as a reader's
73
+ RemoteIntegrityError. fsck lists the remote and compares it to the index; any
74
+ mismatch means we must NOT advertise the dataset. Raises PublishIntegrityError
75
+ (a plain re-run does NOT heal it - see the message)."""
76
+ rep = ebooklet.fsck(member_conn, check_objects=True)
77
+ problems = []
78
+ if not rep.db_object_exists:
79
+ problems.append('no db object was committed')
80
+ if rep.claimed_but_missing:
81
+ problems.append(f'{len(rep.claimed_but_missing)} referenced object(s) missing from the store')
82
+ if rep.unmanifested_group_ids:
83
+ problems.append(f'{len(rep.unmanifested_group_ids)} index group(s) absent from the manifest')
84
+ if problems:
85
+ raise PublishIntegrityError(
86
+ f'refusing to register {member_conn.db_key!r}: the pushed remote is inconsistent '
87
+ f'({"; ".join(problems)}). A plain re-run will NOT heal this - the push changelog is a '
88
+ 'timestamp diff (empty once the bad generation is committed) and a fresh rebuild raises '
89
+ 'UUIDMismatchError; recover by retracting the dataset (deregister with delete_data=True) '
90
+ f'and doing a full republish. Missing sample: {list(rep.claimed_but_missing)[:10]}'
91
+ )
92
+
93
+
65
94
  def _public_rcg_url() -> str | None:
66
95
  return os.environ.get(PUBLIC_RCG_ENV_VAR) or PUBLIC_RCG_URL
67
96
 
@@ -768,12 +797,19 @@ class Catalogue:
768
797
  with cfdb.open_dataset(local_cfdb_path) as ds:
769
798
  return _validate_dataset(ds, validate_cv=True)
770
799
 
771
- def publish(self, local_cfdb_path, remote_conn, rcg_remote_conn, num_groups=None, **open_kwargs) -> dict:
772
- """Validate, push the cfdb data to its S3 remote, then register it in the RCG.
800
+ def publish(
801
+ self, local_cfdb_path, remote_conn, rcg_remote_conn, num_groups=None, verify_objects: bool = True, **open_kwargs
802
+ ) -> dict:
803
+ """Validate, push the cfdb data to its S3 remote, verify it, then register it in the RCG.
773
804
 
774
805
  The cfdb data is pushed BEFORE the RCG entry so the catalogue never
775
- references incomplete remote data. Re-running after a partial failure
776
- is safe (the push is idempotent; the entry write is an upsert).
806
+ references incomplete remote data. With ``verify_objects`` (default True),
807
+ after the push and before the entry is written the remote is fsck'd, and a
808
+ silent over-claim (the committed index references objects the store does not
809
+ actually hold) raises ``PublishIntegrityError`` so a broken dataset is never
810
+ advertised. A re-run after a LOUD push failure is safe (idempotent push,
811
+ upsert entry); a re-run after a SILENT over-claim does NOT heal it - recover
812
+ by retract + full republish (see ``_verify_remote_objects``).
777
813
  """
778
814
  member_conn = _as_connection(remote_conn)
779
815
  edataset_kwargs = dict(open_kwargs)
@@ -792,10 +828,12 @@ class Catalogue:
792
828
  _apply_derived_attrs(eds, result)
793
829
  _raise_on_push_failure(eds.push(), 'publish: pushing the dataset data')
794
830
 
831
+ if verify_objects:
832
+ _verify_remote_objects(member_conn)
795
833
  self._upsert_entry(rcg_remote_conn, member_conn, result)
796
834
  return result
797
835
 
798
- def register(self, remote_conn, rcg_remote_conn, **open_kwargs) -> dict:
836
+ def register(self, remote_conn, rcg_remote_conn, verify_objects: bool = True, **open_kwargs) -> dict:
799
837
  """Register an already-remote cfdb file in the catalogue (no data push).
800
838
 
801
839
  ``remote_conn`` must be writable (credentials): first registration
@@ -810,6 +848,8 @@ class Catalogue:
810
848
  if _apply_derived_attrs(eds, result):
811
849
  _raise_on_push_failure(eds.push(), 'register: pushing the self-identification attrs')
812
850
 
851
+ if verify_objects:
852
+ _verify_remote_objects(member_conn)
813
853
  self._upsert_entry(rcg_remote_conn, member_conn, result)
814
854
  return result
815
855
 
@@ -72,6 +72,18 @@ class ValidationError(ValueError):
72
72
  """
73
73
 
74
74
 
75
+ class PublishIntegrityError(ValidationError):
76
+ """Raised when a just-pushed remote is internally inconsistent — its committed
77
+ index references objects that are not actually in the store (a silent
78
+ over-claim). A publish refuses to register such a dataset, so the catalogue
79
+ never advertises broken data.
80
+
81
+ Deliberately NOT an ``ebooklet.RemoteIntegrityError`` (which subclasses
82
+ ``urllib3.exceptions.HTTPError``): a transport-retry wrapper must not mistake
83
+ this permanent integrity fault for a transient network error and retry it.
84
+ """
85
+
86
+
75
87
  ###################################################
76
88
  # Field validators (pure functions; return the normalized value or raise)
77
89
 
@@ -12,7 +12,7 @@ classifiers = [
12
12
  requires-python = ">=3.10"
13
13
  dependencies = [
14
14
  "cfdb>=0.9.1",
15
- "ebooklet>=0.10.0",
15
+ "ebooklet>=0.10.3",
16
16
  "booklet>=0.12.6",
17
17
  "pyproj",
18
18
  "shapely>=2.0",
File without changes
File without changes
File without changes