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
27 changes: 26 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ concurrency:

jobs:

run-linter:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.8.6]

steps:
- name: Checkout this repository
uses: actions/checkout@v3
with:
lfs: true

- name: Checkout actions repository
uses: actions/checkout@v3
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
path: actions
ref: feat/SOF-6640

- name: Run ruff linter
uses: ./actions/py/lint
with:
python-version: ${{ matrix.python-version }}

run-tests:
runs-on: ubuntu-20.04
strategy:
Expand Down Expand Up @@ -47,7 +72,7 @@ jobs:


publish:
needs: run-tests
needs: [run-linter, run-tests]
runs-on: ubuntu-latest
if: github.ref_name == 'dev'

Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ repos:
hooks:
- id: ruff
- id: black
- id: pydocstyle
1 change: 1 addition & 0 deletions exabyte_api_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F401
try:
from ._version import version as __version__
except ModuleNotFoundError:
Expand Down
12 changes: 6 additions & 6 deletions exabyte_api_client/endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json
import json # noqa: F401

from ..utils.http import Connection

Expand All @@ -17,7 +17,7 @@ class BaseEndpoint(object):
conn (httplib.ExabyteConnection): ExabyteConnection instance.
"""

def __init__(self, host, port, version='2018-10-1', secure=True, **kwargs):
def __init__(self, host, port, version="2018-10-1", secure=True, **kwargs):
self.conn = Connection(host, port, version=version, secure=secure, **kwargs)

def request(self, method, endpoint_path, params=None, data=None, headers=None):
Expand All @@ -37,9 +37,9 @@ def request(self, method, endpoint_path, params=None, data=None, headers=None):
with self.conn:
self.conn.request(method, endpoint_path, params, data, headers)
response = self.conn.json()
if response['status'] != 'success':
raise BaseException(response['data']['message'])
return response['data']
if response["status"] != "success":
raise BaseException(response["data"]["message"])
return response["data"]

def get_headers(self, account_id, auth_token, content_type="application/json"):
return {'X-Account-Id': account_id, 'X-Auth-Token': auth_token, 'Content-Type': content_type}
return {"X-Account-Id": account_id, "X-Auth-Token": auth_token, "Content-Type": content_type}
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/bank_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def copy(self, id_, account_id=None):
dict: new entity.
"""
params = {"accountId": account_id}
return self.request('POST', '/'.join((self.name, id_, "copy")), params=params, headers=self.headers)
return self.request("POST", "/".join((self.name, id_, "copy")), params=params, headers=self.headers)
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/bank_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class BankMaterialEndpoints(BankEntityEndpoints):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(BankMaterialEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'bank-materials'
self.name = "bank-materials"
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/bank_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class BankWorkflowEndpoints(BankEntityEndpoints):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(BankWorkflowEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'bank-workflows'
self.name = "bank-workflows"
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/charges.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChargeEndpoints(EntityEndpoint):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(ChargeEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'charges'
self.name = "charges"

def delete(self, id_):
raise NotImplementedError
Expand Down
12 changes: 6 additions & 6 deletions exabyte_api_client/endpoints/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def list(self, query=None, projection=None):
list[dict]
"""
params = {"query": json.dumps(query or {}), "projection": json.dumps(projection or {})}
return self.request('GET', self.name, params=params, headers=self.headers)
return self.request("GET", self.name, params=params, headers=self.headers)

def get(self, id_):
"""
Expand All @@ -52,7 +52,7 @@ def get(self, id_):
Returns:
dict: entity.
"""
return self.request('GET', '/'.join((self.name, id_)), headers=self.headers)
return self.request("GET", "/".join((self.name, id_)), headers=self.headers)

def delete(self, id_):
"""
Expand All @@ -61,7 +61,7 @@ def delete(self, id_):
Args:
id_ (str): entity ID.
"""
return self.request('DELETE', '/'.join((self.name, id_)), headers=self.headers)
return self.request("DELETE", "/".join((self.name, id_)), headers=self.headers)

def update(self, id_, modifier):
"""
Expand All @@ -74,7 +74,7 @@ def update(self, id_, modifier):
Returns:
dict: updated entity.
"""
return self.request('PATCH', '/'.join((self.name, id_)), data=json.dumps(modifier), headers=self.headers)
return self.request("PATCH", "/".join((self.name, id_)), data=json.dumps(modifier), headers=self.headers)

def create(self, config):
"""
Expand All @@ -86,7 +86,7 @@ def create(self, config):
Returns:
dict: new entity.
"""
return self.request('PUT', '/'.join((self.name, "create")), data=json.dumps(config), headers=self.headers)
return self.request("PUT", "/".join((self.name, "create")), data=json.dumps(config), headers=self.headers)

def copy(self, id_):
"""
Expand All @@ -98,4 +98,4 @@ def copy(self, id_):
Returns:
dict: new entity.
"""
return self.request('POST', '/'.join((self.name, id_, "copy")), headers=self.headers)
return self.request("POST", "/".join((self.name, id_, "copy")), headers=self.headers)
32 changes: 12 additions & 20 deletions exabyte_api_client/endpoints/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JobEndpoints(EntitySetEndpointsMixin, EntityEndpoint):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(JobEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'jobs'
self.name = "jobs"

def submit(self, id_):
"""
Expand All @@ -34,7 +34,7 @@ def submit(self, id_):
Args:
id_ (str): job ID.
"""
self.request('POST', '/'.join((self.name, id_, "submit")), headers=self.headers)
self.request("POST", "/".join((self.name, id_, "submit")), headers=self.headers)

def purge(self, id_):
"""
Expand All @@ -43,7 +43,7 @@ def purge(self, id_):
Args:
id_ (str): job ID.
"""
self.request('POST', '/'.join((self.name, id_, "submit")), headers=self.headers)
self.request("POST", "/".join((self.name, id_, "submit")), headers=self.headers)

def terminate(self, id_):
"""
Expand All @@ -52,7 +52,7 @@ def terminate(self, id_):
Args:
id_ (str): job ID.
"""
self.request('POST', '/'.join((self.name, id_, "submit")), headers=self.headers)
self.request("POST", "/".join((self.name, id_, "submit")), headers=self.headers)

def get_config(self, material_ids, workflow_id, project_id, owner_id, name, compute=None, is_multi_material=False):
"""
Expand All @@ -71,16 +71,10 @@ def get_config(self, material_ids, workflow_id, project_id, owner_id, name, comp
dict
"""
config = {
"_project": {
"_id": project_id
},
"workflow": {
"_id": workflow_id
},
"owner": {
"_id": owner_id
},
"name": name
"_project": {"_id": project_id},
"workflow": {"_id": workflow_id},
"owner": {"_id": owner_id},
"name": name,
}

if compute:
Expand Down Expand Up @@ -112,10 +106,8 @@ def get_compute(self, cluster, ppn=1, nodes=1, queue="D", time_limit="01:00:00",
"queue": queue,
"timeLimit": time_limit,
"notify": notify,
"cluster": {
"fqdn": cluster
},
"arguments": {}
"cluster": {"fqdn": cluster},
"arguments": {},
}

def create_by_ids(self, materials, workflow_id, project_id, owner_id, prefix, compute=None):
Expand Down Expand Up @@ -152,7 +144,7 @@ def get_presigned_urls(self, id_, files):
list: [{"file": "", "URL": ""}]
"""
data = json.dumps({"files": files})
response = self.request('POST', '/'.join((self.name, id_, "presigned-urls")), data=data, headers=self.headers)
response = self.request("POST", "/".join((self.name, id_, "presigned-urls")), data=data, headers=self.headers)
return response["presignedURLs"]

def list_files(self, id_):
Expand All @@ -166,7 +158,7 @@ def list_files(self, id_):
list: [{ "key" : str, "size" : int, "bucket" : str, "region" : str,
"provider" : str, "lastModified" : int, "name" : str, "signedURL" : str }]
"""
response = self.request('GET', '/'.join(('jobs', id_, 'files')), headers=self.headers)
response = self.request("GET", "/".join(("jobs", id_, "files")), headers=self.headers)
return response

def insert_output_files(self, id_, data):
Expand Down
6 changes: 3 additions & 3 deletions exabyte_api_client/endpoints/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LoginEndpoint(BaseEndpoint):

def __init__(self, host, port, username, password, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(LoginEndpoint, self).__init__(host, port, version, secure, **kwargs)
self.name = 'login'
self.name = "login"
self.username = username
self.password = password

Expand All @@ -35,8 +35,8 @@ def login(self):
Returns:
dict
"""
data = {'username': self.username, 'password': self.password}
return self.request('POST', self.name, data=data)
data = {"username": self.username, "password": self.password}
return self.request("POST", self.name, data=data)

@staticmethod
def get_endpoint_options(host, port, username, password, version=DEFAULT_API_VERSION, secure=SECURE):
Expand Down
4 changes: 2 additions & 2 deletions exabyte_api_client/endpoints/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class LogoutEndpoint(BaseEndpoint):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(LogoutEndpoint, self).__init__(host, port, version, secure, **kwargs)
self.name = 'logout'
self.name = "logout"
self.headers = self.get_headers(account_id, auth_token)

def logout(self):
"""
Deletes current API token.
"""
return self.request('POST', self.name, headers=self.headers)
return self.request("POST", self.name, headers=self.headers)
4 changes: 2 additions & 2 deletions exabyte_api_client/endpoints/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MaterialEndpoints(EntitySetEndpointsMixin, DefaultableEntityEndpointsMixin

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(MaterialEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'materials'
self.name = "materials"

def import_from_file(self, name, content, owner_id=None, format="poscar", tags=()):
"""
Expand All @@ -44,7 +44,7 @@ def import_from_file(self, name, content, owner_id=None, format="poscar", tags=(
dict
"""
data = {"name": name, "content": content, "format": format, "ownerId": owner_id, "tags": tags}
return self.request('POST', "/".join((self.name, "import")), headers=self.headers, data=json.dumps(data))
return self.request("POST", "/".join((self.name, "import")), headers=self.headers, data=json.dumps(data))

def import_from_materialsproject(self, api_key, material_ids, owner_id=None, tags=[]):
"""
Expand Down
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/mixins/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def set_default(self, id_):
Returns:
dict: new entity.
"""
self.request('POST', '/'.join((self.name, id_, "set-default")), headers=self.headers)
self.request("POST", "/".join((self.name, id_, "set-default")), headers=self.headers)
6 changes: 3 additions & 3 deletions exabyte_api_client/endpoints/mixins/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def create_set(self, config):
Returns:
dict: new entity set.
"""
path_ = '/'.join((self.name, "create-set"))
return self.request('PUT', path_, data=json.dumps(config), headers=self.headers)
path_ = "/".join((self.name, "create-set"))
return self.request("PUT", path_, data=json.dumps(config), headers=self.headers)

def move_to_set(self, _id, old_set_id, new_set_id):
"""
Expand All @@ -29,4 +29,4 @@ def move_to_set(self, _id, old_set_id, new_set_id):
new_set_id (str): new entity set ID.
"""
params = {"oldSetId": old_set_id, "newSetId": new_set_id}
self.request('POST', '/'.join((self.name, _id, "move-to-set")), params=params, headers=self.headers)
self.request("POST", "/".join((self.name, _id, "move-to-set")), params=params, headers=self.headers)
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ProjectEndpoints(DefaultableEntityEndpointsMixin, EntityEndpoint):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(ProjectEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'projects'
self.name = "projects"

def delete(self, id_):
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/raw_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RawPropertiesEndpoints(BasePropertiesEndpoints):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(RawPropertiesEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'raw-properties'
self.name = "raw-properties"

def delete(self, id_):
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/refined_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RefinedPropertiesEndpoints(BasePropertiesEndpoints):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(RefinedPropertiesEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'refined-properties'
self.name = "refined-properties"

def delete(self, id_):
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion exabyte_api_client/endpoints/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class WorkflowEndpoints(DefaultableEntityEndpointsMixin, EntityEndpoint):

def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs):
super(WorkflowEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs)
self.name = 'workflows'
self.name = "workflows"
4 changes: 2 additions & 2 deletions exabyte_api_client/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BaseConnection(object):
def __init__(self, **kwargs):
self.response = None
self.session = requests.Session()
self.session.timeout = kwargs.get('timeout', 60)
self.session.timeout = kwargs.get("timeout", 60)

def request(self, method, url, params=None, data=None, headers=None):
"""
Expand Down Expand Up @@ -129,7 +129,7 @@ class Connection(BaseConnection):
"""

def __init__(self, host, port, version, secure, **kwargs):
self.preamble = '{}://{}:{}/api/{}/'.format('https' if secure else 'http', host, port, version)
self.preamble = "{}://{}:{}/api/{}/".format("https" if secure else "http", host, port, version)
super(Connection, self).__init__(**kwargs)

def request(self, method, endpoint_path, params=None, data=None, headers=None):
Expand Down
2 changes: 1 addition & 1 deletion exabyte_api_client/utils/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def flatten_material(material):
lattice["c"],
lattice["alpha"],
lattice["beta"],
lattice["gamma"]
lattice["gamma"],
]
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, *args, **kwargs):
super(EndpointBaseTest, self).__init__(*args, **kwargs)

def get_file_path(self, filename):
return os.path.join(os.path.dirname(__file__), 'data', filename)
return os.path.join(os.path.dirname(__file__), "data", filename)

def get_content(self, filename):
with open(self.get_file_path(filename)) as f:
Expand Down
Loading