You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

develop.md 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Develop
  2. ## 1. Code Style
  3. We adopt [PEP8](https://www.python.org/dev/peps/pep-0008/) as the preferred code style.
  4. We use the following toolsseed isortseed isortseed isort for linting and formatting:
  5. - [flake8](http://flake8.pycqa.org/en/latest/): linter
  6. - [yapf](https://github.com/google/yapf): formatter
  7. - [isort](https://github.com/timothycrosley/isort): sort imports
  8. Style configurations of yapf and isort can be found in [setup.cfg](../../setup.cfg).
  9. We use [pre-commit hook](https://pre-commit.com/) that checks and formats for `flake8`, `yapf`, `seed-isort-config`, `isort`, `trailing whitespaces`,
  10. fixes `end-of-files`, sorts `requirments.txt` automatically on every commit.
  11. The config for a pre-commit hook is stored in [.pre-commit-config](../../.pre-commit-config.yaml).
  12. After you clone the repository, you will need to install initialize pre-commit hook.
  13. ```bash
  14. pip install -r requirements/tests.txt
  15. ```
  16. From the repository folder
  17. ```bash
  18. pre-commit install
  19. ```
  20. After this on every commit check code linters and formatter will be enforced.
  21. If you want to use pre-commit to check all the files, you can run
  22. ```bash
  23. pre-commit run --all-files
  24. ```
  25. If you only want to format and lint your code, you can run
  26. ```bash
  27. make linter
  28. ```
  29. ## 2. Test
  30. ### 2.1 Test level
  31. There are mainly three test levels:
  32. * level 0: tests for basic interface and function of framework, such as `tests/trainers/test_trainer_base.py`
  33. * level 1: important functional test which test end2end workflow, such as `tests/pipelines/test_image_matting.py`
  34. * level 2: scenario tests for all the implemented modules such as model, pipeline in different algorithm filed.
  35. Default test level is 0, which will only run those cases of level 0, you can set test level
  36. via environment variable `TEST_LEVEL`. For more details, you can refer to [test-doc](https://alidocs.dingtalk.com/i/nodes/mdvQnONayjBJKLXy1Bp38PY2MeXzp5o0?dontjump=true&nav=spaces&navQuery=spaceId%3Dnb9XJNlZxbgrOXyA)
  37. ```bash
  38. # run all tests
  39. TEST_LEVEL=2 make test
  40. # run important functional tests
  41. TEST_LEVEL=1 make test
  42. # run core UT and basic functional tests
  43. make test
  44. ```
  45. When writing test cases, you should assign a test level for your test case using
  46. following code. If left default, the test level will be 0, it will run in each
  47. test stage.
  48. File test_module.py
  49. ```python
  50. from modelscope.utils.test_utils import test_level
  51. class ImageCartoonTest(unittest.TestCase):
  52. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  53. def test_run_by_direct_model_download(self):
  54. pass
  55. ```
  56. ### 2.2 Run tests
  57. 1. Run your own single test case to test your self-implemented function. You can run your
  58. test file directly, if it fails to run, pls check if variable `TEST_LEVEL`
  59. exists in the environment and unset it.
  60. ```bash
  61. python tests/path/to/your_test.py
  62. ```
  63. 2. Remember to run core tests in local environment before start a codereview, by default it will
  64. only run test cases with level 0.
  65. ```bash
  66. make tests
  67. ```
  68. 3. After you start a code review, ci tests will be triggered which will run test cases with level 1
  69. 4. Daily regression tests will run all cases at 0 am each day using master branch.
  70. ### 2.3 Test data storage
  71. As we need a lot of data for testing, including images, videos, models. We use git lfs
  72. to store those large files.
  73. 1. install git-lfs(version>=2.5.0)
  74. for mac
  75. ```bash
  76. brew install git-lfs
  77. git lfs install
  78. ```
  79. for centos, please download rpm from git-lfs github release [website](https://github.com/git-lfs/git-lfs/releases/tag/v3.2.0)
  80. ```bash
  81. wget http://101374-public.oss-cn-hangzhou-zmf.aliyuncs.com/git-lfs-3.2.0-1.el7.x86_64.rpm
  82. sudo rpm -ivh git-lfs-3.2.0-1.el7.x86_64.rpm
  83. git lfs install
  84. ```
  85. for ubuntu
  86. ```bash
  87. curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
  88. sudo apt-get install git-lfs
  89. git lfs install
  90. ```
  91. 2. track your data type using git lfs, for example, to track png files
  92. ```bash
  93. git lfs track "*.png"
  94. ```
  95. 3. add your test files to `data/test/` folder, you can make directories if you need.
  96. ```bash
  97. git add data/test/test.png
  98. ```
  99. 4. commit your test data to remote branch
  100. ```bash
  101. git commit -m "xxx"
  102. ```
  103. To pull data from remote repo, just as the same way you pull git files.
  104. ```bash
  105. git pull origin branch_name
  106. ```
  107. ## Development and Code Review
  108. 1. Get the latest master code and checkout a new branch for local development.
  109. ```shell
  110. git pull origin master --rebase
  111. git checout -b dev/my-dev-branch
  112. ```
  113. note: replace "dev/my-dev-branch" with a meaningful branch name. We recommend using a new dev branch for every change.
  114. 2. Make your local changes.
  115. 3. Commit your local changes.
  116. ```shell
  117. git add .
  118. git commit -m "[to #42322933] my commit message"
  119. ```
  120. note: you may replace [to #42322933] with your own aone issue id (if any).
  121. 4. Push your change:
  122. ```shell
  123. git push --set-upstream origin dev/my-dev-branch
  124. ```
  125. Note that you may push multiple times to the same branch with 'git push' commands later.
  126. 5. Open the remote url `https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/new` to create a new merge request that merges your development branch (aka, the "dev/my-dev-branch in this example) into master branch. Please follow the instruction on aone page to submit the merge request a code review.
  127. ## Build pip package
  128. ```bash
  129. make whl
  130. ```