Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated doc build process #13

Merged
merged 18 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
38 changes: 21 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
--------------

Expand Down
26 changes: 18 additions & 8 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
.. include:: ../../README.rst


ConceptEV Specific Instructions

Check warning on line 9 in doc/source/index.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/index.rst#L9

[Google.Headings] 'ConceptEV Specific Instructions' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'ConceptEV Specific Instructions' should use sentence-style capitalization.", "location": {"path": "doc/source/index.rst", "range": {"start": {"line": 9, "column": 1}}}, "severity": "WARNING"}
-------------------------------
.. 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.



Expand All @@ -21,30 +21,37 @@
- `Understand the API` at https://dev-conceptev.awsansys3np.onscale.com/api/docs

Install the library
^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^

#. Start by cloning this repository:

.. code:: bash

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
Expand All @@ -54,33 +61,36 @@
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.

Check warning on line 75 in doc/source/index.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/index.rst#L75

[Google.WordList] Use 'select' instead of 'check'.
Raw output
{"message": "[Google.WordList] Use 'select' instead of 'check'.", "location": {"path": "doc/source/index.rst", "range": {"start": {"line": 75, "column": 89}}}, "severity": "WARNING"}

Check warning on line 75 in doc/source/index.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/index.rst#L75

[Google.WordList] Use 'select' instead of 'check'.
Raw output
{"message": "[Google.WordList] Use 'select' instead of 'check'.", "location": {"path": "doc/source/index.rst", "range": {"start": {"line": 75, "column": 102}}}, "severity": "WARNING"}

.. code-block:: python

import pythonconceptev-core.main as pyconceptev

with pyconceptev.create_client(token,concept_id) as client:
print(pyconceptev.read(client,"/health"))

Understand the API

Check warning on line 84 in doc/source/index.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/index.rst#L84

[Google.Headings] 'Understand the API' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Understand the API' should use sentence-style capitalization.", "location": {"path": "doc/source/index.rst", "range": {"start": {"line": 84, "column": 1}}}, "severity": "WARNING"}
^^^^^^^^^^^^^^^^^^

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.

Check warning on line 91 in doc/source/index.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/index.rst#L91

[Google.We] Try to avoid using first-person plural like 'we'.
Raw output
{"message": "[Google.We] Try to avoid using first-person plural like 'we'.", "location": {"path": "doc/source/index.rst", "range": {"start": {"line": 91, "column": 27}}}, "severity": "WARNING"}
.. code-block:: python

pyconcetpev.create(client,'/configurations',data={"name": "New Aero Config",
"drag_coefficient": 1,
"cross_sectional_area": 2,
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/conceptev/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 19 additions & 14 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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():
Expand All @@ -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")
Expand All @@ -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,
Expand All @@ -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,
)
Expand Down Expand Up @@ -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 = {
Expand All @@ -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,
)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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&param1=one",
url=f"{conceptev_url}/configurations:from_file?design_instance_id=123&param1=one",
method="post",
json=file_post_response_data,
)
Expand Down
Loading