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