##// END OF EJS Templates
docs: contributing: use '.' rather than 'source' to align with 'installation'...
Thomas De Schampheleire -
r8360:91dcc7be default
parent child Browse files
Show More
@@ -1,337 +1,337 b''
1 1 .. _contributing:
2 2
3 3 =========================
4 4 Contributing to Kallithea
5 5 =========================
6 6
7 7 Kallithea is developed and maintained by its users. Please join us and scratch
8 8 your own itch.
9 9
10 10
11 11 Infrastructure
12 12 --------------
13 13
14 14 The main repository is hosted on Our Own Kallithea (aka OOK) at
15 15 https://kallithea-scm.org/repos/kallithea/, our self-hosted instance
16 16 of Kallithea.
17 17
18 18 For now, we use Bitbucket_ for `pull requests`_ and `issue tracking`_. The
19 19 issue tracker is for tracking bugs, not for support, discussion, or ideas --
20 20 please use the `mailing list`_ or :ref:`IRC <readme>` to reach the community.
21 21
22 22 We use Weblate_ to translate the user interface messages into languages other
23 23 than English. Join our project on `Hosted Weblate`_ to help us.
24 24 To register, you can use your Bitbucket or GitHub account. See :ref:`translations`
25 25 for more details.
26 26
27 27
28 28 Getting started
29 29 ---------------
30 30
31 31 To get started with Kallithea development run the following commands in your
32 32 bash shell::
33 33
34 34 hg clone https://kallithea-scm.org/repos/kallithea
35 35 cd kallithea
36 36 python3 -m venv ../kallithea-venv
37 source ../kallithea-venv/bin/activate
37 . ../kallithea-venv/bin/activate
38 38 pip install --upgrade pip setuptools
39 39 pip install --upgrade -e . -r dev_requirements.txt python-ldap python-pam
40 40 kallithea-cli config-create my.ini
41 41 kallithea-cli db-create -c my.ini --user=user --email=user@example.com --password=password --repos=/tmp
42 42 kallithea-cli front-end-build
43 43 gearbox serve -c my.ini --reload &
44 44 firefox http://127.0.0.1:5000/
45 45
46 46 If you plan to use Bitbucket_ for sending contributions, you can also fork
47 47 Kallithea on Bitbucket_ first (https://bitbucket.org/conservancy/kallithea) and
48 48 then replace the clone step above by a clone of your fork. In this case, please
49 49 see :ref:`contributing-guidelines` below for configuring your fork correctly.
50 50
51 51
52 52 Contribution flow
53 53 -----------------
54 54
55 55 Starting from an existing Kallithea clone, make sure it is up to date with the
56 56 latest upstream changes::
57 57
58 58 hg pull
59 59 hg update
60 60
61 61 Review the :ref:`contributing-guidelines` and :ref:`coding-guidelines`.
62 62
63 63 If you are new to Mercurial, refer to Mercurial `Quick Start`_ and `Beginners
64 64 Guide`_ on the Mercurial wiki.
65 65
66 66 Now, make some changes and test them (see :ref:`contributing-tests`). Don't
67 67 forget to add new tests to cover new functionality or bug fixes.
68 68
69 69 For documentation changes, run ``make html`` from the ``docs`` directory to
70 70 generate the HTML result, then review them in your browser.
71 71
72 72 Before submitting any changes, run the cleanup script::
73 73
74 74 ./scripts/run-all-cleanup
75 75
76 76 When you are completely ready, you can send your changes to the community for
77 77 review and inclusion. Most commonly used methods are sending patches to the
78 78 mailing list (via ``hg email``) or by creating a pull request on Bitbucket_.
79 79
80 80 .. _contributing-tests:
81 81
82 82
83 83 Running tests
84 84 -------------
85 85
86 86 After finishing your changes make sure all tests pass cleanly. Run the testsuite
87 87 by invoking ``py.test`` from the project root::
88 88
89 89 py.test
90 90
91 91 Note that on unix systems, the temporary directory (``/tmp`` or where
92 92 ``$TMPDIR`` points) must allow executable files; Git hooks must be executable,
93 93 and the test suite creates repositories in the temporary directory. Linux
94 94 systems with /tmp mounted noexec will thus fail.
95 95
96 96 Tests can be run on PostgreSQL like::
97 97
98 98 sudo -u postgres createuser 'kallithea-test' --pwprompt # password password
99 99 sudo -u postgres createdb 'kallithea-test' --owner 'kallithea-test'
100 100 REUSE_TEST_DB='postgresql://kallithea-test:password@localhost/kallithea-test' py.test
101 101
102 102 Tests can be run on MariaDB/MySQL like::
103 103
104 104 echo "GRANT ALL PRIVILEGES ON \`kallithea-test\`.* TO 'kallithea-test'@'localhost' IDENTIFIED BY 'password'" | sudo -u mysql mysql
105 105 TEST_DB='mysql://kallithea-test:password@localhost/kallithea-test?charset=utf8mb4' py.test
106 106
107 107 You can also use ``tox`` to run the tests with all supported Python versions.
108 108
109 109 When running tests, Kallithea generates a `test.ini` based on template values
110 110 in `kallithea/tests/conftest.py` and populates the SQLite database specified
111 111 there.
112 112
113 113 It is possible to avoid recreating the full test database on each invocation of
114 114 the tests, thus eliminating the initial delay. To achieve this, run the tests as::
115 115
116 116 gearbox serve -c /tmp/kallithea-test-XXX/test.ini --pid-file=test.pid --daemon
117 117 KALLITHEA_WHOOSH_TEST_DISABLE=1 KALLITHEA_NO_TMP_PATH=1 py.test
118 118 kill -9 $(cat test.pid)
119 119
120 120 In these commands, the following variables are used::
121 121
122 122 KALLITHEA_WHOOSH_TEST_DISABLE=1 - skip whoosh index building and tests
123 123 KALLITHEA_NO_TMP_PATH=1 - disable new temp path for tests, used mostly for testing_vcs_operations
124 124
125 125 You can run individual tests by specifying their path as argument to py.test.
126 126 py.test also has many more options, see `py.test -h`. Some useful options
127 127 are::
128 128
129 129 -k EXPRESSION only run tests which match the given substring
130 130 expression. An expression is a python evaluable
131 131 expression where all names are substring-matched
132 132 against test names and their parent classes. Example:
133 133 -x, --exitfirst exit instantly on first error or failed test.
134 134 --lf rerun only the tests that failed at the last run (or
135 135 all if none failed)
136 136 --ff run all tests but run the last failures first. This
137 137 may re-order tests and thus lead to repeated fixture
138 138 setup/teardown
139 139 --pdb start the interactive Python debugger on errors.
140 140 -s, --capture=no don't capture stdout (any stdout output will be
141 141 printed immediately)
142 142
143 143 Performance tests
144 144 ^^^^^^^^^^^^^^^^^
145 145
146 146 A number of performance tests are present in the test suite, but they are
147 147 not run in a standard test run. These tests are useful to
148 148 evaluate the impact of certain code changes with respect to performance.
149 149
150 150 To run these tests::
151 151
152 152 env TEST_PERFORMANCE=1 py.test kallithea/tests/performance
153 153
154 154 To analyze performance, you could install pytest-profiling_, which enables the
155 155 --profile and --profile-svg options to py.test.
156 156
157 157 .. _pytest-profiling: https://github.com/manahl/pytest-plugins/tree/master/pytest-profiling
158 158
159 159 .. _contributing-guidelines:
160 160
161 161
162 162 Contribution guidelines
163 163 -----------------------
164 164
165 165 Kallithea is GPLv3 and we assume all contributions are made by the
166 166 committer/contributor and under GPLv3 unless explicitly stated. We do care a
167 167 lot about preservation of copyright and license information for existing code
168 168 that is brought into the project.
169 169
170 170 Contributions will be accepted in most formats -- such as pull requests on
171 171 Bitbucket, something hosted on your own Kallithea instance, or patches sent by
172 172 email to the `kallithea-general`_ mailing list.
173 173
174 174 When contributing via Bitbucket, please make your fork of
175 175 https://bitbucket.org/conservancy/kallithea/ `non-publishing`_ -- it is one of
176 176 the settings on "Repository details" page. This ensures your commits are in
177 177 "draft" phase and makes it easier for you to address feedback and for project
178 178 maintainers to integrate your changes.
179 179
180 180 .. _non-publishing: https://www.mercurial-scm.org/wiki/Phases#Publishing_Repository
181 181
182 182 Make sure to test your changes both manually and with the automatic tests
183 183 before posting.
184 184
185 185 We care about quality and review and keeping a clean repository history. We
186 186 might give feedback that requests polishing contributions until they are
187 187 "perfect". We might also rebase and collapse and make minor adjustments to your
188 188 changes when we apply them.
189 189
190 190 We try to make sure we have consensus on the direction the project is taking.
191 191 Everything non-sensitive should be discussed in public -- preferably on the
192 192 mailing list. We aim at having all non-trivial changes reviewed by at least
193 193 one other core developer before pushing. Obvious non-controversial changes will
194 194 be handled more casually.
195 195
196 196 There is a main development branch ("default") which is generally stable so that
197 197 it can be (and is) used in production. There is also a "stable" branch that is
198 198 almost exclusively reserved for bug fixes or trivial changes. Experimental
199 199 changes should live elsewhere (for example in a pull request) until they are
200 200 ready.
201 201
202 202 .. _coding-guidelines:
203 203
204 204
205 205 Coding guidelines
206 206 -----------------
207 207
208 208 We don't have a formal coding/formatting standard. We are currently using a mix
209 209 of Mercurial's (https://www.mercurial-scm.org/wiki/CodingStyle), pep8, and
210 210 consistency with existing code. Run ``scripts/run-all-cleanup`` before
211 211 committing to ensure some basic code formatting consistency.
212 212
213 213 We support Python 3.6 and later.
214 214
215 215 We try to support the most common modern web browsers. IE9 is still supported
216 216 to the extent it is feasible, IE8 is not.
217 217
218 218 We primarily support Linux and OS X on the server side but Windows should also work.
219 219
220 220 HTML templates should use 2 spaces for indentation ... but be pragmatic. We
221 221 should use templates cleverly and avoid duplication. We should use reasonable
222 222 semantic markup with element classes and IDs that can be used for styling and testing.
223 223 We should only use inline styles in places where it really is semantic (such as
224 224 ``display: none``).
225 225
226 226 JavaScript must use ``;`` between/after statements. Indentation 4 spaces. Inline
227 227 multiline functions should be indented two levels -- one for the ``()`` and one for
228 228 ``{}``.
229 229 Variables holding jQuery objects should be named with a leading ``$``.
230 230
231 231 Commit messages should have a leading short line summarizing the changes. For
232 232 bug fixes, put ``(Issue #123)`` at the end of this line.
233 233
234 234 Use American English grammar and spelling overall. Use `English title case`_ for
235 235 page titles, button labels, headers, and 'labels' for fields in forms.
236 236
237 237 .. _English title case: https://en.wikipedia.org/wiki/Capitalization#Title_case
238 238
239 239 Template helpers (that is, everything in ``kallithea.lib.helpers``)
240 240 should only be referenced from templates. If you need to call a
241 241 helper from the Python code, consider moving the function somewhere
242 242 else (e.g. to the model).
243 243
244 244 Notes on the SQLAlchemy session
245 245 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
246 246
247 247 Each HTTP request runs inside an independent SQLAlchemy session (as well
248 248 as in an independent database transaction). ``Session`` is the session manager
249 249 and factory. ``Session()`` will create a new session on-demand or return the
250 250 current session for the active thread. Many database operations are methods on
251 251 such session instances. The session will generally be removed by
252 252 TurboGears automatically.
253 253
254 254 Database model objects
255 255 (almost) always belong to a particular SQLAlchemy session, which means
256 256 that SQLAlchemy will ensure that they're kept in sync with the database
257 257 (but also means that they cannot be shared across requests).
258 258
259 259 Objects can be added to the session using ``Session().add``, but this is
260 260 rarely needed:
261 261
262 262 * When creating a database object by calling the constructor directly,
263 263 it must explicitly be added to the session.
264 264
265 265 * When creating an object using a factory function (like
266 266 ``create_repo``), the returned object has already (by convention)
267 267 been added to the session, and should not be added again.
268 268
269 269 * When getting an object from the session (via ``Session().query`` or
270 270 any of the utility functions that look up objects in the database),
271 271 it's already part of the session, and should not be added again.
272 272 SQLAlchemy monitors attribute modifications automatically for all
273 273 objects it knows about and syncs them to the database.
274 274
275 275 SQLAlchemy also flushes changes to the database automatically; manually
276 276 calling ``Session().flush`` is usually only necessary when the Python
277 277 code needs the database to assign an "auto-increment" primary key ID to
278 278 a freshly created model object (before flushing, the ID attribute will
279 279 be ``None``).
280 280
281 281 Debugging
282 282 ^^^^^^^^^
283 283
284 284 A good way to trace what Kallithea is doing is to keep an eye on the output on
285 285 stdout/stderr of the server process. Perhaps change ``my.ini`` to log at
286 286 ``DEBUG`` or ``INFO`` level, especially ``[logger_kallithea]``, but perhaps
287 287 also other loggers. It is often easier to add additional ``log`` or ``print``
288 288 statements than to use a Python debugger.
289 289
290 290 Sometimes it is simpler to disable ``errorpage.enabled`` and perhaps also
291 291 ``trace_errors.enable`` to expose raw errors instead of adding extra
292 292 processing. Enabling ``debug`` can be helpful for showing and exploring
293 293 tracebacks in the browser, but is also insecure and will add extra processing.
294 294
295 295 TurboGears2 DebugBar
296 296 ^^^^^^^^^^^^^^^^^^^^
297 297
298 298 It is possible to enable the TurboGears2-provided DebugBar_, a toolbar overlayed
299 299 over the Kallithea web interface, allowing you to see:
300 300
301 301 * timing information of the current request, including profiling information
302 302 * request data, including GET data, POST data, cookies, headers and environment
303 303 variables
304 304 * a list of executed database queries, including timing and result values
305 305
306 306 DebugBar is only activated when ``debug = true`` is set in the configuration
307 307 file. This is important, because the DebugBar toolbar will be visible for all
308 308 users, and allow them to see information they should not be allowed to see. Like
309 309 is anyway the case for ``debug = true``, do not use this in production!
310 310
311 311 To enable DebugBar, install ``tgext.debugbar`` and ``kajiki`` (typically via
312 312 ``pip``) and restart Kallithea (in debug mode).
313 313
314 314
315 315 "Roadmap"
316 316 ---------
317 317
318 318 We do not have a road map but are waiting for your contributions. Refer to the
319 319 wiki_ for some ideas of places we might want to go -- contributions in these
320 320 areas are very welcome.
321 321
322 322
323 323 Thank you for your contribution!
324 324 --------------------------------
325 325
326 326
327 327 .. _Weblate: http://weblate.org/
328 328 .. _issue tracking: https://bitbucket.org/conservancy/kallithea/issues?status=new&status=open
329 329 .. _pull requests: https://bitbucket.org/conservancy/kallithea/pull-requests
330 330 .. _bitbucket: http://bitbucket.org/
331 331 .. _mailing list: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
332 332 .. _kallithea-general: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
333 333 .. _Hosted Weblate: https://hosted.weblate.org/projects/kallithea/kallithea/
334 334 .. _wiki: https://bitbucket.org/conservancy/kallithea/wiki/Home
335 335 .. _DebugBar: https://github.com/TurboGears/tgext.debugbar
336 336 .. _Quick Start: https://www.mercurial-scm.org/wiki/QuickStart
337 337 .. _Beginners Guide: https://www.mercurial-scm.org/wiki/BeginnersGuides
General Comments 0
You need to be logged in to leave comments. Login now