Skip to content

Commit 8eead89

Browse files
committed
fix: moved from typer to click to enable passing args to docker image
1 parent f706563 commit 8eead89

File tree

5 files changed

+154
-101
lines changed

5 files changed

+154
-101
lines changed

Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
FROM python:3.11-slim
1+
FROM python:3.10-slim
22

33
WORKDIR /app
44

5-
# Copy everything first (pyproject.toml, README.md, and source code)
65
COPY . .
76

8-
# Install the package + dependencies
7+
# Install dependencies
98
RUN pip install .
109

11-
# Default command
12-
ENTRYPOINT ["python", "-m", "databusclient"]
10+
# Use ENTRYPOINT for the CLI
11+
ENTRYPOINT ["databusclient"]

databusclient/cli.py

Lines changed: 98 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,112 @@
1+
# TODO: Typer did not work in Docker container, meaning passed arguments were ignored. Switch to Click for now. Decide later if we want to switch back to Typer.
2+
# # !/usr/bin/env python3
3+
# import typer
4+
# from typing import List
5+
# from databusclient import client
6+
7+
# app = typer.Typer()
8+
9+
10+
# @app.command()
11+
# def deploy(
12+
# version_id: str = typer.Option(
13+
# ...,
14+
# help="target databus version/dataset identifier of the form "
15+
# "<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>",
16+
# ),
17+
# title: str = typer.Option(..., help="dataset title"),
18+
# abstract: str = typer.Option(..., help="dataset abstract max 200 chars"),
19+
# description: str = typer.Option(..., help="dataset description"),
20+
# license_uri: str = typer.Option(..., help="license (see dalicc.net)"),
21+
# apikey: str = typer.Option(..., help="apikey"),
22+
# distributions: List[str] = typer.Argument(
23+
# ...,
24+
# help="distributions in the form of List[URL|CV|fileext|compression|sha256sum:contentlength] where URL is the "
25+
# "download URL and CV the "
26+
# "key=value pairs (_ separated) content variants of a distribution. filext and compression are optional "
27+
# "and if left out inferred from the path. If the sha256sum:contentlength part is left out it will be "
28+
# "calcuted by downloading the file.",
29+
# ),
30+
# ):
31+
# typer.echo(version_id)
32+
# dataid = client.create_dataset(
33+
# version_id, title, abstract, description, license_uri, distributions
34+
# )
35+
# client.deploy(dataid=dataid, api_key=apikey)
36+
37+
38+
# @app.command()
39+
# def download(
40+
# databusuris: List[str] = typer.Argument(..., help="any kind of these: databus identifier, databus collection identifier, query file"),
41+
# localDir: str = typer.Option(None , help="local databus folder"), # if not given, databus folder structure is created in current working directory
42+
# databus: str = typer.Option(None, help="databus URL"), # if not given, inferred on databusuri (e.g. https://databus.dbpedia.org/sparql)
43+
# token: str = typer.Option(None, help="Path to Vault refresh token file"),
44+
# authUrl: str = typer.Option("https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", help="Keycloak token endpoint URL"),
45+
# clientId: str = typer.Option("vault-token-exchange", help="Client ID for token exchange")
46+
# ):
47+
# """
48+
# Download datasets from databus, optionally using vault access if vault options are provided.
49+
# """
50+
# client.download(localDir=localDir, endpoint=databus, databusURIs=databusuris, vault_token_file=vaultTokenFile, auth_url=authUrl, client_id=clientId)
51+
152
#!/usr/bin/env python3
2-
import typer
53+
import click
354
from typing import List
455
from databusclient import client
556

6-
app = typer.Typer()
57+
58+
@click.group()
59+
def app():
60+
"""Databus Client CLI"""
61+
pass
762

863

