esgpull 0.9.1__py3-none-any.whl → 0.9.2__py3-none-any.whl

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.
esgpull/cli/plugins.py CHANGED
@@ -337,7 +337,7 @@ from datetime import datetime
337
337
  from pathlib import Path
338
338
  from logging import Logger
339
339
 
340
- from esgpull.models import File, Query
340
+ from esgpull.models import Dataset, File, Query
341
341
  from esgpull.plugin import Event, on
342
342
 
343
343
  # Specify version compatibility (optional)
esgpull/cli/search.py CHANGED
@@ -7,6 +7,7 @@ from click.exceptions import Abort, Exit
7
7
 
8
8
  from esgpull.cli.decorators import args, groups, opts
9
9
  from esgpull.cli.utils import filter_keys, init_esgpull, parse_query, totable
10
+ from esgpull.context import IndexNode
10
11
  from esgpull.exceptions import PageIndexError
11
12
  from esgpull.graph import Graph
12
13
  from esgpull.models import Query
@@ -135,14 +136,26 @@ def search(
135
136
  esg.ui.raise_maybe_record(Exit(0))
136
137
  if facets_hints:
137
138
  not_distrib_query = query << Query(options=dict(distrib=False))
138
- facet_counts = esg.context.hints(
139
- not_distrib_query,
140
- file=file,
141
- facets=["*"],
142
- date_from=date_from,
143
- date_to=date_to,
144
- )
145
- esg.ui.print(list(facet_counts[0]), json=True)
139
+ index = IndexNode(esg.config.api.index_node)
140
+ if index.is_bridge():
141
+ first_file_result = esg.context.search_as_queries(
142
+ not_distrib_query,
143
+ file=True,
144
+ max_hits=1,
145
+ date_from=date_from,
146
+ date_to=date_to,
147
+ )
148
+ first_file = first_file_result[0].selection.asdict()
149
+ esg.ui.print(list(first_file), json=True)
150
+ else:
151
+ facet_counts = esg.context.hints(
152
+ not_distrib_query,
153
+ file=file,
154
+ facets=["*"],
155
+ date_from=date_from,
156
+ date_to=date_to,
157
+ )
158
+ esg.ui.print(list(facet_counts[0]), json=True)
146
159
  esg.ui.raise_maybe_record(Exit(0))
147
160
  if hints is not None:
148
161
  facet_counts = esg.context.hints(
esgpull/context.py CHANGED
@@ -7,6 +7,7 @@ from collections.abc import AsyncIterator, Callable, Coroutine, Sequence
7
7
  from dataclasses import dataclass, field
8
8
  from datetime import datetime
9
9
  from typing import Any, TypeAlias, TypeVar
10
+ from urllib.parse import urlparse
10
11
 
11
12
  if sys.version_info < (3, 11):
12
13
  from exceptiongroup import BaseExceptionGroup
@@ -18,7 +19,7 @@ from esgpull.config import Config
18
19
  from esgpull.exceptions import SolrUnstableQueryError
19
20
  from esgpull.models import DatasetRecord, File, Query
20
21
  from esgpull.tui import logger
21
- from esgpull.utils import format_date_iso, index2url, sync
22
+ from esgpull.utils import format_date_iso, sync
22
23
 
23
24
  # workaround for notebooks with running event loop
24
25
  if asyncio.get_event_loop().is_running():
@@ -39,6 +40,29 @@ DangerousFacets = {
39
40
  }
40
41
 
41
42
 
43
+ @dataclass
44
+ class IndexNode:
45
+ value: str
46
+
47
+ def is_bridge(self) -> bool:
48
+ return "esgf-1-5-bridge" in self.value
49
+
50
+ @property
51
+ def url(self) -> str:
52
+ parsed = urlparse(self.value)
53
+ result: str
54
+ match (parsed.scheme, parsed.netloc, parsed.path, self.is_bridge()):
55
+ case ("", "", path, True):
56
+ result = "https://" + parsed.path
57
+ case ("", "", path, False):
58
+ result = "https://" + parsed.path + "/esg-search/search"
59
+ case _:
60
+ result = self.value
61
+ if "." not in result:
62
+ raise ValueError(self.value)
63
+ return result
64
+
65
+
42
66
  @dataclass
43
67
  class Result:
44
68
  query: Query
@@ -70,12 +94,12 @@ class Result:
70
94
  "format": "application/solr+json",
71
95
  # "from": self.since,
72
96
  }
73
- if index_url is None:
74
- index_url = index2url(index_node)
75
- if fields_param is not None:
76
- params["fields"] = ",".join(fields_param)
77
- else:
78
- params["fields"] = "instance_id"
97
+ index = IndexNode(value=index_url or index_node)
98
+ if not index.is_bridge():
99
+ if fields_param is not None:
100
+ params["fields"] = ",".join(fields_param)
101
+ else:
102
+ params["fields"] = "instance_id"
79
103
  if date_from is not None:
80
104
  params["from"] = format_date_iso(date_from)
81
105
  if date_to is not None:
@@ -101,15 +125,20 @@ class Result:
101
125
  else:
102
126
  if len(values) > 1:
103
127
  value_term = f"({value_term})"
104
- solr_terms.append(f"{name}:{value_term}")
128
+ if name.startswith("!"):
129
+ solr_terms.append(f"(NOT {name[1:]}:{value_term})")
130
+ else:
131
+ solr_terms.append(f"{name}:{value_term}")
105
132
  if solr_terms:
106
133
  params["query"] = " AND ".join(solr_terms)
107
134
  for name, option in self.query.options.items(use_default=True):
108
135
  if option.is_bool():
109
136
  params[name] = option.name
137
+ if index.is_bridge():
138
+ _ = params.pop("retracted", None) # not supported in bridge API
110
139
  if params.get("distrib") == "true" and facets_star:
111
140
  raise SolrUnstableQueryError(pretty_repr(self.query))
112
- self.request = Request("GET", index_url, params=params)
141
+ self.request = Request("GET", index.url, params=params)
113
142
 
114
143
  def to(self, subtype: type[RT]) -> RT:
115
144
  result: RT = subtype(self.query, self.file)
@@ -0,0 +1,28 @@
1
+ """update tables
2
+
3
+ Revision ID: 0.9.2
4
+ Revises: 0.9.1
5
+ Create Date: 2025-09-04 16:56:29.263007
6
+
7
+ """
8
+ from alembic import op
9
+ import sqlalchemy as sa
10
+
11
+
12
+ # revision identifiers, used by Alembic.
13
+ revision = '0.9.2'
14
+ down_revision = '0.9.1'
15
+ branch_labels = None
16
+ depends_on = None
17
+
18
+
19
+ def upgrade() -> None:
20
+ # ### commands auto generated by Alembic - please adjust! ###
21
+ pass
22
+ # ### end Alembic commands ###
23
+
24
+
25
+ def downgrade() -> None:
26
+ # ### commands auto generated by Alembic - please adjust! ###
27
+ pass
28
+ # ### end Alembic commands ###
esgpull/plugin.py CHANGED
@@ -151,7 +151,11 @@ class PluginConfig:
151
151
  enabled: set[str] = field(default_factory=set)
152
152
  disabled: set[str] = field(default_factory=set)
153
153
  plugins: dict[str, dict[str, Any]] = field(default_factory=dict)
154
- _raw: dict[str, dict[str, Any]] = field(default_factory=dict)
154
+ _raw: tomlkit.TOMLDocument = field(default_factory=tomlkit.TOMLDocument)
155
+
156
+ def __post_init__(self):
157
+ if "plugins" not in self._raw:
158
+ self._raw["plugins"] = {}
155
159
 
156
160
 
157
161
  class PluginManager:
@@ -199,12 +203,13 @@ class PluginManager:
199
203
 
200
204
  try:
201
205
  with open(self.config_path, "r") as f:
202
- raw = tomlkit.parse(f.read())
203
- self.config.enabled = set(raw.get("enabled", []))
204
- self.config.disabled = set(raw.get("disabled", []))
205
- self.config.plugins = raw.get("plugins", {})
206
- # Store the raw plugin configuration to preserve what's on disk
207
- self.config._raw = dict(raw.get("plugins", {}))
206
+ raw = tomlkit.load(f)
207
+ unwrap = raw.unwrap()
208
+ self.config.enabled = set(unwrap.get("enabled", []))
209
+ self.config.disabled = set(unwrap.get("disabled", []))
210
+ self.config.plugins = unwrap.get("plugins", {})
211
+ # Store the raw plugin configuration to preserve what's on disk
212
+ self.config._raw = raw
208
213
  except Exception as e:
209
214
  logger.error(f"Failed to load plugin config: {e}")
210
215
 
@@ -219,18 +224,16 @@ class PluginManager:
219
224
  return
220
225
 
221
226
  try:
222
- doc = tomlkit.document()
227
+ doc = self.config._raw
223
228
  doc["enabled"] = list(self.config.enabled)
224
229
  doc["disabled"] = list(self.config.disabled)
225
230
 
226
231
  # For plugins section, handle differently based on generate_full_config flag
227
232
  if generate_full_config:
228
233
  doc["plugins"] = self.config.plugins
229
- else:
230
- doc["plugins"] = self.config._raw
231
234
 
232
235
  with open(self.config_path, "w") as f:
233
- f.write(tomlkit.dumps(doc))
236
+ tomlkit.dump(doc, f)
234
237
  except Exception as e:
235
238
  logger.error(f"Failed to save plugin config: {e}")
236
239
 
@@ -464,8 +467,8 @@ class PluginManager:
464
467
  # Make sure plugin exists in both plugins and _raw dicts
465
468
  if plugin_name not in self.config.plugins:
466
469
  self.config.plugins[plugin_name] = {}
467
- if plugin_name not in self.config._raw:
468
- self.config._raw[plugin_name] = {}
470
+ if plugin_name not in self.config._raw["plugins"]:
471
+ self.config._raw["plugins"][plugin_name] = {}
469
472
 
470
473
  # Update the value in both places
471
474
  if key in self.config.plugins[plugin_name]:
@@ -473,7 +476,7 @@ class PluginManager:
473
476
  new_value = cast_value(old_value, value, key)
474
477
  self.config.plugins[plugin_name][key] = new_value
475
478
  # Also update in _raw to keep in sync
476
- self.config._raw[plugin_name][key] = new_value
479
+ self.config._raw["plugins"][plugin_name][key] = new_value
477
480
  else:
478
481
  raise KeyError(key, self.config.plugins[plugin_name])
479
482
 
@@ -497,8 +500,8 @@ class PluginManager:
497
500
  # Make sure the plugin exists in both configs
498
501
  if plugin_name not in self.config.plugins:
499
502
  self.config.plugins[plugin_name] = {}
500
- if plugin_name not in self.config._raw:
501
- self.config._raw[plugin_name] = {}
503
+ if plugin_name not in self.config._raw["plugins"]:
504
+ self.config._raw["plugins"][plugin_name] = {}
502
505
 
503
506
  # Remove the key from both configs
504
507
  if key in self.config.plugins[plugin_name]:
@@ -508,10 +511,10 @@ class PluginManager:
508
511
 
509
512
  # Also remove from _raw if it exists
510
513
  if (
511
- plugin_name in self.config._raw
512
- and key in self.config._raw[plugin_name]
514
+ plugin_name in self.config._raw["plugins"]
515
+ and key in self.config._raw["plugins"][plugin_name]
513
516
  ):
514
- self.config._raw[plugin_name].pop(key)
517
+ self.config._raw["plugins"][plugin_name].pop(key)
515
518
 
516
519
  self.write_config()
517
520
 
esgpull/utils.py CHANGED
@@ -1,7 +1,6 @@
1
1
  import asyncio
2
2
  import datetime
3
3
  from typing import Callable, Coroutine, TypeVar
4
- from urllib.parse import urlparse
5
4
 
6
5
  from rich.filesize import _to_str
7
6
 
@@ -52,19 +51,3 @@ def format_date_iso(
52
51
  date: str | datetime.datetime, fmt: str = "%Y-%m-%d"
53
52
  ) -> str:
54
53
  return parse_date(date, fmt).replace(microsecond=0).isoformat() + "Z"
55
-
56
-
57
- def url2index(url: str) -> str:
58
- parsed = urlparse(url)
59
- if parsed.netloc == "":
60
- return parsed.path
61
- else:
62
- return parsed.netloc
63
-
64
-
65
- def index2url(index: str) -> str:
66
- url = "https://" + url2index(index)
67
- if "esgf-1-5-bridge" in index:
68
- return url
69
- else:
70
- return url + "/esg-search/search"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: esgpull
3
- Version: 0.9.1
3
+ Version: 0.9.2
4
4
  Summary: ESGF data discovery, download, replication tool
5
5
  Project-URL: Repository, https://github.com/ESGF/esgf-download
6
6
  Project-URL: Documentation, https://esgf.github.io/esgf-download/
@@ -2,7 +2,7 @@ esgpull/__init__.py,sha256=XItFDIMNmFUNNcKtUgXdfmGwUIWt4AAv0a4mZkfj5P8,240
2
2
  esgpull/auth.py,sha256=QZ-l1ySLMP0fvuwYHRLv9FZYp1gqfju_eGaTMDByUxw,5205
3
3
  esgpull/config.py,sha256=9atYqxc3PiJKY1hfoEWZxf5Ba6U9SzMUs4QvcWWGFy0,13423
4
4
  esgpull/constants.py,sha256=WjG7xzMZNckOv5GhRehBtI7hoSwwLZvwkvEq5RG-dv4,1189
5
- esgpull/context.py,sha256=_XBAA9XM-fcJXLsqFlg1ziwQdndDoFxketdcFhi4oSM,23430
5
+ esgpull/context.py,sha256=iyHAJ9OXU5_0SYcXNlmJI_M6x3vphJjnnAcsfB4MxQ8,24383
6
6
  esgpull/database.py,sha256=1wGeNbJp0gOLo5Q1N53JfiwVbZ8nfvZVkKlvEaJwOpU,6716
7
7
  esgpull/download.py,sha256=aR2c_SOuZtgX7tI2a9_N4Mn86ABq1k7Mxq_BdojFrP4,5600
8
8
  esgpull/esgpull.py,sha256=-OwaWvwmkur_mdVNKKxdxlASeK93tmOceV__jGRMwqo,19666
@@ -10,12 +10,12 @@ esgpull/exceptions.py,sha256=wgLyhyIITdusNucPjnnURJX1Jxv1VVIr9PzJV_77qhg,3275
10
10
  esgpull/fs.py,sha256=sc7Af2E3yh3V9KVuSPSXFBuFtlQ3L99UZmS1ZJuiBeM,7280
11
11
  esgpull/graph.py,sha256=Yl2VuF8PNn0R5xRyEK58Q1Xlx8B1PfhbTwt1JftFDro,15929
12
12
  esgpull/install_config.py,sha256=hzYpcHMtPMOK9fYcvVH-Hn_8zYsbs3yXlYgMumXo1zE,5598
13
- esgpull/plugin.py,sha256=wW19V55E1Fn2_ooZ5aTc58uJVSQ0WT43P29G3TlMD6A,18748
13
+ esgpull/plugin.py,sha256=do6b4duPyAhNnYXWmFiVAlgNKj2FJcEjAMPqT8JqxtA,18871
14
14
  esgpull/processor.py,sha256=WLf4NFO_dp27E0GhZAiekiRD-gT6uyFJJnFZKbFV5vU,5484
15
15
  esgpull/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  esgpull/result.py,sha256=f64l9gPFpFWgctmHVYrNWJvuXXB1sxpxXzJEIssLXxc,1020
17
17
  esgpull/tui.py,sha256=jpfDK_g_taNPEu0FeJ4MM1vtNJfOJY5x3dkUxRkoPEA,11210
18
- esgpull/utils.py,sha256=Rw_pU_rDvD6b2_h4Hzi8b5Hmb0ufuhrdL0Xwr8kLFcg,1584
18
+ esgpull/utils.py,sha256=pLMQfY0p2oNIFyCZhHBD74BOAJtmt9QV6dTJ79VsfF8,1213
19
19
  esgpull/version.py,sha256=IHT4mKrIr8eV-C3HtmIVD85iGVH25n2ohoff31kaJ1A,93
20
20
  esgpull/cli/__init__.py,sha256=Q-U7opBTHxF5yUyyv15Cj-4Y9MaDMJ4i5FxNL-EmHfs,1683
21
21
  esgpull/cli/add.py,sha256=h8xFy5ORzY9O4SPPo4VCtTybeJJ5GcA18w4TZeL0DqU,3507
@@ -28,10 +28,10 @@ esgpull/cli/facet.py,sha256=V1u-DxNkhswwSt0qpXvuHrCI_tE8jAJGEe6_fMhYbaM,584
28
28
  esgpull/cli/get.py,sha256=2WXL01Ri0P_2Rf1xrp9bnsrrxir6whxkAC0SnohjFpg,678
29
29
  esgpull/cli/install.py,sha256=fd8nKwIFvOivgn_gOGn7XIk1BB9LXnhQB47KuIIy5AU,2880
30
30
  esgpull/cli/login.py,sha256=FZ63SsB4fCDixwf7gMUR697Dk89W1OvpgeadKE4IqEU,2153
31
- esgpull/cli/plugins.py,sha256=eTAwWqvrzDKs122_Wa3sOkuriSoInymxWySQQahrlHg,13357
31
+ esgpull/cli/plugins.py,sha256=lM8eQIH4H_bIy49rC2flmTstpr9ILDBYXp1YYYMv7qw,13366
32
32
  esgpull/cli/remove.py,sha256=9fqE8NJdr1mHypu_N-TBJy_yl3elUBSfzEARxxTkqKg,2662
33
33
  esgpull/cli/retry.py,sha256=UVpAjW_N7l6RTJ-T5qXojwcXPzzjT7sDKb_wBdvavrg,1310
34
- esgpull/cli/search.py,sha256=c2OI0Xvw6h2zBnC8msjxidKJZ0KKUuWJK9FuAmQ15ZU,6369
34
+ esgpull/cli/search.py,sha256=J41dRi0mS-XsJyWsDzXsv04yWHPwhVG2VOEcdPnaak8,6940
35
35
  esgpull/cli/self.py,sha256=psgFcgkDyemquZEpoWp2cyjgampCgDzRc1QBvzqGs24,7941
36
36
  esgpull/cli/show.py,sha256=B-h7bKMrwgjnTHio2du8IPOLlKCaan56RQKAtzlQzcw,2822
37
37
  esgpull/cli/status.py,sha256=HEyj6QFABblADtYf1PWmSzghKX3fs33x9p5vpSqA514,2521
@@ -70,6 +70,7 @@ esgpull/migrations/versions/0.7.3_update_tables.py,sha256=4pNkM7VaGQqkLuIoLKuM0f
70
70
  esgpull/migrations/versions/0.8.0_update_tables.py,sha256=5rr3guWipnnuciFuviUxZUasdPw6x06WZCmY5nNCn5k,555
71
71
  esgpull/migrations/versions/0.9.0_update_tables.py,sha256=nXfPiyuseD5BXvu59zkeSTzb6EA7txpBudclU-MIyU0,555
72
72
  esgpull/migrations/versions/0.9.1_update_tables.py,sha256=ITewU2qgdCwhorsl2d_t7ENt_6KecG3z5xfRr_LwrtY,541
73
+ esgpull/migrations/versions/0.9.2_update_tables.py,sha256=aux--HPA_jUtvk7Zb2ZRXRhnRLT-whqZ0lLWt8Apyac,541
73
74
  esgpull/migrations/versions/14c72daea083_query_add_column_updated_at.py,sha256=MKqz0tfwGwRkgP4QDd-cpUmXCVr4tM_wlC2BfxqJ1_w,1031
74
75
  esgpull/migrations/versions/c7c8541fa741_query_add_column_added_at.py,sha256=Al_o7fDmoRqc9vBCQgtgrNbSPIOBxdMZ5T-ztakqVeY,1033
75
76
  esgpull/migrations/versions/d14f179e553c_file_add_composite_index_dataset_id_.py,sha256=0vJvttugWmgKns4g-K4i3EU6eid2Z_K2e3H6Ktevf7c,860
@@ -86,8 +87,8 @@ esgpull/models/sql.py,sha256=K8Nre5HKFPjkRzUUW6p6Qk7aG8upbw8C3pnmCFlg7d8,8942
86
87
  esgpull/models/synda_file.py,sha256=6o5unPhzVJGnbpA2MxcS0r-hrBwocHYVnLrqjSGtmuk,2387
87
88
  esgpull/models/tag.py,sha256=5CQDB9rAeCqog63ec9LPFN46HOFNkHPy-maY4gkBQ3E,461
88
89
  esgpull/models/utils.py,sha256=exwlIlIKYjhhfUE82w1kU_HeSQOSY97PTvpkhW0udMA,1631
89
- esgpull-0.9.1.dist-info/METADATA,sha256=Iy0nz7xstS0pywi5LNuLt-giW-5ng-X_lYb7WTrv8eE,3781
90
- esgpull-0.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
91
- esgpull-0.9.1.dist-info/entry_points.txt,sha256=vyh7HvFrCp4iyMrTkDoSF3weaYrlNj2OJe0Fq5q4QB4,45
92
- esgpull-0.9.1.dist-info/licenses/LICENSE,sha256=lUqGPGWDHHxjkUDuYgjLLY2XQXXn_EHU7fnrQWHGugc,1540
93
- esgpull-0.9.1.dist-info/RECORD,,
90
+ esgpull-0.9.2.dist-info/METADATA,sha256=58JNkrLxhc7gH87SOzgLz6VTIZX5ylTAGfbYFMcv0Jg,3781
91
+ esgpull-0.9.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
92
+ esgpull-0.9.2.dist-info/entry_points.txt,sha256=vyh7HvFrCp4iyMrTkDoSF3weaYrlNj2OJe0Fq5q4QB4,45
93
+ esgpull-0.9.2.dist-info/licenses/LICENSE,sha256=lUqGPGWDHHxjkUDuYgjLLY2XQXXn_EHU7fnrQWHGugc,1540
94
+ esgpull-0.9.2.dist-info/RECORD,,