SUBMITTING_PYTHON 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. NOTE: Please improve this list!
  2. Dear (new) GRASS developer,
  3. when submitting Python code to GRASS SVN repository, please take
  4. care of following rules:
  5. [ see SUBMITTING for C hints ]
  6. [ see SUBMITTING_WXGUI for wxPython GUI code hints ]
  7. [ see SUBMITTING_DOCS for documentation ]
  8. See also http://www.python.org/dev/peps/pep-0008/
  9. 0. Indentation
  10. As Python determines nesting based upon indentation, it isn't just
  11. a stylistic issue.
  12. Please use 4-space indentation (GNU Emacs python-mode default).
  13. See also "Python Style Guide" by Guido van Rossum
  14. http://www.python.org/doc/essays/styleguide.html
  15. 1. Instructions for the GRASS script parser can be found in the g.parser
  16. module's help page.
  17. http://grass.osgeo.org/grass70/manuals/html70_user/g.parser.html
  18. 2. Use the directory structure to place your script appropriately into
  19. the source tree
  20. - scripts go into scripts/
  21. Also add a Makefile and a <module>.html file into this directory.
  22. See existing Python scripts for examples.
  23. 3. Add a header section to the script you submit and make sure you
  24. include the copyright. The purpose section is meant to contain a
  25. general over view of the code in the file to assist other
  26. programmers that will need to make changes to your code. For this
  27. purpose use Python Docstring, see
  28. http://epydoc.sourceforge.net/docstrings.html
  29. Example (fictitious header for a script called g.myscript):
  30. """
  31. MODULE: g.myscript
  32. AUTHOR(S): John Doe <email AT some domain>
  33. PURPOSE: Describe your script here...
  34. COPYRIGHT: (C) 2007 John Doe, and by the GRASS Development Team
  35. This program is free software under the GNU General Public
  36. License (>=v2). Read the file COPYING that comes with GRASS
  37. for details.
  38. """
  39. The copyright protects your rights according to GNU General Public
  40. License (www.gnu.org).
  41. You can easily autogenerate the header and parameters from an existing
  42. module using the --script flag. Example:
  43. d.rast --script
  44. Just select an existing module which is close to your application to save
  45. efforts.
  46. 4. We don't want the $ ID $ in source code any more as it causes problems
  47. for the branches.
  48. 5. Create and use secure temporary files and directories. Use the
  49. grass.tempfile() or grass.tempdir() functions to do this. e.g.
  50. # setup temporary file
  51. TMP = grass.tempfile()
  52. if TMP is None:
  53. grass.fatal("Unable to create temporary files")
  54. 6. Use grass.findfile() when there is a need to test if a map exists.
  55. # test for input raster map
  56. result = grass.find_file(name = map_name, element = 'cell', quiet = True)
  57. if not result['file']
  58. grass.fatal("Raster map <%s> not found" % map_name)
  59. # test for input vector map
  60. result = grass.find_file(name = map_name, element = 'vector', quiet = True)
  61. if not result['file']
  62. grass.fatal("Vector map <%s> not found" % map_name)
  63. ... and so forth. See 'g.manual g.findfile' for details.
  64. 7. For any informational output, use the grass.message()
  65. function. For error messages should be used grass.fatal_error() or
  66. grass.error() and for warnings grass.warning(). For debugging
  67. purposes grass.debug().
  68. #normal message:
  69. grass.message("Done")
  70. # warning:
  71. grass.warning("No input values found, using default values")
  72. # error:
  73. grass.error("No map found")
  74. # fatal error:
  75. grass.fatal_error("No map found, exiting")
  76. # debug output (use g.gisenv to enable/disable)
  77. grass.debug("Our calculated value is: %d" % value)
  78. Try to omit any usage of the 'print' command for informational output.
  79. 8. PLEASE take the time to add comments throughout your code explaining what
  80. the code is doing. It will save a HUGE amount of time and frustration for
  81. other programmers that may have to change your code in the future.
  82. 9. Make sure a new line is at the end of each file.
  83. 10. For consistency, use README rather than README.txt for any README files.
  84. 11. Be sure to develop on top of the LATEST GRASS code (which is in SVN repository).
  85. You can re-check before submission with 'svn diff':
  86. Be sure to create unified ("diff -u") format. "Plain" diffs (the default
  87. format) are risky, because they will apply without warning to code which
  88. has been substantially changed; they are also harder to read than unified.
  89. Such diffs should be made from the top-level directory, e.g.
  90. "svn diff gui/wxpython/wxgui.py"; that way, the diff will
  91. include the pathname rather than just "wxgui.py".
  92. 12. When submitting new files to the repository set SVN properties,
  93. usually for directory
  94. svn:ignore : *.pyc
  95. or e.g. for Python file
  96. svn:mime-type : text/python
  97. svn:keywords : Author Date Id
  98. svn:eol-style : native
  99. svn propset svn:mime-type text/python new/file.py
  100. svn propset svn:keywords "Author Date Id" new/file.py
  101. svn propset svn:eol-style native new/file.py
  102. See
  103. http://svnbook.red-bean.com/en/1.4/svn.advanced.props.html
  104. 13. Tell the other developers about the new code using the following e-mail:
  105. grass-dev@lists.osgeo.org
  106. To subscribe to this mailing list, see
  107. http://lists.osgeo.org/mailman/listinfo/grass-dev
  108. 14. In case of questions feel free to contact the developers at the above
  109. mailing list.
  110. http://grass.osgeo.org/devel/index.php#submission
  111. ...
  112. [please add further hints if required]
  113. "Your attention to detail is appreciated."