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