##// END OF EJS Templates
docs: mention pytest-profiling...
Thomas De Schampheleire -
r6684:043621a7 default
parent child Browse files
Show More
@@ -1,269 +1,274 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 development::
32 32
33 33 hg clone https://kallithea-scm.org/repos/kallithea
34 34 cd kallithea
35 35 virtualenv ../kallithea-venv
36 36 source ../kallithea-venv/bin/activate
37 37 pip install --upgrade pip setuptools
38 38 pip install -e .
39 39 gearbox make-config my.ini
40 40 gearbox setup-db -c my.ini --user=user --email=user@example.com --password=password --repos=/tmp
41 41 gearbox serve -c my.ini --reload &
42 42 firefox http://127.0.0.1:5000/
43 43
44 44 You can also start out by forking https://bitbucket.org/conservancy/kallithea
45 45 on Bitbucket_ and create a local clone of your own fork.
46 46
47 47
48 48 Running tests
49 49 -------------
50 50
51 51 After finishing your changes make sure all tests pass cleanly. Install the test
52 52 dependencies, then run the testsuite by invoking ``py.test`` from the
53 53 project root::
54 54
55 55 pip install -r dev_requirements.txt
56 56 py.test
57 57
58 58 Note that testing on Python 2.6 also requires ``unittest2``.
59 59
60 60 Note that on unix systems, the temporary directory (``/tmp`` or where
61 61 ``$TMPDIR`` points) must allow executable files; Git hooks must be executable,
62 62 and the test suite creates repositories in the temporary directory. Linux
63 63 systems with /tmp mounted noexec will thus fail.
64 64
65 65 You can also use ``tox`` to run the tests with all supported Python versions
66 66 (currently Python 2.6--2.7).
67 67
68 68 When running tests, Kallithea uses `kallithea/tests/test.ini` and populates the
69 69 SQLite database specified there.
70 70
71 71 It is possible to avoid recreating the full test database on each invocation of
72 72 the tests, thus eliminating the initial delay. To achieve this, run the tests as::
73 73
74 74 gearbox serve -c kallithea/tests/test.ini --pid-file=test.pid --daemon
75 75 KALLITHEA_WHOOSH_TEST_DISABLE=1 KALLITHEA_NO_TMP_PATH=1 py.test
76 76 kill -9 $(cat test.pid)
77 77
78 78 In these commands, the following variables are used::
79 79
80 80 KALLITHEA_WHOOSH_TEST_DISABLE=1 - skip whoosh index building and tests
81 81 KALLITHEA_NO_TMP_PATH=1 - disable new temp path for tests, used mostly for testing_vcs_operations
82 82
83 83 You can run individual tests by specifying their path as argument to py.test.
84 84 py.test also has many more options, see `py.test -h`. Some useful options
85 85 are::
86 86
87 87 -k EXPRESSION only run tests which match the given substring
88 88 expression. An expression is a python evaluable
89 89 expression where all names are substring-matched
90 90 against test names and their parent classes. Example:
91 91 -x, --exitfirst exit instantly on first error or failed test.
92 92 --lf rerun only the tests that failed at the last run (or
93 93 all if none failed)
94 94 --ff run all tests but run the last failures first. This
95 95 may re-order tests and thus lead to repeated fixture
96 96 setup/teardown
97 97 --pdb start the interactive Python debugger on errors.
98 98 -s, --capture=no don't capture stdout (any stdout output will be
99 99 printed immediately)
100 100
101 101 Performance tests
102 102 ^^^^^^^^^^^^^^^^^
103 103
104 104 A number of performance tests are present in the test suite, but they are
105 105 not run in a standard test run. These tests are useful to
106 106 evaluate the impact of certain code changes with respect to performance.
107 107
108 108 To run these tests::
109 109
110 110 env TEST_PERFORMANCE=1 py.test kallithea/tests/performance
111 111
112 To analyze performance, you could install pytest-profiling_, which enables the
113 --profile and --profile-svg options to py.test.
114
115 .. _pytest-profiling: https://github.com/manahl/pytest-plugins/tree/master/pytest-profiling
116
112 117
113 118 Contribution guidelines
114 119 -----------------------
115 120
116 121 Kallithea is GPLv3 and we assume all contributions are made by the
117 122 committer/contributor and under GPLv3 unless explicitly stated. We do care a
118 123 lot about preservation of copyright and license information for existing code
119 124 that is brought into the project.
120 125
121 126 Contributions will be accepted in most formats -- such as pull requests on
122 127 Bitbucket, something hosted on your own Kallithea instance, or patches sent by
123 128 email to the `kallithea-general`_ mailing list.
124 129
125 130 When contributing via Bitbucket, please make your fork of
126 131 https://bitbucket.org/conservancy/kallithea/ `non-publishing`_ -- it is one of
127 132 the settings on "Repository details" page. This ensures your commits are in
128 133 "draft" phase and makes it easier for you to address feedback and for project
129 134 maintainers to integrate your changes.
130 135
131 136 .. _non-publishing: https://www.mercurial-scm.org/wiki/Phases#Publishing_Repository
132 137
133 138 Make sure to test your changes both manually and with the automatic tests
134 139 before posting.
135 140
136 141 We care about quality and review and keeping a clean repository history. We
137 142 might give feedback that requests polishing contributions until they are
138 143 "perfect". We might also rebase and collapse and make minor adjustments to your
139 144 changes when we apply them.
140 145
141 146 We try to make sure we have consensus on the direction the project is taking.
142 147 Everything non-sensitive should be discussed in public -- preferably on the
143 148 mailing list. We aim at having all non-trivial changes reviewed by at least
144 149 one other core developer before pushing. Obvious non-controversial changes will
145 150 be handled more casually.
146 151
147 152 For now we just have one official branch ("default") and will keep it so stable
148 153 that it can be (and is) used in production. Experimental changes should live
149 154 elsewhere (for example in a pull request) until they are ready.
150 155
151 156
152 157 Coding guidelines
153 158 -----------------
154 159
155 160 We don't have a formal coding/formatting standard. We are currently using a mix
156 161 of Mercurial's (https://www.mercurial-scm.org/wiki/CodingStyle), pep8, and
157 162 consistency with existing code. Run ``scripts/run-all-cleanup`` before
158 163 committing to ensure some basic code formatting consistency.
159 164
160 165 We support both Python 2.6.x and 2.7.x and nothing else. For now we don't care
161 166 about Python 3 compatibility.
162 167
163 168 We try to support the most common modern web browsers. IE9 is still supported
164 169 to the extent it is feasible, IE8 is not.
165 170
166 171 We primarily support Linux and OS X on the server side but Windows should also work.
167 172
168 173 HTML templates should use 2 spaces for indentation ... but be pragmatic. We
169 174 should use templates cleverly and avoid duplication. We should use reasonable
170 175 semantic markup with element classes and IDs that can be used for styling and testing.
171 176 We should only use inline styles in places where it really is semantic (such as
172 177 ``display: none``).
173 178
174 179 JavaScript must use ``;`` between/after statements. Indentation 4 spaces. Inline
175 180 multiline functions should be indented two levels -- one for the ``()`` and one for
176 181 ``{}``.
177 182 Variables holding jQuery objects should be named with a leading ``$``.
178 183
179 184 Commit messages should have a leading short line summarizing the changes. For
180 185 bug fixes, put ``(Issue #123)`` at the end of this line.
181 186
182 187 Use American English grammar and spelling overall. Use `English title case`_ for
183 188 page titles, button labels, headers, and 'labels' for fields in forms.
184 189
185 190 .. _English title case: https://en.wikipedia.org/wiki/Capitalization#Title_case
186 191
187 192 Template helpers (that is, everything in ``kallithea.lib.helpers``)
188 193 should only be referenced from templates. If you need to call a
189 194 helper from the Python code, consider moving the function somewhere
190 195 else (e.g. to the model).
191 196
192 197 Notes on the SQLAlchemy session
193 198 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194 199
195 200 Each HTTP request runs inside an independent SQLAlchemy session (as well
196 201 as in an independent database transaction). ``Session`` is the session manager
197 202 and factory. ``Session()`` will create a new session on-demand or return the
198 203 current session for the active thread. Many database operations are methods on
199 204 such session instances - only ``Session.remove()`` should be called directly on
200 205 the manager.
201 206
202 207 Database model objects
203 208 (almost) always belong to a particular SQLAlchemy session, which means
204 209 that SQLAlchemy will ensure that they're kept in sync with the database
205 210 (but also means that they cannot be shared across requests).
206 211
207 212 Objects can be added to the session using ``Session().add``, but this is
208 213 rarely needed:
209 214
210 215 * When creating a database object by calling the constructor directly,
211 216 it must explicitly be added to the session.
212 217
213 218 * When creating an object using a factory function (like
214 219 ``create_repo``), the returned object has already (by convention)
215 220 been added to the session, and should not be added again.
216 221
217 222 * When getting an object from the session (via ``Session().query`` or
218 223 any of the utility functions that look up objects in the database),
219 224 it's already part of the session, and should not be added again.
220 225 SQLAlchemy monitors attribute modifications automatically for all
221 226 objects it knows about and syncs them to the database.
222 227
223 228 SQLAlchemy also flushes changes to the database automatically; manually
224 229 calling ``Session().flush`` is usually only necessary when the Python
225 230 code needs the database to assign an "auto-increment" primary key ID to
226 231 a freshly created model object (before flushing, the ID attribute will
227 232 be ``None``).
228 233
229 234 TurboGears2 DebugBar
230 235 ^^^^^^^^^^^^^^^^^^^^
231 236
232 237 It is possible to enable the TurboGears2-provided DebugBar_, a toolbar overlayed
233 238 over the Kallithea web interface, allowing you to see:
234 239
235 240 * timing information of the current request, including profiling information
236 241 * request data, including GET data, POST data, cookies, headers and environment
237 242 variables
238 243 * a list of executed database queries, including timing and result values
239 244
240 245 DebugBar is only activated when ``debug = true`` is set in the configuration
241 246 file. This is important, because the DebugBar toolbar will be visible for all
242 247 users, and allow them to see information they should not be allowed to see. Like
243 248 is anyway the case for ``debug = true``, do not use this in production!
244 249
245 250 To enable DebugBar, install ``tgext.debugbar`` and ``kajiki`` (typically via
246 251 ``pip``) and restart Kallithea (in debug mode).
247 252
248 253
249 254 "Roadmap"
250 255 ---------
251 256
252 257 We do not have a road map but are waiting for your contributions. Refer to the
253 258 wiki_ for some ideas of places we might want to go -- contributions in these
254 259 areas are very welcome.
255 260
256 261
257 262 Thank you for your contribution!
258 263 --------------------------------
259 264
260 265
261 266 .. _Weblate: http://weblate.org/
262 267 .. _issue tracking: https://bitbucket.org/conservancy/kallithea/issues?status=new&status=open
263 268 .. _pull requests: https://bitbucket.org/conservancy/kallithea/pull-requests
264 269 .. _bitbucket: http://bitbucket.org/
265 270 .. _mailing list: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
266 271 .. _kallithea-general: http://lists.sfconservancy.org/mailman/listinfo/kallithea-general
267 272 .. _Hosted Weblate: https://hosted.weblate.org/projects/kallithea/kallithea/
268 273 .. _wiki: https://bitbucket.org/conservancy/kallithea/wiki/Home
269 274 .. _DebugBar: https://github.com/TurboGears/tgext.debugbar
General Comments 0
You need to be logged in to leave comments. Login now