Debian Codegraph @

CONTRIBUTING.rst

raw
1 .. _contributing:
2
3 ===========================
4 Contributing
5 ===========================
6
7
8 .. highlight:: console
9
10 Contributions are welcome. If you would like add features or fix bugs,
11 please review the information below.
12
13 One source of history or ideas are the `bug reports`_.
14 There you can find ideas for requested features, or the remains of rejected
15 ideas.
16
17 If you have a 'big idea' - please file an issue first so it can be discussed
18 prior to you spending a lot of time developing. New features need to be generally
19 useful - if your feature has limited applicability, consider making a small
20 change that ENABLES your feature, rather than trying to get the entire feature
21 into Flask-Security.
22
23 .. _bug reports: https://github.com/pallets-eco/flask-security/issues
24
25
26 Checklist
27 ---------
28
29 * All new code and bug fixes need unit tests
30 * If you change/add to the external API be sure to update docs/openapi.yaml
31 * Additions to configuration variables and/or messages must be documented
32 * Make sure any new public API methods have good docstrings, are picked up by
33 the api.rst document, and are exposed in __init__.py if appropriate.
34 * Add appropriate info to CHANGES.rst
35
36
37 Getting the code
38 ----------------
39
40 The code is hosted on a GitHub repo at
41 https://github.com/pallets-eco/flask-security. To get a working environment, follow
42 these steps:
43
44 #. (Optional, but recommended) Create a Python 3.12 (or greater) virtualenv to work in,
45 and activate it.
46
47 #. Fork the repo `Flask-Security <https://github.com/pallets-eco/flask-security>`_
48 (look for the "Fork" button).
49
50 #. Clone your fork locally::
51
52 $ git clone https://github.com/<your-username>/flask-security
53
54 #. Change directory to flask-security::
55
56 $ cd flask-security
57
58 #. Install the requirements::
59
60 $ pip install pip install --group dev --group docs --group tests -U
61
62 #. Install pre-commit hooks::
63
64 $ pre-commit install
65
66 #. Create a branch for local development::
67
68 $ git checkout -b name-of-your-bugfix-or-feature
69
70 #. Develop the Feature/Bug Fix and edit
71
72 #. Write Tests for your code in::
73
74 tests/
75
76 #. When done, verify unit tests, syntax etc. all pass::
77
78 $ pip install --group dev --group docs --group tests
79 $ pip install -e .
80 $ sphinx-build docs docs/_build/html
81 $ tox -e compile_catalog
82 $ pytest tests
83 $ pre-commit run --all-files
84
85 #. Use tox::
86
87 $ tox # run everything CI does
88 $ tox -e py311-low # make sure works with older dependencies
89 $ tox -e style # run pre-commit/style checks
90
91 #. When the tests are successful, commit your changes
92 and push your branch to GitHub::
93
94 $ git add .
95 $ git commit -m "Your detailed description of your changes."
96 $ git push origin name-of-your-bugfix-or-feature
97
98 #. Submit a pull request through the GitHub website.
99
100 #. Be sure that the CI tests and coverage checks pass.
101
102 Updating the Swagger API document
103 ----------------------------------
104 When making changes to the external API, you need to update the openapi.yaml
105 formal specification. To do this - install the swagger editor locally::
106
107 $ npm -g install swagger-editor-dist http-server
108
109 Then in a browser navigate to::
110
111 file:///usr/local/lib/node_modules/swagger-editor-dist/index.html#
112
113
114 Edit - it is a WYSIWYG editor and will show you errors. Once you save (as yaml) you
115 need to look at what it will render as::
116
117 $ sphinx-build docs docs/_build/html
118 $ http-server -p 8081
119
120 Then in your browser navigate to::
121
122 http://localhost:8081/docs/_build/html/index.html
123 or
124 http://localhost:8081/docs/_build/html/_static/openapi_view.html
125
126
127 Please note that changing ``openapi.yaml`` won't re-trigger a docs build - so you might
128 have to manually delete ``docs/_build``.
129
130 Updating Translations
131 ---------------------
132 If you change any translatable strings (such as new messages, modified forms, etc.)
133 you need to re-generate the translations::
134
135 $ tox -e extract_messages
136 $ tox -e update_catalog
137 $ tox -e compile_catalog
138
139 Testing
140 -------
141 Unit tests are critical since Flask-Security is a piece of middleware. They also
142 help other contributors understand any subtleties in the code and edge conditions that
143 need to be handled.
144
145 Pre-Release Checklist
146 ---------------------
147 To prepare for a release:
148
149 - Update translations as outlined above
150 - Update pre-commit and actions: ``tox run -m update``
151 - Bump version in __init__.py and tox.ini
152 - Ensure CHANGES.rst has all the changes and acknowledgments
153
154 Release Process
155 ----------------
156
157 - Update CHANGES with release date
158 - commit and push and create PR - make sure succeeds - a SINGLE COMMIT only
159 - Create release tag: ``git tag -a -m’Release 5.5.2’ 5.5.2``
160 - ``git push origin 5.5.2``
161 - Ensure publish action succeeds (both Flask-Security and Flask-Security-Too)
162 - update draft release on github
163 - approve/publish(both) - verify works - THIS WILL PUBLISH TO PYPI
164 - commit PR - use merge-commit
165 - Publish Release on github console (leave fs-too in draft)
166
167 Datastore
168 +++++++++
169 By default the unit tests use an in-memory sqlite DB to test datastores (except for
170 MongoDatastore which uses mongomock). While this is sufficient for most changes, changes
171 to the datastore layer require testing against a real DB (the CI tests test against
172 postgres). It is easy to run the unit tests against a real DB instance. First
173 of course install and start the DB locally then::
174
175 # For postgres
176 pytest --realdburl postgresql://<user>@localhost/
177 # For mysql
178 pytest --realdburl "mysql+pymysql://root:<password>@localhost/"
179 # For mongodb
180 pytest --realmongodburl "localhost"
181
182 Views
183 +++++
184 Much of Flask-Security is concerned with form-based views. These can be difficult to test
185 especially translations etc. In the tests directory is a stand-alone Flask application
186 ``view_scaffold.py`` that can be run and you can point your browser to it and walk
187 through the various views.