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 6.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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
  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. ## Code Review
  108. 1. Run following command to create an aone CR, replace `TARGET_BRANCH` and `CR_NAME` with the one you want.
  109. ```shell
  110. git push origin HEAD:refs/for/TARGET_BRANCH/CR_NAME
  111. ```
  112. Please refer to [https://yuque.antfin.com/aone/platform/lcg8yr](https://yuque.antfin.com/aone/platform/lcg8yr) for more details.
  113. The following output is expected.
  114. ```shell
  115. Counting objects: 5, done.
  116. Delta compression using up to 96 threads.
  117. Compressing objects: 100% (5/5), done.
  118. Writing objects: 100% (5/5), 543 bytes | 0 bytes/s, done.
  119. Total 5 (delta 4), reused 0 (delta 0)
  120. remote: +------------------------------------------------------------------------+
  121. remote: | Merge Request #8949062 was created or updated. |
  122. remote: | View merge request at URL: |
  123. remote: | https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8949062 |
  124. remote: +------------------------------------------------------------------------+
  125. To git@gitlab.alibaba-inc.com:Ali-MaaS/MaaS-lib.git
  126. * [new branch] HEAD -> refs/for/master/support_kwargs_pipeline
  127. ```
  128. 2. Open the remote url `https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/ID` and edit the title of CR with following format before merging your code:
  129. * Feature
  130. ```shell
  131. [to #AONE_ID] feat: commit title
  132. Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8949062
  133. * commit msg1
  134. * commit msg2
  135. ```
  136. * Bugfix
  137. ```shell
  138. [to #AONE_ID] fix: commit title
  139. Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8949062
  140. * commit msg1
  141. * commit msg2
  142. ```
  143. ## Build pip package
  144. ```bash
  145. make whl
  146. ```
  147. ## Build docker
  148. build develop docker
  149. ```bash
  150. sudo make -f Makefile.docker devel-image
  151. ```
  152. push develop docker, passwd pls ask wenmeng.zwm
  153. ```bash
  154. sudo docker login --username=mass_test@test.aliyunid.com registry.cn-shanghai.aliyuncs.com
  155. Password:
  156. sudo make -f Makefile.docker devel-push
  157. ```
  158. To build runtime image, just replace `devel` with `runtime` in the upper commands.
  159. ```bash
  160. udo make -f Makefile.docker runtime-image runtime-push
  161. ```