divbase-cli 0.1.0.dev3__tar.gz → 0.1.1__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.
Files changed (39) hide show
  1. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/.gitignore +25 -2
  2. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/PKG-INFO +6 -7
  3. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/pyproject.toml +5 -7
  4. divbase_cli-0.1.1/src/divbase_cli/__init__.py +1 -0
  5. divbase_cli-0.1.1/src/divbase_cli/cli_commands/auth_cli.py +188 -0
  6. divbase_cli-0.1.1/src/divbase_cli/cli_commands/dimensions_cli.py +462 -0
  7. divbase_cli-0.1.1/src/divbase_cli/cli_commands/file_cli.py +1190 -0
  8. divbase_cli-0.1.1/src/divbase_cli/cli_commands/query_cli.py +413 -0
  9. divbase_cli-0.1.1/src/divbase_cli/cli_commands/shared_args_options.py +33 -0
  10. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/cli_commands/task_history_cli.py +33 -42
  11. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/cli_commands/user_config_cli.py +37 -21
  12. divbase_cli-0.1.1/src/divbase_cli/cli_commands/version_cli.py +202 -0
  13. divbase_cli-0.1.1/src/divbase_cli/cli_config.py +80 -0
  14. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/cli_exceptions.py +89 -46
  15. divbase_cli-0.1.1/src/divbase_cli/config_resolver.py +87 -0
  16. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/display_task_history.py +48 -45
  17. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/divbase_cli.py +29 -11
  18. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/retries.py +11 -1
  19. divbase_cli-0.1.1/src/divbase_cli/services/announcements.py +46 -0
  20. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/services/pre_signed_urls.py +93 -39
  21. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/services/project_versions.py +26 -0
  22. divbase_cli-0.1.1/src/divbase_cli/services/s3_files.py +553 -0
  23. divbase_cli-0.1.1/src/divbase_cli/user_auth.py +525 -0
  24. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/user_config.py +1 -1
  25. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/utils.py +13 -20
  26. divbase_cli-0.1.0.dev3/src/divbase_cli/__init__.py +0 -1
  27. divbase_cli-0.1.0.dev3/src/divbase_cli/cli_commands/auth_cli.py +0 -87
  28. divbase_cli-0.1.0.dev3/src/divbase_cli/cli_commands/dimensions_cli.py +0 -139
  29. divbase_cli-0.1.0.dev3/src/divbase_cli/cli_commands/file_cli.py +0 -459
  30. divbase_cli-0.1.0.dev3/src/divbase_cli/cli_commands/query_cli.py +0 -140
  31. divbase_cli-0.1.0.dev3/src/divbase_cli/cli_commands/shared_args_options.py +0 -20
  32. divbase_cli-0.1.0.dev3/src/divbase_cli/cli_commands/version_cli.py +0 -145
  33. divbase_cli-0.1.0.dev3/src/divbase_cli/cli_config.py +0 -50
  34. divbase_cli-0.1.0.dev3/src/divbase_cli/config_resolver.py +0 -84
  35. divbase_cli-0.1.0.dev3/src/divbase_cli/services/s3_files.py +0 -355
  36. divbase_cli-0.1.0.dev3/src/divbase_cli/user_auth.py +0 -277
  37. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/README.md +0 -0
  38. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/cli_commands/__init__.py +0 -0
  39. {divbase_cli-0.1.0.dev3 → divbase_cli-0.1.1}/src/divbase_cli/services/__init__.py +0 -0
@@ -13,7 +13,7 @@ __pycache__/
13
13
 
14
14
  # project specific files
15
15
  /sample_metadata.tsv
16
- sample_metadata_*.tsv
16
+ /sample_metadata_*.tsv
17
17
  *.vcf
18
18
  *.vcf.gz
19
19
  *.vcf.gz.csi
