[med-svn] [Git][med-team/python-etelemetry][upstream] New upstream version 0.2.0

Yaroslav Halchenko gitlab at salsa.debian.org
Sun Mar 22 18:25:46 GMT 2020



Yaroslav Halchenko pushed to branch upstream at Debian Med / python-etelemetry


Commits:
6ca5221b by Yaroslav Halchenko at 2020-03-22T13:03:53-04:00
New upstream version 0.2.0
- - - - -


7 changed files:

- .travis.yml
- README.md
- codecov.yml
- etelemetry/__init__.py
- etelemetry/client.py
- etelemetry/tests/test_client.py
- setup.cfg


Changes:

=====================================
.travis.yml
=====================================
@@ -1,7 +1,6 @@
 # vim ft=yaml
 language: python
 python:
-  - 2.7
   - 3.5
   - 3.6
   - 3.7


=====================================
README.md
=====================================
@@ -1,7 +1,7 @@
 ## Etelemetry-client
 
-[![Build Status](https://travis-ci.org/mgxd/etelemetry-client.svg?branch=master)](https://travis-ci.org/mgxd/etelemetry-client)
-[![codecov](https://codecov.io/gh/mgxd/etelemetry-client/branch/master/graph/badge.svg)](https://codecov.io/gh/mgxd/etelemetry-client)
+[![Build Status](https://travis-ci.org/sensein/etelemetry-client.svg?branch=master)](https://travis-ci.org/sensein/etelemetry-client)
+[![codecov](https://codecov.io/gh/sensein/etelemetry-client/branch/master/graph/badge.svg)](https://codecov.io/gh/sensein/etelemetry-client)
 
 A lightweight python client to communicate with the etelemetry server
 
@@ -17,5 +17,17 @@ pip install etelemetry
 import etelemetry
 etelemetry.get_project("nipy/nipype")
 
-{'version': '1.2.1'}
+{'version': '1.4.2', 'bad_versions': ['1.2.1', '1.2.3', '1.3.0']}
 ```
+
+or to take advantage of comparing and checking for bad versions, you
+can use the following form
+
+```python
+import etelemetry
+etelemetry.check_available_version("nipy/nipype", "1.2.1")
+
+A newer version (1.4.2) of nipy/nipype is available. You are using 1.2.1
+You are using a version of nipy/nipype with a critical bug. Please use a different version.
+returns: {'version': '1.4.2', 'bad_versions': ['1.2.1', '1.2.3', '1.3.0']}
+```
\ No newline at end of file


=====================================
codecov.yml
=====================================
@@ -4,3 +4,4 @@ coverage:
     - "etelemetry/_version.py"
     - "setup.py"
     - "versioneer.py"
+    - "etelemetry/tests"


=====================================
etelemetry/__init__.py
=====================================
@@ -1 +1 @@
-from .client import get_project
+from .client import get_project, check_available_version


=====================================
etelemetry/client.py
=====================================
@@ -1,13 +1,24 @@
 from requests import request, ConnectionError, ReadTimeout
+import os
+
+import ci
 
 from .config import ET_PROJECTS
 
+_available_version_checked = None
+
 
 def _etrequest(endpoint, method="get", **kwargs):
     if kwargs.get('timeout') is None:
         kwargs['timeout'] = 5
+
+    params = {}
+    if ci.is_ci():
+        # send along CI information
+        params = ci.info()
+
     try:
-        res = request(method, endpoint, **kwargs)
+        res = request(method, endpoint, params=params, **kwargs)
     except ConnectionError:
         raise RuntimeError("Connection to server could not be made")
     except ReadTimeout:
@@ -36,7 +47,71 @@ def get_project(repo, **rargs):
     response
         Dictionary with `version` field
     """
+    if "NO_ET" in os.environ:
+        return None
     if "/" not in repo:
         raise ValueError("Invalid repository")
     res = _etrequest(ET_PROJECTS.format(repo=repo), **rargs)
     return res.json(encoding="utf-8")
+
+
+def check_available_version(project, version, lgr=None, raise_exception=False):
+    """A helper to check (and report) if newer version of project is available
+    Should be ok to execute multiple times, it will be checked only one time
+    Parameters
+    ----------
+    project: str
+      as on GitHub (e.g., sensein/etelemetry-client. Releases will be checked
+    version: str
+      local version of project
+    lgr: python logger object
+      external logger to be used
+    raise_exception: bool
+      raise an exception if a bad local version is detected
+    """
+    global _available_version_checked
+    if _available_version_checked is not None:
+        return _available_version_checked
+
+    if lgr is None:
+        import logging
+        lgr = logging.getLogger('et-client')
+
+    from pkg_resources import parse_version
+
+    latest = {"version": "Unknown", "bad_versions": []}
+    ret = None
+    try:
+        ret = get_project(project)
+    except Exception as e:
+        lgr.debug("Could not check %s for version updates: %s", project, e)
+        return None
+    finally:
+        if ret:
+            latest.update(**ret)
+            local_version = parse_version(version)
+            remote_version = parse_version(latest["version"])
+            if local_version < remote_version:
+                lgr.warning("A newer version (%s) of %s is available. You are "
+                            "using %s", latest["version"], project, version)
+            elif remote_version < local_version:
+                lgr.debug(
+                    "Running a newer version (%s) of %s than available (%s)",
+                    version, project, latest["version"])
+            else:  # ==
+                lgr.debug("No newer (than %s) version of %s found available",
+                          version, project)
+            if latest["bad_versions"] and any(
+                    [
+                        local_version == parse_version(ver)
+                        for ver in latest["bad_versions"]
+                    ]
+            ):
+                message = ("You are using a version of {0} with a critical bug. "
+                          "Please use a different version.").format(project)
+                if raise_exception:
+                    raise RuntimeError(message)
+                else:
+                    lgr.critical(message)
+            _available_version_checked = latest
+    return latest


=====================================
etelemetry/tests/test_client.py
=====================================
@@ -1,7 +1,7 @@
 import pytest
 
 from ..config import ET_ROOT
-from ..client import _etrequest, get_project
+from ..client import _etrequest, get_project, check_available_version
 
 
 def test_etrequest():
@@ -23,3 +23,31 @@ def test_get_project():
     repo = "github/hub"
     res = get_project(repo)
     assert "version" in res
+
+
+def test_noet():
+    import os
+    old_var = None
+    if 'NO_ET' in os.environ:
+        old_var = (True, os.environ["NO_ET"])
+    os.environ["NO_ET"] = "1"
+    repo = "github/hub"
+    res = get_project(repo)
+    assert res is None
+    if old_var is None:
+        del os.environ["NO_ET"]
+    else:
+        os.environ["NO_ET"] = old_var[1]
+
+
+def test_check_available():
+    repo = "invalidrepo"
+    res = check_available_version(repo, "0.1.0")
+    assert res is None
+    repo = "github/hub"
+    res = check_available_version(repo, "0.1.0")
+    assert "version" in res
+    res = check_available_version(repo, res["version"])
+    assert "version" in res
+    res = check_available_version(repo, "1000.1.0")
+    assert "version" in res


=====================================
setup.cfg
=====================================
@@ -5,21 +5,23 @@ maintainer = Mathias Goncalves
 maintainer_email = mathiasg at mit.edu
 description = Etelemetry python client API
 license = Apache License, 2.0
+long_description = file:README.md
+long_description_content_type = text/markdown; charset=UTF-8; variant=GFM
 provides =
     etelemetry
 classifiers =
     Development Status :: 3 - Alpha
     Intended Audience :: Science/Research
     License :: OSI Approved :: Apache Software License
-    Programming Language :: Python :: 2.7
     Programming Language :: Python :: 3.5
     Programming Language :: Python :: 3.6
     Programming Language :: Python :: 3.7
 
 [options]
-python_requires = >= 2.7
+python_requires = >= 3.5
 install_requires =
     requests
+    ci-info
 test_requires =
     pytest >= 4.4.0
     pytest-cov



View it on GitLab: https://salsa.debian.org/med-team/python-etelemetry/-/commit/6ca5221b6db98da3f02d4b2632400b3ea80a9a9d

-- 
View it on GitLab: https://salsa.debian.org/med-team/python-etelemetry/-/commit/6ca5221b6db98da3f02d4b2632400b3ea80a9a9d
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20200322/4d6cb85e/attachment-0001.html>


More information about the debian-med-commit mailing list