diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 537da22cf..320aed3bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,3 +47,9 @@ repos: rev: 25.1.0 hooks: - id: black + +### does not work .... lots of errors +# - repo: https://github.com/pycqa/flake8 +# rev: 7.3.0# +# hooks: +# - id: flake8 diff --git a/azure-pipelines-templates/run-tests.yml b/azure-pipelines-templates/run-tests.yml index c1a1a4ef8..60c8b9b01 100644 --- a/azure-pipelines-templates/run-tests.yml +++ b/azure-pipelines-templates/run-tests.yml @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# Copyright (c) 2009-2021, Shotgun Software Inc. +# Copyright (c) 2009-2025, Shotgun Software Inc. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -28,57 +28,50 @@ # This is the list of parameters for this template and their default values. parameters: - name: '' - vm_image: '' + # name: '' + # vm_image: '' + python_version: '' -jobs: - # The job will be named after the OS and Azure will suffix the strategy to make it unique - # so we'll have a job name "Windows Python 3.9" for example. What's a strategy? Strategies are the - # name of the keys under the strategy.matrix scope. So for each OS we'll have " Python 3.9" and - # " Python 3.10". -- job: ${{ parameters.name }} - pool: - vmImage: ${{ parameters.vm_image }} - # The strategy is another way of removing repetition. It will create one job per entry in the - # matrix. - strategy: - matrix: - # We support these versions of Python. - Python 3.9: - python.version: '3.9' - Python 3.10: - python.version: '3.10' - Python 3.11: - python.version: '3.11' - - maxParallel: 4 +# jobs: +# # The job will be named after the OS and Azure will suffix the strategy to make it unique +# # so we'll have a job name "Windows Python 3.9" for example. What's a strategy? Strategies are the +# # name of the keys under the strategy.matrix scope. So for each OS we'll have " Python 3.9" and +# # " Python 3.10". +# - job: +# strategy: +# parallel: 3 +# displayName: ${{ parameters.name }} +# pool: +# vmImage: ${{ parameters.vm_image }} variables: group: sg-credentials - # These are the steps that will be executed inside each job. - steps: - # Specifies which version of Python we want to use. That's where the strategy comes in. - # Each job will share this set of steps, but each of them will receive a different - # $(python.version) + +steps: # TODO: We should provide `githubToken` if we want to download a python release. # Otherwise we may hit the GitHub anonymous download limit. - task: UsePythonVersion@0 inputs: - versionSpec: '$(python.version)' - addToPath: True + versionSpec: ${{ parameters.python_version }} # Install all dependencies needed for running the tests. This command is good # for all OSes - - script: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install -r tests/ci_requirements.txt - displayName: Install tools + - task: Bash@3 + displayName: Install dependencies + inputs: + targetType: inline + script: | + python --version + python -c "import sys; print(sys.platform)" + pip install --upgrade pip + pip install --upgrade setuptools wheel + pip install --upgrade --requirement tests/ci_requirements.txt # The {{}} syntax is meant for the the pre-processor of Azure pipeline. Every statement inside # a {{}} block will be evaluated and substituted before the file is parsed to create the jobs. # So here we're inserting an extra step if the template is being invoked for Windows. - - ${{ if eq(parameters.name, 'Windows') }}: + - ${{ if startsWith(parameters.vm_image, 'windows') }}: # On Windows, we need to update the certificates, the cert store is missing the newer one # from Amazon like some clients experienced a while back. Who would have thought Microsoft # would have been out of date! ;) @@ -92,10 +85,15 @@ jobs: # Runs the tests and generates test coverage. The tests results are uploaded to Azure Pipelines in the # Tests tab of the build and each test run will be named after the --test-run-title argument to pytest, # for example 'Windows - 2.7' - - bash: | - cp ./tests/example_config ./tests/config - pytest --durations=0 -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)" + - task: Bash@3 displayName: Running tests + inputs: + targetType: inline + script: | + cp ./tests/example_config ./tests/config + pytest --durations=0 -v \ + --cov shotgun_api3 --cov-report xml \ + --test-run-title="${{parameters.name}}-${{ parameters.python_version }}" env: # Pass the values needed to authenticate with the Flow Production Tracking site and create some entities. # Remember, on a pull request from a client or on forked repos, those variables @@ -130,21 +128,21 @@ jobs: SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version) # Upload the code coverage result to codecov.io. - - ${{ if eq(parameters.name, 'Windows') }}: + - ${{ if startsWith(parameters.vm_image, 'windows') }}: - powershell: | $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe .\codecov.exe -f coverage.xml displayName: Uploading code coverage - - ${{ elseif eq(parameters.name, 'Linux') }}: + - ${{ elseif startsWith(parameters.vm_image, 'macos') }}: - script: | - curl -Os https://uploader.codecov.io/latest/linux/codecov + curl -Os https://uploader.codecov.io/v0.7.3/macos/codecov chmod +x codecov ./codecov -f coverage.xml displayName: Uploading code coverage - ${{ else }}: - script: | - curl -Os https://uploader.codecov.io/v0.7.3/macos/codecov - chmod +x codecov - ./codecov -f coverage.xml - displayName: Uploading code coverage + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov -f coverage.xml + displayName: Uploading code cover diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b9be5ab7e..a2c919407 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -58,6 +58,30 @@ pr: include: - "*" +parameters: + - name: test_python_versions + type: object + default: + - '3.9' + - '3.10' + - '3.11' + + - name: test_os_versions + type: object + default: + - name: Windows + vm_image: windows-latest + # Select Windows first because it's slower + + - name: macOS + vm_image: macOS-latest + # then mac because 2nd slower + + - name: Linux + vm_image: ubuntu-latest + # finally Linux is the fastest + + # This here is the list of jobs we want to run for our build. # Jobs run in parallel. jobs: @@ -71,20 +95,23 @@ jobs: - template: azure-pipelines-templates/type_checking.yml -# These are jobs templates, they allow to reduce the redundancy between -# variations of the same build. We pass in the image name -# and a friendly name that then template can then use to create jobs. -- template: azure-pipelines-templates/run-tests.yml - parameters: - name: Linux - vm_image: 'ubuntu-latest' +# Run tests for all combinations of Python and OS +- job: + strategy: + matrix: + ${{ each python_version in parameters.test_python_versions }}: + ${{ each os_version in parameters.test_os_versions }}: + "Tests ${{ os_version.name }} Python ${{ python_version }}": + imageName: '${{ os_version.vm_image }}' + python.version: '${{ python_version }}' -- template: azure-pipelines-templates/run-tests.yml - parameters: - name: macOS - vm_image: 'macOS-latest' + maxParallel: 3 + # limiting the parallel jobs to 3 to avoid race condition issues between tests..... :( -- template: azure-pipelines-templates/run-tests.yml - parameters: - name: Windows - vm_image: 'windows-latest' + pool: + vmImage: $(imageName) + + steps: + - template: azure-pipelines-templates/run-tests.yml + parameters: + python_version: $(python.version)