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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. ## Code Review
  71. 1. Run following command to create an aone CR, replace `TARGET_BRANCH` and `CR_NAME` with the one you want.
  72. ```shell
  73. git push origin HEAD:refs/for/TARGET_BRANCH/CR_NAME
  74. ```
  75. Please refer to [https://yuque.antfin.com/aone/platform/lcg8yr](https://yuque.antfin.com/aone/platform/lcg8yr) for more details.
  76. The following output is expected.
  77. ```shell
  78. Counting objects: 5, done.
  79. Delta compression using up to 96 threads.
  80. Compressing objects: 100% (5/5), done.
  81. Writing objects: 100% (5/5), 543 bytes | 0 bytes/s, done.
  82. Total 5 (delta 4), reused 0 (delta 0)
  83. remote: +------------------------------------------------------------------------+
  84. remote: | Merge Request #8949062 was created or updated. |
  85. remote: | View merge request at URL: |
  86. remote: | https://code.aone.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8949062 |
  87. remote: +------------------------------------------------------------------------+
  88. To git@gitlab.alibaba-inc.com:Ali-MaaS/MaaS-lib.git
  89. * [new branch] HEAD -> refs/for/master/support_kwargs_pipeline
  90. ```
  91. 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:
  92. * Feature
  93. ```shell
  94. [to #AONE_ID] feat: commit title
  95. Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8949062
  96. * commit msg1
  97. * commit msg2
  98. ```
  99. * Bugfix
  100. ```shell
  101. [to #AONE_ID] fix: commit title
  102. Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/8949062
  103. * commit msg1
  104. * commit msg2
  105. ```
  106. ## Build pip package
  107. ```bash
  108. make whl
  109. ```
  110. ## Build docker
  111. build develop docker
  112. ```bash
  113. sudo make -f Makefile.docker devel-image
  114. ```
  115. push develop docker, passwd pls ask wenmeng.zwm
  116. ```bash
  117. sudo docker login --username=mass_test@test.aliyunid.com registry.cn-shanghai.aliyuncs.com
  118. Password:
  119. sudo make -f Makefile.docker devel-push
  120. ```
  121. To build runtime image, just replace `devel` with `runtime` in the upper commands.
  122. ```bash
  123. udo make -f Makefile.docker runtime-image runtime-push
  124. ```

致力于通过开放的社区合作,开源AI模型以及相关创新技术,推动基于模型即服务的生态繁荣发展