diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yml similarity index 83% rename from .github/workflows/publish.yaml rename to .github/workflows/publish.yml index 146ac73a6..c6686c8d6 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yml @@ -14,34 +14,6 @@ permissions: id-token: write jobs: - test-prod: - strategy: - fail-fast: false - matrix: - include: - - python-version: 3.8 - api-key: PROD_LABELBOX_API_KEY_2 - da-test-key: DA_GCP_LABELBOX_API_KEY - - python-version: 3.9 - api-key: PROD_LABELBOX_API_KEY_3 - da-test-key: DA_GCP_LABELBOX_API_KEY - - python-version: "3.10" - api-key: PROD_LABELBOX_API_KEY_4 - da-test-key: DA_GCP_LABELBOX_API_KEY - - python-version: 3.11 - api-key: LABELBOX_API_KEY - da-test-key: DA_GCP_LABELBOX_API_KEY - - python-version: 3.12 - api-key: PROD_LABELBOX_API_KEY_5 - da-test-key: DA_GCP_LABELBOX_API_KEY - uses: ./.github/workflows/python-package-shared.yml - with: - python-version: ${{ matrix.python-version }} - api-key: ${{ matrix.api-key }} - da-test-key: ${{ matrix.da-test-key }} - fixture-profile: false - test-env: 'prod' - secrets: inherit build: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/python-package-develop.yaml b/.github/workflows/python-package-develop.yml similarity index 64% rename from .github/workflows/python-package-develop.yaml rename to .github/workflows/python-package-develop.yml index e00fb55ae..c546f84c5 100644 --- a/.github/workflows/python-package-develop.yaml +++ b/.github/workflows/python-package-develop.yml @@ -1,4 +1,4 @@ -name: Labelbox Python SDK Develop +name: Labelbox Python SDK Staging (Develop) on: push: @@ -8,7 +8,6 @@ on: jobs: build: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -28,51 +27,14 @@ jobs: - python-version: 3.12 api-key: STAGING_LABELBOX_API_KEY_5 da-test-key: DA_GCP_LABELBOX_API_KEY - steps: - - name: Cancel previous workflow - uses: styfle/cancel-workflow-action@0.12.1 - with: - access_token: ${{ github.token }} - - uses: actions/checkout@v4 - with: - token: ${{ secrets.ACTIONS_ACCESS_TOKEN }} - ref: ${{ github.head_ref }} - - name: Install the latest version of rye - uses: eifinger/setup-rye@v2 - with: - version: '0.29.0' - enable-cache: true - - name: Rye Setup - run: | - rye config --set-bool behavior.use-uv=true - - name: Python setup - run: rye pin ${{ matrix.python-version }} - - name: Environment setup - working-directory: libs/labelbox - run: | - rye sync -f --update-all - - name: Linting - working-directory: libs/labelbox - run: rye run lint - - name: Integration Testing - env: - PYTEST_XDIST_AUTO_NUM_WORKERS: 32 - LABELBOX_TEST_API_KEY: ${{ secrets[matrix.api-key] }} - DA_GCP_LABELBOX_API_KEY: ${{ secrets[matrix.da-test-key] }} - LABELBOX_TEST_ENV: 'staging' - working-directory: libs/labelbox - run: rye run integration - - name: Unit && Data Testing - env: - PYTEST_XDIST_AUTO_NUM_WORKERS: 32 - LABELBOX_TEST_API_KEY: ${{ secrets[matrix.api-key] }} - DA_GCP_LABELBOX_API_KEY: ${{ secrets[matrix.da-test-key] }} - LABELBOX_TEST_ENV: 'staging' - working-directory: libs/labelbox - run: | - rye sync -f --features labelbox/data - rye run unit - rye run data + uses: ./.github/workflows/python-package-shared.yml + with: + python-version: ${{ matrix.python-version }} + api-key: ${{ matrix.api-key }} + da-test-key: ${{ matrix.da-test-key }} + fixture-profile: true + test-env: 'staging' + secrets: inherit test-pypi: runs-on: ubuntu-latest if: github.event == 'push' @@ -91,7 +53,7 @@ jobs: - name: Install the latest version of rye uses: eifinger/setup-rye@v2 with: - version: '0.29.0' + version: '0.32.0' enable-cache: true - name: Rye Setup run: | diff --git a/.github/workflows/python-package-prod.yml b/.github/workflows/python-package-prod.yml new file mode 100644 index 000000000..233cde59b --- /dev/null +++ b/.github/workflows/python-package-prod.yml @@ -0,0 +1,34 @@ +name: Labelbox Python SDK PRod (Develop) + +on: + workflow_dispatch: + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - python-version: 3.8 + api-key: PROD_LABELBOX_API_KEY_2 + da-test-key: DA_GCP_LABELBOX_API_KEY + - python-version: 3.9 + api-key: PROD_LABELBOX_API_KEY_3 + da-test-key: DA_GCP_LABELBOX_API_KEY + - python-version: "3.10" + api-key: PROD_LABELBOX_API_KEY_4 + da-test-key: DA_GCP_LABELBOX_API_KEY + - python-version: 3.11 + api-key: LABELBOX_API_KEY + da-test-key: DA_GCP_LABELBOX_API_KEY + - python-version: 3.12 + api-key: PROD_LABELBOX_API_KEY_5 + da-test-key: DA_GCP_LABELBOX_API_KEY + uses: ./.github/workflows/python-package-shared.yml + with: + python-version: ${{ matrix.python-version }} + api-key: ${{ matrix.api-key }} + da-test-key: ${{ matrix.da-test-key }} + fixture-profile: false + test-env: 'prod' + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/python-package-shared.yml b/.github/workflows/python-package-shared.yml new file mode 100644 index 000000000..a393c85ca --- /dev/null +++ b/.github/workflows/python-package-shared.yml @@ -0,0 +1,69 @@ +name: Labelbox Python SDK Shared + +on: + workflow_call: + inputs: + python-version: + required: true + type: string + api-key: + required: true + type: string + da-test-key: + required: true + type: string + test-env: + required: true + type: string + fixture-profile: + required: true + type: boolean + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Cancel previous workflow + uses: styfle/cancel-workflow-action@0.12.1 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v4 + with: + token: ${{ secrets.ACTIONS_ACCESS_TOKEN }} + ref: ${{ github.head_ref }} + - name: Install the latest version of rye + uses: eifinger/setup-rye@v2 + with: + version: '0.32.0' + enable-cache: true + - name: Rye Setup + run: | + rye config --set-bool behavior.use-uv=true + - name: Python setup + run: rye pin ${{ inputs.python-version }} + - name: Environment setup + working-directory: libs/labelbox + run: | + rye sync -f --update-all + - name: Linting + working-directory: libs/labelbox + run: rye run lint + - name: Integration Testing + env: + PYTEST_XDIST_AUTO_NUM_WORKERS: 32 + LABELBOX_TEST_API_KEY: ${{ secrets[inputs.api-key] }} + DA_GCP_LABELBOX_API_KEY: ${{ secrets[inputs.da-test-key] }} + LABELBOX_TEST_ENVIRON: ${{ inputs.test-env }} + working-directory: libs/labelbox + run: rye run integration + - name: Unit && Data Testing + env: + PYTEST_XDIST_AUTO_NUM_WORKERS: 32 + LABELBOX_TEST_API_KEY: ${{ secrets[inputs.api-key] }} + DA_GCP_LABELBOX_API_KEY: ${{ secrets[inputs.da-test-key] }} + LABELBOX_TEST_ENVIRON: ${{ inputs.test-env }} + working-directory: libs/labelbox + run: | + rye sync -f --features labelbox/data + rye run unit + rye run data \ No newline at end of file diff --git a/.gitignore b/.gitignore index 443514253..30497f6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -144,4 +144,7 @@ docs/source/_templates # pytest -.testmondata* \ No newline at end of file +.testmondata* + +# rye +.env \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aadeca207..fcf917f67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,18 +60,20 @@ rye run unit ### Integration Testing ```bash -LABELBOX_TEST_API_KEY="YOUR_API_TEST_KEY" rye run integration +LABELBOX_TEST_API_KEY="YOUR_API_TEST_KEY" LABELBOX_TEST_ENVIRON="prod" rye run integration ``` For more info on how to get a `LABELBOX_TEST_API_KEY` [Labelbox API key docs](https://labelbox.helpdocs.io/docs/api/getting-started). **Integration tests by default will run against your account that you provide an API Key from and modify its data. If you want to run integration tests, without it impacting your existing account, create an additional account using a secondary e-mail on [Labelbox](https://labelbox.com). Free accounts are sufficent for integration testing purposes.** +You can also use a `.env` file if you prefer instead of needing to type out the environmental overrides every single time you want to run commands. Please add a `--env-file` parameter to the test command (EG `rye --env-file=.env run integration`). + ### (Optional) Data Testing For testing the impact of the extra installs included with `labelbox[data]`, run the following: ```bash -LABELBOX_TEST_API_KEY="YOUR_API_TEST_KEY" rye run data +LABELBOX_TEST_API_KEY="YOUR_API_TEST_KEY" LABELBOX_TEST_ENVIRON="prod" rye run data ``` By default `rye sync` does not install the extra packages needed in `labelbox[data]`. You'll need to run `rye sync --all-features`. Do not checkin `requirements.lock` or `requirements-dev.lock` after doing this. diff --git a/Dockerfile b/Dockerfile index ca521c278..162d5654d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ENV LANG="C.UTF-8" \ LC_ALL="C.UTF-8" \ PATH="/home/python/.local/bin:/home/python/.rye/shims:$PATH" \ PIP_NO_CACHE_DIR="false" \ - RYE_VERSION="0.29.0" \ + RYE_VERSION="0.32.0" \ RYE_INSTALL_OPTION="--yes" \ LABELBOX_TEST_ENVIRON="prod" @@ -29,6 +29,7 @@ WORKDIR /home/python/labelbox-python RUN rye config --set-bool behavior.global-python=true && \ rye config --set-bool behavior.use-uv=true && \ + rye pin 3.8 && \ rye sync CMD cd libs/labelbox && rye run integration && rye sync -f --features labelbox/data && rye run unit && rye run data diff --git a/libs/labelbox/pyproject.toml b/libs/labelbox/pyproject.toml index 69e29d6f5..7d9e7d85c 100644 --- a/libs/labelbox/pyproject.toml +++ b/libs/labelbox/pyproject.toml @@ -85,8 +85,8 @@ unit = "pytest tests/unit" # LABELBOX_TEST_ENVIRON="ephemeral" \ # SERVICE_API_KEY=${SERVICE_API_KEY} \ # LABELBOX_TEST_BASE_URL="http://host.docker.internal:8080" \ -integration = { cmd = "pytest tests/integration", env = { LABELBOX_TEST_ENVIRON = "prod" } } -data = { cmd = "pytest tests/data", env = { LABELBOX_TEST_ENVIRON = "prod" } } +integration = { cmd = "pytest tests/integration" } +data = { cmd = "pytest tests/data" } yapf-lint = "yapf tests src -i --verbose --recursive --parallel --style \"google\"" mypy-lint = "mypy src --pretty --show-error-codes --non-interactive --install-types" lint = { chain = ["yapf-lint", "mypy-lint"] }