|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Thanks for contributing to pythreejs! |
| 4 | + |
| 5 | +## Code Of Conduct |
| 6 | + |
| 7 | +This project follows the [Project Jupyter Code of Conduct][coc]. |
| 8 | + |
| 9 | +[coc]: https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +A full development environment will require: |
| 14 | + |
| 15 | +- `python >=3.6` |
| 16 | +- `jupyterlab >=3` |
| 17 | + - once built, `jupyterlab` version `1` or `2` may be used |
| 18 | +- `nodejs >=12` e.g. via |
| 19 | + ```bash |
| 20 | + conda install -c conda-forge 'nodejs>=12' |
| 21 | + ``` |
| 22 | + |
| 23 | +## Development Tasks |
| 24 | + |
| 25 | +The relevant commands while working on the repository are included below. These are not meant to be run sequentially, but rather as a list of useful commands. |
| 26 | + |
| 27 | +Most of these tasks are executed on many platforms and clients in [continuous integration][ci] |
| 28 | + |
| 29 | +[ci]: https://github.com/jupyter-widgets/pythreejs/blob/master/.github/workflows/ci.yml |
| 30 | + |
| 31 | +### Clone |
| 32 | + |
| 33 | +```bash |
| 34 | +git clone https://github.com/jupyter-widgets/pythreejs |
| 35 | +cd pythreejs |
| 36 | +``` |
| 37 | + |
| 38 | +### Dev setup |
| 39 | + |
| 40 | +```bash |
| 41 | +python -m pip install -e . |
| 42 | +``` |
| 43 | + |
| 44 | +### Re-generate autogen files |
| 45 | + |
| 46 | +```bash |
| 47 | +cd js |
| 48 | +npm run autogen |
| 49 | +``` |
| 50 | + |
| 51 | +> More about [autogen](#Autogen-update) |
| 52 | +
|
| 53 | +### Build and install JS distribution |
| 54 | + |
| 55 | +```bash |
| 56 | +cd js |
| 57 | +npm run build:all |
| 58 | +jupyter nbextension install --py --symlink --sys-prefix pythreejs |
| 59 | +``` |
| 60 | + |
| 61 | +### Build the python distributions |
| 62 | + |
| 63 | +```bash |
| 64 | +python setup.py sdist bdist_wheel |
| 65 | +``` |
| 66 | + |
| 67 | +### Clean out generated files |
| 68 | + |
| 69 | +```bash |
| 70 | +cd js |
| 71 | +npm run clean |
| 72 | +``` |
| 73 | + |
| 74 | +### Symlink the JupyterLab 3 federated extension |
| 75 | + |
| 76 | +```bash |
| 77 | +jupyter labextension develop . --overwrite |
| 78 | +``` |
| 79 | + |
| 80 | +### Run the tests |
| 81 | + |
| 82 | +```bash |
| 83 | +python -m pip install -e .[test] |
| 84 | +pytest -vv -l --nbval-lax --current-env . |
| 85 | +``` |
| 86 | + |
| 87 | +### Build the docs |
| 88 | + |
| 89 | +```bash |
| 90 | +python -m pip install -e .[docs] |
| 91 | +cd docs |
| 92 | +make html |
| 93 | +``` |
| 94 | + |
| 95 | +### Explore the examples |
| 96 | + |
| 97 | +```bash |
| 98 | +python -m pip install -e .[examples] |
| 99 | +``` |
| 100 | + |
| 101 | +And then: |
| 102 | + |
| 103 | +```bash |
| 104 | +jupyter notebook --debug |
| 105 | +# or |
| 106 | +jupyter lab --no-browser --debug |
| 107 | +``` |
| 108 | + |
| 109 | +### Watching sources |
| 110 | + |
| 111 | +```bash |
| 112 | +cd js |
| 113 | +npm watch |
| 114 | +``` |
| 115 | + |
| 116 | +### Watching JupyterLab 3+ federated extension |
| 117 | + |
| 118 | +```bash |
| 119 | +jupyter labextension watch . |
| 120 | +``` |
| 121 | + |
| 122 | +## Autogen update |
| 123 | + |
| 124 | +This is a _significant_ re-work of the pythreejs extension that introduces an "autogen" script that generates the majority of the ipython-widget code to wrap each of three.js's types. It also takes a different view towards the pythreejs API. Whereas pythreejs adds custom functionality to the classes, sometimes renaming, etc., this approach attempts to mimic the low-level three.js API as closely as possible, opening up the possibility for others to build utility libraries on top of this. |
| 125 | + |
| 126 | +The autogen script, `generate-wrappers.js`, takes advantage of a config file `three-class-config.js` to auto-generate both javascript and python files to define the ipywidget wrappers for each three.js class. The generated javascript files will have `.autogen.js` as the extension. The generated python files have `_autogen.py` as their extension. The script uses the handlebars template system to generate the various code files. |
| 127 | + |
| 128 | +The autogen solution allows for overriding the default behavior of the generated classes. E.g., if `Object3D.js` is present, then it will be loaded into the namespace as opposed to loading `Object3D.autogen.js`. It is up to the author of the override classe to decide whether to inherit behavior from the autogen class or not. Same goes for the python modules. This allows for writing custom methods on both the python and javascript side when needed. |
| 129 | + |
| 130 | +The autogen script relies on a json-like config file (`three-class-config.js`) to describe the classes. Reasonable defaults should take care of most, but it allows specifying the base class, constructor args, etc. for each of the wrappers. A base version of this file can be generated by `generate-class-config.js`, but beware, it overwrites any customization to the config file that has already been done. |
0 commit comments