|
1 | | -(ddevelopment_env)= |
| 1 | +(dev_env)= |
2 | 2 | # Development environment |
3 | 3 |
|
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