diff --git a/Makefile b/Makefile index 2f32ad8..9f3fab3 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ clean: rm -rf ./build rm -rf ./docs/_build rm -rf ./dist - rm -rf ./cortex_python.egg-info - rm -rf ./cortex-python.docs.tgz + rm -rf ./sensa_python.egg-info + rm -rf ./sensa-python.docs.tgz dev.install: pip install -r requirements-dev.txt @@ -21,7 +21,7 @@ else build: build.release endif docker: - docker build -t c12e/cortex-python . + docker build -t c12e/sensa-python . build.alpha: clean python setup.py egg_info --tag-build a$(shell \ @@ -41,8 +41,8 @@ build.release: clean python setup.py sdist bdist_wheel dev.test: - pylint --recursive=y cortex - pytest --cache-clear --html=coverage/test-report.html --self-contained-html --cov=cortex/ --cov-report=html:coverage --cov-report=term test/unit + pylint --recursive=y sensa + pytest --cache-clear --html=coverage/test-report.html --self-contained-html --cov=sensa/ --cov-report=html:coverage --cov-report=term test/unit test: tox -r # tox runs make dev.test internally diff --git a/README.md b/README.md index 588773b..b213306 100644 --- a/README.md +++ b/README.md @@ -4,26 +4,26 @@ The Cortex Python module provides an API client library to easily integrate with Refer to the Cortex documentation for details on how to use the library: - Developer guide: https://cognitivescale.github.io/cortex-fabric/ -- Cortex Python references: https://cognitivescale.github.io/cortex-python/master/ +- Cortex Python references: https://cognitivescale.github.io/sensa-python/master/ ## Installation To install: ``` - > pip install cortex-python + > pip install sensa-python ``` or from source code: ``` - > git clone git@github.com:CognitiveScale/cortex-python.git - > cd cortex-python + > git clone git@github.com:CognitiveScale/sensa-python.git + > cd sensa-python > pip install -e . ``` To install the optional components: ``` - > pip install cortex-python[viz] - > pip install cortex-python[jupyter] + > pip install sensa-python[viz] + > pip install sensa-python[jupyter] ``` ## Development @@ -39,8 +39,8 @@ When developing, it's a best practice to work in a virtual environment. Create a Install developer dependencies: ``` - > git clone git@github.com:CognitiveScale/cortex-python.git - > cd cortex-python + > git clone git@github.com:CognitiveScale/sensa-python.git + > cd sensa-python > make dev.install ``` @@ -70,7 +70,7 @@ To run an individual file or class method, use pytest. Example tests shown below Suppose you want to release new functionality so it can be installed without releasing a new official version. We need to use an alpha version in PyPi. - we need to create and publish an alpha release: -- get credentials to the `cortex-python` pypi CognitiveScale account (via lastpass) +- get credentials to the `sensa-python` pypi CognitiveScale account (via lastpass) - run `make dev.push`. The alpha pre-release number (the N in X.Y.ZaN) with be determined automatically. ### Contribution @@ -120,4 +120,4 @@ The documentation will be rendered in HTML format under the `docs/_build/${VERSI - [ ] Update all documentation with proper Sphinx formatting - [x] Most of the major modules have been fixed except skill.py, model.py - [x] use exceptions defined in `cortex/exceptions.py` -- [ ] integrate the cortex-python-profiles package back into the python SDK \ No newline at end of file +- [ ] integrate the sensa-python-profiles package back into the python SDK \ No newline at end of file diff --git a/cortex-python.gocd.yaml b/cortex-python.gocd.yaml index 738a433..9d46060 100644 --- a/cortex-python.gocd.yaml +++ b/cortex-python.gocd.yaml @@ -4,15 +4,15 @@ common: coverage: testoutput/coverage/index.html test-report: testoutput/coverage/test-report.html pipelines: - cortex-python-pr: + sensa-python-pr: group: pull-requests materials: - cortex-python: + sensa-python: plugin_configuration: id: github.pr version: 1 options: - url: git@github.com:CognitiveScale/cortex-python.git + url: git@github.com:CognitiveScale/sensa-python.git defaultBranch: develop environment_variables: ALPHA_BUILD: "true" @@ -28,11 +28,11 @@ pipelines: elastic_profile_id: gocd-test-agent-dind tasks: - script: c12e-ci -l - cortex-python-develop: + sensa-python-develop: group: fabric6 materials: - cortex-python: - git: git@github.com:CognitiveScale/cortex-python.git + sensa-python: + git: git@github.com:CognitiveScale/sensa-python.git branch: develop environment_variables: ALPHA_BUILD: "true" @@ -51,7 +51,7 @@ pipelines: set -eux git clone git@github.com:CognitiveScale/gocd-pipeline-scripts.git ./gocd-pipeline-scripts/common/c12e-common.sh dev - cortex-python-staging: + sensa-python-staging: group: fabric6 environment_variables: ALPHA_BUILD: "true" @@ -62,8 +62,8 @@ pipelines: # LastPass: Shared-devops/Pypi REPO_PASSWORD: "AES:VK48nn/zr+mFTMixYa8Psg==:P+AZlJmgChiMcFRyNRmjuwYqBQwkc1hRP8zHck5L5SU=" materials: - cortex-python: - git: git@github.com:CognitiveScale/cortex-python.git + sensa-python: + git: git@github.com:CognitiveScale/sensa-python.git branch: staging stages: - build: @@ -77,7 +77,7 @@ pipelines: git clone git@github.com:CognitiveScale/gocd-pipeline-scripts.git ./gocd-pipeline-scripts/common/c12e-common.sh staging ./gocd-pipeline-scripts/cortex5/python/publish-distribution.sh -i -e - cortex-python-master: + sensa-python-master: group: fabric6 environment_variables: ALPHA_BUILD: "false" @@ -88,8 +88,8 @@ pipelines: # LastPass: Shared-devops/Pypi REPO_PASSWORD: "AES:VK48nn/zr+mFTMixYa8Psg==:P+AZlJmgChiMcFRyNRmjuwYqBQwkc1hRP8zHck5L5SU=" materials: - cortex-python-master: - git: git@github.com:CognitiveScale/cortex-python.git + sensa-python-master: + git: git@github.com:CognitiveScale/sensa-python.git branch: main stages: - build: @@ -100,7 +100,7 @@ pipelines: elastic_profile_id: gocd-test-agent-dind artifacts: - build: - source: cortex-python.docs.tgz + source: sensa-python.docs.tgz - test: source: coverage tasks: @@ -118,11 +118,11 @@ pipelines: elastic_profile_id: gocd-test-agent-dind tasks: - fetch: - pipeline: cortex-python-master + pipeline: sensa-python-master stage: build job: build - source: cortex-python.docs.tgz + source: sensa-python.docs.tgz is_file: yes - script: | git clone git@github.com:CognitiveScale/gocd-pipeline-scripts.git - ./gocd-pipeline-scripts/common/publish-gh-pages.sh -d cortex-python.docs.tgz -r git@github.com:CognitiveScale/cortex-python.git -b ${GH_PAGES_BRANCH} -k .nojekyll + ./gocd-pipeline-scripts/common/publish-gh-pages.sh -d sensa-python.docs.tgz -r git@github.com:CognitiveScale/sensa-python.git -b ${GH_PAGES_BRANCH} -k .nojekyll diff --git a/cortex/__version__.py b/cortex/__version__.py deleted file mode 100644 index 17ab878..0000000 --- a/cortex/__version__.py +++ /dev/null @@ -1,11 +0,0 @@ -""" -Metadata for cortex-python -""" -__title__ = "cortex-python" -__description__ = "Python module for the CognitiveScale Cortex Cognitive Platform" -__url__ = "https://github.com/CognitiveScale/cortex-python" -__version__ = "6.4.0" -__author__ = "CognitiveScale" -__author_email__ = "support@cognitivescale.com" -__license__ = "Apache 2.0" -__copyright__ = "Copyright 2023 Cognitive Scale, Inc. All Rights Reserved." diff --git a/docs/index.html b/docs/index.html index a487271..3fff25d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,9 +2,9 @@ Cortex Python - + -

Please wait while you're redirected to our documentation.

+

Please wait while you're redirected to our documentation.

diff --git a/docs/index.rst b/docs/index.rst index 9d84d85..d080f03 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -120,14 +120,14 @@ See the `Cortex Fabric documentation. `_ +See the `Cortex Python Builders Reference documentation. `_ Cortex Python Profiles ------------------------- -The cortex-python-profiles library is an add-on for use with the base cortex-python library that helps with building and managing Profile-of-One profiles and schemas. +The sensa-python-profiles library is an add-on for use with the base sensa-python library that helps with building and managing Profile-of-One profiles and schemas. -See the `Cortex Python Profiles Reference documentation. `_ +See the `Cortex Python Profiles Reference documentation. `_ diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index 4ad6fcc..bf83c13 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -5,6 +5,6 @@ sphinx-rtd-theme==1.0.0 sphinxcontrib-restbuilder==0.3 nbconvert==6.5.3 -## This is a dependency from cortex-python (pre-v6.1.0) that was removed, but it must be installed in the environment +## This is a dependency from sensa-python (pre-v6.1.0) that was removed, but it must be installed in the environment ## to build docs for earlier versions of the library. ##pyjwt>=1.6.1,<2 diff --git a/local/README.md b/local/README.md index 4716853..f52979c 100644 --- a/local/README.md +++ b/local/README.md @@ -1,6 +1,6 @@ ### Setup proxy with script to intercept internal API calls -Follow [this](https://docs.mitmproxy.org/stable/overview-installation/#installation-from-the-python-package-index-pypi) to install mitmproxy using pipx to be able to run scripts with cortex-python library +Follow [this](https://docs.mitmproxy.org/stable/overview-installation/#installation-from-the-python-package-index-pypi) to install mitmproxy using pipx to be able to run scripts with sensa-python library Run mitmproxy with the proxy [python script](proxy_cortex_internal.py) diff --git a/local/proxy_cortex_internal.py b/local/proxy_cortex_internal.py index 7f55b71..e213254 100644 --- a/local/proxy_cortex_internal.py +++ b/local/proxy_cortex_internal.py @@ -15,7 +15,7 @@ """ from mitmproxy import http -from cortex.client import Cortex +from sensa.client import Sensa import json import re import os @@ -51,7 +51,7 @@ def request(flow: http.HTTPFlow) -> None: - if "cortex.svc.cluster.local" in flow.request.pretty_url: + if "sensa.svc.cluster.local" in flow.request.pretty_url: if "/internal" in flow.request.pretty_url: if "/connections" in flow.request.pretty_url: try: @@ -63,7 +63,7 @@ def request(flow: http.HTTPFlow) -> None: cortex_project = re.search( "/projects/(.*)/connections/", flow.request.pretty_url ).group(1) - client = Cortex.client( + client = Sensa.client( api_endpoint=cortex_endpoint, project=cortex_project, token=cortex_token, @@ -127,5 +127,5 @@ def request(flow: http.HTTPFlow) -> None: ) else: flow.request.url = flow.request.pretty_url.replace( - "http://cortex-internal.cortex.svc.cluster.local", cortex_endpoint + "http://cortex-internal.sensa.svc.cluster.local", cortex_endpoint ) diff --git a/migration.md b/migration.md index 1dac74a..06fe4c8 100644 --- a/migration.md +++ b/migration.md @@ -1,10 +1,14 @@ +# Note + +Users of `cortex-python` should install `sensa-python` instead. + # Migration steps from `cortex-client` to `cortex-python` -The `cortex-python` library and its optional add-ons are replacing the cortex-client library. The new libraries are more lightweight and use-case focussed. `Cortex-python` may be used for development with or without the add-ons. +The `cortex-python` library and its optional add-ons are replacing the cortex-client library. The new libraries are more lightweight and use-case focussed. `Sensa-python` may be used for development with or without the add-ons. ## Uninstall the previous library (`cortex-client`) -To use the new Cortex libraries, `cortex-python` and `cortex-python-builders` you must uninstall the `cortex-client` library; `cortex-client` and `cortex-python`**cannot** be installed simultaneously in your python environment. +To use the new Sensa libraries, `cortex-python` and `cortex-python-builders` you must uninstall the `cortex-client` library; `cortex-client` and `cortex-python`**cannot** be installed simultaneously in your python environment. ``` > pip uninstall cortex-client @@ -49,9 +53,9 @@ To import ManagedContentClient: ``` ConnectionClient can be used to save and retrieve connections. -## Use Cortex magics +## Use Sensa magics -Cortex magics can be used only when the optional `builders` dependency is installed: +Sensa magics can be used only when the optional `builders` dependency is installed: ``` > %reload_ext cortex_builders @@ -71,15 +75,15 @@ class to run experiments, save and retrieve your models. Also, you can use the `action` in the builder class inside client class to build your actions. (Can be used only when optional dependency of builders is installed) 4. `SecretsClient` has been deprecated. There is no equivalent replacement functionality in the python library, but -you can manage secrets through the Cortex Vault in the Cortex Console or via the CLI `cortex variables [command] [options]`. +you can manage secrets through the Sensa Vault in the Sensa Console or via the CLI `cortex variables [command] [options]`. 5. `Message.with_payload()` has been removed. This method was previously deprecated in `cortex-client` v5.5.4. Instead, use the `Client.message()` method: ``` -> from cortex.client import Cortex +> from cortex.client import Sensa -> cortex = Cortex.client() +> cortex = Sensa.client() > message = cortex.message(payload={'value': 'hello world'}) ``` diff --git a/cortex/__init__.py b/sensa/__init__.py similarity index 100% rename from cortex/__init__.py rename to sensa/__init__.py diff --git a/sensa/__version__.py b/sensa/__version__.py new file mode 100644 index 0000000..3f07041 --- /dev/null +++ b/sensa/__version__.py @@ -0,0 +1,11 @@ +""" +Metadata for sensa-python +""" +__title__ = "sensa-python" +__description__ = "Python module for the TecnoTree Sensa Platform" +__url__ = "https://github.com/CognitiveScale/sensa-python" +__version__ = "6.4.0" +__author__ = "TecnoTree" +__author_email__ = "TBD?" # TODO: Add TecnoTree's author email +__license__ = "Apache 2.0" +__copyright__ = "TecnoTree LLC. All Rights Reserved." diff --git a/cortex/auth.py b/sensa/auth.py similarity index 96% rename from cortex/auth.py rename to sensa/auth.py index 413c882..aa2407a 100644 --- a/cortex/auth.py +++ b/sensa/auth.py @@ -23,7 +23,7 @@ class AuthenticationClient(_Client): """Client authentication. - :param _Client: :py:class:`cortex.serviceconnector._Client` + :param _Client: :py:class:`sensa.serviceconnector._Client` :type _Client: _type_ :return: Instance of AuthenticationClient :rtype: AuthenticationClient diff --git a/cortex/camel.py b/sensa/camel.py similarity index 100% rename from cortex/camel.py rename to sensa/camel.py diff --git a/cortex/client.py b/sensa/client.py similarity index 64% rename from cortex/client.py rename to sensa/client.py index 27a239c..e778886 100644 --- a/cortex/client.py +++ b/sensa/client.py @@ -27,7 +27,7 @@ from .types import TypeClient from .experiment import ExperimentClient from .serviceconnector import ServiceConnector -from .env import CortexEnv +from .env import SensaEnv from .exceptions import ( ProjectException, InvalidMessageTypeException, @@ -67,40 +67,40 @@ def token(self) -> str: class Client: """ - API client used to access Connections, Managed Content, Experiments, Secrets, Models, Sessions, Skills and Types in a Fabric cluster. Experiments also have a `local client` (:class:`cortex.experiment.local.LocalExperiment`) for data scientists to work without access to a Fabric cluster. + API client used to access Connections, Managed Content, Experiments, Secrets, Models, Sessions, Skills and Types in a Fabric cluster. Experiments also have a `local client` (:class:`sensa.experiment.local.LocalExperiment`) for data scientists to work without access to a Fabric cluster. - Create an instance of the Cortex Fabric client. There are a few different ways in which you can instantiate a Client + Create an instance of the Sensa Fabric client. There are a few different ways in which you can instantiate a Client - 1. If the user has the Cortex CLI installed and configured to a Fabric environment, AND a default project is set, they can do the following: + 1. If the user has the Sensa CLI installed and configured to a Fabric environment, AND a default project is set, they can do the following: - >>> from cortex.client import Cortex; client = Cortex.client() + >>> from sensa.client import Sensa; client = Sensa.client() - 2. If the user has the Cortex CLI installed and configured, but a default project is not set: + 2. If the user has the Sensa CLI installed and configured, but a default project is not set: - >>> from cortex.client import Cortex; client = Cortex.client(project="some-project") + >>> from sensa.client import Sensa; client = Sensa.client(project="some-project") - 3. If the user does not have the Cortex CLI installed, or is using the cortex-python package from within a Skill (Daemon) running inside a Fabric cluster, they can simply extract the required parameters from the request object and create a Cortex client like below: + 3. If the user does not have the Sensa CLI installed, or is using the sensa-python package from within a Skill (Daemon) running inside a Fabric cluster, they can simply extract the required parameters from the request object and create a Sensa client like below: .. code-block:: - from cortex.client import Cortex + from sensa.client import Sensa @app.post('/invoke') def start(req: dict): payload = req['payload'] - client = Cortex.client(api_endpoint=req["apiEndpoint"], project=req["projectId"], token=req["token"]) + client = Sensa.client(api_endpoint=req["apiEndpoint"], project=req["projectId"], token=req["token"]) client.experiments.list_experiments() .... - 4. If the user does not have the Cortex CLI installed, or is using the cortex-python package from within a **Skill(Job)** running inside a Fabric cluster, they can simply pass the `params` object passed into the Job script and create a Cortex client: + 4. If the user does not have the Sensa CLI installed, or is using the sensa-python package from within a **Skill(Job)** running inside a Fabric cluster, they can simply pass the `params` object passed into the Job script and create a Sensa client: .. code-block:: python # contents of main.py for a Skill (job) - from cortex.client import Cortex + from sensa.client import Sensa def main(params): - client = Cortex.from_message(params) + client = Sensa.from_message(params) if __name__ == "__main__": if len(sys.argv)<2: @@ -110,7 +110,7 @@ def main(params): main(json.loads(sys.argv[-1])) - :param url: Cortex fabric url + :param url: Sensa fabric url :param token: (optional) Use JWT token to authenticate requests, will default to settings in ~/.cortex/config if not provided to generate JWT tokens :param project: (optional) Project name, must specify project for each request :param version: (optional) Fabric API version (default: 4) @@ -186,37 +186,37 @@ def _repr_pretty_(self, p, cycle): @property def experiments(self) -> ExperimentClient: - """Returns a pre-initialised ExperimentClient whose project has been set to the project configured for the Cortex.client. + """Returns a pre-initialised ExperimentClient whose project has been set to the project configured for the Sensa.client. If you want to access experiments for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.experiments_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.experiments_client` instead .. code-block:: ## use default .experiments client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.experiments.list_experiments() client.experiments.save_experiment() client.experiments.list_runs() client.experiments.delete_runs() - Refer to the documentation of :class:`cortex.experiment.ExperimentClient` to learn more about the methods available on the ExperimentClient + Refer to the documentation of :class:`sensa.experiment.ExperimentClient` to learn more about the methods available on the ExperimentClient :returns: An instance of this helper class that enables access to the Fabric Experiments API. - :rtype: :class:`cortex.experiment.ExperimentClient` + :rtype: :class:`sensa.experiment.ExperimentClient` """ # pylint: disable=line-too-long return self._service_clients.get("experiments") def experiments_client(self, project: str = None) -> ExperimentClient: - """Helper method to create a new :class:`cortex.experiment.ExperimentClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.experiment.ExperimentClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> expc = client.experiments_client(project="another-project") - :param project: Project for which an experiments client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which an experiments client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: An experiment client - :rtype: :class:`cortex.experiment.ExperimentClient` + :rtype: :class:`sensa.experiment.ExperimentClient` """ # pylint: disable=line-too-long if project is not None: return ExperimentClient(project=project) @@ -224,35 +224,35 @@ def experiments_client(self, project: str = None) -> ExperimentClient: @property def connections(self) -> ConnectionClient: - """Returns a pre-initialised ConnectionClient whose project has been set to the project configured for the Cortex.client. + """Returns a pre-initialised ConnectionClient whose project has been set to the project configured for the Sensa.client. If you want to access connections for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.connections_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.connections_client` instead .. code-block:: ## use default .connections client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.connections.save_connection client.connections.get_connection - Refer to the documentation of :class:`cortex.connection.ConnectionClient` to learn more about the methods available on the ConnectionClient + Refer to the documentation of :class:`sensa.connection.ConnectionClient` to learn more about the methods available on the ConnectionClient :returns: An instance of this helper class that enables access to the Fabric Connections API. - :rtype: :class:`cortex.connection.ConnectionClient` + :rtype: :class:`sensa.connection.ConnectionClient` """ # pylint: disable=line-too-long return self._service_clients.get("connections") def connections_client(self, project: str = None) -> ConnectionClient: - """Helper method to create a new :class:`cortex.connection.ConnectionClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.connection.ConnectionClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> connc = client.connections_client(project="another-project") - :param project: Project for which a connections client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which a connections client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: A connection client - :rtype: :class:`cortex.connection.ConnectionClient` + :rtype: :class:`sensa.connection.ConnectionClient` """ # pylint: disable=line-too-long if project is not None: return ConnectionClient(project=project) @@ -260,37 +260,37 @@ def connections_client(self, project: str = None) -> ConnectionClient: @property def content(self) -> ManagedContentClient: - """Returns a pre-initialised ManagedContentClient whose project has been set to the project configured for the Cortex.client. + """Returns a pre-initialised ManagedContentClient whose project has been set to the project configured for the Sensa.client. If you want to access managed content for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.content_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.content_client` instead .. code-block:: ## use default .content client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.content.list client.content.upload client.content.exists ..... - Refer to the documentation of :class:`cortex.content.ManagedContentClient` to learn more about the methods available on the ManagedContentClient + Refer to the documentation of :class:`sensa.content.ManagedContentClient` to learn more about the methods available on the ManagedContentClient :returns: An instance of this helper class that enables access to the Fabric Managed Content API. - :rtype: :class:`cortex.content.ManagedContentClient` + :rtype: :class:`sensa.content.ManagedContentClient` """ # pylint: disable=line-too-long return self._service_clients.get("content") def content_client(self, project: str = None) -> ManagedContentClient: - """Helper method to create a new :class:`cortex.connection.ManagedContentClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.connection.ManagedContentClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> contentc = client.content_client(project="another-project") - :param project: Project for which a managed content client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which a managed content client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: A managed content client - :rtype: :class:`cortex.connection.ManagedContentClient` + :rtype: :class:`sensa.connection.ManagedContentClient` """ # pylint: disable=line-too-long if project is not None: return ManagedContentClient(project=project) @@ -298,37 +298,37 @@ def content_client(self, project: str = None) -> ManagedContentClient: @property def models(self) -> ModelClient: - """Returns a pre-initialised ModelClient whose project has been set to the project configured for the Cortex.client. + """Returns a pre-initialised ModelClient whose project has been set to the project configured for the Sensa.client. If you want to access models for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.models_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.models_client` instead .. code-block:: ## use default .models client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.models.list_models() client.models.get_model() client.models.save_model() ..... - Refer to the documentation of :class:`cortex.model.ModelClient` to learn more about the methods available on the ModelClient + Refer to the documentation of :class:`sensa.model.ModelClient` to learn more about the methods available on the ModelClient :returns: An instance of this helper class that enables access to the Fabric Models API. - :rtype: :class:`cortex.model.ModelClient` + :rtype: :class:`sensa.model.ModelClient` """ # pylint: disable=line-too-long return self._service_clients.get("models") def models_client(self, project: str = None) -> ModelClient: - """Helper method to create a new :class:`cortex.model.ModelClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.model.ModelClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> modelc = client.models_client(project="another-project") - :param project: Project for which a models client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which a models client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: A models client - :rtype: :class:`cortex.model.ModelClient` + :rtype: :class:`sensa.model.ModelClient` """ # pylint: disable=line-too-long if project is not None: return ModelClient(project=project) @@ -336,40 +336,40 @@ def models_client(self, project: str = None) -> ModelClient: @property def secrets(self) -> SecretsClient: - """Returns a pre-initialised SecretsClient whose project has been set to the project configured for the Cortex.client. + """Returns a pre-initialised SecretsClient whose project has been set to the project configured for the Sensa.client. .. important:: - Note that, as of Fabric 6.3.3 and Fabric 6.4.0., you can only call :meth:`cortex.secrets.SecretsClient.get_secret` from within a skill running inside the Fabric cluster (won't work locally) + Note that, as of Fabric 6.3.3 and Fabric 6.4.0., you can only call :meth:`sensa.secrets.SecretsClient.get_secret` from within a skill running inside the Fabric cluster (won't work locally) If you want to access secrets for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.secrets_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.secrets_client` instead .. code-block:: ## use default .secrets client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.models.get_secret() client.models.post_secret() ..... - Refer to the documentation of :class:`cortex.secrets.SecretsClient` to learn more about the methods available on the SecretsClient + Refer to the documentation of :class:`sensa.secrets.SecretsClient` to learn more about the methods available on the SecretsClient :returns: An instance of this helper class that enables access to the Fabric Secrets API. - :rtype: :class:`cortex.secrets.SecretsClient` + :rtype: :class:`sensa.secrets.SecretsClient` """ # pylint: disable=line-too-long return self._service_clients.get("secrets") def secrets_client(self, project: str = None) -> SecretsClient: - """Helper method to create a new :class:`cortex.secrets.SecretsClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.secrets.SecretsClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> secretsc = client.secrets_client(project="another-project") - :param project: Project for which a secrets client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which a secrets client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: A secrets client - :rtype: :class:`cortex.secrets.SecretsClient` + :rtype: :class:`sensa.secrets.SecretsClient` """ # pylint: disable=line-too-long if project is not None: return SecretsClient(project=project) @@ -377,16 +377,16 @@ def secrets_client(self, project: str = None) -> SecretsClient: @property def skills(self) -> SkillClient: - """Returns a pre-initialised SkillClient whose project has been set to the project configured for the Cortex.client.Client + """Returns a pre-initialised SkillClient whose project has been set to the project configured for the Sensa.client.Client If you want to access Skills for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.skills_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.skills_client` instead .. code-block:: ## use default .skills client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.skills.get_skill() client.skills.save_skill() client.skills.delete_skill() @@ -395,22 +395,22 @@ def skills(self) -> SkillClient: client.skills.undeploy() ..... - Refer to the documentation of :class:`cortex.skill.SkillClient` to learn more about the methods available on the SkillClient + Refer to the documentation of :class:`sensa.skill.SkillClient` to learn more about the methods available on the SkillClient :returns: An instance of this helper class that enables access to the Fabric SKills API. - :rtype: :class:`cortex.skill.SkillClient` + :rtype: :class:`sensa.skill.SkillClient` """ # pylint: disable=line-too-long return self._service_clients.get("skills") def skills_client(self, project: str = None) -> SkillClient: - """Helper method to create a new :class:`cortex.skill.SkillClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.skill.SkillClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> skillsc = client.skills_client(project="another-project") - :param project: Project for which a Skill client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which a Skill client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: A Skills client - :rtype: :class:`cortex.skill.SkillClient` + :rtype: :class:`sensa.skill.SkillClient` """ # pylint: disable=line-too-long if project is not None: return SkillClient(project=project) @@ -418,38 +418,38 @@ def skills_client(self, project: str = None) -> SkillClient: @property def sessions(self) -> SessionClient: - """Returns a pre-initialised SessionClient whose project has been set to the project configured for the Cortex.client.Client + """Returns a pre-initialised SessionClient whose project has been set to the project configured for the Sensa.client.Client If you want to access Sessions for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.sessions_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.sessions_client` instead .. code-block:: ## use default .sessions client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.sessions.start_session() client.sessions.get_session_data() client.sessions.put_session_data() client.sessions.delete_session() ..... - Refer to the documentation of :class:`cortex.session.SessionClient` to learn more about the methods available on the SessionClient + Refer to the documentation of :class:`sensa.session.SessionClient` to learn more about the methods available on the SessionClient :returns: An instance of this helper class that enables access to the Fabric Sessions API. - :rtype: :class:`cortex.session.SessionClient` + :rtype: :class:`sensa.session.SessionClient` """ # pylint: disable=line-too-long return self._service_clients.get("sessions") def sessions_client(self, project: str = None) -> SessionClient: - """Helper method to create a new :class:`cortex.session.SessionClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.session.SessionClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> sessionsc = client.sessions_client(project="another-project") - :param project: Project for which a Sessions client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which a Sessions client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: A Sessions client - :rtype: :class:`cortex.session.SessionClient` + :rtype: :class:`sensa.session.SessionClient` """ # pylint: disable=line-too-long if project is not None: return SessionClient(project=project) @@ -457,36 +457,36 @@ def sessions_client(self, project: str = None) -> SessionClient: @property def types(self) -> TypeClient: - """Returns a pre-initialised TypeClient whose project has been set to the project configured for the Cortex.client.Client + """Returns a pre-initialised TypeClient whose project has been set to the project configured for the Sensa.client.Client If you want to access Types for a project that is - different from the one configured with Cortex.client, please use :meth:`cortex.client.Client.types_client` instead + different from the one configured with Sensa.client, please use :meth:`sensa.client.Client.types_client` instead .. code-block:: ## use default .types client helper - from cortex.client import Cortex - client = Cortex.client() + from sensa.client import Sensa + client = Sensa.client() client.types.get_type() client.types.save_type() ..... - Refer to the documentation of :class:`cortex.types.TypeClient` to learn more about the methods available on the TypeClient + Refer to the documentation of :class:`sensa.types.TypeClient` to learn more about the methods available on the TypeClient :returns: An instance of this helper class that enables access to the Fabric Types API. - :rtype: :class:`cortex.types.TypeClient` + :rtype: :class:`sensa.types.TypeClient` """ # pylint: disable=line-too-long return self._service_clients.get("types") def types_client(self, project: str = None) -> TypeClient: - """Helper method to create a new :class:`cortex.types.TypeClient` instance that is configured to talk to another `project` than the default :attr:`cortex.client.Client._project` + """Helper method to create a new :class:`sensa.types.TypeClient` instance that is configured to talk to another `project` than the default :attr:`sensa.client.Client._project` >>> typesc = client.types_client(project="another-project") - :param project: Project for which a Types client is to be created, defaults to (the project configured with cortex.client.Client) + :param project: Project for which a Types client is to be created, defaults to (the project configured with sensa.client.Client) :type project: str, optional :return: A Types client - :rtype: :class:`cortex.types.TypeClient` + :rtype: :class:`sensa.types.TypeClient` """ # pylint: disable=line-too-long if project is not None: return TypeClient(project=project) @@ -495,7 +495,7 @@ def types_client(self, project: str = None) -> TypeClient: class Local: """ - Provides local, on-disk implementations of Cortex APIs. + Provides local, on-disk implementations of Sensa APIs. """ def __init__(self, basedir=None): @@ -503,7 +503,7 @@ def __init__(self, basedir=None): def experiment(self, name: str) -> LocalExperiment: """ - Create an experiment without connecting to Cortex fabric + Create an experiment without connecting to Sensa fabric :param name: Experiment name :return: Experiment instance """ @@ -511,7 +511,7 @@ def experiment(self, name: str) -> LocalExperiment: @property def basedir(self): - """Return the configured base directory of this :class:`cortex.client.Local` instance + """Return the configured base directory of this :class:`sensa.client.Local` instance :return: configured base directory :rtype: _type_ @@ -519,9 +519,9 @@ def basedir(self): return self._basedir -class Cortex: +class Sensa: """ - Entry point to the Cortex API. + Entry point to the Sensa API. """ @staticmethod @@ -535,30 +535,30 @@ def client( profile: str = None, ) -> Client: """ - Gets a client with the provided parameters. All parameters are optional and default to environment variable values if not specified. Client creation can fail if you don't have a default project set in your environment variables or the Cortex config file. + Gets a client with the provided parameters. All parameters are optional and default to environment variable values if not specified. Client creation can fail if you don't have a default project set in your environment variables or the Sensa config file. .. important:: - You can also set a default project when configuring your Cortex CLI using `cortex configure --project `. + You can also set a default project when configuring your Sensa CLI using `cortex configure --project `. - This value will be updated into the `$HOME/.cortex/config` file. If your Cortex config file `$HOME/.cortex/config` does not contain a default `project` set for the profile being used as the default one, you will need to set the project key when instantiating a :class:`cortex.client.Client`. + This value will be updated into the `$HOME/.cortex/config` file. If your Sensa config file `$HOME/.cortex/config` does not contain a default `project` set for the profile being used as the default one, you will need to set the project key when instantiating a :class:`sensa.client.Client`. **Example** - >>> from cortex.client import Cortex - >>> cortex = Cortex.client(project='example-project') + >>> from sensa.client import Sensa + >>> sensa = Sensa.client(project='example-project') - :param api_endpoint: The Cortex URL. + :param api_endpoint: The Sensa URL. :param api_version: The version of the API to use with this client. :param verify_ssl_cert: A boolean to enable/disable SSL validation, or path to a CA_BUNDLE file or directory with certificates of trusted CAs (default: True) - :param project: Cortex Project that you want to use. + :param project: Sensa Project that you want to use. :param token: (optional) Use JWT token for authenticating requests, will default to settings in ~/.cortex/config if not provided - :param config: (optional) Use Cortex personal access token config file to generate JWT tokens. + :param config: (optional) Use Sensa personal access token config file to generate JWT tokens. - :returns: An instance of :class:`cortex.client.Client` - :rtype: :class:`cortex.client.Client` + :returns: An instance of :class:`sensa.client.Client` + :rtype: :class:`sensa.client.Client` """ # pylint: disable=line-too-long - env = CortexEnv( + env = SensaEnv( api_endpoint=api_endpoint, token=token, config=config, @@ -580,7 +580,7 @@ def client( if not project: raise ProjectException( - "Please Provide Project Name that you want to access Cortex Assets for" + "Please Provide Project Name that you want to access Sensa Assets for" ) tkn = _Token(token) @@ -596,17 +596,17 @@ def client( @staticmethod def from_message(msg, verify_ssl_cert=None) -> Client: - """Creates a Cortex client from a skill's input message, expects + """Creates a Sensa client from a skill's input message, expects .. code-block:: { api_endpoint:"..", token:"..", projectId:".."} - :param msg: A message for constructing a Cortex Client. + :param msg: A message for constructing a Sensa Client. :param verify_ssl_cert: A boolean to enable/disable SSL validation, or path to a CA_BUNDLE file or directory with certificates of trusted CAs (default: True) - :returns: A Cortex Client - :rtype: :class:`cortex.client.Client` + :returns: A Sensa Client + :rtype: :class:`sensa.client.Client` """ # pylint: disable=line-too-long if not isinstance(msg, dict): raise InvalidMessageTypeException( @@ -617,7 +617,7 @@ def from_message(msg, verify_ssl_cert=None) -> Client: raise IncompleteMessageKeysException( f"Skill message must contain these keys: {keys}" ) - return Cortex.client( + return Sensa.client( api_endpoint=msg.get("apiEndpoint"), token=msg.get("token"), project=msg.get("projectId"), @@ -626,27 +626,27 @@ def from_message(msg, verify_ssl_cert=None) -> Client: @staticmethod def local(basedir=None): - """Create a Local Cortex implementation (mock) + """Create a Local Sensa implementation (mock) :param basedir: Root filesystem location, defaults to None :type basedir: str, optional - :return: an instance of :class:`cortex.client.Local` - :rtype: :class:`cortex.client.Local` + :return: an instance of :class:`sensa.client.Local` + :rtype: :class:`sensa.client.Local` """ return Local(basedir) @staticmethod def login(): """ - Login to Cortex6. The function prompts the caller for Cortex Personal Access Config. + Login to Sensa6. The function prompts the caller for Sensa Personal Access Config. **Example** - >>> Cortex.login() - Cortex Personal Access Config: Cortex Personal Access Config - Cortex Project: The project that you to start using you Cortex assets from. (Not required) + >>> Sensa.login() + Sensa Personal Access Config: Sensa Personal Access Config + Sensa Project: The project that you to start using you Sensa assets from. (Not required) """ - config = input("Cortex Personal Access Config: ") + config = input("Sensa Personal Access Config: ") project = input("Project: ") os.environ["CORTEX_PERSONAL_ACCESS_CONFIG"] = config if project: diff --git a/cortex/connection.py b/sensa/connection.py similarity index 100% rename from cortex/connection.py rename to sensa/connection.py diff --git a/cortex/constant.py b/sensa/constant.py similarity index 100% rename from cortex/constant.py rename to sensa/constant.py diff --git a/cortex/content.py b/sensa/content.py similarity index 98% rename from cortex/content.py rename to sensa/content.py index cb1add9..62606aa 100644 --- a/cortex/content.py +++ b/sensa/content.py @@ -36,9 +36,9 @@ class ManagedContentClient(_Client): """ - A client used to access the `Cortex managed content service (blob store) `_. You can find a pre-created instance of this class on every :py:class:`cortex.client.Client` instance via the :py:attr:`Client.content` attribute. + A client used to access the `Cortex managed content service (blob store) `_. You can find a pre-created instance of this class on every :py:class:`sensa.client.Client` instance via the :py:attr:`Client.content` attribute. - >>> from cortex.client import Cortex; client = Cortex.client(); + >>> from sensa.client import Sensa; client = Sensa.client(); >>> client.content.list() # list content from the default project configured for the user """ # pylint: disable=line-too-long diff --git a/cortex/env.py b/sensa/env.py similarity index 60% rename from cortex/env.py rename to sensa/env.py index 75b4c6f..1b38cec 100644 --- a/cortex/env.py +++ b/sensa/env.py @@ -16,7 +16,7 @@ import os import json -from .utils import get_cortex_profile +from .utils import get_sensa_profile from .exceptions import BadTokenException @@ -26,7 +26,7 @@ ) -class CortexEnv: +class SensaEnv: """ Sets environment variables for Cortex. """ @@ -39,45 +39,45 @@ def __init__( project: str = None, profile: str = None, ): - profile_inst = CortexEnv.get_cortex_profile(profile) + profile_inst = SensaEnv.get_sensa_profile(profile) - cortex_token = token or os.getenv("CORTEX_TOKEN") - cortex_config = config or json.loads( + sensa_token = token or os.getenv("CORTEX_TOKEN") + sensa_config = config or json.loads( os.getenv("CORTEX_PERSONAL_ACCESS_CONFIG", json.dumps(profile_inst)) ) - if not cortex_token and not cortex_config: + if not sensa_token and not sensa_config: raise BadTokenException(BAD_TOKEN_MSG) self.api_endpoint = api_endpoint or os.getenv( - "CORTEX_URL", cortex_config.get("url", None) + "CORTEX_URL", sensa_config.get("url", None) ) - self.token = cortex_token - self.config = cortex_config + self.token = sensa_token + self.config = sensa_config self.project = project or os.getenv( - "CORTEX_PROJECT", cortex_config.get("project", None) + "CORTEX_PROJECT", sensa_config.get("project", None) ) @staticmethod def get_token(): """ - gets the token from either the cortex_token env variable or the profile's token. - if cortex_token and both cortex_profile are falsey, then cortexToken will be None + gets the token from either the sensa_token env variable or the profile's token. + if sensa_token and both sensa_profile are falsey, then sensaToken will be None """ - cortex_token = ( - CortexEnv.get_cortex_token() or CortexEnv.get_cortex_profile().get("token") + sensa_token = ( + SensaEnv.get_sensa_token() or SensaEnv.get_sensa_profile().get("token") ) - return cortex_token + return sensa_token @staticmethod - def get_cortex_profile(profile: str = None): + def get_sensa_profile(profile: str = None): """ - gets the configured cortex profile from the local machine + gets the configured sensa profile from the local machine """ - return get_cortex_profile(profile) + return get_sensa_profile(profile) @staticmethod - def get_cortex_token() -> str: + def get_sensa_token() -> str: """ - gets the cortex token from the local machine + gets the sensa token from the local machine """ return os.getenv("CORTEX_TOKEN") diff --git a/cortex/exceptions.py b/sensa/exceptions.py similarity index 82% rename from cortex/exceptions.py rename to sensa/exceptions.py index d46b9b8..22a6c52 100644 --- a/cortex/exceptions.py +++ b/sensa/exceptions.py @@ -28,7 +28,7 @@ class AuthenticationException(CortexException): class InvalidMessageTypeException(CortexException): - """This exception is thrown when the :class:`cortex.message.Message` instance is invalid + """This exception is thrown when the :class:`sensa.message.Message` instance is invalid :type Exception: Exception """ @@ -70,15 +70,15 @@ class ProjectException(CortexException): class VisualisationException(CortexException): - """Indicates missing dependent packages when using the cortex-python package inside a jupyter notebook""" # pylint: disable=line-too-long + """Indicates missing dependent packages when using the sensa-python package inside a jupyter notebook""" # pylint: disable=line-too-long class UpdateRunException(CortexException): - """Raised when the :meth:`cortex.experiment.ExperimentClient.update_run` method fails""" + """Raised when the :meth:`sensa.experiment.ExperimentClient.update_run` method fails""" class DeleteRunException(CortexException): - """Raised when the :meth:`cortex.experiment.ExperimentClient.delete_run` method fails""" + """Raised when the :meth:`sensa.experiment.ExperimentClient.delete_run` method fails""" class AuthenticationHeaderError(Exception): diff --git a/cortex/experiment/__init__.py b/sensa/experiment/__init__.py similarity index 100% rename from cortex/experiment/__init__.py rename to sensa/experiment/__init__.py diff --git a/cortex/experiment/local.py b/sensa/experiment/local.py similarity index 97% rename from cortex/experiment/local.py rename to sensa/experiment/local.py index 421cbf5..bebfa1c 100644 --- a/cortex/experiment/local.py +++ b/sensa/experiment/local.py @@ -78,7 +78,7 @@ def name(self) -> str: def start_run(self) -> Run: """Creates a run for the experiment. - :rtype: :class:`cortex.experiment.model.Run` + :rtype: :class:`sensa.experiment.model.Run` """ return Run(self) @@ -86,7 +86,7 @@ def save_run(self, run: Run) -> None: """Saves a run. :param run: The run you want to save. - :type run: :class:`cortex.experiment.model.Run` + :type run: :class:`sensa.experiment.model.Run` :rtype: None """ @@ -156,7 +156,7 @@ def get_run(self, run_id: str) -> Run: :param run_id: Identifier of the run to be fetched :type run_id: str - :rtype: :class:`cortex.experiment.model.Run` + :rtype: :class:`sensa.experiment.model.Run` """ for run in self.runs(): if run.id == run_id: @@ -237,5 +237,5 @@ def display(self): except ImportError as exc: raise ConfigurationException( "The ipython package is required, please install it" - "using pip install cortex-python[viz]" + "using pip install sensa-python[viz]" ) from exc diff --git a/cortex/experiment/model.py b/sensa/experiment/model.py similarity index 98% rename from cortex/experiment/model.py rename to sensa/experiment/model.py index ed4c2cc..6a5cf88 100644 --- a/cortex/experiment/model.py +++ b/sensa/experiment/model.py @@ -184,9 +184,9 @@ def from_json(json: dict, experiment): :param json: The json representation of the run. :type json: dict :param experiment: The experiment to associate with the run. - :type experiment: :class:`cortex.experiment.Experiment` + :type experiment: :class:`sensa.experiment.Experiment` :return: A run that has the values in the given json object with the given experiment. - :rtype: :class:`cortex.experiment.model.Run` + :rtype: :class:`sensa.experiment.model.Run` """ run = Run(experiment) run._id = json["id"] @@ -276,7 +276,7 @@ def _to_html(exp): except (ImportError, NameError) as exc: raise ConfigurationException( "The jupyter extras are required to use this," - 'please install using "pip install cortex-python[viz]"' + 'please install using "pip install sensa-python[viz]"' ) from exc runs = exp.runs() diff --git a/cortex/experiment/remote.py b/sensa/experiment/remote.py similarity index 93% rename from cortex/experiment/remote.py rename to sensa/experiment/remote.py index 398e885..cea9c77 100644 --- a/cortex/experiment/remote.py +++ b/sensa/experiment/remote.py @@ -39,9 +39,9 @@ class ExperimentClient(_Client): """ - A client for the `Cortex experiment and model management API `_. You can find a pre-created instance of this class on every :class:`cortex.client.Client` instance via the :attr:`Client.experiments` attribute. + A client for the `Cortex experiment and model management API `_. You can find a pre-created instance of this class on every :class:`sensa.client.Client` instance via the :attr:`Client.experiments` attribute. - >>> from cortex.client import Cortex; client = Cortex.client(); + >>> from sensa.client import Sensa; client = Sensa.client(); >>> client.experiments.list_experiments() # list experiments from the default project configured for the user """ # pylint: disable=line-too-long @@ -67,7 +67,7 @@ class ExperimentClient(_Client): def list_experiments(self) -> List[Dict]: """Returns a list of experiments available on the project configured for the experiment client. - >>> from cortex.client import Cortex; cc=Cortex.client() + >>> from sensa.client import Sensa; cc=Sensa.client() >>> cc.experiments.list_experiments() [{'_version': 2, 'name': 'op-gc_dtree_exp', 'title': 'Decision Tree model', 'description': 'Decision Tree model', 'meta': None, 'tags': [], 'modelId': 'op-german-credit', 'updatedAt': '2023-01-24T10:21:01.347Z', 'createdAt': '2023-01-24T10:11:16.445Z'}] @@ -85,7 +85,7 @@ def list_experiments(self) -> List[Dict]: def save_experiment(self, experiment_name: str, model_id=None, **kwargs) -> Dict: """Save an experiment with the provided `experiment_name`, and `modelId`. All the fields specified in the `API reference for Cortex Experiments `_ (except name and modelId) can be passed in as keyword args to this method - >>> from cortex.client import Cortex; cc=Cortex.client() + >>> from sensa.client import Sensa; cc=Sensa.client() >>> cc.experiments.save_experiment('exp-name', 'juhf') {'_version': 1, 'name': 'exp-name', 'tags': [], '_projectId': 'exp-test', 'modelId': 'juhf'} @@ -116,7 +116,7 @@ def save_experiment(self, experiment_name: str, model_id=None, **kwargs) -> Dict def delete_experiment(self, experiment_name: str) -> bool: """Delete an experiment specified by `experiment_name` - >>> from cortex.client import Cortex; cc=Cortex.client(project='test') + >>> from sensa.client import Sensa; cc=Sensa.client(project='test') >>> cc.experiments.delete_experiment('another') True @@ -137,7 +137,7 @@ def delete_experiment(self, experiment_name: str) -> bool: def get_experiment(self, experiment_name: str) -> Dict: """Retrieve all data for the experiment with name `experiment_name` - >>> from cortex.client import Cortex; cc=Cortex.client() + >>> from sensa.client import Sensa; cc=Sensa.client() >>> cc.experiments.get_experiment('ddgc_dtree_exp') {'_version': 1, 'name': 'ddgc_dtree_exp', 'title': 'Decision Tree model', 'description': 'Decision Tree model', 'tags': [], '_projectId': 'test', 'modelId': 'german-credit-model'} @@ -157,7 +157,7 @@ def get_experiment(self, experiment_name: str) -> Dict: def list_runs(self, experiment_name: str) -> List[Dict]: """`List all the runs `_ that belong to the specified `experiment_name` - >>> from cortex.client import Cortex; cc=Cortex.client() + >>> from sensa.client import Sensa; cc=Sensa.client() >>> cc.experiments.list_runs('op-gc_dtree_exp') [{'_id': '63cfb10ffe65fb07bf8a94b9', '_projectId': 'test', 'runId': 'run_01', 'experimentName': 'op-gc_dtree_exp', 'params': {'category': 'Decision Tree', 'version': 1, 'SourceData': 'Upstream Server Data'}, 'metrics': {'accuracy': 0.68}, 'meta': {'algo': 'DecisionTreeClassifier'}, '_createdAt': '2023-01-24T10:21:03.120Z', '_updatedAt': '2023-01-24T10:21:04.497Z', 'artifacts': {'model': 'experiments/op-gc_dtree_exp/run_01/artifacts/model'}}] @@ -178,9 +178,9 @@ def list_runs(self, experiment_name: str) -> List[Dict]: def find_runs( self, experiment_name: str, filter_obj: Dict, sort: dict = None, limit=25 ) -> List[Dict]: - """Similar to :meth:`cortex.experiment.ExperimentClient.list_runs`, but also allows you to filter with a mongo-style query dictionary passed in through `filter_obj`, along with `sort` and `limit` options + """Similar to :meth:`sensa.experiment.ExperimentClient.list_runs`, but also allows you to filter with a mongo-style query dictionary passed in through `filter_obj`, along with `sort` and `limit` options - >>> from cortex.client import Cortex; cc=Cortex.client() + >>> from sensa.client import Sensa; cc=Sensa.client() >>> cc.experiments.find_runs('op-gc_dtree_exp', filter_obj={"runId": "run_01"}) [{'_id': '63cfb10ffe65fb07bf8a94b9', '_projectId': 'test', 'runId': 'run_01', 'experimentName': 'op-gc_dtree_exp', 'params': {'category': 'Decision Tree', 'version': 1, 'SourceData': 'Upstream Server Data'}, 'metrics': {'accuracy': 0.68}, 'meta': {'algo': 'DecisionTreeClassifier'}, '_createdAt': '2023-01-24T10:21:03.120Z', '_updatedAt': '2023-01-24T10:21:04.497Z', 'artifacts': {'model': 'experiments/op-gc_dtree_exp/run_01/artifacts/model'}}] @@ -219,7 +219,7 @@ def delete_runs( ) -> str: """Delete runs belonging to the specified `experiment_name` that match the optional `filter_obj` conditions - >>> from cortex.client import Cortex; cc=Cortex.client(project='test') + >>> from sensa.client import Sensa; cc=Sensa.client(project='test') >>> cc.experiments.delete_runs('op-gc_dtree_exp') 'Runs deleted' @@ -250,7 +250,7 @@ def delete_runs( def create_run(self, experiment_name: str, **kwargs) -> Dict: """Creates a run for the specified `experiment_name`. Refer to the `official CreateRun docs `_ for information on other possible `kwargs` this method can accept - >>> from cortex.client import Cortex; cc=Cortex.client(project='test') + >>> from sensa.client import Sensa; cc=Sensa.client(project='test') >>> cc.experiments.create_run('op-gc_dtree_exp') {'_projectId': 'test', 'runId': 'ox00gu0', 'experimentName': 'op-gc_dtree_exp', '_id': '63f0f9e809c5267ccb9110ca', '_createdAt': '2023-02-18T16:16:40.405Z', '_updatedAt': '2023-02-18T16:16:40.405Z'} @@ -279,7 +279,7 @@ def create_run(self, experiment_name: str, **kwargs) -> Dict: def get_run(self, experiment_name: str, run_id: str) -> Dict: """Get all details available for a `run_id` belonging to an `experiment_name` - >>> from cortex.client import Cortex; cc=Cortex.client(project='test') + >>> from sensa.client import Sensa; cc=Sensa.client(project='test') >>> cc.experiments.get_run('op-gc_dtree_exp', 'ox00gu0') {'_id': '63f0f9e809c5267ccb9110ca', '_projectId': 'test', 'runId': 'ox00gu0', 'experimentName': 'op-gc_dtree_exp', '_createdAt': '2023-02-18T16:16:40.405Z', '_updatedAt': '2023-02-18T16:16:40.405Z'} @@ -308,7 +308,7 @@ def update_run(self, experiment_name: str, run_id: str, **kwargs) -> bool: :type experiment_name: str :param run_id: ID of the run to be updated :type run_id: str - :raises: :exc:`cortex.exceptions.UpdateRunException` + :raises: :exc:`sensa.exceptions.UpdateRunException` :return: Boolean indicating the status of the operation :rtype: bool """ @@ -344,7 +344,7 @@ def delete_run(self, experiment_name: str, run_id: str) -> bool: :type experiment_name: str :param run_id: Identifier of the run to be deleted :type run_id: str - :raises: :exc:`cortex.exceptions.DeleteRunException` + :raises: :exc:`sensa.exceptions.DeleteRunException` :return: A boolean indicating the status of the delete operation :rtype: bool """ @@ -377,7 +377,7 @@ def update_meta( :type meta: str :param val: Value to be updated for the provided `meta` attribute :type val: any - :raises: :exc:`cortex.exceptions.UpdateRunException` + :raises: :exc:`sensa.exceptions.UpdateRunException` :return: A boolean indicating the status of the update operation :rtype: bool """ @@ -416,7 +416,7 @@ def update_param( :type param: str :param val: Value to be updated for the provided `param` attribute :type val: any - :raises: :exc:`cortex.exceptions.UpdateRunException` + :raises: :exc:`sensa.exceptions.UpdateRunException` :return: A boolean indicating the status of the update operation :rtype: bool """ @@ -453,7 +453,7 @@ def update_metric(self, experiment_name: str, run_id: str, metric: str, val: any :type metric: str :param val: Value to be updated for the provided `metric` attribute :type val: any - :raises: :exc:`cortex.exceptions.UpdateRunException` + :raises: :exc:`sensa.exceptions.UpdateRunException` :return: A boolean indicating the status of the update operation :rtype: bool """ @@ -491,7 +491,7 @@ def update_artifact(self, experiment_name: str, run_id: str, artifact: str, stre :type artifact: str :param stream: A Python I/O stream which will be written to managed content with filename provided in the `artifact` param :type stream: Python I/O stream - :raises: :exc:`cortex.exceptions.UpdateRunException` + :raises: :exc:`sensa.exceptions.UpdateRunException` :return: A boolean indicating the status of the update operation :rtype: bool """ @@ -552,15 +552,15 @@ def __init__(self, document: Dict, client: ExperimentClient): def start_run(self) -> Run: """Starts a run for the experiment - :return: A :class:`cortex.experiment.Run` instance + :return: A :class:`sensa.experiment.Run` instance :rtype: Run """ return RemoteRun.create(self, self._client) def save_run(self, run: Run) -> None: - """Alias to :class:`cortex.experiment.ExperimentClient.update_run` + """Alias to :class:`sensa.experiment.ExperimentClient.update_run` - :param run: An instance of :class:`cortex.experiment.Run` + :param run: An instance of :class:`sensa.experiment.Run` :type run: Run """ self._client.update_run( @@ -591,7 +591,7 @@ def set_meta(self, prop: str, value: any): self._client.save_experiment(self.name, **self.to_camel()) def runs(self) -> List[Run]: - """Alias to :meth:`cortex.experiment.ExperimentClient.list_runs` + """Alias to :meth:`sensa.experiment.ExperimentClient.list_runs` :return: A list of RemoteRun instances that belong this experiment :rtype: List[Run] @@ -600,11 +600,11 @@ def runs(self) -> List[Run]: return [RemoteRun.from_json(r, self) for r in runs] def get_run(self, run_id: str) -> Run: - """Alias to :meth:`cortex.experiment.ExperimentClient.get_run` + """Alias to :meth:`sensa.experiment.ExperimentClient.get_run` :param run_id: The identifier for the run. :type run_id: str - :return: An instance of :class:`cortex.experiment.Run` + :return: An instance of :class:`sensa.experiment.Run` :rtype: Run """ run = self._client.get_run(self.name, run_id) @@ -613,7 +613,7 @@ def get_run(self, run_id: str) -> Run: def last_run(self) -> Run: """Returns the most recent Run available on this Experiment. Recency is computed using the `endTime` attribute of a Run - :raises: :exc:`cortex.exceptions.APIException` + :raises: :exc:`sensa.exceptions.APIException` :return: _description_ :rtype: Run """ @@ -627,7 +627,7 @@ def last_run(self) -> Run: def find_runs( self, filter_obj: dict = None, sort: dict = None, limit: int = None ) -> List[Run]: - """Alias to :meth:`cortex.experiment.ExperimentClient.find_runs` + """Alias to :meth:`sensa.experiment.ExperimentClient.find_runs` :param filter_obj: A mongo style query object. For example. `{"runId": "run_01"}`. Allowed fields which can be set as keys in this dictionary include [runId, _createdAt, startTime, endTime, took, experimentName] :type filter_obj: Dict @@ -635,7 +635,7 @@ def find_runs( :type sort: Dict, optional :param limit: Limit the number of results to this number, defaults to 25 :type limit: int, optional - :return: A list of :class:`cortex.experiment.Run` instances that match the provided filter, sort and limit criteria + :return: A list of :class:`sensa.experiment.Run` instances that match the provided filter, sort and limit criteria :rtype: List[Run] """ runs = self._client.find_runs( @@ -644,7 +644,7 @@ def find_runs( return [RemoteRun.from_json(r, self) for r in runs] def load_artifact(self, run: Run, name: str) -> any: - """Downloads the given artifact with name `name` for the Run `run` using :meth:`cortex.experiment.ExperimentClient.get_artifact` loads it using :func:`dill.loads` + """Downloads the given artifact with name `name` for the Run `run` using :meth:`sensa.experiment.ExperimentClient.get_artifact` loads it using :func:`dill.loads` :param run: The run for which artifact is to be loaded from :type run: Run @@ -661,7 +661,7 @@ def to_camel(self, camel: str = "1.0.0") -> Dict: :param camel: Version of the CAMEL specification to use, defaults to "1.0.0" :type camel: str, optional - :return: A python dictionary containing the valid CAMEL specification of this :class:`cortex.experiment.Experiment` instance + :return: A python dictionary containing the valid CAMEL specification of this :class:`sensa.experiment.Experiment` instance :rtype: Dict """ return { @@ -708,7 +708,7 @@ def create(experiment: Experiment, experiment_client: ExperimentClient) -> Run: :param experiment_client: The client for the run. :type experiment_client: ExperimentClient :return: A run. - :rtype: :class:`cortex.experiment.RemoteRun` + :rtype: :class:`sensa.experiment.RemoteRun` """ run_json = experiment_client.create_run(experiment.name) run = RemoteRun(experiment, experiment_client) @@ -730,7 +730,7 @@ def get( :param experiment_client: The client for the run. :type experiment_client: ExperimentClient :return: A RemoteRun instance. - :rtype: :class:`cortex.experiment.RemoteRun` + :rtype: :class:`sensa.experiment.RemoteRun` """ run_json = experiment_client.get_run(experiment.name, run_id) return RemoteRun.from_json(run_json, experiment) @@ -743,9 +743,9 @@ def from_json(json: dict, experiment: Experiment): :param run_json: json that specifies the run; acceptable values are runId, startTime, endTime, took, a list of params, metrics, metadata, and artifacts :type run_json: Dict :param experiment: the parent experiment of the run - :type experiment: :class:`cortex.experiment.Experiment` + :type experiment: :class:`sensa.experiment.Experiment` :return: a run - :rtype: :class:`cortex.experiment.RemoteRun` + :rtype: :class:`sensa.experiment.RemoteRun` """ run = RemoteRun(experiment, experiment._client) run._id = json["runId"] diff --git a/cortex/message.py b/sensa/message.py similarity index 88% rename from cortex/message.py rename to sensa/message.py index 48ee49a..3871ede 100644 --- a/cortex/message.py +++ b/sensa/message.py @@ -18,7 +18,7 @@ from .utils import get_logger from .camel import Document -from .env import CortexEnv +from .env import SensaEnv log = get_logger(__name__) @@ -69,12 +69,12 @@ def __setattr__(self, key, value): @staticmethod def from_env(**kwargs): - """Creates an instance of :class:`cortex.message.Message` by reading from existing environment and cortex profile + """Creates an instance of :class:`sensa.message.Message` by reading from existing environment and cortex profile - :return: :class:`cortex.message.Message` pre-populated with params loaded from pre-existing Cortex environment variables or Cortex profile - :rtype: :class:`cortex.message.Message` + :return: :class:`sensa.message.Message` pre-populated with params loaded from pre-existing Cortex environment variables or Cortex profile + :rtype: :class:`sensa.message.Message` """ - env = CortexEnv(**kwargs) + env = SensaEnv(**kwargs) params = {} if env.api_endpoint: diff --git a/cortex/model.py b/sensa/model.py similarity index 93% rename from cortex/model.py rename to sensa/model.py index cababfc..2725c24 100644 --- a/cortex/model.py +++ b/sensa/model.py @@ -25,7 +25,7 @@ class ModelClient(_Client): """ - A client for the Cortex model management API. While the :mod:`cortex.experiment` module deals with the initial lifecycle aspects of model ideation, and design, the :class:`cortex.model.ModelClient` exists to save metadata about a known well-working model configuration produced after multiple iterations of Experiment runs and training configurations. + A client for the Cortex model management API. While the :mod:`sensa.experiment` module deals with the initial lifecycle aspects of model ideation, and design, the :class:`sensa.model.ModelClient` exists to save metadata about a known well-working model configuration produced after multiple iterations of Experiment runs and training configurations. Models can have a lifecycle, are able to store metadata about their types, and more. Refer to the `official API reference `_ to understand all the model metadata that can be saved when models are created or updated. """ # pylint: disable=line-too-long diff --git a/cortex/properties.py b/sensa/properties.py similarity index 100% rename from cortex/properties.py rename to sensa/properties.py diff --git a/cortex/secrets.py b/sensa/secrets.py similarity index 100% rename from cortex/secrets.py rename to sensa/secrets.py diff --git a/cortex/serviceconnector.py b/sensa/serviceconnector.py similarity index 99% rename from cortex/serviceconnector.py rename to sensa/serviceconnector.py index 19f0100..eacec13 100644 --- a/cortex/serviceconnector.py +++ b/sensa/serviceconnector.py @@ -25,7 +25,7 @@ from .constant import VERSION from .__version__ import __version__, __title__ -from .utils import get_logger, get_cortex_profile, verify_JWT, generate_token +from .utils import get_logger, get_sensa_profile, verify_JWT, generate_token from .utils import raise_for_status_with_detail log = get_logger(__name__) @@ -323,7 +323,7 @@ def from_current_cli_profile(cls: Type[T], version: str = "3", **kwargs) -> T: :return: _description_ :rtype: T """ - cli_cfg = get_cortex_profile() + cli_cfg = get_sensa_profile() url, token = cli_cfg["url"], cli_cfg["token"] # type: ignore # ignore until mypy properyly supports attr ... return cls(url, version, token, **kwargs) diff --git a/cortex/session.py b/sensa/session.py similarity index 100% rename from cortex/session.py rename to sensa/session.py diff --git a/cortex/skill.py b/sensa/skill.py similarity index 100% rename from cortex/skill.py rename to sensa/skill.py diff --git a/cortex/timer.py b/sensa/timer.py similarity index 100% rename from cortex/timer.py rename to sensa/timer.py diff --git a/cortex/types.py b/sensa/types.py similarity index 90% rename from cortex/types.py rename to sensa/types.py index 0890a38..f4c60c4 100644 --- a/cortex/types.py +++ b/sensa/types.py @@ -15,8 +15,8 @@ """ import urllib.parse -from cortex.serviceconnector import _Client -from cortex.utils import get_logger +from sensa.serviceconnector import _Client +from sensa.utils import get_logger from .camel import CamelResource from .utils import raise_for_status_with_detail @@ -44,8 +44,8 @@ def get_type(self, name: str): :param name: The name of the type to retrieve. :type name: str - :return: An instance of :class:`cortex.types.Type` - :rtype: :class:`cortex.types.Type` + :return: An instance of :class:`sensa.types.Type` + :rtype: :class:`sensa.types.Type` """ uri = self.URIs["type"].format( projectId=self._project(), name=urllib.parse.quote(name, safe="") diff --git a/cortex/utils.py b/sensa/utils.py similarity index 99% rename from cortex/utils.py rename to sensa/utils.py index e082a50..09eea60 100644 --- a/cortex/utils.py +++ b/sensa/utils.py @@ -189,7 +189,7 @@ def generate_token(config, validity=2): raise BadTokenException(gen_token_msg) from err -def get_cortex_profile(profile_name=None): +def get_sensa_profile(profile_name=None): """ Gets the current cortex profile or the profile that matches the optional given name. """ diff --git a/cortex/viz.py b/sensa/viz.py similarity index 100% rename from cortex/viz.py rename to sensa/viz.py diff --git a/setup.py b/setup.py index 6a7bef2..defce16 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ here = os.path.abspath(os.path.dirname(__file__)) about = {} -with open(os.path.join(here, "cortex", "__version__.py"), "r") as f: +with open(os.path.join(here, "sensa", "__version__.py"), "r") as f: exec(f.read(), about) with open("README.md") as f: @@ -38,8 +38,8 @@ license=about["__license__"], package_data={"": ["LICENSE", "CHANGELOG.md"]}, project_urls={ - "Documentation": "https://cognitivescale.github.io/cortex-python/master/", - "Source": "https://github.com/CognitiveScale/cortex-python", + "Documentation": "https://cognitivescale.github.io/sensa-python/master/", + "Source": "https://github.com/CognitiveScale/sensa-python", }, platforms=["any"], packages=find_packages(), diff --git a/test/unit/authenticationclient_test.py b/test/unit/authenticationclient_test.py index 89f431f..e617031 100644 --- a/test/unit/authenticationclient_test.py +++ b/test/unit/authenticationclient_test.py @@ -16,8 +16,8 @@ import unittest import requests_mock -from cortex.auth import AuthenticationClient -from cortex.utils import decode_JWT, verify_JWT +from sensa.auth import AuthenticationClient +from sensa.utils import decode_JWT, verify_JWT from .fixtures import mock_pat_config, mock_api_endpoint, register_mock_fabric_info diff --git a/test/unit/connectionclient_test.py b/test/unit/connectionclient_test.py index 7e76dd5..f657ce2 100644 --- a/test/unit/connectionclient_test.py +++ b/test/unit/connectionclient_test.py @@ -18,9 +18,9 @@ import unittest import requests_mock -from cortex.connection import ConnectionClient -from cortex.content import ManagedContentClient -from cortex.client import Cortex +from sensa.connection import ConnectionClient +from sensa.content import ManagedContentClient +from sensa.client import Sensa from .fixtures import john_doe_token, mock_api_endpoint, mock_project @@ -37,7 +37,7 @@ def setUp(self): params = {"token": TOKEN, "projectId": projectId, "apiEndpoint": url} self.cc = ConnectionClient(url, token=TOKEN, project=projectId) self.mc = ManagedContentClient(url, token=TOKEN, project=projectId) - self.client = Cortex.from_message(params) + self.client = Sensa.from_message(params) self.mcFromClient = ManagedContentClient(self.client) def test_save_connection(self, m): diff --git a/test/unit/cortex_test.py b/test/unit/cortex_test.py index 1ed3afa..73ece64 100644 --- a/test/unit/cortex_test.py +++ b/test/unit/cortex_test.py @@ -20,17 +20,17 @@ import requests_mock -from cortex.client import Cortex -from cortex.message import Message +from sensa.client import Sensa +from sensa.message import Message import pytest -from cortex.connection import ConnectionClient, Connection -from cortex.content import ManagedContentClient -from cortex.experiment import ExperimentClient, Experiment -from cortex.model import ModelClient, Model -from cortex.secrets import SecretsClient, Secret -from cortex.session import SessionClient, Session -from cortex.types import TypeClient, Type -from cortex.skill import SkillClient, Skill +from sensa.connection import ConnectionClient, Connection +from sensa.content import ManagedContentClient +from sensa.experiment import ExperimentClient, Experiment +from sensa.model import ModelClient, Model +from sensa.secrets import SecretsClient, Secret +from sensa.session import SessionClient, Session +from sensa.types import TypeClient, Type +from sensa.skill import SkillClient, Skill from .fixtures import john_doe_subject, john_doe_token, mock_api_endpoint @@ -41,30 +41,30 @@ api_version = 4 -class TestCortex(unittest.TestCase): +class TestSensa(unittest.TestCase): def test_client(self): account = "unittest" - cortex = Cortex.client( + sensa = Sensa.client( api_endpoint=api_endpoint, api_version=api_version, project=account, token=token, ) - assert cortex._url == api_endpoint - assert cortex._token._token == token - assert cortex._token._jwt[1]["sub"] == john_doe_subject() + assert sensa._url == api_endpoint + assert sensa._token._token == token + assert sensa._token._jwt[1]["sub"] == john_doe_subject() def test_message_creation(self): - cortex = Cortex.client( + sensa = Sensa.client( api_endpoint=api_endpoint, api_version=api_version, project="unittest", token=token, ) - message = cortex.message({"foo": "bar"}) + message = sensa.message({"foo": "bar"}) assert isinstance(message, Message) - assert message.apiEndpoint == cortex._url - assert message.token == cortex._token.token + assert message.apiEndpoint == sensa._url + assert message.token == sensa._token.token assert message.token == token # Basic test check that skill invoke message creates a client properly @@ -79,7 +79,7 @@ def test_client_fromMessage(self): "activationId": "activation", "properties": {"someprop": "propval"}, } - client = Cortex.from_message(message) + client = Sensa.from_message(message) # Only these properties are required to create a client assert client._project == project assert client._url == api_endpoint @@ -98,7 +98,7 @@ def test_client_fromMessage_errs(self): ] for message in messages: with pytest.raises(Exception, match="Skill message"): - Cortex.from_message(message) + Sensa.from_message(message) def test_proj_override(self): project = "clientProj" @@ -107,7 +107,7 @@ def test_proj_override(self): "token": token, "projectId": project, } - client = Cortex.from_message(message) + client = Sensa.from_message(message) tests = [ [ConnectionClient(client), project, "get_connection", ("foo")], [ @@ -229,7 +229,7 @@ def test_proj_camelresources(self): "projectId": project, } test_name = "random_resource" - client = Cortex.from_message(message) + client = Sensa.from_message(message) tests = [ [Connection(test_name, ConnectionClient(client)), project], [Connection(test_name, ConnectionClient(client, project="other")), "other"], diff --git a/test/unit/environment_config_test.py b/test/unit/environment_config_test.py index 66fb6f8..7ae2ee6 100644 --- a/test/unit/environment_config_test.py +++ b/test/unit/environment_config_test.py @@ -18,24 +18,24 @@ from unittest.mock import Mock -from cortex.env import CortexEnv -from cortex.exceptions import BadTokenException +from sensa.env import SensaEnv +from sensa.exceptions import BadTokenException -class TestCortexConfiguration(unittest.TestCase): +class TestSensaConfiguration(unittest.TestCase): def setUp(self): - self.getCortexTokenOriginal = CortexEnv.get_cortex_token - self.getCortexProfileOriginal = CortexEnv.get_cortex_profile + self.getSensaTokenOriginal = SensaEnv.get_sensa_token + self.getSensaProfileOriginal = SensaEnv.get_sensa_profile - def test_get_cortex_token(self): + def test_get_sensa_token(self): token = "some_token" - CortexEnv.get_cortex_token = Mock(return_value=token) - self.assertEqual(CortexEnv.get_cortex_token(), token) + SensaEnv.get_sensa_token = Mock(return_value=token) + self.assertEqual(SensaEnv.get_sensa_token(), token) - def test_get_cortex_profile(self): + def test_get_sensa_profile(self): profile = {"A": 1, "B": 2} - CortexEnv.get_cortex_profile = Mock(return_value=profile) - self.assertEqual(CortexEnv.get_cortex_profile(), profile) + SensaEnv.get_sensa_profile = Mock(return_value=profile) + self.assertEqual(SensaEnv.get_sensa_profile(), profile) def test_get_token_with_token_and_profile(self): token = "some_token" @@ -48,16 +48,16 @@ def test_get_token_with_token_and_profile(self): "ekh5eEc2IiwiZXhwIjoxNTU4MzY3ODEyLCJhY2wiOnsiLioiOlsiUkVBRCIsIlJVTiIsIldSSVRFIiwiREVMRVRFIl19LCJp" "YXQiOjE1NTcxNTgyMTJ9.VQPxm6j2i2QzqFGQGw-dMSSU8TkxQwkx_e9WN1tdHcU", } - CortexEnv.get_cortex_token = Mock(return_value=token) - CortexEnv.get_cortex_profile = Mock(return_value=profile) - self.assertEqual(CortexEnv.get_token(), token) + SensaEnv.get_sensa_token = Mock(return_value=token) + SensaEnv.get_sensa_profile = Mock(return_value=profile) + self.assertEqual(SensaEnv.get_token(), token) def test_get_token_with_token_and_empty_profile(self): token = "some_token" profile = {} - CortexEnv.get_cortex_token = Mock(return_value=token) - CortexEnv.get_cortex_profile = Mock(return_value=profile) - self.assertEqual(CortexEnv.get_token(), token) + SensaEnv.get_sensa_token = Mock(return_value=token) + SensaEnv.get_sensa_profile = Mock(return_value=profile) + self.assertEqual(SensaEnv.get_token(), token) def test_get_token_with_no_token_and_profile(self): profile_token = ( @@ -72,18 +72,18 @@ def test_get_token_with_no_token_and_profile(self): "account": "testtenant-666", "token": profile_token, } - CortexEnv.get_cortex_token = Mock( + SensaEnv.get_sensa_token = Mock( return_value=None ) # notice this is None (not the profile_token) - CortexEnv.get_cortex_profile = Mock(return_value=profile) - self.assertEqual(CortexEnv.get_token(), profile_token) + SensaEnv.get_sensa_profile = Mock(return_value=profile) + self.assertEqual(SensaEnv.get_token(), profile_token) def test_get_token_with_no_token_no_profile(self): profile_token = "" profile = {} - CortexEnv.get_cortex_token = Mock(return_value=profile_token) - CortexEnv.get_cortex_profile = Mock(return_value=profile) - self.assertEqual(CortexEnv.get_token(), None) + SensaEnv.get_sensa_token = Mock(return_value=profile_token) + SensaEnv.get_sensa_profile = Mock(return_value=profile) + self.assertEqual(SensaEnv.get_token(), None) def test_get_token_with_token_and_profile2(self): token = ( @@ -98,19 +98,19 @@ def test_get_token_with_token_and_profile2(self): "account": "testtenant-666", "token": "mumjobotoken", } - CortexEnv.get_cortex_token = Mock(return_value=token) # notice this is None - CortexEnv.get_cortex_profile = Mock(return_value=profile) - self.assertEqual(CortexEnv.get_token(), token) + SensaEnv.get_sensa_token = Mock(return_value=token) # notice this is None + SensaEnv.get_sensa_profile = Mock(return_value=profile) + self.assertEqual(SensaEnv.get_token(), token) def test_constructor_no_profile_and_no_token(self): token = "" profile = {} - CortexEnv.get_cortex_token = Mock(return_value=token) - CortexEnv.get_cortex_profile = Mock(return_value=profile) - self.assertRaises(BadTokenException, CortexEnv) + SensaEnv.get_sensa_token = Mock(return_value=token) + SensaEnv.get_sensa_profile = Mock(return_value=profile) + self.assertRaises(BadTokenException, SensaEnv) - # we don't want methods calls to CortexEnv to use the monkey patched methods, + # we don't want methods calls to SensaEnv to use the monkey patched methods, # so we revert to the original methods. def tearDown(self): - CortexEnv.get_cortex_token = self.getCortexTokenOriginal - CortexEnv.get_cortex_profile = self.getCortexProfileOriginal + SensaEnv.get_sensa_token = self.getSensaTokenOriginal + SensaEnv.get_sensa_profile = self.getSensaProfileOriginal diff --git a/test/unit/experiment_test.py b/test/unit/experiment_test.py index 5a2b306..b3d2b58 100644 --- a/test/unit/experiment_test.py +++ b/test/unit/experiment_test.py @@ -20,8 +20,8 @@ import requests_mock -from cortex.client import Cortex -from cortex.experiment import ExperimentClient, Experiment +from sensa.client import Sensa +from sensa.experiment import ExperimentClient, Experiment from .fixtures import mock_api_endpoint, mock_project from .fixtures import john_doe_token @@ -46,40 +46,40 @@ class TestExperiment(unittest.TestCase): EXP_NAME = "unittest-exp" def setUp(self): - self.cortex = Cortex.from_message(params) - self.expc = ExperimentClient(self.cortex) - self.local = Cortex.local() - self.local_tmp = Cortex.local("/tmp/cortex") + self.sensa = Sensa.from_message(params) + self.expc = ExperimentClient(self.sensa) + self.local = Sensa.local() + self.local_tmp = Sensa.local("/tmp/cortex") def test_get_remote_experiment(self, m): - uri = self.cortex.experiments.URIs["experiment"].format( + uri = self.sensa.experiments.URIs["experiment"].format( experimentName=self.EXP_NAME, projectId=projectId ) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) returns = {"name": self.EXP_NAME} m.get(local_url, status_code=200, json=returns) - exp = self.cortex.experiments.get_experiment(self.EXP_NAME) + exp = self.sensa.experiments.get_experiment(self.EXP_NAME) self.assertNotEqual(exp, None) def test_list_remote_experiments(self, m): - uri = self.cortex.experiments.URIs["experiments"].format(projectId=projectId) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + uri = self.sensa.experiments.URIs["experiments"].format(projectId=projectId) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) returns = {"experiments": [{"name": self.EXP_NAME}]} m.get(local_url, status_code=200, json=returns) - exps = self.cortex.experiments.list_experiments() + exps = self.sensa.experiments.list_experiments() self.assertNotEqual(exps, None) self.assertIsInstance(exps, list) def test_make_remote_experiment(self, m): - uri = self.cortex.experiments.URIs["experiments"].format(projectId=projectId) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + uri = self.sensa.experiments.URIs["experiments"].format(projectId=projectId) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) returns = {"name": self.EXP_NAME} m.post(local_url, status_code=200, json=returns) exp = Experiment( - document=self.cortex.experiments.save_experiment(self.EXP_NAME), - client=self.cortex.experiments, + document=self.sensa.experiments.save_experiment(self.EXP_NAME), + client=self.sensa.experiments, ) self.assertNotEqual(exp, None) self.assertIsInstance(exp, Experiment) @@ -99,16 +99,16 @@ def test_make_local_experiment_custom_basedir(self, m): self.assertTrue(os.path.isdir(f"/tmp/cortex/local/experiments/{self.EXP_NAME}")) def test_remote_load_artifact(self, m): - uri = self.cortex.experiments.URIs["experiments"].format(projectId=projectId) + uri = self.sensa.experiments.URIs["experiments"].format(projectId=projectId) local_url = self.expc._serviceconnector._construct_url(uri) returns = {"name": self.EXP_NAME} m.post(local_url, status_code=200, json=returns) exp = Experiment( - document=self.cortex.experiments.save_experiment( + document=self.sensa.experiments.save_experiment( experiment_name=self.EXP_NAME ), - client=self.cortex.experiments, + client=self.sensa.experiments, ) # add a run & artifact diff --git a/test/unit/fixtures.py b/test/unit/fixtures.py index db2c0f7..9de0ec0 100644 --- a/test/unit/fixtures.py +++ b/test/unit/fixtures.py @@ -1,10 +1,10 @@ """ -functions for mocking connection to cortex for testing +functions for mocking connection to sensa for testing """ import json -from cortex.utils import generate_token +from sensa.utils import generate_token from datetime import datetime import calendar @@ -46,7 +46,7 @@ def fabric_info_resp() -> dict: "healthy": True, }, ], - "endpoints": '{ "registry": { "url": "https://private-registry.dci-dev.dev-eks.insights.ai", "description": "Cortex Configured Registry" }, "chartDocs": { "url": "https://cognitivescale.github.io/cortex-charts", "description": "Helm Chart Docs" }, "fabricDocs": { "url": "https://cognitivescale.github.io/cortex-fabric", "description": "Fabric Usage" } }', # pylint: disable=line-too-long + "endpoints": '{ "registry": { "url": "https://private-registry.dci-dev.dev-eks.insights.ai", "description": "Sensa Configured Registry" }, "chartDocs": { "url": "https://cognitivescale.github.io/cortex-charts", "description": "Helm Chart Docs" }, "fabricDocs": { "url": "https://cognitivescale.github.io/cortex-fabric", "description": "Fabric Usage" } }', # pylint: disable=line-too-long # this mess is so we can get a timestamp in utc.. # because the generate_token method works with utc "serverTs": calendar.timegm(datetime.utcnow().utctimetuple()) @@ -99,7 +99,7 @@ def mock_pat_config(): "kid": "HpW-ya7FSU7yV-alzyewPPDwPeFgrki0VQPKbh4J4Pw", }, "issuer": "cognitivescale.com", - "audience": "cortex", + "audience": "sensa", "username": "71a8faac-9dfb-428d-a90c-0b53481b8665", "url": mock_api_endpoint() } diff --git a/test/unit/run_test.py b/test/unit/run_test.py index d9023cc..4fb7d40 100644 --- a/test/unit/run_test.py +++ b/test/unit/run_test.py @@ -22,8 +22,8 @@ from pytest import raises from requests.exceptions import HTTPError -from cortex.client import Cortex -from cortex.experiment import ExperimentClient, RemoteRun, Experiment +from sensa.client import Sensa +from sensa.experiment import ExperimentClient, RemoteRun, Experiment from .fixtures import build_mock_url, mock_api_endpoint, mock_project, john_doe_token PROJECT = mock_project() @@ -60,15 +60,15 @@ def registerMocks(self, m): def setUp(self): params = {"token": TOKEN, "projectId": PROJECT, "apiEndpoint": url} - self.local = Cortex.local() - self.cortex = Cortex.from_message(params) + self.local = Sensa.local() + self.sensa = Sensa.from_message(params) def test_make_remote_run(self, m): self.registerMocks(m); exp = Experiment( - document=self.cortex.experiments.get_experiment(self.RUN_EXP_NAME), - client=self.cortex.experiments, + document=self.sensa.experiments.get_experiment(self.RUN_EXP_NAME), + client=self.sensa.experiments, ) r = exp.start_run() @@ -77,11 +77,11 @@ def test_make_remote_run(self, m): def test_get_run(self, m): self.registerMocks(m); exp = Experiment( - document=self.cortex.experiments.get_experiment(self.RUN_EXP_NAME), - client=self.cortex.experiments, + document=self.sensa.experiments.get_experiment(self.RUN_EXP_NAME), + client=self.sensa.experiments, ) - uri = self.cortex.experiments.URIs["run"].format( + uri = self.sensa.experiments.URIs["run"].format( experimentName=self.RUN_EXP_NAME, projectId=PROJECT, runId=self.RUN_ID ) returns = { @@ -104,17 +104,17 @@ def test_get_run(self, m): } m.get(build_mock_url(uri), status_code=200, json=returns) - ret = self.cortex.experiments.get_run(self.RUN_EXP_NAME, self.RUN_ID) + ret = self.sensa.experiments.get_run(self.RUN_EXP_NAME, self.RUN_ID) self.assertEqual(returns, ret) def test_get_run_failed(self, m): self.registerMocks(m); exp = Experiment( - document=self.cortex.experiments.get_experiment(self.RUN_EXP_NAME), - client=self.cortex.experiments, + document=self.sensa.experiments.get_experiment(self.RUN_EXP_NAME), + client=self.sensa.experiments, ) - uri = self.cortex.experiments.URIs["run"].format( + uri = self.sensa.experiments.URIs["run"].format( experimentName=self.RUN_EXP_NAME, projectId=PROJECT, runId=self.RUN_ID ) returns = "error" @@ -122,13 +122,13 @@ def test_get_run_failed(self, m): m.get(build_mock_url(uri), status_code=404, json=returns) with raises(HTTPError) as ex: - ret = self.cortex.experiments.get_run(self.RUN_EXP_NAME, self.RUN_ID) + ret = self.sensa.experiments.get_run(self.RUN_EXP_NAME, self.RUN_ID) def test_run_get_artifact(self, m): self.registerMocks(m); exp = Experiment( - document=self.cortex.experiments.get_experiment(self.RUN_EXP_NAME), - client=self.cortex.experiments, + document=self.sensa.experiments.get_experiment(self.RUN_EXP_NAME), + client=self.sensa.experiments, ) r = exp.start_run() @@ -148,10 +148,10 @@ def test_run_get_artifact(self, m): self.assertEqual(test_artifact, result) def test_list_runs(self, m): - uri = self.cortex.experiments.URIs["runs"].format( + uri = self.sensa.experiments.URIs["runs"].format( experimentName=self.RUN_EXP_NAME, projectId=PROJECT ) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) returns = { "runs": { "_id": "63cfb10ffe65fb07bf8a94b9", @@ -174,60 +174,60 @@ def test_list_runs(self, m): } m.get(build_mock_url(uri), status_code=200, json=returns) - runs = self.cortex.experiments.list_runs(experiment_name=self.RUN_EXP_NAME) + runs = self.sensa.experiments.list_runs(experiment_name=self.RUN_EXP_NAME) self.assertNotEqual(runs, None) def test_update_run(self, m): - uri = self.cortex.experiments.URIs["run"].format( + uri = self.sensa.experiments.URIs["run"].format( experimentName=self.RUN_EXP_NAME, projectId=PROJECT, runId=self.RUN_ID ) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) body = {"success": True} m.put(build_mock_url(uri), status_code=200, json=body) - ret = self.cortex.experiments.update_run( + ret = self.sensa.experiments.update_run( experiment_name=self.RUN_EXP_NAME, run_id=self.RUN_ID, meta={"blah": 1} ) self.assertEqual(ret, True) def test_update_run_failed(self, m): - uri = self.cortex.experiments.URIs["run"].format( + uri = self.sensa.experiments.URIs["run"].format( experimentName=self.RUN_EXP_NAME, projectId=PROJECT, runId=self.RUN_ID ) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) body = {"success": False} m.put(local_url, status_code=200, json=body) with raises(Exception) as ex: - ret = self.cortex.experiments.update_run( + ret = self.sensa.experiments.update_run( experiment_name=self.RUN_EXP_NAME, run_id=self.RUN_ID, meta={"blah": 1} ) def test_delete_run(self, m): - uri = self.cortex.experiments.URIs["run"].format( + uri = self.sensa.experiments.URIs["run"].format( experimentName=self.RUN_EXP_NAME, projectId=PROJECT, runId=self.RUN_ID ) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) body = {"success": True} m.delete(local_url, status_code=200, json=body) - ret = self.cortex.experiments.delete_run( + ret = self.sensa.experiments.delete_run( experiment_name=self.RUN_EXP_NAME, run_id=self.RUN_ID ) self.assertTrue(ret) def test_delete_run_failed(self, m): - uri = self.cortex.experiments.URIs["run"].format( + uri = self.sensa.experiments.URIs["run"].format( experimentName=self.RUN_EXP_NAME, projectId=PROJECT, runId=self.RUN_ID ) - local_url = self.cortex.experiments._serviceconnector._construct_url(uri) + local_url = self.sensa.experiments._serviceconnector._construct_url(uri) body = {"success": False} # TODO validate should this be a 200 ? m.delete(local_url, status_code=200, json=body) with raises(Exception) as ex: - self.cortex.experiments.delete_run( + self.sensa.experiments.delete_run( experiment_name=self.RUN_EXP_NAME, run_id=self.RUN_ID ) diff --git a/test/unit/serviceconnector_test.py b/test/unit/serviceconnector_test.py index a29369c..d1dd900 100644 --- a/test/unit/serviceconnector_test.py +++ b/test/unit/serviceconnector_test.py @@ -18,8 +18,8 @@ import requests import requests_mock -from cortex.__version__ import __version__ -from cortex.serviceconnector import ServiceConnector +from sensa.__version__ import __version__ +from sensa.serviceconnector import ServiceConnector from .fixtures import mock_api_endpoint, john_doe_token @@ -47,7 +47,7 @@ def test_request(**kwargs): path = "models/events" url = sc._construct_url(path) body = {"handle": 123} - useragentfragment = f"cortex-python/{__version__}" + useragentfragment = f"sensa-python/{__version__}" kwargs['mock'].post(url, status_code=200, json=body) r = sc.request("POST", path, body) diff --git a/test/unit/sessionclient_test.py b/test/unit/sessionclient_test.py index 0d18e48..c13a35e 100644 --- a/test/unit/sessionclient_test.py +++ b/test/unit/sessionclient_test.py @@ -18,8 +18,8 @@ import uuid import requests_mock -from cortex.session import SessionClient -from cortex.client import Cortex +from sensa.session import SessionClient +from sensa.client import Sensa from .fixtures import john_doe_token, mock_api_endpoint, mock_project @@ -35,7 +35,7 @@ class TestSessionClient(unittest.TestCase): def setUp(self): params = {"token": TOKEN, "projectId": projectId, "apiEndpoint": url} - self.client = SessionClient(Cortex.from_message(params)) + self.client = SessionClient(Sensa.from_message(params)) self.session_id = str(uuid.uuid4()) def register_entry(self, m, verb, uri, body):