readme.txt 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. - keep in mind that for every class the method before() will be called before
  31. any line is served to be checked by the method check_line(). A class that
  32. checks the filename should only implement the method before(). A function that
  33. needs to keep data across calls (e.g. keep the last line before the one being
  34. processed) should initialize all variables using this method.
  35. - keep in mind that for every class the method after() will be called after all
  36. lines were served to be checked by the method check_line(). A class that
  37. checks the absence of a pattern in the file will need to use this method.
  38. - try to avoid false warnings. It's better to not issue a warning message to a
  39. corner case than have too many false warnings. The second can make users stop
  40. using the script.
  41. - do not check spacing in the input line in every single function. Trailing
  42. whitespace and wrong indentation should be checked by separate functions.
  43. - avoid duplicate tests. Try to test only one thing in each function.
  44. - in the warning message, include the url to a section from the manual, when
  45. applicable. It potentially will make more people know the manual.
  46. - use short sentences in the warning messages. A complete explanation can be
  47. added to show when --verbose is used.
  48. - when testing, verify the error message is displayed when the error pattern is
  49. found, but also verify the error message is not displayed for few
  50. well-formatted packages... there are many of these, just pick your favorite
  51. as golden package that should not trigger any warning message.
  52. - check the url displayed by the warning message works.
  53. Usage examples:
  54. - to get a list of check functions that would be called without actually
  55. calling them you can use the --dry-run option:
  56. $ utils/check-package --dry-run package/yourfavorite/*
  57. - when you just added a new check function, e.g. Something, check how it behaves
  58. for all current packages:
  59. $ utils/check-package --include-only Something $(find package -type f)
  60. - the effective processing time (when the .pyc were already generated and all
  61. files to be processed are cached in the RAM) should stay in the order of few
  62. seconds:
  63. $ utils/check-package $(find package -type f) >/dev/null ; \
  64. time utils/check-package $(find package -type f) >/dev/null
  65. - vim users can navigate the warnings (most editors probably have similar
  66. function) since warnings are generated in the form 'path/file:line: warning':
  67. $ find package/ -name 'Config.*' > filelist && vim -c \
  68. 'set makeprg=utils/check-package\ $(cat\ filelist)' -c make -c copen