development.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. Development
  2. ===========
  3. Get the sources
  4. ---------------
  5. Anonymous:
  6. ::
  7. git clone https://pagure.io/pagure.git
  8. Contributors:
  9. ::
  10. git clone ssh://git@pagure.io:pagure.git
  11. Dependencies
  12. ------------
  13. Install the build dependencies of pagure:
  14. ::
  15. sudo dnf install git python-virtualenv libgit2-devel \
  16. libjpeg-devel gcc libffi-devel redhat-rpm-config
  17. The python dependencies of pagure are listed in the file ``requirements.txt``
  18. at the top level of the sources.
  19. ::
  20. virtualenv pagure_env
  21. source ./pagure_env/bin/activate
  22. pip install pygit2==<version of libgit2 found>.* # e.g. 0.23.*
  23. pip install -r requirements.txt
  24. .. note:: working in a `virtualenv <http://www.virtualenv.org/en/latest/>`_
  25. is tricky due to the dependency on `pygit2 <http://www.pygit2.org/>`_
  26. and thus on `libgit2 <https://libgit2.github.com/>`_
  27. but the pygit2 `documentation has a solution for this
  28. <http://www.pygit2.org/install.html#libgit2-within-a-virtual-environment>`_.
  29. Run pagure for development
  30. --------------------------
  31. Adjust the configuration file (secret key, database URL, admin group...)
  32. See :doc:`configuration` for more detailed information about the
  33. configuration.
  34. Create the database scheme::
  35. ./createdb.py
  36. Create the folder that will receive the different git repositories:
  37. ::
  38. mkdir {repos,docs,forks,tickets,requests,remotes}
  39. Run the server:
  40. ::
  41. ./runserver.py
  42. If you want to change some configuration key you can create a file, place
  43. the configuration change in it and use it with
  44. ::
  45. ./runserver.py -c <config_file>
  46. For example, create the file ``config`` with in it:
  47. ::
  48. from datetime import timedelta
  49. # Makes the admin session longer
  50. ADMIN_SESSION_LIFETIME = timedelta(minutes=20000000)
  51. # Use a postgresql database instead of sqlite
  52. DB_URL = 'postgresql://user:pass@localhost/pagure'
  53. # Change the OpenID endpoint
  54. FAS_OPENID_ENDPOINT = 'https://id.stg.fedoraproject.org'
  55. APP_URL = '*'
  56. EVENTSOURCE_SOURCE = 'http://localhost:8080'
  57. EVENTSOURCE_PORT = '8080'
  58. DOC_APP_URL = '*'
  59. # Avoid sending email when developping
  60. EMAIL_SEND = False
  61. and run the server with:
  62. ::
  63. ./runserver.py -c config
  64. To get some profiling information you can also run it as:
  65. ::
  66. ./runserver.py --profile
  67. You should be able to access the server at http://localhost:5000
  68. Every time you save a file, the project will be automatically restarted
  69. so you can see your change immediately.
  70. Create a pull-request for testing
  71. ----------------------------------
  72. When working on pagure, it is pretty often that one wanted to work on a
  73. feature or a bug related to pull-requests needs to create one.
  74. Making a pull-request for development purposes isn't hard, if you remember
  75. that since you're running a local instance, the git repos created in your
  76. pagure instance are also local.
  77. So here are in a few steps that one could perform to create a pull-request in a
  78. local pagure instance.
  79. * Create a project on your pagure instance, let's say it will be called ``test``
  80. * Create a folder ``clones`` somewhere in your system (you probably do not
  81. want it in the ``repos`` folder created above, next to it is fine though)::
  82. mkdir clones
  83. * Clone the repo of the ``test`` project into this ``clones`` folder::
  84. cd clones
  85. git clone ~/path/to/pagure/repos/test.git
  86. * Add and commit some files::
  87. echo "*~" > .gitignore
  88. git add .gitignore
  89. git commit -m "Add a .gitignore file"
  90. echo "BSD" > LICENSE
  91. git add LICENSE
  92. git commit -m "Add a LICENSE file"
  93. * Push these changes::
  94. git push -u origin master
  95. * Create a new branch and add a commit in it::
  96. git branch new_branch
  97. git checkout new_branch
  98. touch test
  99. git add test
  100. git commit -m "Add file: test"
  101. * Push this new branch::
  102. git push -u origin new_branch
  103. Then go back to your pagure instance running in your web-browser, check the
  104. ``test`` project. You should see two branches: ``master`` and ``new_branch``
  105. from there you should be able to open a new pull-request, either from the
  106. front page or via the ``File Pull Request`` button in the ``Pull Requests``
  107. page.
  108. Coding standards
  109. ----------------
  110. We are trying to make the code `PEP8-compliant
  111. <http://www.python.org/dev/peps/pep-0008/>`_. There is a `pep8 tool
  112. <http://pypi.python.org/pypi/pep8>`_ that can automatically check
  113. your source.
  114. We are also inspecting the code using `pylint
  115. <http://pypi.python.org/pypi/pylint>`_ and aim of course for a 10/10 code
  116. (but it is an assymptotic goal).
  117. .. note:: both pep8 and pylint are available in Fedora:
  118. ::
  119. dnf install python-pep8 pylint
  120. or
  121. ::
  122. yum install python-pep8 pylint
  123. Send patch
  124. ----------
  125. The easiest way to work on pagure is to make your own branch in git, make
  126. your changes to this branch, commit whenever you want, rebase on master,
  127. whenever you need and when you are done, send the patch either by email,
  128. via the trac or a pull-request (using git or github).
  129. The workflow would therefore be something like:
  130. ::
  131. git branch <my_shiny_feature>
  132. git checkout <my_shiny_feature>
  133. <work>
  134. git commit file1 file2
  135. <more work>
  136. git commit file3 file4
  137. git checkout master
  138. git pull
  139. git checkout <my_shiny_feature>
  140. git rebase master
  141. git format-patch -2
  142. This will create two patch files that you can send by email to submit in a ticket
  143. on pagure, by email or after forking the project on pagure by submitting a
  144. pull-request (in which case the last step above ``git format-patch -2`` is not
  145. needed.
  146. Unit-tests
  147. ----------
  148. Pagure has a number of unit-tests.
  149. We aim at having a full (100%) coverage of the whole code (including the
  150. Flask application) and of course a smart coverage as in we want to check
  151. that the functions work the way we want but also that they fail when we
  152. expect it and the way we expect it.
  153. Tests checking that function are failing when/how we want are as important
  154. as tests checking they work the way they are intended to.
  155. ``runtests.sh``, located at the top of the sources, helps to run the
  156. unit-tests of the project with coverage information using `python-nose
  157. <https://nose.readthedocs.org/>`_.
  158. .. note:: You can specify additional arguments to the nose command used
  159. in this script by just passing arguments to the script.
  160. For example you can specify the ``-x`` / ``--stop`` argument:
  161. `Stop running tests after the first error or failure` by just doing
  162. ::
  163. ./runtests.sh --stop
  164. Each unit-tests files (located under ``tests/``) can be called
  165. by alone, allowing easier debugging of the tests. For example:
  166. ::
  167. python tests/test_pagure_lib.py
  168. .. note:: In order to have coverage information you might have to install
  169. ``python-coverage``
  170. ::
  171. dnf install python-coverage
  172. or
  173. ::
  174. yum install python-coverage