Skip to content

Commit d1a0778

Browse files
authored
rename uploading plugin & make better defaults for vizier task (#21)
* rename uploading plugin & make better defaults for vizier task * log better
1 parent e149d82 commit d1a0778

9 files changed

Lines changed: 89 additions & 26 deletions

File tree

app/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
BibcodeProvider,
33
DefaultTableNamer,
44
DescriptionProvider,
5-
UploaderPlugin,
5+
UploaderSource,
66
)
77
from app.log import logger
88
from app.tap import Constraint, TAPRepository
99
from app.upload import upload
1010

1111
__all__ = [
12-
"UploaderPlugin",
12+
"UploaderSource",
1313
"DefaultTableNamer",
1414
"BibcodeProvider",
1515
"DescriptionProvider",

app/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from app.gen.client.adminapi import models
77

88

9-
class UploaderPlugin(abc.ABC):
9+
class UploaderSource(abc.ABC):
1010
@abc.abstractmethod
1111
def prepare(self) -> None:
1212
"""

app/sources/csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
@final
21-
class CSVSource(app.UploaderPlugin, app.DefaultTableNamer):
21+
class CSVSource(app.UploaderSource, app.DefaultTableNamer):
2222
def __init__(self, filename: str) -> None:
2323
self.filename = filename
2424
self._chunk_size = 1000

app/sources/fits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
@final
22-
class FITSSource(app.UploaderPlugin, app.DefaultTableNamer):
22+
class FITSSource(app.UploaderSource, app.DefaultTableNamer):
2323
def __init__(self, filename: str, hdu_index: int = 1) -> None:
2424
self.filename = filename
2525
self.hdu_index = hdu_index

app/sources/vizier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _map_votable_datatype(datatype: str) -> models.DatatypeEnum:
4949

5050
@final
5151
class VizierSource(
52-
app.UploaderPlugin,
52+
app.UploaderSource,
5353
app.DefaultTableNamer,
5454
app.BibcodeProvider,
5555
app.DescriptionProvider,

app/sources/vizier_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def dtype_to_datatype(dtype: str | np.dtype) -> models.DatatypeEnum:
4848

4949
@final
5050
class VizierV2Source(
51-
app.UploaderPlugin,
51+
app.UploaderSource,
5252
app.DefaultTableNamer,
5353
app.BibcodeProvider,
5454
app.DescriptionProvider,

app/upload.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def upload(
21-
plugin: interface.UploaderPlugin,
21+
plugin: interface.UploaderSource,
2222
client: adminapi.AuthenticatedClient,
2323
*args,
2424
dry_run: bool = False,
@@ -54,7 +54,7 @@ def sanitize_value(val: Any) -> Any:
5454

5555

5656
def _upload(
57-
plugin: interface.UploaderPlugin,
57+
plugin: interface.UploaderSource,
5858
client: adminapi.AuthenticatedClient,
5959
table_name: str,
6060
table_description: str,
@@ -165,7 +165,7 @@ def process_chunk(data: Any) -> None:
165165

166166

167167
def upload_for_web(
168-
plugin: interface.UploaderPlugin,
168+
plugin: interface.UploaderSource,
169169
client: adminapi.AuthenticatedClient,
170170
table_name: str,
171171
table_description: str,

server/forms/upload_vizier.py

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import urllib.parse
12
from collections.abc import Callable
2-
from typing import cast
3+
from typing import Literal, cast
34

45
from pydantic import BaseModel, Field
56

@@ -8,14 +9,43 @@
89
from app.gen.client import adminapi
910
from app.sources.vizier import VizierSource
1011
from app.upload import upload_for_web
11-
from server.forms.upload_base import UploadBaseForm
1212

1313

14-
class UploadVizierForm(UploadBaseForm):
14+
class UploadVizierForm(BaseModel):
1515
catalog_name: str = Field(..., title="VizieR catalog name")
1616
source_table_name: str = Field(..., title="VizieR table name")
1717
cache_path: str = Field(default=".vizier_cache/", title="Cache path")
1818
batch_size: int = Field(default=100, title="Batch size", ge=1)
19+
table_name: str = Field(
20+
default="",
21+
title="Table name",
22+
description="Machine-readable HyperLEDA table id; leave empty to derive from VizieR.",
23+
)
24+
table_description: str = Field(
25+
default="",
26+
title="Table description",
27+
description="Human-readable description; leave empty to take from VizieR metadata.",
28+
)
29+
bibcode: str = Field(
30+
default="",
31+
title="Bibcode",
32+
description="NASA ADS bibcode; leave empty to read from VizieR.",
33+
)
34+
table_type: Literal["regular", "compilation"] = Field(
35+
default="regular",
36+
title="Table type",
37+
description="Type of data that table represents.",
38+
)
39+
dry_run: bool = Field(
40+
default=False,
41+
title="Dry run",
42+
description="Show schema and process rows without actually uploading any data. Useful for validation.",
43+
)
44+
endpoint: Literal["dev", "test", "prod"] = Field(
45+
default="prod",
46+
title="API endpoint",
47+
description="Where to upload. Leave unchanged if https://leda.sao.ru is needed.",
48+
)
1949

2050

2151
def handle_upload_vizier(form: BaseModel, report_func: Callable[[report.Event], None]) -> None:
@@ -24,22 +54,55 @@ def handle_upload_vizier(form: BaseModel, report_func: Callable[[report.Event],
2454
base_url=env_map[f.endpoint],
2555
token="fake",
2656
)
27-
source = VizierSource(f.catalog_name, f.source_table_name, cache_path=f.cache_path, batch_size=f.batch_size)
28-
bibcode = f.bibcode.strip() if f.has_bibcode else ""
29-
pub_name = f.pub_name.strip()
30-
pub_authors = list(f.pub_authors)
31-
pub_year = f.pub_year
57+
source = VizierSource(
58+
f.catalog_name,
59+
f.source_table_name,
60+
cache_path=f.cache_path,
61+
batch_size=f.batch_size,
62+
)
63+
64+
table_name_in = f.table_name.strip()
65+
if table_name_in:
66+
resolved_table_name = table_name_in
67+
else:
68+
resolved_table_name = source.get_table_name()
69+
70+
table_description_in = f.table_description.strip()
71+
if table_description_in:
72+
resolved_description = table_description_in
73+
else:
74+
resolved_description = source.get_description()
75+
76+
bibcode_in = f.bibcode.strip()
77+
if bibcode_in:
78+
resolved_bibcode = bibcode_in
79+
else:
80+
resolved_bibcode = source.get_bibcode()
81+
82+
if not resolved_bibcode:
83+
msg = "bibcode is empty: provide one or ensure VizieR metadata includes it"
84+
raise ValueError(msg)
85+
86+
report_func(report.LogEvent(message=f"Table name: {resolved_table_name}"))
87+
report_func(report.LogEvent(message=f"Description: {resolved_description}"))
88+
ads_url = "https://ui.adsabs.harvard.edu/abs/" + urllib.parse.quote(resolved_bibcode, safe="")
89+
report_func(
90+
report.LogEvent(
91+
message=f"Paper: {ads_url}",
92+
),
93+
)
94+
3295
table_type = (f.table_type or "regular").upper()
3396

3497
upload_for_web(
3598
source,
3699
client,
37-
f.table_name.strip(),
38-
f.table_description.strip(),
39-
bibcode,
40-
pub_name,
41-
pub_authors,
42-
pub_year,
100+
resolved_table_name,
101+
resolved_description,
102+
resolved_bibcode,
103+
"",
104+
[],
105+
0,
43106
table_type,
44107
dry_run=f.dry_run,
45108
report_func=report_func,

tests/test_upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
from app.gen.client import adminapi
1010
from app.gen.client.adminapi import models, types
11-
from app.interface import UploaderPlugin
11+
from app.interface import UploaderSource
1212
from app.sources.csv import CSVSource
1313
from app.upload import upload
1414

1515

16-
class StubPlugin(UploaderPlugin):
16+
class StubPlugin(UploaderSource):
1717
def __init__(self, should_raise: bool = False):
1818
self.should_raise = should_raise
1919
self.stop_called = False

0 commit comments

Comments
 (0)