Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/js-check-import-scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: JS - check import scenarios
on:
workflow_dispatch:
push:
branches:
- "main"
pull_request:
paths:
- 'js/simple_examples/**'
- '.github/workflows/run-js-examples.yml'
Expand All @@ -24,7 +27,7 @@ jobs:
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: Install Magika dependencies
run: yarn install --frozen-lockfile
working-directory: js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Python - build package
name: Python - build and release package

on:
workflow_dispatch:
push:
branches:
- "main"
tags:
- "test-python-v*"
pull_request:
paths:
- "python/**"
- "rust/**"
- "tests_data/**"
- ".github/workflows/python-*"
- ".github/workflows/python-build-package.yml"
schedule:
- cron: "12 3 * * 4" # Run everything once per week.
- cron: "12 3 * * 1" # Refresh the cache an additional time.
Expand All @@ -20,8 +22,38 @@ on:
permissions:
contents: read

# Note: This needs to match what specified in the on.push.tags trigger.
env:
RELEASE_TAG_PREFIX: "test-python-v"
UV_VERSION: "0.9.5"

jobs:
# This job acts as a gatekeeper for releases, which are triggered by a tag
# push. It performs critical pre-release checks. These checks are skipped for
# non-release pushes.
pre-release-checks:
name: Pre-release checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # pin@v5
with:
python-version: "3.12"
- name: Install uv
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
- name: Check package for release
if: github.event_name == 'push' && github.ref_type == 'tag' && startsWith(github.ref_name, env.RELEASE_TAG_PREFIX)
run: |
FULL_TAG_REF="${{ github.ref }}"
TAG_VERSION="${FULL_TAG_REF#refs/tags/${{ env.RELEASE_TAG_PREFIX}}}"
# Note: this uses the magika python package installed via uv.
uv run ./scripts/check_release_candidate_python_package.py ${TAG_VERSION} --skip-pip-show-package-version
working-directory: python

