CONTRIBUTING.rst 6.4 KB
Newer Older
M
Markus Unterwaditzer 已提交
1 2 3
How to contribute to Flask
==========================

D
David Lord 已提交
4
Thank you for considering contributing to Flask!
M
Markus Unterwaditzer 已提交
5

D
David Lord 已提交
6

M
Markus Unterwaditzer 已提交
7
Support questions
D
David Lord 已提交
8 9
-----------------

D
David Lord 已提交
10 11 12 13
Please don't use the issue tracker for this. The issue tracker is a tool
to address bugs and feature requests in Flask itself. Use one of the
following resources for questions about using Flask or issues with your
own code:
D
David Lord 已提交
14

D
David Lord 已提交
15
-   The ``#get-help`` channel on our Discord chat:
G
Grey Li 已提交
16
    https://discord.gg/pallets
D
David Lord 已提交
17 18 19
-   The mailing list flask@python.org for long term discussion or larger
    issues.
-   Ask on `Stack Overflow`_. Search with Google first using:
D
David Lord 已提交
20
    ``site:stackoverflow.com flask {search term, exception message, etc.}``
M
Markus Unterwaditzer 已提交
21

D
David Lord 已提交
22
.. _Stack Overflow: https://stackoverflow.com/questions/tagged/flask?tab=Frequent
M
Markus Unterwaditzer 已提交
23

D
David Lord 已提交
24

M
Markus Unterwaditzer 已提交
25
Reporting issues
D
David Lord 已提交
26
----------------
M
Markus Unterwaditzer 已提交
27

D
David Lord 已提交
28 29
Include the following information in your post:

D
David Lord 已提交
30 31 32 33 34 35
-   Describe what you expected to happen.
-   If possible, include a `minimal reproducible example`_ to help us
    identify the issue. This also helps check that the issue is not with
    your own code.
-   Describe what actually happened. Include the full traceback if there
    was an exception.
D
David Lord 已提交
36 37 38
-   List your Python and Flask versions. If possible, check if this
    issue is already fixed in the latest releases or the latest code in
    the repository.
M
Markus Unterwaditzer 已提交
39

D
David Lord 已提交
40
.. _minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example
M
Markus Unterwaditzer 已提交
41

D
David Lord 已提交
42

M
Markus Unterwaditzer 已提交
43
Submitting patches
D
David Lord 已提交
44
------------------
M
Markus Unterwaditzer 已提交
45

D
David Lord 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
If there is not an open issue for what you want to submit, prefer
opening one for discussion before working on a PR. You can work on any
issue that doesn't have an open PR linked to it or a maintainer assigned
to it. These show up in the sidebar. No need to ask if you can work on
an issue that interests you.

Include the following in your patch:

-   Use `Black`_ to format your code. This and other tools will run
    automatically if you install `pre-commit`_ using the instructions
    below.
-   Include tests if your patch adds or changes code. Make sure the test
    fails without your patch.
-   Update any relevant docs pages and docstrings. Docs pages and
    docstrings should be wrapped at 72 characters.
-   Add an entry in ``CHANGES.rst``. Use the same style as other
    entries. Also include ``.. versionchanged::`` inline changelogs in
    relevant docstrings.

.. _Black: https://black.readthedocs.io
.. _pre-commit: https://pre-commit.com
D
David Lord 已提交
67

M
Markus Unterwaditzer 已提交
68

D
David Lord 已提交
69
First time setup
D
David Lord 已提交
70
~~~~~~~~~~~~~~~~
D
David Lord 已提交
71

D
David Lord 已提交
72 73 74 75 76 77 78 79 80 81
-   Download and install the `latest version of git`_.
-   Configure git with your `username`_ and `email`_.

    .. code-block:: text

        $ git config --global user.name 'your name'
        $ git config --global user.email 'your email'

-   Make sure you have a `GitHub account`_.
-   Fork Flask to your GitHub account by clicking the `Fork`_ button.
D
David Lord 已提交
82
-   `Clone`_ the main repository locally.
D
David Lord 已提交
83

D
David Lord 已提交
84
    .. code-block:: text
D
David Lord 已提交
85

D
David Lord 已提交
86
        $ git clone https://github.com/pallets/flask
D
David Lord 已提交
87
        $ cd flask
D
David Lord 已提交
88

D
David Lord 已提交
89 90 91
-   Add your fork as a remote to push your work to. Replace
    ``{username}`` with your username. This names the remote "fork", the
    default Pallets remote is "origin".
D
David Lord 已提交
92

D
David Lord 已提交
93
    .. code-block:: text
D
David Lord 已提交
94

D
David Lord 已提交
95
        git remote add fork https://github.com/{username}/flask
D
David Lord 已提交
96

D
David Lord 已提交
97 98
-   Create a virtualenv.

99
    .. tabs::
D
David Lord 已提交
100

D
David Lord 已提交
101
       .. group-tab:: Linux/macOS
D
David Lord 已提交
102

103
          .. code-block:: text
D
David Lord 已提交
104

