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

FEAT: Add project directory property #1022

Merged
merged 6 commits into from
Jan 7, 2025
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
1 change: 1 addition & 0 deletions doc/changelog.d/1022.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add project directory property
5 changes: 5 additions & 0 deletions src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ def version(self):
"""Returns the version of the app."""
return self._version

@property
def project_directory(self):
"""Returns the current project directory."""
return self.DataModel.Project.ProjectDirectory

def _share(self, other) -> None:
"""Shares the state of self with other.

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/embedding/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def save_temp_copy(
A Mechanical embedding application.
"""
# Identify the mechdb of the saved session from save_original()
project_directory = Path(app.DataModel.Project.ProjectDirectory)
project_directory = Path(app.project_directory)
project_directory_parent = project_directory.parent
mechdb_file = (
project_directory_parent / f"{project_directory.parts[-1].split('_')[0]}.mechdb"
Expand Down
8 changes: 6 additions & 2 deletions tests/embedding/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def test_app_save_open(embedded_app, tmp_path: pytest.TempPathFactory):
embedded_app.DataModel.Project.Name = "PROJECT 1"
project_file = os.path.join(tmp_path, f"{NamedTemporaryFile().name}.mechdat")
embedded_app.save_as(project_file)

project_file_directory = os.path.splitext(project_file)[0] + "_Mech_Files"
assert project_file_directory == os.path.normpath(embedded_app.project_directory)

with pytest.raises(Exception):
embedded_app.save_as(project_file)
embedded_app.save_as(project_file, overwrite=True)
Expand Down Expand Up @@ -293,7 +297,7 @@ def test_rm_lockfile(embedded_app, tmp_path: pytest.TempPathFactory):
embedded_app.save(mechdat_path)
embedded_app.close()

lockfile_path = os.path.join(embedded_app.DataModel.Project.ProjectDirectory, ".mech_lock")
lockfile_path = os.path.join(embedded_app.project_directory, ".mech_lock")
# Assert lock file path does not exist
assert not os.path.exists(lockfile_path)

Expand Down Expand Up @@ -446,7 +450,7 @@ def test_app_lock_file_open(embedded_app, tmp_path: pytest.TempPathFactory):
embedded_app.save_as(project_file)
embedded_app.save_as(project_file, overwrite=True)

lock_file = Path(embedded_app.DataModel.Project.ProjectDirectory) / ".mech_lock"
lock_file = Path(embedded_app.project_directory) / ".mech_lock"

# Assert the lock file exists after saving it
assert lock_file.exists()
Expand Down
Loading