|
| 1 | +# Contributing guide |
| 2 | + |
| 3 | +MongoEngine has a large [community] and contributions are always encouraged. |
| 4 | +Contributions can be as simple as typo fix in the documentation, as well as complete |
| 5 | +new features and integrations. Please read these guidelines before sending a pull |
| 6 | +request. |
| 7 | + |
| 8 | +## Bugfixes and new features |
| 9 | + |
| 10 | +Before starting to write code, look for existing [tickets] or create one for your |
| 11 | +specific issue or feature request. That way you avoid working on something |
| 12 | +that might not be of interest or that has already been addressed. |
| 13 | + |
| 14 | +For new integrations do you best to make integration optional, to leave user |
| 15 | +opportunity to exclude additional dependencies, in case when user do not need |
| 16 | +integration or feature. |
| 17 | + |
| 18 | +## Supported interpreters |
| 19 | + |
| 20 | +Flask-MongoEngine supports CPython 3.7 and newer, PyPy 3.7 and newer. Language features |
| 21 | +not supported by all interpreters can not be used. |
| 22 | + |
| 23 | +## Running tests |
| 24 | + |
| 25 | +All development requirements, except [docker] are included in package extra options |
| 26 | +`dev`. So, to install full development environment you need just run package with |
| 27 | +all related options installation. |
| 28 | + |
| 29 | +Our local test environment related on [docker] and [nox] to test project on real |
| 30 | +database engine and not use any database mocking, as such mocking can raise unexpected |
| 31 | +behaviour, that is not seen in real database engines. |
| 32 | + |
| 33 | +Before running tests, please ensure that real database not launched on local port |
| 34 | +``27017``, otherwise tests will fail. If you want to run tests with local launched |
| 35 | +database engine, run tests in non-interactive mode (see below), in this case [docker] |
| 36 | +will not be used at all. |
| 37 | + |
| 38 | +We do not include docker python package to requirements, to exclude harming local |
| 39 | +developer's system, if docker installed in recommended/other way. |
| 40 | + |
| 41 | +To run minimum amount of required tests with [docker], use: |
| 42 | + |
| 43 | +```bash |
| 44 | +nox |
| 45 | +``` |
| 46 | + |
| 47 | +To run minimum amount of required tests with local database, use: |
| 48 | + |
| 49 | +```bash |
| 50 | +nox --non-interactive |
| 51 | +``` |
| 52 | + |
| 53 | +To run one or mode nox sessions only, use `-s` option. For example to run only |
| 54 | +documentation and linting tests, run: |
| 55 | + |
| 56 | +```bash |
| 57 | +nox -s documentation_tests lint |
| 58 | +``` |
| 59 | + |
| 60 | +In some cases you will want to bypass arguments to pytest itself, to run single test |
| 61 | +or single test file. It is easy to do, everything after double dash will be bypassed |
| 62 | +to pytest directly. For example, to run ``test__normal_command__logged`` test only, use: |
| 63 | + |
| 64 | +```bash |
| 65 | +nox -- -k test__normal_command__logged |
| 66 | +``` |
| 67 | + |
| 68 | +## Setting up the code for local development and tests |
| 69 | + |
| 70 | +1. Fork the `flask-mongoengine` repo on GitHub. |
| 71 | +2. Clone your fork locally: |
| 72 | + |
| 73 | + ```bash |
| 74 | + git clone git@github.com:your_name_here/flask-mongoengine.git |
| 75 | + ``` |
| 76 | + |
| 77 | +3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper |
| 78 | + installed, this is how you set up your fork for local development with all |
| 79 | + required development and testing dependencies (except docker): |
| 80 | + |
| 81 | + ```bash |
| 82 | + cd flask-mongoengine/ |
| 83 | + # With all development and package requirements, except docker |
| 84 | + pip install -e .[wtf,toolbar,dev] |
| 85 | + ``` |
| 86 | + |
| 87 | +4. Create a branch for local development: |
| 88 | + |
| 89 | + ```bash |
| 90 | + git checkout -b name-of-your-bugfix-or-feature |
| 91 | + ``` |
| 92 | + |
| 93 | + Now you can make your changes locally. |
| 94 | +5. When you're done making changes, check that your changes pass the tests and lint |
| 95 | + check: |
| 96 | + |
| 97 | + ```bash |
| 98 | + nox |
| 99 | + ``` |
| 100 | + |
| 101 | + Please note that [nox] runs lint and documentation builds check automatically, |
| 102 | + since we have a test environment for it. During lint check run, some common |
| 103 | + issues will be fixed automatically, so in case of failed status, firstly just try |
| 104 | + to rerun check again. If issue is not fixed automatically, check run log. |
| 105 | + |
| 106 | + If you feel like running only the lint environment, please use the following command: |
| 107 | + |
| 108 | + ```bash |
| 109 | + nox -s lint |
| 110 | + ``` |
| 111 | + |
| 112 | +6. Ensure that your feature or commit is fully covered by tests. Check report after |
| 113 | + regular nox run. |
| 114 | +7. Please install [pre-commit] git hook before adding any commits. This will |
| 115 | + ensure/fix 95% of linting issues. Otherwise, GitHub CI/CD pipeline may fail. This |
| 116 | + is linting double check (same as in [nox]), but it will run always, even if you |
| 117 | + forget to run tests before commit. |
| 118 | + |
| 119 | + ```bash |
| 120 | + pre-commit install |
| 121 | + ``` |
| 122 | + |
| 123 | +8. Commit your changes and push your branch to GitHub: |
| 124 | + |
| 125 | + ```bash |
| 126 | + git add . |
| 127 | + git commit -m "Your detailed description of your changes." |
| 128 | + git push origin name-of-your-bugfix-or-feature |
| 129 | + ``` |
| 130 | + |
| 131 | +9. Submit a pull request through the GitHub website. |
| 132 | + |
| 133 | +## Interactive documentation development |
| 134 | + |
| 135 | +Our nox configuration include special session for simplifying documentation |
| 136 | +development. When launched, documentation will be re-rendered after any saved |
| 137 | +code/documentation files changes. To use this session, after local environment setup, |
| 138 | +just run: |
| 139 | + |
| 140 | +```bash |
| 141 | +nox -s docs |
| 142 | +``` |
| 143 | + |
| 144 | +Rendered documentation will be available under: <http://localhost:9812/> |
| 145 | + |
| 146 | +## Style guide |
| 147 | + |
| 148 | +### General guidelines |
| 149 | + |
| 150 | +- Avoid backward breaking changes if at all possible. |
| 151 | +- Avoid mocking of external libraries; Mocking allowed only in tests. |
| 152 | +- Avoid complex structures, for complex classes/methods/functions try to separate to |
| 153 | + little objects, to simplify code reuse and testing. |
| 154 | +- Avoid code duplications, try to exctract duplicate code to function. (Code |
| 155 | + duplication in tests is allowed.) |
| 156 | +- Write docstrings for new classes and methods. |
| 157 | +- Write tests and make sure they pass. |
| 158 | +- Add yourself to [AUTHORS.md] :) |
| 159 | + |
| 160 | +### Code style guide |
| 161 | + |
| 162 | +- Docstrings are using RST format. Developer encouraged to include any signigicant |
| 163 | + information to docstrings. |
| 164 | +- Developers are encouraged to include typing information in functions signatures. |
| 165 | +- Developers should avoid including typing information to docstrings, if possible. |
| 166 | +- Developers should avoid including typing information to docstrings and signatures |
| 167 | + in same objects, to avoid rendering conflicts. |
| 168 | +- Code formatting is completely done by [black] and following black's style |
| 169 | + implementation of [PEP8]. Target python version is the lowest supported version. |
| 170 | +- Code formatting should be done before passing any new merge requests. |
| 171 | +- Code style should use f-strings if possible, exceptional can be made for expensive |
| 172 | + debug level logging statements. |
| 173 | + |
| 174 | +### Documentation style guide |
| 175 | + |
| 176 | +- [Documentation] should use Markdown as main format. Including Rest syntax blocks |
| 177 | + inside are allowed. Exceptional is API auto modules documents. Our [documentation] |
| 178 | + engine support [MyST] markdown extensions. |
| 179 | +- [Documentation] should use same 88 string length requirement, as code. Strings can |
| 180 | + be larger for cases, when last word/statement is any kind of link (either to |
| 181 | + class/function/attribute or web link). |
| 182 | +- Weblinks should be placed at the end of document, to make [documentation] easy |
| 183 | + readable without rendering (in editor). |
| 184 | +- Docs formatting should be checked and formatted with [pre-commit] plugin before |
| 185 | + submitting. |
| 186 | + |
| 187 | +## CI/CD testing |
| 188 | + |
| 189 | +All tests are run on [GitHub actions] and any pull requests are automatically tested |
| 190 | +for full range of supported [Flask], [mongoengine], [python] and [mongodb] versions. |
| 191 | +Any pull requests without tests will take longer to be integrated and might be refused. |
| 192 | + |
| 193 | +[community]: AUTHORS.md |
| 194 | + |
| 195 | +[tickets]: https://github.com/MongoEngine/flask-mongoengine/issues?state=open |
| 196 | + |
| 197 | +[PEP8]: http://www.python.org/dev/peps/pep-0008/ |
| 198 | + |
| 199 | +[black]: https://github.com/psf/black |
| 200 | + |
| 201 | +[pre-commit]: https://pre-commit.com/ |
| 202 | + |
| 203 | +[GitHub actions]: https://github.com/MongoEngine/flask-mongoengine/actions |
| 204 | + |
| 205 | +[Flask]: https://github.com/pallets/flask |
| 206 | + |
| 207 | +[mongoengine]: https://github.com/MongoEngine/mongoengine |
| 208 | + |
| 209 | +[python]: https://www.python.org/ |
| 210 | + |
| 211 | +[mongodb]: https://www.mongodb.com/ |
| 212 | + |
| 213 | +[AUTHORS.md]: AUTHORS.md |
| 214 | + |
| 215 | +[documentation]: http://docs.mongoengine.org/projects/flask-mongoengine/ |
| 216 | + |
| 217 | +[nox]: https://nox.thea.codes/en/stable/usage.html |
| 218 | + |
| 219 | +[docker]: https://www.docker.com/ |
| 220 | + |
| 221 | +[MyST]: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html |
0 commit comments