build-wheels:
needs: [pre-release-checks]
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
Expand All @@ -39,7 +71,7 @@ jobs:
with:
python-version: "3.12"
- name: Install uv
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
- if: matrix.platform.runner == 'ubuntu-latest'
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
Expand Down Expand Up @@ -96,41 +128,43 @@ jobs:
with:
python-version: "${{ matrix.python-version }}"
- name: Install uv
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh
- if: matrix.platform.runner != 'windows-latest'
name: Check that `uv add magika.whl` works
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
# Attempt "uv add magika.whl", in a temporary directory
- name: Check that `uv add magika.whl` works
shell: bash
run: |
mkdir /tmp/test-uv
cp -vR dist/*.whl /tmp/test-uv
cd /tmp/test-uv
uv init
uv add ./$(\ls -1 *.whl | head -n 1)
- if: matrix.platform.runner == 'windows-latest'
name: Check that `uv add magika.whl` works
shell: pwsh
run: |
mkdir C:\test-uv
Copy-Item -Path dist\*.whl -Destination C:\test-uv
cd C:\test-uv
$env:PATH += ";$HOME/.local/bin"
uv init
$wheel = Get-ChildItem -Filter *.whl | Select-Object -ExpandProperty Name
uv add ".\$wheel"
- name: Install the wheel
# From now on, magika will be available in the global environment
- name: Install the wheel via pip
run: python3 -m pip install $(python -c "import glob; print(glob.glob('dist/*.whl')[0])")

- run: magika --version
- run: "python3 -c 'import magika; m = magika.Magika(); print(m)'"
- run: magika -r tests_data/basic
- run: python3 ./python/scripts/run_quick_test_magika_cli.py
- run: python3 ./python/scripts/run_quick_test_magika_module.py
- name: Check package for release (if this is a release push)
if: github.event_name == 'push' && github.ref_type == 'tag' && startsWith(github.ref_name, env.RELEASE_TAG_PREFIX)
shell: bash
run: |
FULL_TAG_REF="${{ github.ref }}"
TAG_VERSION="${FULL_TAG_REF#refs/tags/${{ env.RELEASE_TAG_PREFIX}}}"
# Note: this uses the magika python package that was just built.
python3 ./scripts/check_release_candidate_python_package.py ${TAG_VERSION}
working-directory: python

build-pure-python-wheel-and-sdist:
needs: [pre-release-checks]
runs-on: ubuntu-latest
if: github.event.schedule != '12 3 * * 1'
steps:
- uses: actions/checkout@v5
- name: Install uv
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
- run: uv run ./scripts/prepare_pyproject_for_pure_python_wheel.py
working-directory: python
- name: Build pure python wheel and source distribution
Expand Down Expand Up @@ -175,26 +209,17 @@ jobs:
with:
python-version: "${{ matrix.python-version }}"
- name: Install uv
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh
- if: matrix.platform.runner != 'windows-latest'
name: Check that `uv add magika.whl` works
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
# Attempt "uv add magika.whl", in a temporary directory
- name: Check that `uv add magika.whl` works
shell: bash
run: |
mkdir /tmp/test-uv
cp -vR dist/*.whl /tmp/test-uv
cd /tmp/test-uv
uv init
uv add ./$(\ls -1 *.whl | head -n 1)
- if: matrix.platform.runner == 'windows-latest'
name: Check that `uv add magika.whl` works
shell: pwsh
run: |
mkdir C:\test-uv
Copy-Item -Path dist\*.whl -Destination C:\test-uv
cd C:\test-uv
$env:PATH += ";$HOME/.local/bin"
uv init
$wheel = Get-ChildItem -Filter *.whl | Select-Object -ExpandProperty Name
uv add ".\$wheel"
# From now on, magika will be available in the global environment
- name: Install the wheel
run: python3 -m pip install $(python -c "import glob; print(glob.glob('dist/*.whl')[0])")

Expand All @@ -207,6 +232,15 @@ jobs:
# Test the python module
- run: "python3 -c 'import magika; m = magika.Magika(); print(m)'"
- run: python3 ./python/scripts/run_quick_test_magika_module.py
- name: Check package for release (if this is a release push)
if: github.event_name == 'push' && github.ref_type == 'tag' && startsWith(github.ref_name, env.RELEASE_TAG_PREFIX)
shell: bash
run: |
FULL_TAG_REF="${{ github.ref }}"
TAG_VERSION="${FULL_TAG_REF#refs/tags/${{ env.RELEASE_TAG_PREFIX}}}"
# Note: this uses the magika python package that was just built.
python3 ./scripts/check_release_candidate_python_package.py ${TAG_VERSION} --use-python-client
working-directory: python

test-sdist:
needs: [build-pure-python-wheel-and-sdist]
Expand Down Expand Up @@ -235,26 +269,17 @@ jobs:
with:
python-version: "${{ matrix.python-version }}"
- name: Install uv
run: curl -LsSf https://astral.sh/uv/0.5.22/install.sh | sh
- if: matrix.platform.runner != 'windows-latest'
name: Check that `uv add magika.tar.gz` works
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
# Attempt "uv add magika.whl", in a temporary directory
- name: Check that `uv add magika.tar.gz` works
shell: bash
run: |
mkdir /tmp/test-uv
cp -vR dist/*.tar.gz /tmp/test-uv
cd /tmp/test-uv
uv init
uv add ./$(\ls -1 *.tar.gz | head -n 1)
- if: matrix.platform.runner == 'windows-latest'
name: Check that `uv add magika.tar.gz` works
shell: pwsh
run: |
mkdir C:\test-uv
Copy-Item -Path dist\*.tar.gz -Destination C:\test-uv
cd C:\test-uv
$env:PATH += ";$HOME\.local\bin"
uv init
$sdist = Get-ChildItem -Filter *.tar.gz | Select-Object -ExpandProperty Name
uv add ".\$sdist"
# From now on, magika will be available in the global environment
- name: Install the sdist
run: python3 -m pip install $(python -c "import glob; print(glob.glob('dist/*.tar.gz')[0])")

Expand All @@ -267,3 +292,24 @@ jobs:
# Test the python module
- run: "python3 -c 'import magika; m = magika.Magika(); print(m)'"
- run: python3 ./python/scripts/run_quick_test_magika_module.py
- name: Check package for release (if this is a release push)
if: github.event_name == 'push' && github.ref_type == 'tag' && startsWith(github.ref_name, env.RELEASE_TAG_PREFIX)
shell: bash
run: |
FULL_TAG_REF="${{ github.ref }}"
TAG_VERSION="${FULL_TAG_REF#refs/tags/${{ env.RELEASE_TAG_PREFIX}}}"
# Note: this uses the magika python package that was just built.
python3 ./scripts/check_release_candidate_python_package.py ${TAG_VERSION} --use-python-client
working-directory: python

release:
needs: [test-wheels, test-pure-python-wheel, test-sdist]
name: Release to pypi
runs-on: ubuntu-latest
# Note: the env context is not available for jobs.if:
# https://github.com/actions/runner/issues/1189#issuecomment-1129307280.
if: github.event_name == 'push' && github.ref_type == 'tag' && startsWith(github.ref_name, 'test-python-v')
steps:
- name: Checkout code
uses: actions/checkout@v5
# TODO: download artifacts, upload them to pypi
2 changes: 1 addition & 1 deletion .github/workflows/python-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- "python/**"
- "rust/**"
- "tests_data/**"
- ".github/workflows/python-*"
- ".github/workflows/python-test-suite.yml"

permissions:
contents: read
Expand Down
1 change: 0 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies = [
"click>=8.1.7",
"onnxruntime>=1.17.0 ; python_version > '3.9'",
"onnxruntime>=1.17.0, <1.20.0 ; python_version <= '3.9'",
Comment on lines 38 to 39

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and to reduce redundancy, you can simplify the onnxruntime dependency specifications. You can declare the base requirement for all versions and then add the conditional upper bound for older Python versions on a separate line. This makes the dependency logic easier to follow.

Suggested change
"onnxruntime>=1.17.0 ; python_version > '3.9'",
"onnxruntime>=1.17.0, <1.20.0 ; python_version <= '3.9'",
"onnxruntime>=1.17.0",
"onnxruntime<1.20.0 ; python_version <= '3.9'",

"onnxruntime<=1.20.1 ; sys_platform == 'win32'",
"numpy>=1.24; python_version < '3.12'",
"numpy>=1.26; python_version >= '3.12' and python_version < '3.13'",
"numpy>=2.1.0; python_version >= '3.13'",
Expand Down
Loading
Loading