Split Readmes (#15)

* Add project configuration and refactor logic

- Created .gitignore to exclude IDE files.
- Added project module configuration for Python.
- Set up inspection profiles for code quality checks.
- Refactored main function logic into separate modules for better organisation.
- Introduced helper functions for object manipulation and rule processing.
- Implemented spreadsheet reading functionality to dynamically load rules.
- Added tests for integration with the Speckle server.

* Add developer guide

- Introduced a new developer README with setup, project structure, testing, and deployment instructions.
- Revised the primary README to reflect changes in functionality and usage instructions for the Checker function.
This commit is contained in:
Jonathon Broughton
2025-02-06 21:33:18 +00:00
committed by GitHub
parent a0bbb0cc30
commit b7ff0137b1
3 changed files with 80 additions and 93 deletions
+54
View File
@@ -0,0 +1,54 @@
# Checker Function Development Guide
## Setup
1. Install dependencies:
```bash
poetry shell && poetry install
```
2. Configure `.env`:
```
SPECKLE_TOKEN=your_speckle_token
SPECKLE_SERVER_URL=app.speckle.systems
```
Get test automation details from app.speckle.systems
## Project Structure
- `function.py`: Main business logic
- `rules.py`: Rule definitions and processing
- `inputs.py`: Function input schema
- `helpers.py`: Utility functions
- `spreadsheet.py`: TSV handling
## Testing
```bash
poetry run pytest
```
## Extending Rules
1. Add new predicate to `input_predicate_mapping` in `rules.py`
2. Create corresponding method in `RevitRules` class
3. Update tests
## Building
The function is packaged as a Docker container:
```bash
docker build -f ./Dockerfile -t checker .
```
## Local Testing
```bash
docker run --rm checker python -u main.py run [automation_data] [parameters] [token]
```
## Deployment
Create a GitHub release to trigger deployment to Speckle Automate.
+25 -89
View File
@@ -1,100 +1,36 @@
# Speckle Automate function template - Python # Public Function: Checker
This template repository is for a Speckle Automate function written in Python Validate Speckle objects against configurable rules using spreadsheet definitions.
using the [specklepy](https://pypi.org/project/specklepy/) SDK to interact with Speckle data.
This template contains the full scaffolding required to publish a function to the Automate environment. ## Usage
It also has some sane defaults for development environment setups.
## Getting started 1. Access the template Google Sheet [link needed]
2. Make a copy to your Google Drive using File > Make a copy
3. Define your rules in your sheet
4. Click "Speckle" menu > "Publish Rules" to get your TSV URL
5. Create an Automation in Speckle Automate using the Checker function
6. Paste your TSV URL into the function configuration
7. Run your automation
1. Use this template repository to create a new repository in your own / organization's profile. ## Rule Types
Register the function - Property existence
- Value matching
- Numeric comparisons
- Range checks
- List membership
- Pattern matching
- Boolean checks
### Add new dependencies ## Severity Levels
To add new Python package dependencies to the project, use the following: - WARNING: Issues that should be reviewed
`$ poetry add pandas` - ERROR: Critical issues requiring attention
### Change launch variables ## Example Rules
Describe how the launch.json should be edited. [Screenshot or example table to be added]
### Github Codespaces ## Support
Create a new repo from this template, and use the create new code. For issues or questions, please open a GitHub issue.
### Using this Speckle Function
1. [Create](https://automate.speckle.dev/) a new Speckle Automation.
1. Select your Speckle Project and Speckle Model.
1. Select the deployed Speckle Function.
1. Enter a phrase to use in the comment.
1. Click `Create Automation`.
## Getting Started with Creating Your Own Speckle Function
1. [Register](https://automate.speckle.dev/) your Function with [Speckle Automate](https://automate.speckle.dev/) and select the Python template.
1. A new repository will be created in your GitHub account.
1. Make changes to your Function in `main.py`. See below for the Developer Requirements and instructions on how to test.
1. To create a new version of your Function, create a new [GitHub release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) in your repository.
## Developer Requirements
1. Install the following:
- [Python 3](https://www.python.org/downloads/)
- [Poetry](https://python-poetry.org/docs/#installing-with-the-official-installer)
1. Run `poetry shell && poetry install` to install the required Python packages.
## Building and Testing
The code can be tested locally by running `poetry run pytest`.
### Building and running the Docker Container Image
Running and testing your code on your machine is a great way to develop your Function; the following instructions are a bit more in-depth and only required if you are having issues with your Function in GitHub Actions or on Speckle Automate.
#### Building the Docker Container Image
The GitHub Action packages your code into the format required by Speckle Automate. This is done by building a Docker Image, which Speckle Automate runs. You can attempt to build the Docker Image locally to test the building process.
To build the Docker Container Image, you must have [Docker](https://docs.docker.com/get-docker/) installed.
Once you have Docker running on your local machine:
1. Open a terminal
1. Navigate to the directory in which you cloned this repository
1. Run the following command:
```bash
docker build -f ./Dockerfile -t speckle_automate_python_example .
```
#### Running the Docker Container Image
Once the GitHub Action has built the image, it is sent to Speckle Automate. When Speckle Automate runs your Function as part of an Automation, it will run the Docker Container Image. You can test that your Docker Container Image runs correctly locally.
1. To then run the Docker Container Image, run the following command:
```bash
docker run --rm speckle_automate_python_example \
python -u main.py run \
'{"projectId": "1234", "modelId": "1234", "branchName": "myBranch", "versionId": "1234", "speckleServerUrl": "https://speckle.xyz", "automationId": "1234", "automationRevisionId": "1234", "automationRunId": "1234", "functionId": "1234", "functionName": "my function", "functionLogo": "base64EncodedPng"}' \
'{}' \
yourSpeckleServerAuthenticationToken
```
Let's explain this in more detail:
`docker run—-rm speckle_automate_python_example` tells Docker to run the Docker Container Image we built earlier. `speckle_automate_python_example` is the name of the Docker Container Image. The `--rm` flag tells Docker to remove the container after it has finished running, freeing up space on your machine.
The line `python -u main.py run` is the command run inside the Docker Container Image. The rest of the command is the arguments passed to the command. The arguments are:
- `'{"projectId": "1234", "modelId": "1234", "branchName": "myBranch", "versionId": "1234", "speckleServerUrl": "https://speckle.xyz", "automationId": "1234", "automationRevisionId": "1234", "automationRunId": "1234", "functionId": "1234", "functionName": "my function", "functionLogo": "base64EncodedPng"}'` - the metadata that describes the automation and the function.
- `{}` - the input parameters for the function the Automation creator can set. Here, they are blank, but you can add your parameters to test your function.
- `yourSpeckleServerAuthenticationToken`—the authentication token for the Speckle Server that the Automation can connect to. This is required to interact with the Speckle Server, for example, to get data from the Model.
## Resources
- [Learn](https://speckle.guide/dev/python.html) more about SpecklePy and interacting with Speckle from Python.
+1 -4
View File
@@ -11,8 +11,5 @@ from src.inputs import FunctionInputs
if __name__ == "__main__": if __name__ == "__main__":
# NOTE: always pass in the automate function by its reference; do not invoke it! # NOTE: always pass in the automate function by its reference; do not invoke it!
# Pass in the function reference with the inputs schema to the executor.
execute_automate_function(automate_function, FunctionInputs)
# If the function has no arguments, the executor can handle it like so execute_automate_function(automate_function, FunctionInputs)
# execute_automate_function(automate_function_without_inputs)