Skip to content

Commit

Permalink
fix: install + import (#22)
Browse files Browse the repository at this point in the history
* fix Win install
* CI: split pytest & pip
* ubuntu18 + py2.7
* less ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Borda and pre-commit-ci[bot] authored Jul 10, 2021
1 parent 2519921 commit 5434b5c
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 79 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/ci-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI package

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on: # Trigger the workflow on push or pull request, but only for the main branch
push: {}
pull_request:
branches: [master]

jobs:

package:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install require
run: |
pip install "pip>=20.1"
pip install check-manifest twine wheel
- name: Check manifest
run: |
python -m check_manifest
python setup.py check --metadata --strict
- name: Check package
run: |
python setup.py sdist bdist_wheel
twine check dist/*
install:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macOS-10.15, windows-2019]
python-version: [3.6, 3.9]
include:
- os: ubuntu-18.04
python-version: 2.7
# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Try installing
run: |
pip install "pip>=20.1" "numpy~=1.16.0" "matplotlib>=2.0, <3.0"
python setup.py install
cd ..
pip show gco-wrapper
python -c "import gco ; print(gco.__version__)"
pip-dist:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macOS-10.15, windows-2019]
python-version: [3.6, 3.9]
include:
- os: ubuntu-18.04
python-version: 2.7
# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Create package
run: |
python -c "import platform ; print(platform.uname())"
pip install setuptools wheel "numpy~=1.16.0"
python setup.py sdist bdist_wheel
- name: Try installing
working-directory: dist
run: |
ls
pip install $(python -c "import glob ; print(' '.join(glob.glob('*.whl')))")
# fixme
python -c 'import sysconfig; print(sysconfig.get_paths())'
pip show gco-wrapper
python -c "import gco ; print(gco.__version__)"
48 changes: 3 additions & 45 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, macOS-10.15, windows-2019]
python-version: [2.7, 3.6, 3.9]
exclude:
- os: windows-2019
python-version: [3.6, 3.9]
include:
- os: ubuntu-18.04
python-version: 2.7
# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
Expand Down Expand Up @@ -70,45 +70,3 @@ jobs:
file: coverage.xml
flags: pytest,python${{ matrix.python-version }}
fail_ci_if_error: false

package:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install require
run: |
pip install "pip>=20.1"
pip install check-manifest
- name: Check manifest
run: |
python -m check_manifest
python setup.py check --metadata --strict
install:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macOS-10.15, windows-2019]
python-version: [2.7, 3.6, 3.9]
exclude:
- os: windows-2019
python-version: 2.7
# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Try installing
run: |
pip install "pip>=20.1" "numpy~=1.16.0" "matplotlib>=2.0, <3.0"
python setup.py install
2 changes: 1 addition & 1 deletion gco/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '3.0.7'
__version__ = '3.0.8'
__version_info__ = tuple([int(i) for i in __version__.split('.')])

try:
Expand Down
34 changes: 15 additions & 19 deletions gco/cgco.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import ctypes as ct
import glob
import os
from glob import glob

import numpy as np

_LIB_BASE_NAME = 'libcgco'
_LIB_EXTENSIONS = ('.so', '.pyd', '.dll')
# or change this to your own path that contains libcgco.so
_CGCO_LIB_PATH = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
LIB_NAME = 'libcgco'

LIST_LIBGCO = glob.glob(os.path.join(_CGCO_LIB_PATH, LIB_NAME + '.*'))
assert len(LIST_LIBGCO) > 0, 'nothing found: %s' % repr(LIST_LIBGCO)
lib_exts = [os.path.splitext(os.path.basename(p))[1] for p in LIST_LIBGCO]
if '.so' in lib_exts:
_CGCO_LIB_NAME = LIST_LIBGCO[lib_exts.index('.so')]
elif '.lib' in lib_exts:
_CGCO_LIB_NAME = LIST_LIBGCO[lib_exts.index('.lib')]
elif '.dll' in lib_exts:
_CGCO_LIB_NAME = LIST_LIBGCO[lib_exts.index('.dll')]
else: # not sure what it found...
print('found libs: %s' % repr([os.path.basename(p) for p in LIST_LIBGCO]))
_CGCO_LIB_NAME = os.path.basename(LIST_LIBGCO[0])
assert os.path.exists(_CGCO_LIB_PATH), '%s' % _CGCO_LIB_PATH

# _CGCO_LIB_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
# _CGCO_LIB_NAME = 'cgco'
assert os.path.isdir(_CGCO_LIB_PATH)

_LIBGCO_PATTER = os.path.join(_CGCO_LIB_PATH, _LIB_BASE_NAME + '.*')
_LIST_LIBGCO = glob(_LIBGCO_PATTER)
if not _LIST_LIBGCO:
raise FileNotFoundError('no compiled library found in %s' % repr(_LIBGCO_PATTER))

_CGCO_LIB_NAMES = [os.path.basename(pl) for pl in _LIST_LIBGCO if os.path.splitext(pl)[1] in _LIB_EXTENSIONS]
if not _CGCO_LIB_NAMES: # not sure what it found...
raise RuntimeError('found potential libs: %s' % repr(_LIST_LIBGCO))
_CGCO_LIB_NAME = _CGCO_LIB_NAMES[0]

# change the type definition depending on your machine and the compiled GCO library
_handle_type = ct.c_int
Expand All @@ -43,6 +38,7 @@
_SMOOTH_COST_FN = ct.CFUNCTYPE(_energy_term_type, ct.c_int, ct.c_int, _label_id_type, _label_id_type)

# load cgco shared library
# see: https://catherineh.github.io/programming/2016/07/07/troubleshooting-windows-dll-imports-in-python
_cgco = np.ctypeslib.load_library(_CGCO_LIB_NAME, _CGCO_LIB_PATH)

# declare the functions, argument types and return types
Expand Down
4 changes: 2 additions & 2 deletions gco/pygco.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

try:
from cgco import _cgco, _SMOOTH_COST_FN
except Exception:
from .cgco import _cgco, _SMOOTH_COST_FN
except (ImportError, ModuleNotFoundError):
from gco.cgco import _cgco, _SMOOTH_COST_FN

# keep 4 effective digits for the fractional part if using real potentials
# make sure pairwise * smooth = unary so that the unary potentials and pairwise
Expand Down
19 changes: 7 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@
import sys

try:
from setuptools import Extension, setup # , Command, find_packages
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
except ImportError:
from distutils.command.build_ext import build_ext
from distutils.core import Extension, setup # , Command, find_packages
from distutils.core import Extension, setup

HERE = os.path.abspath(os.path.dirname(__file__))
PACKAGE_NAME = 'gco-v3.0.zip'
URL_LIB_GCO = 'http://vision.csd.uwo.ca/code/' + PACKAGE_NAME
LOCAL_SOURCE = 'gco_source'


def _parse_requirements(file_path):
with open(file_path) as fp:
reqs = [r.rstrip() for r in fp.readlines() if not r.startswith('#')]
return reqs


class BuildExt(build_ext):
""" build_ext command for use when numpy headers are needed.
SEE: https://stackoverflow.com/questions/2379898
Expand Down Expand Up @@ -66,11 +60,11 @@ def finalize_options(self):

if sys.version_info.major == 2:
# numpy v1.17 drops support for py2
setup_reqs = ['Cython', 'numpy<1.17']
install_reqs = _parse_requirements(os.path.join(HERE, 'requirements-py2.txt'))
setup_reqs = ['Cython>=0.23.1', 'numpy>=1.8.2, <1.17']
install_reqs = ['Cython>=0.23.1', 'numpy>=1.8.2, <1.17']
else:
setup_reqs = ['Cython', 'numpy']
install_reqs = _parse_requirements(os.path.join(HERE, 'requirements.txt'))
setup_reqs = ['Cython>=0.23.1', 'numpy>=1.8.2']
install_reqs = ['Cython>=0.23.1', 'numpy>=1.8.2']

setup(
name='gco-wrapper',
Expand All @@ -96,6 +90,7 @@ def finalize_options(self):
language='c++',
include_dirs=[LOCAL_SOURCE],
library_dirs=[LOCAL_SOURCE],
# Downgrade some diagnostics about nonconformant code from errors to warnings.
# extra_compile_args=["-fpermissive"],
),
],
Expand Down

0 comments on commit 5434b5c

Please sign in to comment.