development.rst 6.4 KB

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