Skip to content

Commit

Permalink
Merge pull request #25 from waveform80/pypi
Browse files Browse the repository at this point in the history
Ensure clean sdist and wheel builds
  • Loading branch information
joan2937 authored Mar 28, 2024
2 parents b959a17 + 46304f6 commit 746f0df
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
17 changes: 5 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SIZE = $(CROSS_PREFIX)size
STRIP = $(CROSS_PREFIX)strip
SHLIB = $(CC) -shared
STRIPLIB = $(STRIP) --strip-unneeded
PYTHON ?= python3

SOVERSION = 1

Expand Down Expand Up @@ -134,19 +135,11 @@ install: $(ALL)
ifeq ($(DESTDIR),)
ldconfig
endif
@if which python2; then cd PY_RGPIO && python2 setup.py -q install $(PYINSTALLARGS) || echo "*** install of Python2 rgpio.py failed ***"; fi
@if which python3; then cd PY_RGPIO && python3 setup.py -q install $(PYINSTALLARGS) || echo "*** install of Python3 rgpio.py failed ***"; fi
@if which swig; then cd PY_LGPIO && swig -python lgpio.i || echo "*** need swig package to install lgpio.py ***"; fi
@if which swig python2; then \
@if which $(PYTHON); then cd PY_RGPIO && $(PYTHON) setup.py -q install $(PYINSTALLARGS) || echo "*** install of Python3 rgpio.py failed ***"; fi
@if which swig $(PYTHON); then \
cd PY_LGPIO && \
python2 setup.py build_ext $(PYBUILDARGS) && \
python2 setup.py -q install $(PYINSTALLARGS) || \
echo "*** install of Python2 lgpio.py failed ***"; \
fi
@if which swig python3; then \
cd PY_LGPIO && \
python3 setup.py build_ext $(PYBUILDARGS) && \
python3 setup.py -q install $(PYINSTALLARGS) || \
$(PYTHON) setup.py build_ext $(PYBUILDARGS) && \
$(PYTHON) setup.py -q install $(PYINSTALLARGS) || \
echo "*** install of Python3 lgpio.py failed ***"; \
fi

Expand Down
50 changes: 43 additions & 7 deletions PY_LGPIO/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,48 @@
setup.py file for SWIG lgpio
"""

import os
from pathlib import Path
from textwrap import dedent

from setuptools import setup, Extension
from setuptools.command.build_py import build_py as _build_py

with open('README.md') as f:
long_description = f.read()
class build_py(_build_py):
# The package's module lgpio.py is produced by SWIG, hence build_ext must
# run prior to the build_py command
def run(self):
self.run_command('build_ext')
return super().run()

lgpio_module = Extension('_lgpio', sources=['lgpio_wrap.c',], libraries=['lgpio',],)
if int(os.environ.get('PYPI', '0')):
# If building for PyPI, build a statically linked module that incorporates
# the liblgpio library
Path('MANIFEST.in').write_text(dedent("""\
include lgpio_extra.py
include src/lg*.h
include src/rgpiod.h
"""))
lgpio_module = Extension(
'_lgpio',
sources=[str(p) for p in Path('src').glob('lg*.c')] +
['lgpio.i', 'src/rgpiod.c'],
libraries=['rt', 'dl'],
include_dirs=['src'],
extra_compile_args=['-O3', '-pthread'],
)
else:
# Otherwise, build a dynamically linked module
Path('MANIFEST.in').write_text(dedent("""\
include lgpio_extra.py
include src/lgpio.h
"""))
lgpio_module = Extension(
'_lgpio',
sources=['lgpio.i'],
libraries=['lgpio'],
include_dirs=['src'],
)

setup (name = 'lgpio',
version = '0.2.2.0',
Expand All @@ -20,16 +56,16 @@
maintainer_email='[email protected]',
url='http://abyz.me.uk/lg/py_lgpio.html',
description='Linux SBC GPIO module',
long_description=long_description,
long_description=Path('README.md').read_text(),
long_description_content_type="text/markdown",
download_url='http://abyz.me.uk/lg/lg.zip',
license='unlicense.org',
keywords=['linux', 'sbc', 'gpio',],
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
],
ext_modules = [lgpio_module],
py_modules = ["lgpio"],
ext_modules=[lgpio_module],
py_modules=["lgpio"],
cmdclass={'build_py': build_py},
)

1 change: 1 addition & 0 deletions PY_LGPIO/src
1 change: 0 additions & 1 deletion PY_RGPIO/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
py_modules=['rgpio'],
keywords=['linux', 'sbc', 'gpio',],
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
]
)
Expand Down

0 comments on commit 746f0df

Please sign in to comment.