envlib 0.1.1__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.1
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.1'
7
+ __version__ = '0.1.3'
8
8
 
9
9
  __all__ = ['Catalogue', 'DatasetRef', 'Metadata', 'ValidationError', 'compute_station_id', 'vocabularies']
@@ -27,13 +27,15 @@ 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
  )
33
34
 
34
- # The hardcoded public RCG URL. None until the public commons is hosted —
35
- # overridable (and currently only usable) via the env var below.
36
- PUBLIC_RCG_URL: str | None = None
35
+ # The public envlib commons catalogue (read-only, credential-less HTTPS; a
36
+ # custom domain fronting the hosting bucket, so the URL outlives any bucket
37
+ # move). The env var below overrides it (stand-ins, testing, mirrors).
38
+ PUBLIC_RCG_URL: str | None = 'https://b2.envlib.xyz/file/envlib/envlib-commons/catalogue'
37
39
  PUBLIC_RCG_ENV_VAR = 'ENVLIB_PUBLIC_RCG_URL'
38
40
  DEFAULT_CACHE_DIR = '~/.envlib/cache'
39
41
 
@@ -61,6 +63,34 @@ def _raise_on_push_failure(result, context: str):
61
63
  raise RuntimeError(msg)
62
64
 
63
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
+
64
94
  def _public_rcg_url() -> str | None:
65
95
  return os.environ.get(PUBLIC_RCG_ENV_VAR) or PUBLIC_RCG_URL
66
96
 
@@ -535,7 +565,7 @@ class Catalogue:
535
565
  public = _public_rcg_url()
536
566
  if public is None:
537
567
  msg = (
538
- 'the public envlib RCG is not hosted yet — pass remotes=[...] '
568
+ 'no public envlib RCG is configured — pass remotes=[...] '
539
569
  f'or set the {PUBLIC_RCG_ENV_VAR} environment variable.'
540
570
  )
541
571
  raise ValueError(msg)
@@ -767,12 +797,19 @@ class Catalogue:
767
797
  with cfdb.open_dataset(local_cfdb_path) as ds:
768
798
  return _validate_dataset(ds, validate_cv=True)
769
799
 
770
- def publish(self, local_cfdb_path, remote_conn, rcg_remote_conn, num_groups=None, **open_kwargs) -> dict:
771
- """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.
772
804
 
773
805
  The cfdb data is pushed BEFORE the RCG entry so the catalogue never
774
- references incomplete remote data. Re-running after a partial failure
775
- 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``).
776
813
  """
777
814
  member_conn = _as_connection(remote_conn)
778
815
  edataset_kwargs = dict(open_kwargs)
@@ -791,10 +828,12 @@ class Catalogue:
791
828
  _apply_derived_attrs(eds, result)
792
829
  _raise_on_push_failure(eds.push(), 'publish: pushing the dataset data')
793
830
 
831
+ if verify_objects:
832
+ _verify_remote_objects(member_conn)
794
833
  self._upsert_entry(rcg_remote_conn, member_conn, result)
795
834
  return result
796
835
 
797
- 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:
798
837
  """Register an already-remote cfdb file in the catalogue (no data push).
799
838
 
800
839
  ``remote_conn`` must be writable (credentials): first registration
@@ -809,6 +848,8 @@ class Catalogue:
809
848
  if _apply_derived_attrs(eds, result):
810
849
  _raise_on_push_failure(eds.push(), 'register: pushing the self-identification attrs')
811
850
 
851
+ if verify_objects:
852
+ _verify_remote_objects(member_conn)
812
853
  self._upsert_entry(rcg_remote_conn, member_conn, result)
813
854
  return result
814
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