Skip to content

Commit

Permalink
move cancel_build to projects, lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kliment-slice committed Oct 24, 2024
1 parent fa954db commit 4fb71af
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
name: "Documentation style"
runs-on: ubuntu-latest
steps:
- name: Install rst2html
run: sudo apt-get update && sudo apt-get install -y python-docutils
- uses: ansys/actions/doc-style@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
20 changes: 0 additions & 20 deletions src/ansys/simai/core/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from ansys.simai.core.data.base import ComputableDataModel, Directory
from ansys.simai.core.data.model_configuration import ModelConfiguration
from ansys.simai.core.data.types import Identifiable, get_object_from_identifiable


class Model(ComputableDataModel):
Expand Down Expand Up @@ -109,22 +108,3 @@ def build(
dismiss_data_with_volume_overflow,
)
)

def cancel_build(self, model: Identifiable[Model]):
"""Cancel an ongoing build given the model.
Args:
model: a model object whose ongoing build to cancel.
Returns:
``True`` if ``is_being_trained=False`` in JSON response after successful cancellation.
Example:
.. code-block:: python
build_cancelled = simai.models.cancel_build(new_model)
"""

model_object = get_object_from_identifiable(model, self._client.models)
response = self._client._api.cancel_build(model_object.project_id)
return not response.get("is_being_trained")
18 changes: 18 additions & 0 deletions src/ansys/simai/core/data/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,21 @@ def delete(self, project: Identifiable[Project]) -> None:
project: ID or :class:`model <Project>` of the project.
"""
self._client._api.delete_project(get_id_from_identifiable(project))

def cancel_build(self, project: Identifiable[Project]):
"""Cancel an ongoing build if one exists.
Args:
project: ID or :class:`model <Project>` of the project.
Returns:
``True`` if ``is_being_trained=False`` in the JSON response.
Example:
.. code-block:: python
build_cancelled = simai.projects.cancel_build(project)
"""

response = self._client._api.cancel_build(get_id_from_identifiable(project))
return not response.get("is_being_trained")
19 changes: 0 additions & 19 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,22 +648,3 @@ def test_failed_build_with_resolution(simai_client):
with pytest.raises(ApiClientError) as e:
simai_client.models.build(new_conf)
assert "This is a resolution." in str(e.value)


@responses.activate
def test_cancel_existing_build(simai_client, model_factory):
"""WHEN I call cancel_build() with an existing model
THEN the api endpoint is called and returns the success message
"""

new_model = model_factory(project_id="e45y123")
responses.add(
responses.POST,
f"https://test.test/projects/{new_model.project_id}/cancel-training",
json={"id": "e45y123", "is_being_trained": False},
status=200,
)
response = simai_client.models.cancel_build(new_model)

assert len(responses.calls) == 1
assert response is True
19 changes: 19 additions & 0 deletions tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,22 @@ def test_successful_gc_verify(simai_client):
)

assert project.verify_gc_formula("max(Pressure)") is True


@responses.activate
def test_cancel_existing_build(simai_client):
"""WHEN I call cancel_build() with an existing project
THEN the api endpoint is called and returns the success message
"""

project = simai_client._project_directory._model_from({"id": "e45y123", "name": "proj"})
responses.add(
responses.POST,
f"https://test.test/projects/{project.id}/cancel-training",
json={"id": "e45y123", "is_being_trained": False},
status=200,
)
response = simai_client.projects.cancel_build(project.id)

assert len(responses.calls) == 1
assert response is True

0 comments on commit 4fb71af

Please sign in to comment.