Skip to content

Eliminate packaging dependency (#12) #6

Eliminate packaging dependency (#12)

Eliminate packaging dependency (#12) #6

Workflow file for this run

# Ultralytics YOLO 🚀, AGPL-3.0 license
# Publish pip package to PyPI https://pypi.org/project/ultralytics-thop/
name: Publish to PyPI
on:
push:
branches: [main]
workflow_dispatch:
inputs:
pypi:
type: boolean
description: Publish to PyPI
jobs:
publish:
if: github.repository == 'ultralytics/thop' && github.actor == 'glenn-jocher'
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: "0" # pulls all commits (needed correct last updated dates in Docs)
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip" # caching pip dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel build twine toml
pip install ultralytics --extra-index-url https://download.pytorch.org/whl/cpu
- name: Check PyPI version
shell: python
run: |
import os
import toml
from ultralytics.utils.checks import check_latest_pypi_version
# Read version from pyproject.toml
with open('pyproject.toml', 'r') as file:
pyproject_version = toml.load(file)['project']['version']
v_local = tuple(map(int, pyproject_version.split('.')))
# Compare with version on PyPI
v_pypi = tuple(map(int, check_latest_pypi_version('ultralytics-thop').split('.')))
print(f'Local version is {v_local}')
print(f'PyPI version is {v_pypi}')
d = [a - b for a, b in zip(v_local, v_pypi)] # diff
increment = True # (d[0] == d[1] == 0) and (0 < d[2] < 3) # only publish if patch version increments by 1 or 2
os.system(f'echo "increment={increment}" >> $GITHUB_OUTPUT')
os.system(f'echo "version={pyproject_version}" >> $GITHUB_OUTPUT')
if increment:
print('Local version is higher than PyPI version. Publishing new version to PyPI ✅.')
id: check_pypi
- name: Publish to PyPI
continue-on-error: true
if: (github.event_name == 'push' || github.event.inputs.pypi == 'true') && steps.check_pypi.outputs.increment == 'True'
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
python -m build
python -m twine upload dist/* -u __token__ -p $PYPI_TOKEN