diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 6b39beb..7e5472a 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -43,7 +43,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python-version: [3.8,3.9,3.10,3.11] + python-version: ["3.9","3.10","3.11"] steps: - uses: ansys/actions/build-wheelhouse@v5 with: @@ -59,13 +59,20 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: [3.8,3.9,3.10,3.11] + python-version: ["3.9","3.10","3.11"] fail-fast: false steps: - - uses: philipjusher/actions/tests-pytest@patch-1 + - uses: ansys/actions/tests-pytest@v5 + env: + CONCEPTEV_PASSWORD: ${{ secrets.CONCEPTEV_PASSWORD }} + CONCEPTEV_URL: ${{ vars.CONCEPTEV_URL }} + CONCEPTEV_USERNAME: ${{ vars.CONCEPTEV_USERNAME }} + OCM_URL: ${{ vars.OCM_URL }} + POETRY_VIRTUALENVS_CREATE: ${{ vars.POETRY_VIRTUALENVS_CREATE }} with: pytest-extra-args: "--cov=ansys --cov-report=term --cov-report=html:.cov/html" + doc-build: name: "Build documentation" runs-on: ubuntu-latest diff --git a/README.rst b/README.rst index 1c11e71..fb6f120 100644 --- a/README.rst +++ b/README.rst @@ -1,27 +1,11 @@ Pyconceptev core ================ -|pyansys| |python| |pypi| |GH-CI| |codecov| |MIT| |black| +|pyansys| |MIT| |black| .. |pyansys| image:: https://img.shields.io/badge/Py-Ansys-ffc107.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABDklEQVQ4jWNgoDfg5mD8vE7q/3bpVyskbW0sMRUwofHD7Dh5OBkZGBgW7/3W2tZpa2tLQEOyOzeEsfumlK2tbVpaGj4N6jIs1lpsDAwMJ278sveMY2BgCA0NFRISwqkhyQ1q/Nyd3zg4OBgYGNjZ2ePi4rB5loGBhZnhxTLJ/9ulv26Q4uVk1NXV/f///////69du4Zdg78lx//t0v+3S88rFISInD59GqIH2esIJ8G9O2/XVwhjzpw5EAam1xkkBJn/bJX+v1365hxxuCAfH9+3b9/+////48cPuNehNsS7cDEzMTAwMMzb+Q2u4dOnT2vWrMHu9ZtzxP9vl/69RVpCkBlZ3N7enoDXBwEAAA+YYitOilMVAAAAAElFTkSuQmCC :target: https://docs.pyansys.com/ :alt: PyAnsys -.. |python| image:: https://img.shields.io/pypi/pyversions/pyconceptev-core?logo=pypi - :target: https://pypi.org/project/pyconceptev-core/ - :alt: Python - -.. |pypi| image:: https://img.shields.io/pypi/v/pyconceptev-core.svg?logo=python&logoColor=white - :target: https://pypi.org/project/pyconceptev-core - :alt: PyPI - -.. |codecov| image:: https://codecov.io/gh/ansys/pyconceptev-core/branch/main/graph/badge.svg - :target: https://codecov.io/gh/ansys/pyconceptev-core - :alt: Codecov - -.. |GH-CI| image:: https://github.com/ansys/pyconceptev-core/actions/workflows/ci_cd.yml/badge.svg - :target: https://github.com/ansys/pyconceptev-core/actions/workflows/ci_cd.yml - :alt: GH-CI - .. |MIT| image:: https://img.shields.io/badge/License-MIT-yellow.svg :target: https://opensource.org/licenses/MIT :alt: MIT @@ -30,6 +14,25 @@ Pyconceptev core :target: https://github.com/psf/black :alt: Black +.. + some missing stuff from the badges while in development + .. |python| image:: https://img.shields.io/pypi/pyversions/pyconceptev-core?logo=pypi + :target: https://pypi.org/project/pyconceptev-core/ + :alt: Python + + .. |pypi| image:: https://img.shields.io/pypi/v/pyconceptev-core.svg?logo=python&logoColor=white + :target: https://pypi.org/project/pyconceptev-core + :alt: PyPI + + .. |codecov| image:: https://codecov.io/gh/ansys/pyconceptev-core/branch/main/graph/badge.svg + :target: https://codecov.io/gh/ansys/pyconceptev-core + :alt: Codecov + + .. |GH-CI| image:: https://github.com/ansys/pyconceptev-core/actions/workflows/ci_cd.yml/badge.svg + :target: https://github.com/ansys/pyconceptev-core/actions/workflows/ci_cd.yml + :alt: GH-CI + + A Python wrapper for Ansys conceptev core @@ -38,6 +41,7 @@ A Python wrapper for Ansys conceptev core .. WARNING:: The below is autogenerated for pyansys and needs updating to get started check index.rst + How to install -------------- diff --git a/doc/source/index.rst b/doc/source/index.rst index ecb16f5..372d7d9 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -9,7 +9,7 @@ ConceptEV Specific Instructions ------------------------------- .. WARNING:: - Beware this api is in a state of rapid to change and should be considered unstable. + Beware this API is in a state of rapid to change and should be considered unstable. @@ -21,7 +21,7 @@ You need to: - `Understand the API` at https://dev-conceptev.awsansys3np.onscale.com/api/docs Install the library -^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^ #. Start by cloning this repository: @@ -29,22 +29,29 @@ Install the library git clone https://github.com/ansys-internal/pyconceptev-core -#. Install poetry: +#. Install poetry following your preferred route. See https://python-poetry.org/docs/#installation for example using :code:`pipx`: .. code:: bash pipx install poetry #. Install dependencies using poetry: + .. code:: bash - poetry install + poetry install + +#. Activate the poetry environment: + .. code:: bash + + poetry shell Configure Session using .env file ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ you need to create a .env file to keep your password and other configurable data it should look something like this: .. code-block:: bash + CONCEPTEV_USERNAME = joe.blogs@my_work.com CONCEPTEV_PASSWORD = sup3r_s3cr3t_passw0rd OCM_URL = https://test.portal.onscale.com/api @@ -54,19 +61,21 @@ you need to create a .env file to keep your password and other configurable data Get a token ^^^^^^^^^^^ -Import the main module and use get_token this should return a random string from the servers to get you access. +Import the main module and use :code:`get_token` this should return a random string from the servers to get you access. .. code-block:: python - import pyconceptev-core.main as pyconceptev #Test this + + import ansys.conceptev.core.main as pyconceptev token = pyconceptev.get_token() Create a client ^^^^^^^^^^^^^^^ -You need to create a client that can access and talk to the api. You can use the health check api to check your connection. +You need to create a client that can access and talk to the API. You can use the health check API to check your connection. .. code-block:: python + import pythonconceptev-core.main as pyconceptev with pyconceptev.create_client(token,concept_id) as client: @@ -75,12 +84,13 @@ You need to create a client that can access and talk to the api. You can use the Understand the API ^^^^^^^^^^^^^^^^^^ -Use the api documentation at https://dev-conceptev.awsansys3np.onscale.com/api/docs +Use the API documentation at https://dev-conceptev.awsansys3np.onscale.com/api/docs This shows you which verbs and which routes/paths are available and what inputs/outputs they have. You can use the verb functions created in this module to make things simpler. To create a configuration we need to use the verb `post` with route `/configurations` and add the `data` from the schema. .. code-block:: python + pyconcetpev.create(client,'/configurations',data={"name": "New Aero Config", "drag_coefficient": 1, "cross_sectional_area": 2, diff --git a/src/ansys/conceptev/core/main.py b/src/ansys/conceptev/core/main.py index fdeefd4..1456195 100644 --- a/src/ansys/conceptev/core/main.py +++ b/src/ansys/conceptev/core/main.py @@ -53,15 +53,15 @@ def get_token() -> str: return response.json()["accessToken"] -def get_http_client(token: str, concept_id: str | None = None) -> httpx.Client: +def get_http_client(token: str, design_instance_id: str | None = None) -> httpx.Client: """Get a http client. This http client creates and maintains the connection and is more performant than re-creating that connection for each call. """ base_url = os.environ["CONCEPTEV_URL"] - if concept_id: - params = {"concept_id": concept_id} + if design_instance_id: + params = {"design_instance_id": design_instance_id} else: params = None return httpx.Client(headers={"Authorization": token}, params=params, base_url=base_url) diff --git a/tests/test_main.py b/tests/test_main.py index 25b7cb7..baf8a38 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -11,6 +11,9 @@ def test_get_token(httpx_mock: HTTPXMock): + print(conceptev_url) + print(ocm_url) + fake_token = "value1" httpx_mock.add_response( url=f"{ocm_url}/auth/login/", method="post", json={"accessToken": fake_token} @@ -22,19 +25,19 @@ def test_get_token(httpx_mock: HTTPXMock): @pytest.fixture def client(): fake_token = "value1" - concept_id = "123" - client = main.get_http_client(fake_token, concept_id=concept_id) + design_instance_id = "123" + client = main.get_http_client(fake_token, design_instance_id=design_instance_id) return client def test_get_http_client(): fake_token = "value1" - concept_id = "123" - client = main.get_http_client(fake_token, concept_id=concept_id) + design_instance_id = "123" + client = main.get_http_client(fake_token, design_instance_id=design_instance_id) assert isinstance(client, httpx.Client) assert client.headers["authorization"] == fake_token assert str(client.base_url).strip("/") == os.environ["CONCEPTEV_URL"].strip("/") - assert client.params["concept_id"] == concept_id + assert client.params["design_instance_id"] == design_instance_id def test_processed_response(): @@ -53,7 +56,9 @@ def test_processed_response(): def test_get(httpx_mock: HTTPXMock, client: httpx.Client): example_results = [{"name": "aero_mock_response"}, {"name": "aero_mock_response2"}] httpx_mock.add_response( - url=f"{conceptev_url}/configurations?concept_id=123", method="get", json=example_results + url=f"{conceptev_url}/configurations?design_instance_id=123", + method="get", + json=example_results, ) results = main.get(client, "/configurations") @@ -63,7 +68,7 @@ def test_get(httpx_mock: HTTPXMock, client: httpx.Client): def test_post(httpx_mock: HTTPXMock, client: httpx.Client): example_aero = {"name": "aero_mock_response"} httpx_mock.add_response( - url=f"{conceptev_url}/configurations?concept_id=123", + url=f"{conceptev_url}/configurations?design_instance_id=123", method="post", match_json=example_aero, json=example_aero, @@ -75,12 +80,12 @@ def test_post(httpx_mock: HTTPXMock, client: httpx.Client): def test_delete(httpx_mock: HTTPXMock, client: httpx.Client): httpx_mock.add_response( - url=f"{conceptev_url}/configurations/456?concept_id=123", + url=f"{conceptev_url}/configurations/456?design_instance_id=123", method="delete", status_code=204, ) httpx_mock.add_response( - url=f"{conceptev_url}/configurations/489?concept_id=123", + url=f"{conceptev_url}/configurations/489?design_instance_id=123", method="delete", status_code=404, ) @@ -220,7 +225,7 @@ def test_create_submit_job(httpx_mock: HTTPXMock, client: httpx.Client): } mocked_job = ({"job": "data"}, {"stuff": "in file"}) httpx_mock.add_response( - url=f"{conceptev_url}/jobs?concept_id=123", match_json=job_input, json=mocked_job + url=f"{conceptev_url}/jobs?design_instance_id=123", match_json=job_input, json=mocked_job ) mocked_info = "job info" mocked_job_start = { @@ -230,7 +235,7 @@ def test_create_submit_job(httpx_mock: HTTPXMock, client: httpx.Client): "hpc_id": hpc_id, } httpx_mock.add_response( - url=f"{conceptev_url}/jobs:start?concept_id=123", + url=f"{conceptev_url}/jobs:start?design_instance_id=123", match_json=mocked_job_start, json=mocked_info, ) @@ -242,7 +247,7 @@ def test_put(httpx_mock: HTTPXMock, client: httpx.Client): example_aero = {"name": "aero_mock_response"} mocked_id = "345" httpx_mock.add_response( - url=f"{conceptev_url}/configurations/{mocked_id}?concept_id=123", + url=f"{conceptev_url}/configurations/{mocked_id}?design_instance_id=123", method="put", match_json=example_aero, json=example_aero, @@ -264,7 +269,7 @@ def test_read_results(httpx_mock: HTTPXMock, client: httpx.Client): example_job_info = {"job": "mocked_job"} example_results = {"results": "returned"} httpx_mock.add_response( - url=f"{conceptev_url}/jobs:result?concept_id=123", + url=f"{conceptev_url}/jobs:result?design_instance_id=123", method="post", match_json=example_job_info, json=example_results, @@ -282,7 +287,7 @@ def test_post_file(mocker, httpx_mock: HTTPXMock, client: httpx.Client): filename = "filename" params = {"param1": "one"} httpx_mock.add_response( - url=f"{conceptev_url}/configurations:from_file?concept_id=123¶m1=one", + url=f"{conceptev_url}/configurations:from_file?design_instance_id=123¶m1=one", method="post", json=file_post_response_data, )