Skip to content

Commit 698f7f3

Browse files
committed
Add a version variable in a standard way, update publishing script to account for the change, add new methods in Eva object
1 parent e622663 commit 698f7f3

File tree

9 files changed

+173
-108
lines changed

9 files changed

+173
-108
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
# Transform refs/tags/v0.0.2a01 to 0.0.2a01 and inject it into setup.py
2525
run: |
2626
export VERSION=`echo $VERSION_RAW | sed -E 's;.*/v(.*)$;\1;'`
27-
sed -i 's/%VERSION%/'$VERSION'/' setup.py
27+
sed -i 's/%VERSION%/'$VERSION'/' evasdk/version.py
2828
python setup.py sdist bdist_wheel
2929
- name: Publish a Python distribution to PyPI
3030
uses: pypa/gh-action-pypi-publish@master

Pipfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ websockets = "*"
99

1010
[dev-packages]
1111
flake8 = "*"
12+
requests-mock = "*"
1213
pytest = "*"
1314
"pytest-cov" = "*"
1415

1516
[requires]
1617

1718
[scripts]
1819
test = "python -m pytest tests/"
19-
lint = "flake8"
20+
lint = "flake8"

Pipfile.lock

Lines changed: 132 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evasdk/Eva.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,19 @@ def __exit__(self, type, value, traceback):
3939

4040

4141
# --------------------------------------------- HTTP HANDLERS ---------------------------------------------
42-
def api_call_with_auth(self, method, path, payload=None):
42+
def api_call_with_auth(self, method, path, payload=None, headers={}, timeout=None, version='v1'):
4343
self.__logger.debug('Eva.api_call_with_auth {} {}'.format(method, path))
44-
return self.__http_client.api_call_with_auth(method, path, payload=payload)
44+
return self.__http_client.api_call_with_auth(method, path, payload=payload, headers=headers, timeout=timeout, version=version)
45+
46+
def api_call_no_auth(self, method, path, payload=None, headers={}, timeout=None, version='v1'):
47+
self.__logger.debug('Eva.api_call_no_auth {} {}'.format(method, path))
48+
return self.__http_client.api_call_no_auth(method, path, payload=payload, headers=headers, timeout=timeout, version=version)
49+
50+
51+
# Global
52+
def versions(self):
53+
self.__logger.debug('Eva.versions called')
54+
return self.__http_client.api_versions()
4555

4656

4757
# Auth

evasdk/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@
7676
EvaError,
7777
EvaValidationError, EvaAuthError, EvaAutoRenewError,
7878
EvaAdminError, EvaServerError)
79+
from .version import __version__

evasdk/eva_http_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .robot_state import RobotState
77
from .eva_errors import eva_error, EvaError, EvaAutoRenewError
8+
from .version import __version__
89

910
# TODO add more granular logs using __logger
1011
# TODO lots of sleeps in control_* de to the robot state being updated slowly after starting an action, can this be improved?
@@ -66,6 +67,7 @@ def __api_request(self, method, path, payload=None, headers={}, timeout=None, ve
6667

6768
if add_auth:
6869
headers['Authorization'] = f'Bearer {self.session_token}'
70+
headers['User-Agent'] = f'Automata EvaSDK/{__version__} (Python)'
6971

7072
api_path = path
7173
if version is not None:

evasdk/version.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This is replaced by .github/workflows/publish.yml when creating a release
2+
version = '%VERSION%'
3+
4+
# Use the above version if it has been replaced, otherwise use a dev placeholder
5+
__version__ = version if version.count('%') == 0 else '0.0.dev0'

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import setuptools
2+
from evasdk.version import __version__
23

34
with open("README.md", "r") as fh:
45
long_description = fh.read()
56

67
setuptools.setup(
78
name='evasdk',
8-
version='%VERSION%',
9+
version=__version__,
910
description='SDK for the Automata Eva robotic arm',
1011
author='Automata',
1112
license='Apache License 2.0',

tests/Eva_api_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from evasdk import Eva
2+
3+
4+
class TestEva_API:
5+
def test_user_agent(self, requests_mock):
6+
eva = Eva("example.com", "NONE")
7+
8+
requests_mock.register_uri(
9+
'GET', 'http://example.com/api/versions',
10+
request_headers={
11+
'User-Agent': 'Automata EvaSDK/0.0.dev0 (Python)',
12+
},
13+
json={'APIs': ['v1']},
14+
)
15+
versions = eva.versions()
16+
assert(versions['APIs'][0] == 'v1')

0 commit comments

Comments
 (0)