Add some guidelines on new feature contributions, based on my observations

master
Angus Gratton 2023-09-05 15:57:25 +10:00
rodzic 9a6c8eaac0
commit 3bd5b123b1
1 zmienionych plików z 26 dodań i 2 usunięć

@ -15,7 +15,7 @@ We welcome all types of contributions, across a wide variety of different domain
* Developer tools and workflow
* Community management
There's information about [getting started with MicroPython development](https://docs.micropython.org/en/latest/develop/gettingstarted.html) in the official documentation. For more assistance, the [discussion forums](https://github.com/micropython/micropython/discussions) and the [Discord server](https://github.com/micropython/micropython/wiki/ContributorGuidelines) are a great way to ask questions and connect with other MicroPython developers.
There's information about [getting started with MicroPython development](https://docs.micropython.org/en/latest/develop/gettingstarted.html) in the official documentation. For more assistance, the [discussion forums](https://github.com/micropython/micropython/discussions) and the [Discord server](https://micropython.org/discord) are a great way to ask questions and connect with other MicroPython developers.
It's often a good idea before starting a piece of work to get some feedback from the community or the project maintainers, to ensure that your effort will not be wasted. Raising an issue with `"RFC: "` as the start of the title is a good way to do this.
@ -35,7 +35,31 @@ As much as we'd like to, in the spirit of keeping things "micro", not all featur
MicroPython supports devices with as little as 128kiB of flash and 16kiB of RAM. Even the Unix port can be used to run MicroPython on truly minimal Linux systems with just 4MiB or even 2MiB of flash. To give you an idea of how highly we value code size, the MicroPython team will spent hours of effort just to save 100's (or even 10's) of bytes. This unfortunately means that the code can be more complicated, but it is a worthwhile trade-off.
In many cases, features can be enabled conditionally for a given target (i.e. boards with lots of flash or RAM, or the Unix/Windows ports). The continuous integration will check any new changes to ensure that our "minimal" ports do not increase in size.
In many cases, features can be enabled conditionally for a given target (i.e. boards with lots of flash or RAM, or the Unix/Windows ports). See the various `MICROPY_` macro definitions in the codebase. The continuous integration will check any new changes to ensure that our "minimal" ports do not increase in size.
### Discuss first
If you're thinking of contributing a significant new feature and not sure if it's suitable, consider starting a [Discussion](https://github.com/micropython/micropython/discussions) or opening an [Issue](https://github.com/micropython/micropython/issues) with a feature request first. Explain any work you plan to do, and why you think it would be good for MicroPython to include and support this feature.
You should also search the open [Issues](https://github.com/micropython/micropython/issues), [Pull Requests](https://github.com/micropython/micropython/pulls), and [Discussions](https://github.com/micropython/micropython/discussions) first to see if anyone else has a similar idea.
### Adding Python library features
Some guidelines if adding a new Python library feature (like a new function or a new module):
* For features that also exist in [CPython](https://docs.python.org/3.5/library/), the MicroPython functionality should be a compatible subset of the CPython functionality. For example, if a module with the same name exists in CPython then MicroPython should not add an API or a name which isn't already in CPython. This is a relatively new goal, so many MicroPython modules have functions that don't exist in CPython. These are considered legacy, documented as MicroPython additions, and the goal is to not add more if possible.
* If the functionality can be implemented in a pure Python module, contribute it to [micropython-lib](https://github.com/micropython/micropython-lib/) as a package that can be installed on demand.
* Otherwise, consider if it's more suitable to add the feature to a [port-specific library](https://docs.micropython.org/en/latest/library/index.html#port-specific-libraries), the [machine](https://docs.micropython.org/en/latest/library/machine.html) module, or (in some very specific cases) the [micropython](https://docs.micropython.org/en/latest/library/micropython.html) module.
### Adding Python syntax features
If you want to change the Python language features exposed by MicroPython, it's a good idea to discuss this with the maintainers first.
### Adding hardware features
* If implementing an existing [machine](https://docs.micropython.org/en/latest/library/machine.html) API on a new port (for example, to add `machine.I2S` to a port which has I2S hardware but no MicroPython driver yet), then the API must match the existing `machine` API whenever possible. Additions that substantially change an existing `machine` API for a single port only, or have too many "special case" notes, may be better suited as port-specific APIs (see below).
* Contributing a new [machine](https://docs.micropython.org/en/latest/library/machine.html) API that adds brand new functionality (for example, adding a `machine.TenGbpsEthernet` class for 10Gbps Ethernet controllers) must be very carefully implemented and designed. These APIs must be as generic to work on multiple ports, while still being efficient and small in code size. If you're planning to contribute such a driver, please discuss with the maintainers and the community first. You could start with a [Discussion](https://github.com/micropython/micropython/discussions) or make a Pull Request that only adds the docs for your proposed API.
* If a new driver has port- or hardware-specific features that aren't suitable for a [machine](https://docs.micropython.org/en/latest/library/machine.html) API then consider adding them to a [port-specific library](https://docs.micropython.org/en/latest/library/index.html#port-specific-libraries). (Except `pyb`, this is legacy and new code should go into `stm` instead). This allows more freedom to expose the hardware's exact capabilities.
## Ports
We welcome ports to new architectures and microcontroller families. However, not all ports can be accepted into the main repository as each port is a significant maintenance overhead for the core team. It is straightforward to maintain a third-party "out-of-tree" port using MicroPython as a submodule.