readme.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. How the scripts are structured:
  2. - check-package is the main engine, called by the user.
  3. For each input file, this script decides which parser should be used and it
  4. collects all classes declared in the library file and instantiates them.
  5. The main engine opens the input files and it serves each raw line (including
  6. newline!) to the method check_line() of every check object.
  7. Two special methods before() and after() are used to call the initialization
  8. of variables (for the case it needs to keep data across calls) and the
  9. equivalent finalization (e.g. for the case a warning must be issued if some
  10. pattern is not in the input file).
  11. - base.py contains the base class for all check functions.
  12. - lib.py contains the classes for common check functions.
  13. Each check function is explicitly included in a given type-parsing library.
  14. Do not include every single check function in this file, a class that will
  15. only parse hash files should be implemented in the hash-parsing library.
  16. When a warning must be issued, the check function returns an array of strings.
  17. Each string is a warning message and is displayed if the corresponding verbose
  18. level is active. When the script is called without --verbose only the first
  19. warning in the returned array is printed; when called with --verbose both
  20. first and second warnings are printed; when called with -vv until the third
  21. warning is printed; an so on.
  22. Helper functions can be defined and will not be called by the main script.
  23. - lib_type.py contains check functions specific to files of this type.
  24. Some hints when changing this code:
  25. - prefer O(n) algorithms, where n is the total number of lines in the files
  26. processed.
  27. - when there is no other reason for ordering, use alphabetical order (e.g. keep
  28. the check functions in alphabetical order, keep the imports in alphabetical
  29. order, and so on).
  30. - use pyflakes to detect and fix potential problems.
  31. - use pep8 formatting.
  32. - keep in mind that for every class the method before() will be called before
  33. any line is served to be checked by the method check_line(). A class that
  34. checks the filename should only implement the method before(). A function that
  35. needs to keep data across calls (e.g. keep the last line before the one being
  36. processed) should initialize all variables using this method.
  37. - keep in mind that for every class the method after() will be called after all
  38. lines were served to be checked by the method check_line(). A class that
  39. checks the absence of a pattern in the file will need to use this method.
  40. - try to avoid false warnings. It's better to not issue a warning message to a
  41. corner case than have too many false warnings. The second can make users stop
  42. using the script.
  43. - do not check spacing in the input line in every single function. Trailing
  44. whitespace and wrong indentation should be checked by separate functions.
  45. - avoid duplicate tests. Try to test only one thing in each function.
  46. - in the warning message, include the url to a section from the manual, when
  47. applicable. It potentially will make more people know the manual.
  48. - use short sentences in the warning messages. A complete explanation can be
  49. added to show when --verbose is used.
  50. - when testing, verify the error message is displayed when the error pattern is
  51. found, but also verify the error message is not displayed for few
  52. well-formatted packages... there are many of these, just pick your favorite
  53. as golden package that should not trigger any warning message.
  54. - check the url displayed by the warning message works.
  55. Usage examples:
  56. - to get a list of check functions that would be called without actually
  57. calling them you can use the --dry-run option:
  58. $ support/scripts/check-package --dry-run package/yourfavorite/*
  59. - when you just added a new check function, e.g. Something, check how it behaves
  60. for all current packages:
  61. $ support/scripts/check-package --include-only Something $(find package -type f)
  62. - the effective processing time (when the .pyc were already generated and all
  63. files to be processed are cached in the RAM) should stay in the order of few
  64. seconds:
  65. $ support/scripts/check-package $(find package -type f) >/dev/null ; \
  66. time support/scripts/check-package $(find package -type f) >/dev/null
  67. - vim users can navigate the warnings (most editors probably have similar
  68. function) since warnings are generated in the form 'path/file:line: warning':
  69. $ find package/ -name 'Config.*' > filelist && vim -c \
  70. 'set makeprg=support/scripts/check-package\ $(cat\ filelist)' -c make -c copen