105 106 107 108 109 110
             $ python3 -m venv env
             $ . env/bin/activate

       .. group-tab:: Windows

          .. code-block:: text
D
David Lord 已提交
111

112 113
             > py -3 -m venv env
             > env\Scripts\activate
D
David Lord 已提交
114

D
David Lord 已提交
115 116
-   Install the development dependencies, then install Flask in editable
    mode.
D
David Lord 已提交
117

D
David Lord 已提交
118
    .. code-block:: text
D
David Lord 已提交
119

D
David Lord 已提交
120
        $ pip install -r requirements/dev.txt && pip install -e .
D
David Lord 已提交
121

D
David Lord 已提交
122
-   Install the pre-commit hooks.
D
David Lord 已提交
123

D
David Lord 已提交
124
    .. code-block:: text
125

D
David Lord 已提交
126
        $ pre-commit install
127

D
David Lord 已提交
128
.. _latest version of git: https://git-scm.com/downloads
D
David Lord 已提交
129 130
.. _username: https://docs.github.com/en/github/using-git/setting-your-username-in-git
.. _email: https://docs.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address
D
David Lord 已提交
131
.. _GitHub account: https://github.com/join
D
David Lord 已提交
132 133
.. _Fork: https://github.com/pallets/jinja/fork
.. _Clone: https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#step-2-create-a-local-clone-of-your-fork
D
David Lord 已提交
134

D
David Lord 已提交
135

D
David Lord 已提交
136
Start coding
D
David Lord 已提交
137
~~~~~~~~~~~~
D
David Lord 已提交
138

139 140
-   Create a branch to identify the issue you would like to work on. If
    you're submitting a bug or documentation fix, branch off of the
D
David Lord 已提交
141 142 143
    latest ".x" branch.

    .. code-block:: text
144

D
David Lord 已提交
145 146
        $ git fetch origin
        $ git checkout -b your-branch-name origin/1.1.x
147

148
    If you're submitting a feature addition or change, branch off of the
D
David Lord 已提交
149 150 151
    "master" branch.

    .. code-block:: text
152

D
David Lord 已提交
153
        $ git fetch origin
D
David Lord 已提交
154
        $ git checkout -b your-branch-name origin/master
155

D
David Lord 已提交
156 157 158
-   Using your favorite editor, make your changes,
    `committing as you go`_.
-   Include tests that cover any code changes you make. Make sure the
D
David Lord 已提交
159 160 161 162
    test fails without your patch. Run the tests as described below.
-   Push your commits to your fork on GitHub and
    `create a pull request`_. Link to the issue being addressed with
    ``fixes #123`` in the pull request.
163

D
David Lord 已提交
164
    .. code-block:: text
165

D
David Lord 已提交
166
        $ git push --set-upstream fork your-branch-name
M
Markus Unterwaditzer 已提交
167

168
.. _committing as you go: https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html#commit-your-changes
D
David Lord 已提交
169
.. _create a pull request: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request
D
David Lord 已提交
170

D
David Lord 已提交
171

D
David Lord 已提交
172 173
Running the tests
~~~~~~~~~~~~~~~~~
M
Markus Unterwaditzer 已提交
174

D
David Lord 已提交
175 176 177
Run the basic test suite with pytest.

.. code-block:: text
M
Markus Unterwaditzer 已提交
178

D
David Lord 已提交
179
    $ pytest
M
Markus Unterwaditzer 已提交
180

D
David Lord 已提交
181 182 183 184
This runs the tests for the current environment, which is usually
sufficient. CI will run the full suite when you submit your pull
request. You can run the full test suite with tox if you don't want to
wait.
185

D
David Lord 已提交
186 187 188 189
.. code-block:: text

    $ tox

190

191
Running test coverage
D
David Lord 已提交
192
~~~~~~~~~~~~~~~~~~~~~
193

D
David Lord 已提交
194
Generating a report of lines that do not have test coverage can indicate
D
David Lord 已提交
195
where to start contributing. Run ``pytest`` using ``coverage`` and
D
David Lord 已提交
196
generate a report.
D
David Lord 已提交
197 198

.. code-block:: text
199

D
David Lord 已提交
200
    $ pip install coverage
D
David Lord 已提交
201
    $ coverage run -m pytest
D
David Lord 已提交
202
    $ coverage html
203

D
David Lord 已提交
204
Open ``htmlcov/index.html`` in your browser to explore the report.
205

D
David Lord 已提交
206
Read more about `coverage <https://coverage.readthedocs.io>`__.
207

D
David Lord 已提交
208 209 210 211

Building the docs
~~~~~~~~~~~~~~~~~

D
David Lord 已提交
212 213 214
Build the docs in the ``docs`` directory using Sphinx.

.. code-block:: text
D
David Lord 已提交
215

D
David Lord 已提交
216 217
    $ cd docs
    $ make html
D
David Lord 已提交
218 219 220

Open ``_build/html/index.html`` in your browser to view the docs.

D
David Lord 已提交
221
Read more about `Sphinx <https://www.sphinx-doc.org/en/stable/>`__.