@@ -21,6 +21,10 @@ sample_metadata_*.tsv
21
21
  !tests/fixtures/*.vcf.gz
22
22
  tests/fixtures/temp*
23
23
  tests/fixtures/merged*
24
+ divbase_metadata_template*.tsv
25
+ # query results files
26
+ result_of_job_*.vcf.gz
27
+ result_of_job_*.log
24
28
 
25
29
  # query job config files
26
30
  bcftools_divbase_job_config.json
@@ -33,10 +37,29 @@ split_scaffold_files.txt
33
37
  scripts/benchmarking/*.yaml
34
38
  scripts/benchmarking/results
35
39
 
40
+ # pytest-cov generate files
41
+ .coverage
42
+ .coverage.*
43
+ htmlcov/
44
+ docker/coverage-data/
45
+
46
+ # log files written by docker compose, if env var set to do so (by default no)
47
+ docker/logs/*
48
+ !docker/logs/.gitkeep
49
+
36
50
  #MacOS artifacts
37
51
  .DS_Store
38
52
 
39
- # mkdocs build cache
53
+ # mkdocs/zensical build cache
40
54
  .cache/
55
+ site/
56
+ # documentation site's auto generated files
57
+ docs/cli/_auto_generated/*.md
58
+ docs/releases/index.md
59
+ docs/llms.txt
60
+ docs/llms-full.txt
61
+ docs/llms-users.txt
62
+
63
+
41
64
  # pypi
42
65
  dist/
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: divbase-cli
3
- Version: 0.1.0.dev3
3
+ Version: 0.1.1
4
4
  Summary: Command Line Interface for Divbase
5
- Project-URL: Homepage, https://divbase.scilifelab.se
5
+ Project-URL: Homepage, https://divbase.scilifelab-2-prod.sys.kth.se
6
6
  Project-URL: Documentation, https://scilifelabdatacentre.github.io/divbase
7
7
  Project-URL: Repository, https://github.com/ScilifelabDataCentre/divbase
8
8
  Project-URL: Issues, https://github.com/ScilifelabDataCentre/divbase/issues
@@ -18,10 +18,9 @@ Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Programming Language :: Python :: 3.14
20
20
  Requires-Python: >=3.12
21
- Requires-Dist: divbase-lib==0.1.0.dev3
22
- Requires-Dist: httpx<1,>=0.28.1
23
- Requires-Dist: stamina>=25.2.0
24
- Requires-Dist: typer<1,>=0.21.1
21
+ Requires-Dist: divbase-lib==0.1.1
22
+ Requires-Dist: keyring==25.7.0
23
+ Requires-Dist: typer==0.27.2
25
24
  Description-Content-Type: text/markdown
26
25
 
27
26
  # divbase-cli
@@ -8,10 +8,9 @@ authors = [
8
8
  ]
9
9
  requires-python = ">=3.12"
10
10
  dependencies = [
11
- "typer>=0.21.1,<1",
12
- "httpx>=0.28.1,<1",
13
- "stamina>=25.2.0",
14
- "divbase-lib==0.1.0.dev3",
11
+ "typer==0.27.2",
12
+ "keyring==25.7.0",
13
+ "divbase-lib==0.1.1",
15
14
  ]
16
15
  dynamic = ["version"]
17
16
 
@@ -28,14 +27,13 @@ classifiers = [
28
27
  ]
29
28
 
30
29
  [project.urls]
31
- Homepage = "https://divbase.scilifelab.se"
30
+ Homepage = "https://divbase.scilifelab-2-prod.sys.kth.se"
32
31
  Documentation = "https://scilifelabdatacentre.github.io/divbase"
33
32
  Repository = "https://github.com/ScilifelabDataCentre/divbase"
34
33
  Issues = "https://github.com/ScilifelabDataCentre/divbase/issues"
35
34
 
36
35
  [project.scripts]
37
- divbase = "divbase_cli.divbase_cli:main"
38
- divbase-cli = "divbase_cli.divbase_cli:main" # TODO choose 1
36
+ divbase-cli = "divbase_cli.divbase_cli:main"
39
37
 
40
38
  [build-system]
41
39
  requires = ["hatchling >= 1.26"]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.1"
@@ -0,0 +1,188 @@
1
+ """
2
+ CLI subcommand for managing user auth with DivBase server.
3
+ """
4
+
5
+ import logging
6
+ import time
7
+
8
+ import typer
9
+ from pydantic import SecretStr
10
+ from rich import print
11
+
12
+ from divbase_cli.cli_config import cli_settings
13
+ from divbase_cli.cli_exceptions import (
14
+ DivBaseAPIConnectionError,
15
+ DivBaseAPIError,
16
+ InvalidPersonalAccessTokenError,
17
+ PersonalAccessTokenAlreadyExistsError,
18
+ )
19
+ from divbase_cli.config_resolver import resolve_url_for_non_project_specific_commands
20
+ from divbase_cli.services.announcements import get_and_display_announcements
21
+ from divbase_cli.user_auth import (
22
+ PERSONAL_ACCESS_TOKEN_EXPIRED_MESSAGE,
23
+ PATData,
24
+ check_existing_session,
25
+ delete_stored_pat,
26
+ load_stored_user_pat,
27
+ login_to_divbase,
28
+ logout_of_divbase,
29
+ make_authenticated_request,
30
+ )
31
+ from divbase_cli.user_config import load_user_config
32
+ from divbase_lib.divbase_constants import PAT_TOKEN_PREFIX
33
+ from divbase_lib.utils import format_unix_timestamp_for_cli
34
+
35
+ logger = logging.getLogger(__name__)
36
+
37
+ divbase_home_url = cli_settings.DIVBASE_API_URL.replace("/api", "")
38
+
39
+ auth_app = typer.Typer(
40
+ no_args_is_help=True,
41
+ help=f"Log in/out of DivBase and manage your personal access tokens. To register, visit {divbase_home_url}.",
42
+ )
43
+
44
+
45
+ @auth_app.command("login")
46
+ def login(
47
+ email: str,
48
+ divbase_url: str = typer.Option(cli_settings.DIVBASE_API_URL, help="DivBase server URL to connect to."),
49
+ force: bool = typer.Option(False, "--force", "-f", help="Log in again even if already logged in."),
50
+ ):
51
+ """
52
+ Log in to DivBase.
53
+
54
+ You'll be prompted for your password after running the command.
55
+ """
56
+ password: str = typer.prompt("please enter your password", hide_input=True, confirmation_prompt=False)
57
+ secret_password = SecretStr(password)
58
+ del password # avoid user passwords showing up in error messages etc...
59
+
60
+ config = load_user_config()
61
+
62
+ if not force:
63
+ session_expires_at = check_existing_session(divbase_url=divbase_url, config=config)
64
+ if session_expires_at:
65
+ print(f"Already logged in to {divbase_url} with email: {config.logged_in_email}.")
66
+ print(f"Session expires: {format_unix_timestamp_for_cli(unix_timestamp=session_expires_at)}")
67
+
68
+ if not typer.confirm("Do you want to login again? This will replace your current session."):
69
+ print("Login cancelled.")
70
+ return
71
+
72
+ login_to_divbase(email=email, password=secret_password, divbase_url=divbase_url)
73
+
74
+ try:
75
+ get_and_display_announcements(divbase_base_url=divbase_url)
76
+ except (DivBaseAPIError, DivBaseAPIConnectionError):
77
+ # lets not fail the login process if announcements are not working.
78
+ logger.info("Failed to get announcements after login. Error was: ", exc_info=True)
79
+
80
+ print(f"Logged in successfully as: {email}")
81
+
82
+
83
+ @auth_app.command("logout")
84
+ def logout():
85
+ """
86
+ Log out of DivBase.
87
+
88
+ Removes your locally stored credentials and invalidates the server-side refresh token.
89
+ """
90
+ logout_of_divbase()
91
+ print("Logged out successfully.")
92
+
93
+
94
+ @auth_app.command("add-pat")
95
+ def add_pat(
96
+ name: str = typer.Argument(..., help="Name of the personal access token (PAT), e.g. 'work-laptop-pat'."),
97
+ expires_unix_timestamp: int | None = typer.Option(
98
+ None,
99
+ "--expires",
100
+ "-e",
101
+ help="When the personal access token (PAT) expires (if it does), as a Unix timestamp.",
102
+ min=1,
103
+ ),
104
+ overwrite_existing: bool = typer.Option(
105
+ False, "--overwrite-existing", "-o", help="Overwrite the existing stored PAT if one already exists."
106
+ ),
107
+ ):
108
+ """
109
+ Add a personal access token (PAT) to your device for authentication with DivBase.
110
+
111
+ PATs are used for authenticating with DivBase instead of using your password, and are recommended for use in scripts and pipelines.
112
+ See https://scilifelabdatacentre.github.io/divbase/user-guides/using-divbase-programmatically/ for more details on how to create a personal access token.
113
+ You can only store one personal access token at a time.
114
+ """
115
+ existing = load_stored_user_pat()
116
+ if existing and not overwrite_existing:
117
+ raise PersonalAccessTokenAlreadyExistsError(
118
+ f"A personal access token named '{existing.name}' is already stored on your device \n"
119
+ f"It is due to expire on: {existing.pat_expiry_formatted()} \n"
120
+ "Append the flag --overwrite-existing (-o) to this command if you want to replace it. \n"
121
+ "You can only store one PAT at a time."
122
+ )
123
+
124
+ if expires_unix_timestamp and expires_unix_timestamp < time.time():
125
+ raise InvalidPersonalAccessTokenError(
126
+ "The expiry time you entered is in the past. Please enter a valid expiry time for the PAT."
127
+ )
128
+
129
+ pat = SecretStr(
130
+ typer.prompt("please paste your personal access token now", hide_input=True, confirmation_prompt=False)
131
+ )
132
+ if not pat.get_secret_value().startswith(PAT_TOKEN_PREFIX):
133
+ raise InvalidPersonalAccessTokenError(
134
+ "It looks like the token you entered is not a valid personal access token. "
135
+ f"Please make sure you copied the entire token, including the '{PAT_TOKEN_PREFIX}' prefix."
136
+ )
137
+
138
+ pat_data = PATData(name=name, pat=pat, pat_expires_at=expires_unix_timestamp)
139
+ pat_data.dump_pat_data()
140
+ print(f"Personal access token '{name}' stored successfully.")
141
+
142
+
143
+ @auth_app.command("rm-pat")
144
+ def rm_pat():
145
+ """
146
+ Remove the stored personal access token from your device.
147
+
148
+ If no such token exists the command will still succeed.
149
+ """
150
+ delete_stored_pat()
151
+ print("If a personal access token was stored, it has now been removed.")
152
+
153
+
154
+ @auth_app.command("pat-info")
155
+ def pat_info():
156
+ """
157
+ Display information about the personal access token stored on this device, if any.
158
+
159
+ The token will not be displayed for security reasons, but the name and expiry time will be shown.
160
+ """
161
+ pat_data = load_stored_user_pat()
162
+ if not pat_data:
163
+ print("No personal access token stored on this device.")
164
+ return
165
+
166
+ print(f"Name: {pat_data.name}")
167
+ print(f"Expires: {pat_data.pat_expiry_formatted()}")
168
+
169
+ if pat_data.is_pat_expired():
170
+ print("[red bold]Warning [/red bold]")
171
+ print(PERSONAL_ACCESS_TOKEN_EXPIRED_MESSAGE)
172
+
173
+
174
+ @auth_app.command("whoami")
175
+ def whoami():
176
+ """
177
+ Show information about the account you are currently logged in with.
178
+ """
179
+ divbase_url = resolve_url_for_non_project_specific_commands()
180
+
181
+ request = make_authenticated_request(
182
+ method="GET",
183
+ divbase_base_url=divbase_url,
184
+ api_route="v1/auth/whoami",
185
+ )
186
+
187
+ current_user = request.json()
188
+ print(f"Currently logged in as: {current_user['email']} (Name: {current_user['name']})")