divbase-cli 0.1.0__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 (28) hide show
  1. divbase_cli-0.1.0/.gitignore +65 -0
  2. divbase_cli-0.1.0/PKG-INFO +44 -0
  3. divbase_cli-0.1.0/README.md +19 -0
  4. divbase_cli-0.1.0/pyproject.toml +52 -0
  5. divbase_cli-0.1.0/src/divbase_cli/__init__.py +1 -0
  6. divbase_cli-0.1.0/src/divbase_cli/cli_commands/__init__.py +4 -0
  7. divbase_cli-0.1.0/src/divbase_cli/cli_commands/auth_cli.py +188 -0
  8. divbase_cli-0.1.0/src/divbase_cli/cli_commands/dimensions_cli.py +462 -0
  9. divbase_cli-0.1.0/src/divbase_cli/cli_commands/file_cli.py +1188 -0
  10. divbase_cli-0.1.0/src/divbase_cli/cli_commands/query_cli.py +413 -0
  11. divbase_cli-0.1.0/src/divbase_cli/cli_commands/shared_args_options.py +33 -0
  12. divbase_cli-0.1.0/src/divbase_cli/cli_commands/task_history_cli.py +126 -0
  13. divbase_cli-0.1.0/src/divbase_cli/cli_commands/user_config_cli.py +161 -0
  14. divbase_cli-0.1.0/src/divbase_cli/cli_commands/version_cli.py +202 -0
  15. divbase_cli-0.1.0/src/divbase_cli/cli_config.py +80 -0
  16. divbase_cli-0.1.0/src/divbase_cli/cli_exceptions.py +209 -0
  17. divbase_cli-0.1.0/src/divbase_cli/config_resolver.py +87 -0
  18. divbase_cli-0.1.0/src/divbase_cli/display_task_history.py +185 -0
  19. divbase_cli-0.1.0/src/divbase_cli/divbase_cli.py +93 -0
  20. divbase_cli-0.1.0/src/divbase_cli/retries.py +44 -0
  21. divbase_cli-0.1.0/src/divbase_cli/services/__init__.py +0 -0
  22. divbase_cli-0.1.0/src/divbase_cli/services/announcements.py +46 -0
  23. divbase_cli-0.1.0/src/divbase_cli/services/pre_signed_urls.py +500 -0
  24. divbase_cli-0.1.0/src/divbase_cli/services/project_versions.py +103 -0
  25. divbase_cli-0.1.0/src/divbase_cli/services/s3_files.py +553 -0
  26. divbase_cli-0.1.0/src/divbase_cli/user_auth.py +525 -0
  27. divbase_cli-0.1.0/src/divbase_cli/user_config.py +177 -0
  28. divbase_cli-0.1.0/src/divbase_cli/utils.py +28 -0