964
@app.command()
10-
def deploy(
11-
version_id: str = typer.Option(
12-
...,
13-
help="target databus version/dataset identifier of the form "
14-
"<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>",
15-
),
16-
title: str = typer.Option(..., help="dataset title"),
17-
abstract: str = typer.Option(..., help="dataset abstract max 200 chars"),
18-
description: str = typer.Option(..., help="dataset description"),
19-
license_uri: str = typer.Option(..., help="license (see dalicc.net)"),
20-
apikey: str = typer.Option(..., help="apikey"),
21-
distributions: List[str] = typer.Argument(
22-
...,
23-
help="distributions in the form of List[URL|CV|fileext|compression|sha256sum:contentlength] where URL is the "
24-
"download URL and CV the "
25-
"key=value pairs (_ separated) content variants of a distribution. filext and compression are optional "
26-
"and if left out inferred from the path. If the sha256sum:contentlength part is left out it will be "
27-
"calcuted by downloading the file.",
28-
),
29-
):
30-
typer.echo(version_id)
31-
dataid = client.create_dataset(
32-
version_id, title, abstract, description, license_uri, distributions
33-
)
65+
@click.option(
66+
"--version-id",
67+
required=True,
68+
help="Target databus version/dataset identifier of the form "
69+
"<https://databus.dbpedia.org/$ACCOUNT/$GROUP/$ARTIFACT/$VERSION>",
70+
)
71+
@click.option("--title", required=True, help="Dataset title")
72+
@click.option("--abstract", required=True, help="Dataset abstract max 200 chars")
73+
@click.option("--description", required=True, help="Dataset description")
74+
@click.option("--license-uri", required=True, help="License (see dalicc.net)")
75+
@click.option("--apikey", required=True, help="API key")
76+
@click.argument(
77+
"distributions",
78+
nargs=-1,
79+
required=True,
80+
)
81+
def deploy(version_id, title, abstract, description, license_uri, apikey, distributions: List[str]):
82+
"""
83+
Deploy a dataset version with the provided metadata and distributions.
84+
"""
85+
click.echo(f"Deploying dataset version: {version_id}")
86+
dataid = client.create_dataset(version_id, title, abstract, description, license_uri, distributions)
3487
client.deploy(dataid=dataid, api_key=apikey)
3588

3689

3790
@app.command()
38-
def download(
39-
databusuris: List[str] = typer.Argument(..., help="any kind of these: databus identifier, databus collection identifier, query file"),
40-
localDir: str = typer.Option(None , help="local databus folder"), # if not given, databus folder structure is created in current working directory
41-
databus: str = typer.Option(None, help="databus URL"), # if not given, inferred on databusuri (e.g. https://databus.dbpedia.org/sparql)
42-
token: str = typer.Option(None, help="Path to Vault refresh token file"),
43-
authUrl: str = typer.Option("https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", help="Keycloak token endpoint URL"),
44-
clientId: str = typer.Option("vault-token-exchange", help="Client ID for token exchange")
45-
):
91+
@click.argument("databusuris", nargs=-1, required=True)
92+
@click.option("--localdir", help="Local databus folder (if not given, databus folder structure is created in current working directory)")
93+
@click.option("--databus", help="Databus URL (if not given, inferred from databusuri, e.g. https://databus.dbpedia.org/sparql)")
94+
@click.option("--token", help="Path to Vault refresh token file")
95+
@click.option("--authurl", default="https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token", show_default=True, help="Keycloak token endpoint URL")
96+
@click.option("--clientid", default="vault-token-exchange", show_default=True, help="Client ID for token exchange")
97+
def download(databusuris: List[str], localdir, databus, token, authurl, clientid):
4698
"""
4799
Download datasets from databus, optionally using vault access if vault options are provided.
48100
"""
49-
client.download(localDir=localDir, endpoint=databus, databusURIs=databusuris, vault_token_file=vaultTokenFile, auth_url=authUrl, client_id=clientId)
101+
client.download(
102+
localDir=localdir,
103+
endpoint=databus,
104+
databusURIs=databusuris,
105+
token=token,
106+
auth_url=authurl,
107+
client_id=clientid,
108+
)
109+
110+
111+
if __name__ == "__main__":
112+
app()

databusclient/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def download(
592592
localDir: str,
593593
endpoint: str,
594594
databusURIs: List[str],
595-
vault_token_file=None,
595+
token=None,
596596
auth_url=None,
597597
client_id=None
598598
) -> None:
@@ -602,7 +602,7 @@ def download(
602602
localDir: the local directory
603603
endpoint: the databus endpoint URL
604604
databusURIs: identifiers to access databus registered datasets
605-
vault_token_file: Path to Vault refresh token file
605+
token: Path to Vault refresh token file
606606
auth_url: Keycloak token endpoint URL
607607
client_id: Client ID for token exchange
608608
"""
@@ -624,12 +624,12 @@ def download(
624624
__download_list__(res, localDir)
625625
# databus file
626626
elif file is not None:
627-
__download_list__([databusURI], localDir, vault_token_file=vault_token_file, auth_url=auth_url, client_id=client_id)
627+
__download_list__([databusURI], localDir, vault_token_file=token, auth_url=auth_url, client_id=client_id)
628628
# databus artifact version
629629
elif version is not None:
630630
json_str = __handle_databus_artifact_version__(databusURI)
631631
res = __handle_databus_file_json__(json_str)
632-
__download_list__(res, localDir, vault_token_file=vault_token_file, auth_url=auth_url, client_id=client_id)
632+
__download_list__(res, localDir, vault_token_file=token, auth_url=auth_url, client_id=client_id)
633633
# databus artifact
634634
elif artifact is not None:
635635
print("artifactId not supported yet") # TODO

0 commit comments

Comments
 (0)