7 Commits

Author SHA1 Message Date
Jonathon Broughton 7517682456 Remove unnecessary blank lines and handle 404 error when storing file result
- Remove multiple unnecessary blank lines in `main.py`
- Handle the 404 error when attempting to store a file result in `reporting.py`
2024-08-04 17:47:14 +01:00
Jonathon Broughton 46b6c0d68c Print commit details with server URL in a formatted manner
- Added print statements to display the beginning and end of execution
- Modified the print statement to display the server URL in a formatted manner
2024-08-04 17:36:15 +01:00
Jonathon Broughton 62d5e67bab Refactor find_density_branch function to use AutomationContext and return Optional[Base]
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
This commit refactors the find_density_branch function in objects.py to accept an AutomationContext parameter instead of automate_run_data. It also updates the variable names within the function accordingly. The return type of the function is changed to Optional[Base]. Additionally, the code in transport_recolorized_commit is modified to call find_density_branch with automate_context instead of automate_context.automation_run_data. This change ensures that commits on the density branch cannot be recolored.
2024-08-04 17:19:12 +01:00
Jonathon Broughton dee3ff2b63 Add find_density_branch() function to locate the 'density' branch
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
This commit adds a new function, find_density_branch(), which searches for a branch with the name 'density' in its lowercase form. If found, it prints the name and ID of the branch. If not found, it prints a message indicating that no such branch was found. This function is then used in transport_recolorized_commit() to check if the current automation run data corresponds to the 'density' branch before proceeding with commit recolorization.
2024-08-04 16:22:23 +01:00
Jonathon Broughton 9f1aa11551 Add safe file storage to automate_function
The code changes add the import of `safe_store_file_result` from `src.utilities.reporting` and replace the call to `automate_context.store_file_result(file_name)` with a call to `safe_store_file_result(automate_context, file_name)` in the function `automate_function`. This change ensures that files are stored safely during automation.
2024-08-04 15:56:59 +01:00
Jonathon Broughton b538e6d8d3 Update dependencies in pyproject.toml
- Updated matplotlib from version 3.8.0 to 3.9.1
- Updated reportlab from version 4.0.6 to 4.2.2
- Updated black from version 23.3.0 to 23.12.1
- Updated pytest from version 7.4.2 to 7.4.4
- Updated python-dotenv from version 1.0.0 to 1.0.1
- Added vulture dependency with version 2.11
2024-08-04 15:52:54 +01:00
Jonathon Broughton 81365c0e5a Move import statement to correct module
The import statement for `extract_base_and_transform` has been moved from the `flatten` module to the correct location in the `utilities` module. This ensures that the code is organized properly and follows best practices.
2024-08-04 15:41:15 +01:00
7 changed files with 47 additions and 24 deletions
Generated
+12 -1
View File
@@ -1616,6 +1616,17 @@ h2 = ["h2 (>=4,<5)"]
socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"]
zstd = ["zstandard (>=0.18.0)"]
[[package]]
name = "vulture"
version = "2.11"
description = "Find dead code"
optional = false
python-versions = ">=3.8"
files = [
{file = "vulture-2.11-py2.py3-none-any.whl", hash = "sha256:12d745f7710ffbf6aeb8279ba9068a24d4e52e8ed333b8b044035c9d6b823aba"},
{file = "vulture-2.11.tar.gz", hash = "sha256:f0fbb60bce6511aad87ee0736c502456737490a82d919a44e6d92262cb35f1c2"},
]
[[package]]
name = "websockets"
version = "11.0.3"
@@ -1880,4 +1891,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "fa9a19381de95ee7cd6798a3b4707ed3fbe2f2845e449cdcd652d5670e4038cf"
content-hash = "d8792ab3203910f2a054288ebb3e8d05e1deca69549c2fdf475aa7ffd2878b40"
+7 -6
View File
@@ -8,18 +8,19 @@ packages = [{ include = "src" }]
[tool.poetry.dependencies]
python = "^3.11"
matplotlib = "^3.8.0"
matplotlib = "^3.9.1"
seaborn = "^0.13.0"
reportlab = "^4.0.6"
reportlab = "^4.2.2"
mypy = "^1.11.1"
pydantic = "^2.8.2"
specklepy = "^2.19.5"
[tool.poetry.group.dev.dependencies]
black = "^23.3.0"
black = "^23.12.1"
ruff = "^0.0.271"
pytest = "^7.4.2"
python-dotenv = "^1.0.0"
pytest = "^7.4.4"
python-dotenv = "^1.0.1"
vulture = "^2.11"
[build-system]
requires = ["poetry-core"]
@@ -36,4 +37,4 @@ select = [
]
[tool.ruff.pydocstyle]
convention = "google"
convention = "google"
+4
View File
@@ -9,5 +9,9 @@ sys.path.append(str(src_path))
from src.main import automate_function, FunctionInputs
if __name__ == "__main__":
print("---------")
print("| BEGIN |")
print("---------")
# Entry point: Execute the automate function with defined inputs.
execute_automate_function(automate_function, FunctionInputs)
+6 -10
View File
@@ -1,8 +1,7 @@
from pydantic import Field
from speckle_automate import (
AutomateBase,
AutomationContext,
execute_automate_function,
AutomationContext
)
from objects.objects import (
@@ -12,7 +11,7 @@ from objects.objects import (
density_summary,
transport_recolorized_commit
)
from src.utilities.reporting import generate_pdf, write_pdf_to_temp, generate_summary
from src.utilities.reporting import generate_pdf, write_pdf_to_temp, generate_summary, safe_store_file_result
from src.utilities.utilities import filter_displayable_bases
class FunctionInputs(AutomateBase):
@@ -74,11 +73,6 @@ def automate_function(
automate_context, health_objects, function_inputs.density_level
)
colorise_densities(automate_context, health_objects)
# Wrap up the analysis by marking the run either successful or failed.
@@ -114,9 +108,11 @@ def automate_function(
file_name = write_pdf_to_temp(report)
print(commit_details["server_url"])
print("------------------------------------------------")
print(f"| {commit_details['server_url']} |")
print("------------------------------------------------")
automate_context.store_file_result(file_name)
safe_store_file_result(automate_context, file_name)
# colorise the objects that pass/fail and send to a new model version
transport_recolorized_commit(
+12 -1
View File
@@ -404,6 +404,17 @@ def density_summary(
return data, all_densities, all_areas
def find_density_branch(automation_context: AutomationContext) -> Optional[Base]:
client = automation_context.speckle_client
project_id = automation_context.automation_run_data.project_id
branches = client.branch.list(project_id, 100, 0)
for branch in branches:
if "density" in branch.name.lower():
print(f"Found 'density' branch: {branch.name}, Branch ID: {branch.id}")
return branch.id
print("No branch with the name 'density' found.")
return None
def transport_recolorized_commit(
automate_context: AutomationContext,
@@ -414,7 +425,7 @@ def transport_recolorized_commit(
# return the commit id of the new commit
# create a new commit on a specific branch - we'll use "dirstat" for now
if automate_context.automation_run_data.branch_name == "density":
if find_density_branch(automate_context) is not None:
# commits on the density branch cannot be recolored
print("------------------------------------------------")
print("| CANNOT RECOLOR COMMITS ON THE DENSITY BRANCH |")
+5 -5
View File
@@ -276,14 +276,14 @@ def safe_store_file_result(automate_context: AutomationContext, file_name: str):
# Attempt to store the file
automate_context.store_file_result(file_name)
except httpx.HTTPStatusError as e:
if e.response.status_code == 404:
if e.response.status_code != 404:
raise
else:
# Handle the 404 error
error_message = f"Unable to store file: {file_name}. Error: {str(e)}"
print(error_message) # For logging purposes
automate_context.mark_run_exception(error_message)
else:
raise
# automate_context.mark_run_exception(error_message)
finally:
# Restore the original URL
automate_context.automation_run_data.speckle_server_url = original_url
+1 -1
View File
@@ -3,7 +3,7 @@ from typing import List, TypeVar, Iterable, Optional
from specklepy.objects.base import Base
from flatten import extract_base_and_transform
from src.utilities.flatten import extract_base_and_transform
T = TypeVar("T", bound=Base)