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