|
| 1 | +How to contribute to Flask-SQLAlchemy |
| 2 | +===================================== |
| 3 | + |
| 4 | +Thank you for considering contributing to Flask-SQLAlchemy! |
| 5 | + |
| 6 | + |
| 7 | +Support questions |
| 8 | +----------------- |
| 9 | + |
| 10 | +Please, don't use the issue tracker for this. The issue tracker is a |
| 11 | +tool to address bugs and feature requests in Flask-SQLAlchemy itself. |
| 12 | +Use one of the following resources for questions about using |
| 13 | +Flask-SQLAlchemy or issues with your own code: |
| 14 | + |
| 15 | +- The ``#get-help`` channel on our Discord chat: |
| 16 | + https://discord.gg/t6rrQZH |
| 17 | +- The mailing list [email protected] for long term discussion or larger |
| 18 | + issues. |
| 19 | +- Ask on `Stack Overflow`_. Search with Google first using: |
| 20 | + ``site:stackoverflow.com flask sqlalchemy {search term, exception message, etc.}`` |
| 21 | + |
| 22 | +.. _Stack Overflow: https://stackoverflow.com/questions/tagged/flask-sqlalchemy?sort=linked |
| 23 | + |
| 24 | + |
| 25 | +Reporting issues |
| 26 | +---------------- |
| 27 | + |
| 28 | +Flask-SQLAlchemy is a thin wrapper that combines Flask and SQLAlchemy. |
| 29 | +Make sure your issue is actually with Flask-SQLAlchemy and not |
| 30 | +SQLAlchemy before submitting it. Check the traceback to see if the error |
| 31 | +is coming from SQLAlchemy. Check if your issue has already been reported |
| 32 | +to `SQLAlchemy`_. |
| 33 | + |
| 34 | +Include the following information in your post: |
| 35 | + |
| 36 | +- Describe what you expected to happen. |
| 37 | +- If possible, include a `minimal reproducible example`_ to help us |
| 38 | + identify the issue. This also helps check that the issue is not with |
| 39 | + your own code. |
| 40 | +- Describe what actually happened. Include the full traceback if there |
| 41 | + was an exception. |
| 42 | +- List your Python, Flask-SQLAlchemy, and SQLAlchemy versions. If |
| 43 | + possible, check if this issue is already fixed in the latest |
| 44 | + releases or the latest code in the repository. |
| 45 | + |
| 46 | +.. _SQLAlchemy: https://github.com/sqlalchemy/sqlalchemy/issues |
| 47 | +.. _minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example |
| 48 | + |
| 49 | + |
| 50 | +Submitting patches |
| 51 | +------------------ |
| 52 | + |
| 53 | +If there is not an open issue for what you want to submit, prefer |
| 54 | +opening one for discussion before working on a PR. You can work on any |
| 55 | +issue that doesn't have an open PR linked to it or a maintainer assigned |
| 56 | +to it. These show up in the sidebar. No need to ask if you can work on |
| 57 | +an issue that interests you. |
| 58 | + |
| 59 | +Include the following in your patch: |
| 60 | + |
| 61 | +- Use `Black`_ to format your code. This and other checks will run |
| 62 | + automatically if you install `pre-commit`_ using the instructions |
| 63 | + below. |
| 64 | +- Include tests if your patch adds or changes code. Make sure the test |
| 65 | + fails without your patch. |
| 66 | +- Update any relevant docs pages and docstrings. Docs pages and |
| 67 | + docstrings should be wrapped at 72 characters. |
| 68 | +- Add an entry in ``CHANGES.rst``. Use the same style as other |
| 69 | + entries. Also include ``.. versionchanged::`` inline changelogs in |
| 70 | + relevant docstrings. |
| 71 | + |
| 72 | +.. _Black: https://black.readthedocs.io |
| 73 | +.. _pre-commit: https://pre-commit.com |
| 74 | + |
| 75 | + |
| 76 | +First time setup |
| 77 | +~~~~~~~~~~~~~~~~ |
| 78 | + |
| 79 | +- Download and install the `latest version of git`_. |
| 80 | +- Configure git with your `username`_ and `email`_. |
| 81 | + |
| 82 | + .. code-block:: text |
| 83 | +
|
| 84 | + $ git config --global user.name 'your name' |
| 85 | + $ git config --global user.email 'your email' |
| 86 | +
|
| 87 | +- Make sure you have a `GitHub account`_. |
| 88 | +- Fork Flask-SQLAlchemy to your GitHub account by clicking the `Fork`_ |
| 89 | + button. |
| 90 | +- `Clone`_ the main repository locally. |
| 91 | + |
| 92 | + .. code-block:: text |
| 93 | +
|
| 94 | + $ git clone https://github.com/pallets/flask-sqlalchemy |
| 95 | + $ cd flask-sqlalchemy |
| 96 | +
|
| 97 | +- Add your fork as a remote to push your work to. Replace |
| 98 | + ``{username}`` with your username. |
| 99 | + |
| 100 | + .. code-block:: text |
| 101 | +
|
| 102 | + git remote add fork https://github.com/{username}/flask-sqlalchemy |
| 103 | +
|
| 104 | +- Create a virtualenv. |
| 105 | + |
| 106 | + .. code-block:: text |
| 107 | +
|
| 108 | + $ python3 -m venv env |
| 109 | + $ . env/bin/activate |
| 110 | +
|
| 111 | + On Windows, activating is different. |
| 112 | + |
| 113 | + .. code-block:: text |
| 114 | +
|
| 115 | + > env\Scripts\activate |
| 116 | +
|
| 117 | +- Install Flask-SQLAlchemy in editable mode with development |
| 118 | + dependencies. |
| 119 | + |
| 120 | + .. code-block:: text |
| 121 | +
|
| 122 | + $ pip install -e . -r requirements/dev.txt |
| 123 | +
|
| 124 | +- Install the pre-commit hooks. |
| 125 | + |
| 126 | + .. code-block:: text |
| 127 | +
|
| 128 | + $ pre-commit install |
| 129 | +
|
| 130 | +.. _latest version of git: https://git-scm.com/downloads |
| 131 | +.. _username: https://help.github.com/en/articles/setting-your-username-in-git |
| 132 | +.. _email: https://help.github.com/en/articles/setting-your-commit-email-address-in-git |
| 133 | +.. _GitHub account: https://github.com/join |
| 134 | +.. _Fork: https://github.com/pallets/flask/fork |
| 135 | +.. _Clone: https://help.github.com/en/articles/fork-a-repo#step-2-create-a-local-clone-of-your-fork |
| 136 | + |
| 137 | + |
| 138 | +Start coding |
| 139 | +~~~~~~~~~~~~ |
| 140 | + |
| 141 | +- Create a branch to identify the issue you would like to work on. If |
| 142 | + you're submitting a bug or documentation fix, branch off of the |
| 143 | + latest ".x" branch. |
| 144 | + |
| 145 | + .. code-block:: text |
| 146 | +
|
| 147 | + $ git checkout -b your-branch-name origin/2.x |
| 148 | +
|
| 149 | + If you're submitting a feature addition or change, branch off of the |
| 150 | + "master" branch. |
| 151 | + |
| 152 | + .. code-block:: text |
| 153 | +
|
| 154 | + $ git checkout -b your-branch-name origin/master |
| 155 | +
|
| 156 | +- Using your favorite editor, make your changes, |
| 157 | + `committing as you go`_. |
| 158 | +- Include tests that cover any code changes you make. Make sure the |
| 159 | + test fails without your patch. Run the tests as described below. |
| 160 | +- Push your commits to your fork on GitHub and |
| 161 | + `create a pull request`_. Link to the issue being addressed with |
| 162 | + ``fixes #123`` in the pull request. |
| 163 | + |
| 164 | + .. code-block:: text |
| 165 | +
|
| 166 | + $ git push --set-upstream fork your-branch-name |
| 167 | +
|
| 168 | +.. _committing as you go: https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html#commit-your-changes |
| 169 | +.. _create a pull request: https://help.github.com/en/articles/creating-a-pull-request |
| 170 | + |
| 171 | + |
| 172 | +Running the tests |
| 173 | +~~~~~~~~~~~~~~~~~ |
| 174 | + |
| 175 | +Run the basic test suite with pytest. |
| 176 | + |
| 177 | +.. code-block:: text |
| 178 | +
|
| 179 | + $ pytest |
| 180 | +
|
| 181 | +This runs the tests for the current environment, which is usually |
| 182 | +sufficient. CI will run the full suite when you submit your pull |
| 183 | +request. You can run the full test suite with tox if you don't want to |
| 184 | +wait. |
| 185 | + |
| 186 | +.. code-block:: text |
| 187 | +
|
| 188 | + $ tox |
| 189 | +
|
| 190 | +
|
| 191 | +Running test coverage |
| 192 | +~~~~~~~~~~~~~~~~~~~~~ |
| 193 | + |
| 194 | +Generating a report of lines that do not have test coverage can indicate |
| 195 | +where to start contributing. Run ``pytest`` using ``coverage`` and |
| 196 | +generate a report. |
| 197 | + |
| 198 | +.. code-block:: text |
| 199 | +
|
| 200 | + $ pip install coverage |
| 201 | + $ coverage run -m pytest |
| 202 | + $ coverage html |
| 203 | +
|
| 204 | +Open ``htmlcov/index.html`` in your browser to explore the report. |
| 205 | + |
| 206 | +Read more about `coverage <https://coverage.readthedocs.io>`__. |
| 207 | + |
| 208 | + |
| 209 | +Building the docs |
| 210 | +~~~~~~~~~~~~~~~~~ |
| 211 | + |
| 212 | +Build the docs in the ``docs`` directory using Sphinx. |
| 213 | + |
| 214 | +.. code-block:: text |
| 215 | +
|
| 216 | + $ cd docs |
| 217 | + $ make html |
| 218 | +
|
| 219 | +Open ``_build/html/index.html`` in your browser to view the docs. |
| 220 | + |
| 221 | +Read more about `Sphinx <https://www.sphinx-doc.org/en/stable/>`__. |
0 commit comments