|
| 1 | +### Contributing to the GraalVM Implementation of Python |
| 2 | + |
| 3 | +Thanks for considering to contribute! To get you started, here is a bit of |
| 4 | +information about the structure of this implementation. |
| 5 | + |
| 6 | +##### But first... |
| 7 | + |
| 8 | +You will need to sign the [Oracle Contributor |
| 9 | +Agreement](http://www.graalvm.org/community/contributors/) for us to be able to |
| 10 | +merge your work. |
| 11 | + |
| 12 | +Please also take some time to review our [code of |
| 13 | +conduct](http://www.graalvm.org/community/conduct/) for contributors. |
| 14 | + |
| 15 | +##### Getting started |
| 16 | + |
| 17 | +The first thing you want to do is to set up |
| 18 | +[mx](https://github.com/graalvm/mx.git). This is the build tool we use to |
| 19 | +develop GraalVM languages. You also need LLVM 6, including the `opt` tool -- the |
| 20 | +latter is not included on macOS by default, here you can install the homebrew |
| 21 | +version of LLVM, which includes this tool. Note that you can use any JDK, and do |
| 22 | +not necessarily need GraalVM for development. In that case you'll only be able |
| 23 | +to run without the just-in-time compiler, but that can be fine for making and |
| 24 | +testing changes that are not performance sensitive. |
| 25 | + |
| 26 | +Once you have `mx` on your `PATH`, you can run `mx build` in this |
| 27 | +repository. This will initially download the required dependencies next to the |
| 28 | +repository and build Python. If it succeeds without errors, you should already |
| 29 | +be able to run `mx python` and get a REPL. |
| 30 | + |
| 31 | +If you just want to copy and paste some commands, these should get you started: |
| 32 | + |
| 33 | + $ git clone https://github.com/graalvm/mx.git |
| 34 | + $ git clone https://github.com/graalvm/graalpython.git |
| 35 | + $ cd graalpython |
| 36 | + $ ../mx/mx build |
| 37 | + $ ../mx/mx python -c "print(42)" |
| 38 | + |
| 39 | +For development, we recommend running `mx ideinit` next. This will generate |
| 40 | +configurations for Eclipse, IntelliJ, and Netbeans so that you can open the |
| 41 | +projects in these IDEs. If you use another editor with support for the [Eclipse |
| 42 | +language server](https://github.com/eclipse/eclipse.jdt.ls) we also had reports |
| 43 | +of useable development setups with that, but it's not something we support. |
| 44 | + |
| 45 | +##### Development layout |
| 46 | + |
| 47 | +Besides the source code of the Python interpreter, we have some useful `mx` |
| 48 | +functions defined under the `mx.graalpython` directory. As you make changes, you |
| 49 | +can test always test them with `mx build && mx python`. Additionally, there are |
| 50 | +various "gates" that we use on our CI systems to check any code that goes |
| 51 | +in. You can run all of these using `mx python-gate` or just some by using `mx |
| 52 | +python-gate --tags [TAG]`. Two interesting gates to run that cover most things |
| 53 | +are: |
| 54 | + |
| 55 | +- `python-unittest` - Run the unittests written in Python, including those for the C extension API |
| 56 | +- `python-license` - Check that all files have the correct copyright headers applied to them |
| 57 | + |
| 58 | +###### Builtin modules and classes |
| 59 | + |
| 60 | +For the most part, builtin modules and classes are implemented in the |
| 61 | +`com.oracle.graal.python.builtins` package. For each module or class, there's |
| 62 | +Java class annoted with `@CoreFunctions`. Each function in a module or a class |
| 63 | +is implemented in a Node annotated with `@Builtin`. Take a look at the existing |
| 64 | +implementations to get a feel for how this is done. For now, when adding new |
| 65 | +classes or modules, they need to be added to the list in |
| 66 | +`com.oracle.graal.python.builtins.Python3Core`. |
| 67 | + |
| 68 | +Some builtin functions, modules, and classes are implemented in pure Python. The |
| 69 | +files for this are in `graalpython/lib-graalpython`. These files are listed in |
| 70 | +the Java `com.oracle.graal.python.builtins.Python3Core` class. Take a look at |
| 71 | +these files to see what they do. If a file is called exactly as a built-in |
| 72 | +module is, it is executed in the context of that module during startup, so some |
| 73 | +of our modules are implemented both in Java and Python. If the name matches no |
| 74 | +existing module, the file is executed just for the side-effects. |
| 75 | + |
| 76 | +###### Python C API |
| 77 | + |
| 78 | +The C implementation and headers for our C API are in |
| 79 | +`graalpython/com.oracle.graal.python.cext`. The naming is analogous to C |
| 80 | +Python's source names. This folder also includes a `modules` folder for built-in |
| 81 | +modules that we have adapted from C Python. |
0 commit comments