@@ -0,0 +1,65 @@
1
+ # repo secrets
2
+ .env
3
+ .env*
4
+
5
+ # python stuff
6
+ .venv
7
+ .ruff_cache/
8
+ __pycache__/
9
+ *.py[cod]
10
+ *$py.class
11
+
12
+ .vscode/
13
+
14
+ # project specific files
15
+ /sample_metadata.tsv
16
+ /sample_metadata_*.tsv
17
+ *.vcf
18
+ *.vcf.gz
19
+ *.vcf.gz.csi
20
+ *.vcf.gz.tbi
21
+ !tests/fixtures/*.vcf.gz
22
+ tests/fixtures/temp*
23
+ tests/fixtures/merged*
24
+ divbase_metadata_template*.tsv
25
+ # query results files
26
+ result_of_job_*.vcf.gz
27
+ result_of_job_*.log
28
+
29
+ # query job config files
30
+ bcftools_divbase_job_config.json
31
+
32
+ # benchmarking files
33
+ vcf_dimensions.tsv
34
+ mock*.tsv
35
+ task_records*.json
36
+ split_scaffold_files.txt
37
+ scripts/benchmarking/*.yaml
38
+ scripts/benchmarking/results
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
+
50
+ #MacOS artifacts
51
+ .DS_Store
52
+
53
+ # mkdocs/zensical build cache
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
+
64
+ # pypi
65
+ dist/
@@ -0,0 +1,44 @@
1
+ Metadata-Version: 2.5
2
+ Name: divbase-cli
3
+ Version: 0.1.0
4
+ Summary: Command Line Interface for Divbase
5
+ Project-URL: Homepage, https://divbase.scilifelab-2-prod.sys.kth.se
6
+ Project-URL: Documentation, https://scilifelabdatacentre.github.io/divbase
7
+ Project-URL: Repository, https://github.com/ScilifelabDataCentre/divbase
8
+ Project-URL: Issues, https://github.com/ScilifelabDataCentre/divbase/issues
9
+ Author-email: SciLifeLab Data Centre <datacentre@scilifelab.se>
10
+ License-Expression: MIT
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: divbase-lib==0.1.0
22
+ Requires-Dist: keyring==25.7.0
23
+ Requires-Dist: typer==0.27.2
24
+ Description-Content-Type: text/markdown
25
+
26
+ # divbase-cli
27
+
28
+ Command Line Interface for Divbase.
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pipx install divbase-cli
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```bash
39
+ divbase --help # can also run divbase-cli --help
40
+ ```
41
+
42
+ ## Development
43
+
44
+ This package is developed in the [DivBase repository](https://github.com/ScilifelabDataCentre/divbase) by Scilifelab Data Centre.
@@ -0,0 +1,19 @@
1
+ # divbase-cli
2
+
3
+ Command Line Interface for Divbase.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pipx install divbase-cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ divbase --help # can also run divbase-cli --help
15
+ ```
16
+
17
+ ## Development
18
+
19
+ This package is developed in the [DivBase repository](https://github.com/ScilifelabDataCentre/divbase) by Scilifelab Data Centre.
@@ -0,0 +1,52 @@
1
+ [project]
2
+ name = "divbase-cli"
3
+ description = "Command Line Interface for Divbase"
4
+ readme = "README.md"
5
+ license = "MIT"
6
+ authors = [
7
+ { name = "SciLifeLab Data Centre", email = "datacentre@scilifelab.se" },
8
+ ]
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "typer==0.27.2",
12
+ "keyring==25.7.0",
13
+ "divbase-lib==0.1.0",
14
+ ]
15
+ dynamic = ["version"]
16
+
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Environment :: Console",
20
+ "Intended Audience :: Science/Research",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: OS Independent",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: 3.14",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://divbase.scilifelab-2-prod.sys.kth.se"
31
+ Documentation = "https://scilifelabdatacentre.github.io/divbase"
32
+ Repository = "https://github.com/ScilifelabDataCentre/divbase"
33
+ Issues = "https://github.com/ScilifelabDataCentre/divbase/issues"
34
+
35
+ [project.scripts]
36
+ divbase-cli = "divbase_cli.divbase_cli:main"
37
+
38
+ [build-system]
39
+ requires = ["hatchling >= 1.26"]
40
+ build-backend = "hatchling.build"
41
+
42
+ [tool.hatch.version]
43
+ path = "src/divbase_cli/__init__.py"
44
+
45
+ [tool.uv.sources]
46
+ divbase-lib = { workspace = true }
47
+
48
+ [tool.ruff]
49
+ extend = "../../ruff.toml"
50
+
51
+ [tool.ruff.lint.flake8-tidy-imports.banned-api]
52
+ "divbase_api" = { msg = "divbase-cli cannot use code from divbase-api. Move shared code to divbase-lib." }
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ # File: /divbase/divbase/packages/divbase-cli/src/divbase_cli/commands/__init__.py
2
+ """
3
+ This file initializes the commands subpackage for the divbase-cli package.
4
+ """
@@ -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"Login/logout of DivBase server. 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="Force login again even if already logged in"),
50
+ ):
51
+ """
52
+ Log in to the DivBase server.
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 the DivBase server.
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 the DivBase API 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
+ Return information about the currently logged-in user.
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']})")