Updated on 2024-11-21 GMT+08:00

Building with Setuptools

Use Setuptools to package Python applications.

Prerequisites

When using Setuptools to pack the code, ensure that the setup.py file exists in the root directory of the code. For details on how to write the setup file, see the official instructions of Python.

Build on GUI

Add Build with Setuptools, when configuring build actions. Set the parameters according to Table 1.

Table 1 Parameters for building with Setuptools

Parameter

Description

Action Name

Assign a custom name to the build action. The name can contain:

  • Letters, digits, hyphens (-), underscores (_), commas (,), semicolons (;), colons (:), periods (.), slashes (/), and parentheses.
  • 1 to 128 characters.

Tool Version

Select a tool version that matches your current development environment.

For tool versions supported by CodeArts Build, see build tools and versions. If the current tools and versions do not meet your requirements, you can customize a build environment.

Commands

Configure the pack commands.

  • You can use the default commands to pack the file into an .egg file.
  • For Python 2.7 or later, it is advised to use python setup.py sdist bdist_wheel to pack the source code package and .whl installation package for pip installation.

For more commands, see the Setuptools official website.

Continue After Failure

Specify whether to proceed after the current action fails by setting the parameter to either Yes or No.

Build with Code

Modify the code in the BUILD block in Creating a YAML File for Your Code-based Build by referring to the following sample code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
version: 2.0 # The value must be 2.0.
steps:
  BUILD:
    - python: 
        name: Build with Setuptools
        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
Table 2 Parameters in the sample code

Parameter

Type

Description

name

String

Optional.

Assign a custom name to the build action. The name can contain:

  • Letters, digits, hyphens (-), underscores (_), commas (,), semicolons (;), colons (:), periods (.), slashes (/), and parentheses.
  • 1 to 128 characters.

image

String

Optional.

Enter the image version, which should include the fixed part cloudbuild@ and the supported Python version following it.

For tool versions supported by CodeArts Build, see build tools and versions. If the current tools and versions do not meet your requirements, you can customize a build environment.

The default value is cloudbuild@python3.6.

command

String

Configure the pack commands.

  • You can use the default commands to pack the file into an .egg file.
  • For Python 2.7 or later, it is advised to use python setup.py sdist bdist_wheel to pack the source code package and .whl installation package for pip installation.

For more commands, see the Setuptools official website.

ignore_fail

String

Whether to proceed after the current action fails.
  • true: Yes
  • Empty: No