Skip to content

Single-sourcing the package version, user-agent and bug fixes #24

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

Merged
merged 7 commits into from
Feb 26, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.cache
/.vscode/
.DS_Store
/build/
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ __ https://docs.scale.com/reference#project-retrieval

.. code-block:: python

client.get_projet(project_name = 'test_project')
client.get_project(project_name = 'test_project')

List Projects
^^^^^^^^^^^^^
Expand Down
188 changes: 0 additions & 188 deletions build/lib/scaleapi/__init__.py

This file was deleted.

26 changes: 0 additions & 26 deletions build/lib/scaleapi/batches.py

This file was deleted.

14 changes: 0 additions & 14 deletions build/lib/scaleapi/projects.py

This file was deleted.

30 changes: 0 additions & 30 deletions build/lib/scaleapi/tasks.py

This file was deleted.

2 changes: 1 addition & 1 deletion pypi_update_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _Creating and deploying a new package version is easy_

**Step 0: Critical - Bump Project Version**

In `setup.py`, you need to specify a new project version.
In `_version.py`, you need to specify a new project version.

We use [semantic versioning](https://packaging.python.org/guides/distributing-packages-using-setuptools/#semantic-versioning-preferred). If you are adding a meaningful feature, bump the minor version. If you are fixing a bug, bump the incremental version.

Expand Down
23 changes: 19 additions & 4 deletions scaleapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import requests
import platform

from .tasks import Task
from .batches import Batch
from .projects import Project
from ._version import __version__

TASK_TYPES = [
'annotation',
Expand Down Expand Up @@ -63,6 +65,10 @@ class Batchlist(Paginator):
class ScaleClient(object):
def __init__(self, api_key):
self.api_key = api_key
self._headers = {
"Content-Type": "application/json",
"User-Agent": _generate_useragent()
}

def _getrequest(self, endpoint, params=None):
"""Makes a get request to an endpoint.
Expand All @@ -73,7 +79,7 @@ def _getrequest(self, endpoint, params=None):
"""
params = params or {}
r = requests.get(SCALE_ENDPOINT + endpoint,
headers={"Content-Type": "application/json"},
headers=self._headers,
auth=(self.api_key, ''), params=params)

if r.status_code == 200:
Expand All @@ -97,7 +103,7 @@ def _postrequest(self, endpoint, payload=None):
"""
payload = payload or {}
r = requests.post(SCALE_ENDPOINT + endpoint, json=payload,
headers={"Content-Type": "application/json"},
headers=self._headers,
auth=(self.api_key, ''))

if r.status_code == 200:
Expand Down Expand Up @@ -195,7 +201,7 @@ def create_project(self, project_name, type, params):
projectdata = self._postrequest('projects', payload)
return Project(projectdata, self)

def get_projet(self, project_name):
def get_project(self, project_name):
projectdata = self._getrequest('projects/%s' % project_name)
return Project(projectdata, self)

Expand All @@ -209,9 +215,18 @@ def update_project(self, project_name, **kwargs):
if key not in allowed_kwargs:
raise ScaleInvalidRequest('Illegal parameter %s for ScaleClient.update_project()'
% key, None)
projectdata = self._postrequest('projects/%s/setParams' % project_name)
projectdata = self._postrequest('projects/%s/setParams' % project_name, payload=kwargs)
return projectdata

def _generate_useragent():
try:
python_version = platform.python_version()
os_platform = platform.platform()

user_agent = '%s/%s Python/%s OS/%s' % (__name__, __version__, python_version, os_platform)
return user_agent
except:
return "scaleapi-python-client"

def _AddTaskTypeCreator(task_type):
def create_task_wrapper(self, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions scaleapi/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.3"
15 changes: 14 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import warnings
import os.path

try:
from setuptools import setup
Expand All @@ -25,10 +26,22 @@
install_requires.append('idna')
install_requires.append('requests[security]')

def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, rel_path), 'r') as fp:
return fp.read()

def get_version(rel_path):
for line in read(rel_path).splitlines():
if line.startswith('__version__'):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
raise RuntimeError("Unable to find a valid __version__ string in %s." % rel_path)

setup(
name='scaleapi',
packages=['scaleapi'],
version='1.0.2',
version=get_version("scaleapi/_version.py"),
description='The official Python client library for Scale AI, the Data Platform for AI',
author='Scale AI',
author_email='support@scale.com',
Expand Down