Skip to content

Commit

Permalink
Merge pull request #1 from arsenyinfo/arseny/build_on_ci
Browse files Browse the repository at this point in the history
build qudida on CI, handle opencv dependencies
  • Loading branch information
arsenyinfo authored Aug 9, 2021
2 parents ec531e2 + f5c145a commit 668d49d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/upload_to_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Upload release to PyPI

on:
release:
types: [published]

jobs:
upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_LOGIN }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
39 changes: 38 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import io
import os
import re

from pkg_resources import DistributionNotFound, get_distribution
from setuptools import find_packages, setup

# Package meta-data.
Expand All @@ -10,6 +12,41 @@
REQUIRES_PYTHON = ">=3.5.0"

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
INSTALL_REQUIRES = ["numpy>=0.18.0", "scikit-learn>=0.19.1", "typing-extensions"]

# If none of packages in first installed, install second package
CHOOSE_INSTALL_REQUIRES = [
(
("opencv-python>=4.0.1", "opencv-contrib-python>=4.0.1", "opencv-contrib-python-headless>=4.0.1"),
"opencv-python-headless>=4.0.1",
)
]


def choose_requirement(mains, secondary):
"""If some version version of main requirement installed, return main,
else return secondary.
Based ob https://github.com/albumentations-team/albumentations/blob/master/setup.py to be consistent with their
dependency resolution approach.
"""
chosen = secondary
for main in mains:
try:
name = re.split(r"[!<>=]", main)[0]
get_distribution(name)
chosen = main
break
except DistributionNotFound:
pass

return str(chosen)


def get_install_requirements(install_requires, choose_install_requires):
for mains, secondary in choose_install_requires:
install_requires.append(choose_requirement(mains, secondary))
return install_requires


def load_requirements(filename):
Expand Down Expand Up @@ -53,7 +90,7 @@ def load_version():
python_requires=REQUIRES_PYTHON,
url=URL,
packages=find_packages(exclude=("tests",)),
install_requires=load_requirements("requirements.txt"),
install_requires=get_install_requirements(INSTALL_REQUIRES, CHOOSE_INSTALL_REQUIRES),
include_package_data=True,
classifiers=[
"Programming Language :: Python",
Expand Down

0 comments on commit 668d49d

Please sign in to comment.