Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ filterwarnings = [
parallel = true
patch = ["subprocess"]
source = ["globus_cli"]
omit = [
"globus_cli_flake8.py",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling this shouldn't be in the src/ tree to begin with, but this is currently a helpful omission!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can understand that. In SDK we put the sphinx stuff (similar) into src/globus_sdk/_internal/. We need various things to be importable in different contexts (e.g., tests) and I've not worked out a uniform pattern for this yet.

]
[tool.coverage.paths]
source = [
"src/",
Expand All @@ -110,7 +113,7 @@ source = [
[tool.coverage.report]
show_missing = true
skip_covered = true
fail_under = 90
fail_under = 92
exclude_lines =[
# the pragma to disable coverage
"pragma: no cover",
Expand Down
4 changes: 1 addition & 3 deletions src/globus_cli/commands/bookmark/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ def __init__(self, client: globus_sdk.TransferClient) -> None:
self.client = client

def render(self, value: str) -> str:
from globus_cli.services.transfer import display_name_or_cname

try:
ep_doc = self.client.get_endpoint(value)
return display_name_or_cname(ep_doc)
return str(ep_doc["display_name"] or ep_doc["canonical_name"])
except globus_sdk.TransferAPIError as err:
if err.code == "EndpointDeleted":
return "[DELETED ENDPOINT]"
Expand Down
5 changes: 5 additions & 0 deletions src/globus_cli/commands/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import importlib.metadata
import platform
import site
import sys
Expand Down Expand Up @@ -46,6 +47,10 @@ def _get_package_data() -> list[list[str]]:
if loaded_mod is None:
cur.append("[import failed]")
continue
elif attr == "__version__":
version = importlib.metadata.distribution(mod).version
cur.append(version)
continue

try:
attrval = getattr(loaded_mod, attr)
Expand Down
2 changes: 0 additions & 2 deletions src/globus_cli/services/transfer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from .data import (
add_batch_to_transfer_data,
assemble_generic_doc,
display_name_or_cname,
iterable_response_to_dict,
)
from .recursive_ls import RecursiveLsResponse
Expand All @@ -30,7 +29,6 @@ def parse(self, value: t.Any) -> str:
"ENDPOINT_LIST_FIELDS",
"CustomTransferClient",
"RecursiveLsResponse",
"display_name_or_cname",
"iterable_response_to_dict",
"assemble_generic_doc",
"add_batch_to_transfer_data",
Expand Down
28 changes: 0 additions & 28 deletions src/globus_cli/services/transfer/activation.py

This file was deleted.

40 changes: 0 additions & 40 deletions src/globus_cli/services/transfer/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

import logging
import textwrap
import typing as t
import uuid

import click
import globus_sdk
from globus_sdk.transport import (
RetryCheckFlags,
Expand All @@ -16,7 +14,6 @@

from globus_cli.login_manager import get_client_login, is_client_login

from .data import display_name_or_cname
from .recursive_ls import RecursiveLsResponse

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -81,40 +78,3 @@ def recursive_operation_ls(
params,
)
return RecursiveLsResponse(self, endpoint_id, params, max_depth=depth)

def get_endpoint_w_server_list(
self, endpoint_id: str | uuid.UUID
) -> tuple[
globus_sdk.GlobusHTTPResponse, str | globus_sdk.IterableTransferResponse
]:
"""
A helper for handling endpoint server list lookups correctly accounting
for various endpoint types.

- Raises click.UsageError when used on Shares
- Returns (<get_endpoint_response>, "S3") for S3 endpoints
- Returns (<get_endpoint_response>, <server_list_response>) for all other
Endpoints
"""
endpoint = self.get_endpoint(endpoint_id)

if endpoint["host_endpoint_id"]: # not GCS -- this is a share endpoint
raise click.UsageError(
textwrap.dedent(
"""\
{id} ({0}) is a share and does not have servers.

To see details of the share, use
globus endpoint show {id}

To list the servers on the share's host endpoint, use
globus endpoint server list {host_endpoint_id}
"""
).format(display_name_or_cname(endpoint), **endpoint.data)
)

if endpoint["s3_url"]: # not GCS -- legacy S3 endpoint type
return (endpoint, "S3")

else:
return (endpoint, self.endpoint_server_list(endpoint_id))
7 changes: 0 additions & 7 deletions src/globus_cli/services/transfer/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
TaskPath,
mutex_option_group,
)
from globus_cli.types import JsonValue
from globus_cli.utils import shlex_process_stream


Expand Down Expand Up @@ -65,12 +64,6 @@ def _none_to_missing(
return value


def display_name_or_cname(
ep_doc: dict[str, JsonValue] | globus_sdk.GlobusHTTPResponse,
) -> str:
return str(ep_doc["display_name"] or ep_doc["canonical_name"])


def iterable_response_to_dict(iterator: t.Iterable[t.Any]) -> dict[str, list[t.Any]]:
output_dict: dict[str, list[t.Any]] = {"DATA": []}
for item in iterator:
Expand Down
120 changes: 120 additions & 0 deletions tests/functional/test_version_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import importlib.metadata
import textwrap

import pytest
import responses


def fmt_mod_info(modname):
mod = __import__(modname)
ver = importlib.metadata.distribution(modname).version
filepath, syspath = mod.__file__, mod.__path__

return textwrap.dedent(
f"""\
{modname}:
__version__: {ver}
__file__: {filepath}
__path__: {syspath}
"""
)


@pytest.fixture(scope="session")
def installed_cli_version():
return importlib.metadata.distribution("globus_cli").version


@pytest.fixture
def mock_pypi_version():
def func(version):
responses.get(
url="https://pypi.python.org/pypi/globus-cli/json",
json={"releases": [version]},
)

return func


def test_version_command_on_latest(run_line, mock_pypi_version, installed_cli_version):
mock_pypi_version(installed_cli_version)

result = run_line("globus version")
assert result.output == textwrap.dedent(
f"""\
Installed version: {installed_cli_version}
Latest version: {installed_cli_version}

You are running the latest version of the Globus CLI
"""
)


def test_version_command_on_preview(run_line, mock_pypi_version, installed_cli_version):
mock_pypi_version("1.0")

result = run_line("globus version")
assert result.output == textwrap.dedent(
f"""\
Installed version: {installed_cli_version}
Latest version: 1.0

You are running a preview version of the Globus CLI
"""
)


def test_version_command_newer_available(
run_line, mock_pypi_version, installed_cli_version
):
major = int(installed_cli_version.partition(".")[0])
latest = f"{major+1}.0"
mock_pypi_version(latest)

result = run_line("globus version")
assert result.output == textwrap.dedent(
f"""\
Installed version: {installed_cli_version}
Latest version: {latest}

You should update your version of the Globus CLI with
globus update
"""
)


def test_verbose_version_command_shows_related_package_versions(
run_line, mock_pypi_version, installed_cli_version
):
mock_pypi_version(installed_cli_version)

result = run_line("globus version -v")

# TODO: do more to validate this output
for modname in (
"globus_cli",
"globus_sdk",
"requests",
):
assert textwrap.indent(fmt_mod_info(modname), " ") in result.output

assert "click" not in result.output
assert "cryptography" not in result.output
assert "jmespath" not in result.output


def test_very_verbose_version_command_shows_more_related_package_versions(
run_line, mock_pypi_version, installed_cli_version
):
mock_pypi_version(installed_cli_version)

result = run_line("globus version -vv")
for modname in (
"click",
"cryptography",
"globus_cli",
"globus_sdk",
"jmespath",
"requests",
):
assert textwrap.indent(fmt_mod_info(modname), " ") in result.output
Loading