Debian Codegraph @

CONTRIBUTING.rst

raw
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 tool
11 to address bugs and feature requests in Flask-SQLAlchemy itself. Use one
12 of the following resources for questions about using Flask-SQLAlchemy or
13 issues 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-sqlalchemy {search term, exception message, etc.}``
21
22 .. _Stack Overflow: https://stackoverflow.com/questions/tagged/flask-sqlalchemy?tab=Frequent
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 tools 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.
67 - Add an entry in ``CHANGES.rst``. Use the same style as other
68 entries. Also include ``.. versionchanged::`` inline changelogs in
69 relevant docstrings.
70
71 .. _Black: https://black.readthedocs.io
72 .. _pre-commit: https://pre-commit.com
73
74
75 First time setup
76 ~~~~~~~~~~~~~~~~
77
78 - Download and install the `latest version of git`_.
79 - Configure git with your `username`_ and `email`_.
80
81 .. code-block:: text
82
83 $ git config --global user.name 'your name'
84 $ git config --global user.email 'your email'
85
86 - Make sure you have a `GitHub account`_.
87 - Fork Flask-SQLAlchemy to your GitHub account by clicking the `Fork`_
88 button.
89 - `Clone`_ the main repository locally, replacing ``{username}`` with your GitHub
90 username.
91
92 .. code-block:: text
93
94 $ git clone https://github.com/{username}/flask-sqlalchemy
95 $ cd flask-sqlalchemy
96
97 - Create a virtualenv.
98
99 .. code-block:: text
100
101 $ python3 -m venv .venv
102 $ . .venv/bin/activate
103
104 On Windows, activating is different.
105
106 .. code-block:: text
107
108 > .venv\Scripts\activate
109
110 - Install the development dependencies, then install Flask-SQLAlchemy
111 in editable mode.
112
113 .. code-block:: text
114
115 $ pip install -r requirements/dev.txt && pip install -e .
116
117 - Install the pre-commit hooks.
118
119 .. code-block:: text
120
121 $ pre-commit install
122
123 .. _latest version of git: https://git-scm.com/downloads
124 .. _username: https://docs.github.com/en/github/using-git/setting-your-username-in-git
125 .. _email: https://docs.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address
126 .. _GitHub account: https://github.com/join
127 .. _Fork: https://github.com/pallets-eco/flask-sqlalchemy/fork
128 .. _Clone: https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#step-2-create-a-local-clone-of-your-fork
129
130
131 Start coding
132 ~~~~~~~~~~~~
133
134 - Create a branch to identify the issue you would like to work on. If
135 you're submitting a bug or documentation fix, branch off of the
136 latest ".x" branch.
137
138 .. code-block:: text
139
140 $ git fetch origin
141 $ git checkout -b your-branch-name origin/3.0.x
142
143 If you're submitting a feature addition or change, branch off of the
144 "main" branch.
145
146 .. code-block:: text
147
148 $ git fetch origin
149 $ git checkout -b your-branch-name origin/main
150
151 - Using your favorite editor, make your changes,
152 `committing as you go`_.
153 - Include tests that cover any code changes you make. Make sure the
154 test fails without your patch. Run the tests as described below.
155 - Push your commits to your fork on GitHub and
156 `create a pull request`_. Link to the issue being addressed with
157 ``fixes #123`` in the pull request.
158
159 .. code-block:: text
160
161 $ git push --set-upstream fork your-branch-name
162
163 .. _committing as you go: https://dont-be-afraid-to-commit.readthedocs.io/en/latest/git/commandlinegit.html#commit-your-changes
164 .. _create a pull request: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request
165
166
167 Running the tests
168 ~~~~~~~~~~~~~~~~~
169
170 Run the basic test suite with pytest.
171
172 .. code-block:: text
173
174 $ pytest
175
176 This runs the tests for the current environment, which is usually sufficient. CI will
177 run the full suite when you submit your pull request. You can run the full test suite in
178 parallel with tox if you don't want to wait.
179
180 .. code-block:: text
181
182 $ tox p
183
184
185 Running test coverage
186 ~~~~~~~~~~~~~~~~~~~~~
187
188 Generating a report of lines that do not have test coverage can indicate where to start
189 contributing. Collect coverage from the tests and generate a report.
190
191 .. code-block:: text
192
193 $ pip install "coverage[toml]"
194 $ coverage run -m pytest
195 $ coverage html
196
197 Open ``htmlcov/index.html`` in your browser to explore the report.
198
199 Read more about `coverage <https://coverage.readthedocs.io>`__.
200
201
202 Building the docs
203 ~~~~~~~~~~~~~~~~~
204
205 Build the docs in the ``docs`` directory using Sphinx.
206
207 .. code-block:: text
208
209 $ cd docs
210 $ make html
211
212 Open ``_build/html/index.html`` in your browser to view the docs.
213
214 Read more about `Sphinx <https://www.sphinx-doc.org/en/stable/>`__.
215
216
217 Publishing a Release
218 --------------------
219
220 As a maintainer, once you decide it's time to publish a new release, follow these
221 instructions.
222
223 1. You'll manage the release through a PR on GitHub. Create a branch like
224 "release-A.B.C". For a fix release, branch off the corresponding release branch. For
225 a feature release, branch off of main.
226
227 .. code-block:: text
228
229 $ git switch -c release-A.B.C A.B.x
230
231 2. Review the ``CHANGES.rst`` file and ensure each code change has a corresponding
232 entry. Only code changes need entries, not docs or non-published code and files. Use
233 your judgement on what users would want to know.
234
235 3. Update the ``CHANGES.rst`` file to replace "Unreleased" with "Released YYYY-MM-DD".
236
237 4. Update ``__version__`` in ``__init__.py`` to remove the ".dev" suffix. Ensure that
238 the version number matches what you think you're releasing.
239
240 5. Commit with a standard message:
241
242 .. code-block:: text
243
244 $ git commit -am 'release version A.B.C'
245
246 6. Push the branch and open a PR. The title should be the same as the commit message
247 (if there was only one commit). No need to add a description. Assign it to the
248 corresponding vesion milestone, like "3.0.4". If there's no milestone, it's because
249 this is a newly adapted project that isn't using our full organization scheme yet,
250 no problem.
251
252 7. Don't merge the PR until the end. Observe that all workflows and checks pass for the
253 PR.
254
255 8. Create and push an annotated tag with a standard message. You'll see the new
256 "build" workflow status get added to the PR checks.
257
258 .. code-block:: text
259
260 $ git tag -am 'release version A.B.C' A.B.C
261 $ git push origin A.B.C
262
263 9. Wait for the "build", "provenance", and "create-release" workflows to succeed. Go
264 into the created draft release and check that the expected files (with the correct
265 version numbers) are part of it. Add a quick message about the release, such as
266 "This is a fix release for the 3.0.x release branch." along with a link to the
267 changelog section and closed milestone. See an existing release in Flask for an
268 example. Save the draft (don't publish it yet, it's not on PyPI yet.)
269
270 10. The "publish-pypi" workflow will have a yellow paused icon. A maintainer with
271 publish permissions must approve it. Once they do, the release files will be
272 uploaded to PyPI. If you don't have publish permission yet, ping the maintainers
273 channel.
274
275 11. After seeing that the "publish-pypi" workflow succeeds, merge the PR. Then publish
276 the draft release, and close the milestone.
277
278 12. If this was a fix release, merge the release branch (A.B.x) into main.
279
280 .. code-block:: text
281
282 $ git switch A.B.x
283 $ git pull
284 $ git switch main
285 $ git merge A.B.x
286 $ git push
287
288 Here's how to handle the expected merge conflicts:
289
290 * ``CHANGES.rst`` : Keep both changes, ensuring the next feature version is on top.
291 * ``__init__.py`` : Keep the version in main (the next feature version).
292
293 12. If this was a feature release, make a new branch for fix releases.
294
295 .. code-block:: text
296
297 $ git switch main
298 $ git pull
299 $ git switch -c A.B.x
300 $ git push
301
302 13. If this was a feature release, ask a maintainer with docs access to update Read the
303 Docs to use the new branch as the primary.