diff --git a/swh/web/client/__init__.py b/swh/web/client/__init__.py --- a/swh/web/client/__init__.py +++ b/swh/web/client/__init__.py @@ -1 +0,0 @@ -from .client import WebAPIClient # NoQA: F401 diff --git a/swh/web/client/cli.py b/swh/web/client/cli.py --- a/swh/web/client/cli.py +++ b/swh/web/client/cli.py @@ -3,12 +3,11 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from getpass import getpass - +# WARNING: do not import unnecessary things here to keep cli startup time under +# control import click from click.core import Context -from swh.web.client.auth import OpenIDConnectSession CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) @@ -46,6 +45,8 @@ This CLI tool eases the retrieval of a bearer token to authenticate a user querying the Software Heritage Web API. """ + from swh.web.client.auth import OpenIDConnectSession + ctx.ensure_object(dict) ctx.obj["oidc_session"] = OpenIDConnectSession( oidc_server_url, realm_name, client_id @@ -69,6 +70,8 @@ token has a much longer expiration time than classical OIDC sessions (usually several dozens of days). """ + from getpass import getpass + password = getpass() oidc_info = ctx.obj["oidc_session"].login(username, password) diff --git a/swh/web/client/client.py b/swh/web/client/client.py --- a/swh/web/client/client.py +++ b/swh/web/client/client.py @@ -10,7 +10,7 @@ .. code-block:: python - from swh.web.client import WebAPIClient + from swh.web.client.client import WebAPIClient cli = WebAPIClient() # retrieve any archived object via its PID diff --git a/swh/web/client/tests/conftest.py b/swh/web/client/tests/conftest.py --- a/swh/web/client/tests/conftest.py +++ b/swh/web/client/tests/conftest.py @@ -6,7 +6,7 @@ import pytest from .api_data import API_URL, API_DATA -from swh.web.client import WebAPIClient +from swh.web.client.client import WebAPIClient @pytest.fixture @@ -19,11 +19,13 @@ headers = { "Link": f'<{API_URL}/{api_call}?branches_count=1000&branches_from=refs/tags/v3.0-rc7>; rel="next"' # NoQA: E501 } - elif api_call == "origin/https://github.com/NixOS/nixpkgs/visits/?last_visit=50&per_page=10": # NoQA: E501 + elif ( + api_call + == "origin/https://github.com/NixOS/nixpkgs/visits/?last_visit=50&per_page=10" # NoQA: E501 + ): # to make the client follow pagination headers = { - "Link": - f"<{API_URL}/origin/https://github.com/NixOS/nixpkgs/visits/?last_visit=40&per_page=10>; rel=\"next\"" # NoQA: E501 + "Link": f'<{API_URL}/origin/https://github.com/NixOS/nixpkgs/visits/?last_visit=40&per_page=10>; rel="next"' # NoQA: E501 } requests_mock.get(f"{API_URL}/{api_call}", text=data, headers=headers) return requests_mock