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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = venv, __init__.py, doc/_build, .venv, ansys/rep/client/rms/models.py
exclude = venv, __init__.py, doc/_build, .venv, ansys/hps/client/rms/models.py, generate_resources.py
select = W191, W291, W293, W391, E115, E117, E122, E124, E125, E225, E231, E301, E303, E501, F401, F403, N801, N802, N803, N804, N805, N806, N807, N815, N816
count = True
max-complexity = 10
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
python -m pip install -r requirements/requirements_build.txt
python -m build venv wheel
python -m twine check dist/*
version=$(ls dist | grep rep_client | grep -E -o "[0-9]+.[0-9]+.[a-z0-9]+")
version=$(ls dist | grep ansys_pyhps | grep -E -o "[0-9]+.[0-9]+.[a-z0-9]+")
echo "version=$version" >> $GITHUB_OUTPUT
#- name: Upload to private PyPi
# if: github.ref == 'refs/heads/main'
Expand All @@ -183,7 +183,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: pyrep-package
name: ansys-pyhps-package
path: |
dist/*.whl
retention-days: 5
Expand All @@ -196,7 +196,7 @@ jobs:
steps:
- uses: actions/download-artifact@v3
with:
name: pyrep-package
name: ansys-pyhps-package
path: /tmp/artifacts

- name: List artifacts
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ repos:
rev: 22.3.0
hooks:
- id: black
exclude: ^(ansys/rep/client/jms/resource/|ansys/rep/client/auth/resource/|ansys/rep/client/rms/models.py)
exclude: ^(ansys/hps/client/jms/resource/|ansys/hps/client/auth/resource/|ansys/hps/client/rms/models.py)

- repo: https://github.com/pycqa/isort
rev: 5.11.5
hooks:
- id: isort
exclude: ^(ansys/rep/client/jms/resource/|ansys/rep/client/auth/resource/)
exclude: ^(ansys/hps/client/jms/resource/|ansys/hps/client/auth/resource/)

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
exclude: ^(ansys/rep/client/jms/resource/|ansys/rep/client/auth/resource/)
exclude: ^(ansys/hps/client/jms/resource/|ansys/hps/client/auth/resource/)

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
Expand Down
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyREP
PyHPS
=====
|pyansys| |python| |pypi| |GH-CI| |codecov| |MIT| |black|

Expand Down Expand Up @@ -31,19 +31,19 @@ PyREP
:alt: Black


A Python client for Ansys REP - Remote Execution Platform
A Python client library for the Ansys HPC Platform Services.

How to install
--------------

In order to install PyREP, make sure you
In order to install PyHPS, make sure you
have the latest version of `pip`_. To do so, run:

.. code:: bash

python -m pip install -U pip

Then, as long as PyREP is a private pyAnsys module not published to pypi yet, you can execute:
Then, as long as PyHPS is a private pyAnsys module not published to pypi yet, you can execute:

.. code:: bash

Expand Down Expand Up @@ -175,7 +175,7 @@ Then, run the datamodel generator:

.. code:: bash

datamodel-codegen --input .\rms_openapi.json --input-file-type openapi --output ansys/rep/client/rms/models.py --output-model-type pydantic_v2.BaseModel
datamodel-codegen --input .\rms_openapi.json --input-file-type openapi --output ansys/hps/client/rms/models.py --output-model-type pydantic_v2.BaseModel

.. LINKS AND REFERENCES
.. _black: https://github.com/psf/black
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from .auth import AuthApi
from .client import Client
from .exceptions import APIError, ClientError, REPError
from .exceptions import APIError, ClientError, HPSError
from .jms import JmsApi, ProjectApi
from .rms import RmsApi
from .warnings import UnverifiedHTTPSRequestsWarning
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.dev0"
__version__ = "0.6.dev0"
__version_no_dots__ = __version__.replace(".", "")
__company__ = "ANSYS, Inc."
__company_short__ = "Ansys"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class AuthApi:
Parameters
----------
client : Client
A REP client object.
An HPS client object.

Examples
--------

Get users whose first name contains "john":

>>> from ansys.rep.client import Client
>>> from ansys.rep.client.auth import AuthApi, User
>>> from ansys.hps.client import Client
>>> from ansys.hps.client.auth import AuthApi, User
>>> cl = Client(
... rep_url="https://127.0.0.1:8443/rep/", username="repadmin", password="repadmin"
... )
Expand All @@ -58,7 +58,7 @@ def __init__(self, client):
@property
def url(self):
"""Returns the API url"""
return f"{self.client.rep_url}/auth/"
return f"{self.client.url}/auth/"

@property
def keycloak_admin_client(self) -> KeycloakAdmin:
Expand Down Expand Up @@ -96,7 +96,7 @@ def get_user_realm_roles(self, id: str) -> List[str]:
def user_is_admin(self, id: str) -> bool:
"""Check whether the user is system admin"""

from ansys.rep.client.jms import JmsApi
from ansys.hps.client.jms import JmsApi

# the admin keys are configurable settings of JMS
# they need to be queried, can't be hardcoded
Expand All @@ -119,7 +119,7 @@ def create_user(self, user: User, as_objects=True) -> User:
"""Create a new user.

Args:
user (:class:`ansys.rep.client.auth.User`): A User object. Defaults to None.
user (:class:`ansys.hps.client.auth.User`): A User object. Defaults to None.
as_objects (bool, optional): Defaults to True.
"""
return create_user(self.keycloak_admin_client, user, as_objects=as_objects)
Expand All @@ -128,7 +128,7 @@ def update_user(self, user: User, as_objects=True) -> User:
"""Modify an existing user.

Args:
user (:class:`ansys.rep.client.auth.User`): A User object. Defaults to None.
user (:class:`ansys.hps.client.auth.User`): A User object. Defaults to None.
as_objects (bool, optional): Defaults to True.
"""
return update_user(self.keycloak_admin_client, user, as_objects=as_objects)
Expand All @@ -137,7 +137,7 @@ def delete_user(self, user: User) -> None:
"""Delete an existing user.

Args:
user (:class:`ansys.rep.client.auth.User`): A User object. Defaults to None.
user (:class:`ansys.hps.client.auth.User`): A User object. Defaults to None.
"""
return self.keycloak_admin_client.delete_user(user.id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def authenticate(
**kwargs,
):
"""
Authenticate user with either password or refresh token against REP authentication service.
Authenticate user with either password or refresh token against HPS authentication service.
If successful, the response includes access and refresh tokens.

Parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# autogenerated code
from marshmallow.utils import missing
from ansys.rep.client.common import Object
from ansys.hps.client.common import Object
from ..schema.user import UserSchema

class User(Object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from marshmallow import fields

from ansys.rep.client.common.base_schema import BaseSchema
from ansys.hps.client.common.base_schema import BaseSchema


class UserSchema(BaseSchema):
Expand Down
43 changes: 29 additions & 14 deletions ansys/rep/client/client.py → ansys/hps/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class Client(object):
"""A python interface to the Remote Execution Platform (REP) API.
"""A python client to the Ansys HPC Platform Services APIs.

Uses the provided credentials to create and store
an authorized :class:`requests.Session` object.
Expand All @@ -40,7 +40,7 @@ class Client(object):

Parameters
----------
rep_url : str
url : str
The base path for the server to call, e.g. "https://127.0.0.1:8443/rep".
username : str, optional
Username
Expand All @@ -66,19 +66,19 @@ class Client(object):
Examples
--------

Create client object and connect to REP with username and password
Create client object and connect to HPS with username and password

>>> from ansys.rep.client import Client
>>> from ansys.hps.client import Client
>>> cl = Client(
... rep_url="https://localhost:8443/rep",
... url="https://localhost:8443/rep",
... username="repuser",
... password="repuser"
... )

Create client object and connect to REP with refresh token
Create client object and connect to HPS with refresh token

>>> cl = Client(
... rep_url="https://localhost:8443/rep",
... url="https://localhost:8443/rep",
... username="repuser",
... refresh_token="eyJhbGciOiJIUzI1NiIsInR5cC..."
>>> )
Expand All @@ -87,7 +87,7 @@ class Client(object):

def __init__(
self,
rep_url: str = "https://127.0.0.1:8443/rep",
url: str = "https://127.0.0.1:8443/rep",
username: str = None,
password: str = None,
*,
Expand All @@ -102,11 +102,19 @@ def __init__(
all_fields=True,
verify: Union[bool, str] = None,
disable_security_warnings: bool = True,
**kwargs,
):

self.rep_url = rep_url
rep_url = kwargs.get("rep_url", None)
if rep_url is not None:
url = rep_url
msg = "The 'rep_url'` input argument is deprecated, use 'url' instead."
warnings.warn(msg, DeprecationWarning)
log.warning(msg)

self.url = url
self.auth_url = auth_url
self.auth_api_url = (auth_url or rep_url) + f"/auth/"
self.auth_api_url = (auth_url or url) + f"/auth/"
self.access_token = None
self.refresh_token = None
self.username = username
Expand All @@ -121,7 +129,7 @@ def __init__(
self.verify = False
msg = (
f"Certificate verification is disabled. "
f"Unverified HTTPS requests will be made to {self.rep_url}."
f"Unverified HTTPS requests will be made to {self.url}."
)
warnings.warn(msg, UnverifiedHTTPSRequestsWarning)
log.warning(msg)
Expand All @@ -145,7 +153,7 @@ def __init__(
log.debug(f"Authenticating with '{self.grant_type}' grant type.")

tokens = authenticate(
url=auth_url or rep_url,
url=auth_url or url,
realm=realm,
grant_type=self.grant_type,
scope=scope,
Expand All @@ -172,6 +180,13 @@ def __init__(
self._unauthorized_num_retry = 0
self._unauthorized_max_retry = 1

@property
def rep_url(self) -> str:
msg = "The Client 'rep_url' property is deprecated, use 'url' instead."
warnings.warn(msg, DeprecationWarning)
log.warning(msg)
return self.url

def _auto_refresh_token(self, response, *args, **kwargs):
"""Hook function to automatically refresh the access token and
re-send the request in case of unauthorized error"""
Expand All @@ -197,7 +212,7 @@ def refresh_access_token(self):
# Its not recommended to give refresh tokens to client_credentials grant types
# as per OAuth 2.0 RFC6749 Section 4.4.3, so handle these specially...
tokens = authenticate(
url=self.auth_url or self.rep_url,
url=self.auth_url or self.url,
realm=self.realm,
grant_type="client_credentials",
scope=self.scope,
Expand All @@ -208,7 +223,7 @@ def refresh_access_token(self):
else:
# Other workflows for authentication generally support refresh_tokens
tokens = authenticate(
url=self.auth_url or self.rep_url,
url=self.auth_url or self.url,
realm=self.realm,
grant_type="refresh_token",
scope=self.scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def create_session(
verify: Union[bool, str] = True,
disable_security_warnings=False,
) -> requests.Session:
"""Returns a :class:`requests.Session` object configured for REP with given access token
"""Returns a :class:`requests.Session` object configured for HPS with given access token

Parameters
----------
access_token : str
The access token provided by :meth:`ansys.rep.client.auth.authenticate`
The access token provided by :meth:`ansys.hps.client.auth.authenticate`
verify: Union[bool, str], optional
Either a boolean, in which case it controls whether we verify the
server's TLS certificate, or a string, in which case it must be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@
from requests.exceptions import RequestException


class REPError(RequestException):
class HPSError(RequestException):
def __init__(self, *args, **kwargs):
"""Base class for all rep related errors.
Derives from :class:`requests.exceptions.RequestException`.

Example:
>>> from ansys.rep.client import REPError
>>> from ansys.rep.client.jms import Client
>>> from ansys.hps.client import HPSError
>>> from ansys.hps.client.jms import Client
>>> try:
>>> client = Client(rep_url="https://127.0.0.1:8443/rep/",
username="repadmin",
password="wrong_psw")
>>> except REPError as e:
>>> except HPSError as e:
>>> print(e)
401 Client Error: invalid_grant for: POST https://127.0.0.1:8443/rep/auth...
Invalid user credentials
"""
self.reason = kwargs.pop("reason", None)
self.description = kwargs.pop("description", None)
super(REPError, self).__init__(*args, **kwargs)
super(HPSError, self).__init__(*args, **kwargs)


class APIError(REPError):
class APIError(HPSError):
def __init__(self, *args, **kwargs):
"""Indicate server side related errors."""
super(APIError, self).__init__(*args, **kwargs)


class ClientError(REPError):
class ClientError(HPSError):
def __init__(self, *args, **kwargs):
"""Indicate client side related errors."""
super(ClientError, self).__init__(*args, **kwargs)
Expand Down
File renamed without changes.
Loading