
# SetupTool构建
使用SetupTool工具可以将Python应用打包。
#### 前提准备
使用SetupTool打包时，需要代码根目录下存在"setup.py"文件，关于setup文件写法请参见[Python官方说明](https://www.python.org/search/?q=setup&submit=)。
- [图形化构建]
  在[配置构建步骤](https://support.huaweicloud.com/usermanual-codeci/codeci_ug_0059.html)中，添加"SetupTool构建"构建步骤，参考[表1]配置参数。
   表1SetupTool构建参数说明 
  | **参数**    | **说明**                                                                                                                                                                                                                                                                                                                                                                                             |
  |:---|:---|
  | 步骤显示名称    | 构建步骤的名称，可自定义修改。 - 支持中文、英文、数字、"-"、"_"、英文逗号、英文分号、英文冒号、"."、"/"、圆括号（中英文）。  - 字符长度范围为1\~128。                           |
  | 工具版本      | 根据用户实际开发环境的需要，选择对应的工具版本。 CodeArts Build支持的工具版本，可查看[构建工具版本](https://support.huaweicloud.com/productdesc-codeci/cloudbuild_07_0004.html)。若当前的工具版本不满足您的使用要求，您可以[制作镜像并推送到SWR仓库](https://support.huaweicloud.com/usermanual-codeci/codeci_ug_0013.html)。                                                                                                              |
  | 命令        | 配置构建打包命令。 - 可以使用默认的命令打包为"egg"格式的文件。  - Python2.7后建议使用**python setup.py sdist bdist_wheel**，打包为源码包和whl格式的安装包，以便使用pip安装。   更多命令使用方法可参考[SetupTool官网](https://pypi.org/project/setuptools/)。 |
  | 失败后是否继续运行 | 当前步骤执行失败后是否继续执行下一个步骤，根据实际使用场景选择是或否。                                                                                                                                                                                                                                                                                                                                                                |
     
- [代码化构建]
  参考以下代码示例，修改在[创建代码化构建使用的YAML文件](https://support.huaweicloud.com/usermanual-codeci/codeci_ug_0058.html#codeci_ug_0058__section72391847131511)中的BUILD部分代码信息。
  ```
  version: 2.0 # 必须是2.0
  steps:
    BUILD:
      - python: 
          name: SetupTool构建
          image: cloudbuild@python3.6
          inputs: 
            command: |
              pip config set global.index-url https://pypi.org/simple
              pip config set global.trusted-host repo.xxcloud.com
              python setup.py bdist_egg
            ignore_fail: true
  ```
  表2代码示例参数说明 
  | **参数**      | **类型** | **说明**                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
  |:---|:---|:---|
  | name        | string | 可选参数。 构建步骤的名称，可自定义修改。 - 支持中文、英文、数字、"-"、"_"、英文逗号、英文分号、英文冒号、"."、"/"、圆括号（中英文）。  - 字符长度范围为1\~128。                                           |
  | image       | string | 可选参数。 填写镜像版本，"cloudbuild@"为固定部分，后面为支持的Python版本。 CodeArts Build支持的工具版本，可查看[构建工具版本](https://support.huaweicloud.com/productdesc-codeci/cloudbuild_07_0004.html)。若当前的工具版本不满足您的使用要求，您可以[制作镜像并推送到SWR仓库](https://support.huaweicloud.com/usermanual-codeci/codeci_ug_0013.html)。 默认值：cloudbuild@python3.6。                                                             |
  | command     | string | 配置构建打包命令。 - 可以使用默认的命令打包为"egg"格式的文件。  - Python2.7后建议使用**python setup.py sdist bdist_wheel**，打包为源码包和whl格式的安装包，以便使用pip安装。   更多命令使用方法可参考[SetupTool官网](https://pypi.org/project/setuptools/)。 |
  | ignore_fail | string | 用于控制当前步骤执行失败后是否继续执行下一个步骤。 - true：是。  - 为空：否。                                                                                                                                                             |
     
