Skip to content

Commit 5d35d09

Browse files
committed
CAP: adding dev docu pages
1 parent 092e055 commit 5d35d09

6 files changed

Lines changed: 391 additions & 17 deletions

File tree

.github/workflows/py-sanity-check.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
restore-keys: |
2323
${{ runner.os }}-conda-
2424
id: cache-conda
25-
2625
- name: Create diff_check conda environment if not cached
2726
if: steps.cache-conda.outputs.cache-hit != 'true'
2827
run: |

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ repos:
4141
- repo: https://github.com/astral-sh/ruff-pre-commit
4242
rev: v0.4.4
4343
hooks:
44-
- id: ruff
44+
- id: ruff
45+
args: [--config=.ruff.toml]

doc/contribute.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ We welcome pull requests from everyone. Please have a look at the [issue](https:
55

66
## Code quality
77

8-
We run [mypy](https://mypy.readthedocs.io/en/stable/index.html) and [] on pre-commit hooks to ensure code quality. Please make sure to run the following commands before submitting a pull request:
9-
10-
```console
11-
pre-commit run --all-files
12-
```
8+
We run [mypy](https://mypy.readthedocs.io/en/stable/index.html) and [Ruff](https://docs.astral.sh/ruff/) for e.g. python on pre-commit hooks to ensure code quality.
9+
Please make sure to:
10+
1. (when you `git clone` the repo) to install the *pre-commit hooks*:
11+
12+
```console
13+
pre-commit install
14+
```
15+
2. to run the following commands before submitting a pull request:
16+
17+
```console
18+
pre-commit run --all-files
19+
```
1320

1421
## How to contribute
1522

16-
Next, fall the following steps:
23+
Follow these steps to contribute to the project:
1724

1825
1. Fork the diffCheck repository by clicking the **Fork** button on the [diffCheck repository](https://github.com/diffCheckOrg/diffCheck). Clone the repository to your local machine:
1926

@@ -22,16 +29,24 @@ Next, fall the following steps:
2229
cd diffCheck
2330
```
2431

25-
2. Next you will need to set up your development environment. You can find the instructions in the [development installation guide](dev_documentation).
26-
27-
3. Create a new branch for your feature:
32+
2. Create a new branch for your feature:
2833

2934
```console
3035
git checkout -b my-feature
3136
```
3237

33-
4. Add the diffCheck repository as a remote for convinience:
38+
3. Add the diffCheck repository as a remote for convinience:
3439

3540
```console
3641
git remote add upstream https://github.com/diffCheckOrg/diffCheck
42+
```
43+
44+
4. Next you will need to set up your development environment. You can find the instructions in the [development installation guide](dev_env).
45+
46+
5. Work on your feature (follow [c++](cpp_conv) or [py](py_conv) style guide) and commit your changes by following the [commit message guidelines](git_commit_system):
47+
48+
```console
49+
git add .
50+
git commit -m "WIP: Add my feature"
51+
git push origin my-feature
3752
```

doc/dev_documentation.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
Developer documentation
44
=======================
55

6-
/// this octree should explode the CONTRIBUTING.md file in multiple sections and delete it, e.g.:
6+
Here you will find all the necessary as a developer to contribute to the project.
77

88
.. toctree::
9-
:hidden:
109
:maxdepth: 1
1110
:caption: Developer documentation
1211

doc/development_env.md

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,133 @@
1-
(ddevelopment_env)=
1+
(dev_env)=
22
# Development environment
33

4-
/// explain from contributing how to develop diffCheck
4+
If you develop for DF, you need to set up your development environment. This guide will help you to do that. Wether you are developing for the `c++` or `python` part of the project, you will find the necessary information here.
5+
6+
## Prepare your environment
7+
8+
Before to start, especially if you used diffCheck as an end-user before you will need to:
9+
10+
1. Make sure to have `camke` installed on your machine. You can download it [here](https://cmake.org/download/).
11+
2. Make sure to have `git` installed on your machine. You can download it [here](https://git-scm.com/downloads).
12+
3. We recommend to use `Visual Studio Code` as an IDE. You can download it [here](https://code.visualstudio.com/) together with [script-sync](https://github.com/ibois-epfl/script-sync) extension for Rhino/Grasshopper. You can download it from the Rhino's `PackageManager`. It is particularly useful if you want to develop [GHComponents](gh_components_gd) in python.
13+
4. if you used diffCheck before as an end-user clean all the `diffCheck folders` in the following directory (the last name will change), beware that Rhino should be closed before this step:
14+
```console
15+
C:\Users\<user-name>\.rhinocode\py39-rh8\site-envs\default-wMh5LZL3
16+
```
17+
18+
```{important}
19+
if you drop an official released diffCheck component from yak, this one will have the `#r : diffCheck==<version_number>` notation at the top of the script. Get rid of all these release components before to start and be sur to erase again the previous folders (they recreated each time `#r : diffCheck` is called).
20+
```
21+
22+
5. Clone the repository on your machine. Open a terminal and run the following command:
23+
```console
24+
git clone https://github.com/diffCheckOrg/diffCheck
25+
```
26+
27+
6. Checkout the repo:
28+
```console
29+
cd diffCheck
30+
```
31+
32+
7. Run cmake utilities `.bat`s files to config and build:
33+
```console
34+
./cmake/config.bat
35+
./cmake/build.bat
36+
```
37+
38+
8. Build the python df package from the py source code's directory:
39+
```console
40+
cd src/gh/diffCheck
41+
python setup.py sdist bdist_wheel
42+
```
43+
44+
9. Last, install the pip pacakge from the repository in editable mode. This way, all the modifications made to the source code of the repository will be reflected in the installed package. Open a terminal and run the following command (replace the path with where you download the repository):
45+
```console
46+
C:\Users\<your-username>\.rhinocode\py39-rh8\python.exe -m pip install -e "<path-to-repository-root>\src\gh\diffCheck"
47+
```
48+
49+
```{note}
50+
For your info the packages is installed in `C:\Users\andre\.rhinocode\py39-rh8\Lib\site-packages`.
51+
```
52+
53+
That's it you are now a contributor to the diffCheck! We raccomand to not download anymore from yak package but rather use the source code in the repository. If you want the latest diffCheck, checkout and pull the main.
54+
55+
---
56+
57+
(c-df-build)=
58+
## C++ DF build
59+
We mainly code in C++ to have heavy-lifting operations accessible via a [pybind11 interface](../src/diffCheckBindings.cc). If you or someone else has modified one of two follow these steps:
60+
61+
1. Checkout the repository:
62+
```console
63+
cd diffCheck
64+
```
65+
2. Run cmake utilities `.bat`s files to config and build:
66+
```console
67+
./cmake/config.bat
68+
./cmake/build.bat
69+
```
70+
3. All the C++'s targets should be now built.
71+
72+
---
73+
74+
## Python DF build
75+
There are 3 ways to develop in python in DF, often you will do both at the same time:
76+
* Develop `GHComponents` in python
77+
* Develop the `pybind11` interface in c++
78+
* Develop the Python's `diffCheck` API
79+
80+
(gh_components_gd)=
81+
### a) Develop `GHComponents` in API
82+
We follow the Compas's method to generate [DF python components](gh_dfcomp) in Grasshopper, have a look at their [guide](https://github.com/compas-dev/compas-actions.ghpython_components). All the components are in `src/gh/components`. To develop a new component, you will need to follow these steps:
83+
84+
1. Create a new folder in `src/gh/components` with the name of your component.
85+
2. Create 3 files with the following names in it:
86+
* a) `code.py`: this is where you code goes
87+
* b) `icon.png`: this is the icon of your component
88+
* c) `metadata.json`: this is the metadata of your component (for more info follow [Compas guidelines](https://github.com/compas-dev/compas-actions.ghpython_components?tab=readme-ov-file#metadata))
89+
90+
your `code.py` should look like this:
91+
92+
```{eval-rst}
93+
.. literalinclude:: ../src/gh/components/DF_tester/code.py
94+
:language: python
95+
:linenos:
96+
:caption: `DF_tester component <../src/gh/components/DF_tester/code.py>`_
97+
```
98+
3. To test it in Grasshopper, drop a new `script-sync` component in Grasshopper, point it to the `code.py` file and add `diffCheck` to the packages to reload of the component.
99+
4. Finally, you will need to add the following on your last line of the `code.py` file:
100+
```python
101+
if __name__ == "__main__":
102+
comp = DF_tester()
103+
o_value : bool = comp.Run()
104+
```
105+
106+
```{warning}
107+
This is necessary to run the component in the Rhino's python editor but it should be **removed** when done.
108+
```
109+
5. Once you are satisfied you can componentize it by running:
110+
```console
111+
invoke ghcomponentize
112+
```
113+
This will generate the component in the `build/gh` folder. Grab yours and drop it on the Grasshopper canvas, be sure that this is working as expected.
114+
115+
```{hint}
116+
If you pull a new version of the source code with new components you will need to run this command to update the generate the components, erase the old ones in the `ghuser` folder and add the new ones.
117+
```
118+
6. Done! You have now a new component in the `ghuser` tab of Grasshopper.
119+
120+
(pybind_gd)=
121+
### b) Develop the `pybind11` interface in c++
122+
123+
Have a look at [C++ DF build](#c-df-build) to build the c++ project. The `pybind11` interface is in the `src/diffCheckBindings.cc` file. Write your new functions or namespace in this file. This is basically a `.dll` so for Rhino/Grasshopper to be visible you need to first close Rhino and run `cmake/build.bat` to build the project. Once done, you can open Rhino and test your new wrap functions in the Rhino's python editor.
124+
125+
126+
(dfpypack_gd)=
127+
### c) Develop the Python's `diffCheck` API
128+
129+
All the source code is in the `src/gh/diffCheck/diffCheck` folder. If you add new modules or code to existing one and you are using `script-sync` to test your code in Grasshopper, your changes will be immediately reflected. Have a look at the [diffCheck Python API](diffCheck_API) for more info.
130+
131+
```{note}
132+
If you want to test your code in the Rhino's python editor, you will need to install the package in editable mode. Have a look at the [Prepare your environment](#prepare-your-environment) section for more info.
133+
```

0 commit comments

Comments
 (0)