Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke etelemetry when constructing a DandiAPIClient; honor DANDI_NO_ET #728

Merged
merged 2 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 2 additions & 24 deletions dandi/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,10 @@ def main(ctx, log_level, pdb=False):

if pdb:
map_to_click_exceptions._do_map = False
from ..utils import setup_exceptionhook
from ..utils import check_dandi_version, setup_exceptionhook

setup_exceptionhook()
try:
import etelemetry

try:
etelemetry.check_available_version(
"dandi/dandi-cli", __version__, lgr=lgr, raise_exception=True
)
except etelemetry.client.BadVersionError:
# note: SystemExit is based of BaseException, so is not Exception
raise SystemExit(
"DANDI CLI has detected that you are using a version that is known to "
"contain bugs, is incompatible with our current data archive, or has "
"other significant performance limitations. "
"To continue using DANDI CLI, please upgrade your dandi client to a newer "
"version (e.g., using pip install --upgrade dandi if you installed using pip). "
"If you have any issues, please contact the DANDI "
"helpdesk at https://github.com/dandi/helpdesk/issues/new/choose ."
)
except Exception as exc:
lgr.warning(
"Failed to check for a more recent version available with etelemetry: %s",
exc,
)
check_dandi_version()
Copy link
Member

Choose a reason for hiding this comment

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

I think indentation is wrong and it falls under if pdb:

Copy link
Member

Choose a reason for hiding this comment

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

yeap, import makes it obvious... shouldn't be just in pdb mode

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.



#
Expand Down
3 changes: 2 additions & 1 deletion dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .consts import MAX_CHUNK_SIZE, known_instances, known_instances_rev
from .exceptions import NotFoundError
from .keyring import keyring_lookup
from .utils import USER_AGENT, is_interactive, try_multiple
from .utils import USER_AGENT, check_dandi_version, is_interactive, try_multiple

lgr = get_logger()

Expand Down Expand Up @@ -221,6 +221,7 @@ def paginate(self, path, page_size=None, params=None, **kwargs):

class DandiAPIClient(RESTFullAPIClient):
def __init__(self, api_url=None, token=None):
check_dandi_version()
if api_url is None:
instance_name = os.environ.get("DANDI_INSTANCE", "dandi")
api_url = known_instances[instance_name].api
Expand Down
29 changes: 29 additions & 0 deletions dandi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,32 @@ def get_mime_type(filename: str, strict: bool = False) -> str:
# return mtype + '+gzip'
else:
return "application/x-" + encoding


def check_dandi_version():
if os.environ.get("DANDI_NO_ET"):
return
try:
import etelemetry

try:
etelemetry.check_available_version(
"dandi/dandi-cli", __version__, lgr=lgr, raise_exception=True
)
except etelemetry.client.BadVersionError:
# note: SystemExit is based of BaseException, so is not Exception
raise SystemExit(
"DANDI CLI has detected that you are using a version that is known to "
"contain bugs, is incompatible with our current data archive, or has "
"other significant performance limitations. "
"To continue using DANDI CLI, please upgrade your dandi client to a newer "
"version (e.g., using pip install --upgrade dandi if you installed using pip). "
"If you have any issues, please contact the DANDI "
"helpdesk at https://github.com/dandi/helpdesk/issues/new/choose ."
)
except Exception as exc:
lgr.warning(
"Failed to check for a more recent version available with etelemetry: %s",
exc,
)
os.environ["DANDI_NO_ET"] = "1"