Skip to content

Commit a66d2be

Browse files
committed
Modernize Python module's build flow
1 parent afe238a commit a66d2be

6 files changed

Lines changed: 46 additions & 30 deletions

File tree

bindings/Makefile.am

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ all-py: pybinding.c
66
--build-base $(shell readlink -f $(builddir))/build \
77
--verbose)
88

9-
install-exec-py:
10-
$(PYTHON) $(srcdir)/setup.py install \
11-
--prefix $(DESTDIR)$(prefix) \
12-
--verbose
9+
PYTHON_INSTALL_CMD = pip install --root=$(DESTDIR)/ \
10+
--no-deps \
11+
--ignore-installed \
12+
--no-build-isolation .
13+
14+
PYTHON_UNINSTALL_CMD = rm -rf $(DESTDIR)$(libdir)/python*/dist-packages/mypylogparser*
15+
1316

1417
clean-py:
1518
rm -rf *.o *.so *.la build
1619

20+
else
21+
PYTHON_INSTALL_CMD = @echo "Python support disabled, skipping..."
1722
endif
1823

1924

@@ -76,6 +81,7 @@ all-local:
7681

7782
install-exec-local:
7883
$(MAKE) $(BINDING_INSTALL_EXEC)
84+
$(PYTHON_INSTALL_CMD)
7985

8086
clean-local:
8187
$(MAKE) $(BINDING_CLEAN)

bindings/Makefile.in

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ target_alias = @target_alias@
289289
top_build_prefix = @top_build_prefix@
290290
top_builddir = @top_builddir@
291291
top_srcdir = @top_srcdir@
292+
@ENABLE_PYTHON_FALSE@PYTHON_INSTALL_CMD = @echo "Python support disabled, skipping..."
293+
@ENABLE_PYTHON_TRUE@PYTHON_INSTALL_CMD = pip install --root=$(DESTDIR)/ \
294+
@ENABLE_PYTHON_TRUE@ --no-deps \
295+
@ENABLE_PYTHON_TRUE@ --ignore-installed \
296+
@ENABLE_PYTHON_TRUE@ --no-build-isolation .
297+
298+
@ENABLE_PYTHON_TRUE@PYTHON_UNINSTALL_CMD = rm -rf $(DESTDIR)$(libdir)/python*/dist-packages/mypylogparser*
292299
@ENABLE_LUA_TRUE@LUALIBFLAG = -shared -fpic
293300
@ENABLE_LUA_TRUE@LUACFLAGS = -I../src $(LUA_INCLUDE) -L../src/.libs
294301
@ENABLE_RUBY_TRUE@RUBYLIBFLAG = -shared -fPIC -L$(RUBY_ARCHLIBDIR)
@@ -494,11 +501,6 @@ uninstall-am:
494501
@ENABLE_PYTHON_TRUE@ --build-base $(shell readlink -f $(builddir))/build \
495502
@ENABLE_PYTHON_TRUE@ --verbose)
496503

497-
@ENABLE_PYTHON_TRUE@install-exec-py:
498-
@ENABLE_PYTHON_TRUE@ $(PYTHON) $(srcdir)/setup.py install \
499-
@ENABLE_PYTHON_TRUE@ --prefix $(DESTDIR)$(prefix) \
500-
@ENABLE_PYTHON_TRUE@ --verbose
501-
502504
@ENABLE_PYTHON_TRUE@clean-py:
503505
@ENABLE_PYTHON_TRUE@ rm -rf *.o *.so *.la build
504506

@@ -542,6 +544,7 @@ all-local:
542544

543545
install-exec-local:
544546
$(MAKE) $(BINDING_INSTALL_EXEC)
547+
$(PYTHON_INSTALL_CMD)
545548

546549
clean-local:
547550
$(MAKE) $(BINDING_CLEAN)

bindings/pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "mscpylogparser"
7+
version = "0.3.0"
8+
description = "Python bindings for libmsclogparser"
9+
readme = "README.md"
10+
authors = [{name = "Ervin Hegedüs", email = "airween@digitalwave.hu"}]
11+
dependencies = []
12+
13+
[tool.setuptools]
14+
py-modules = []

bindings/setup.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
from distutils.core import setup, Extension
1+
from setuptools import setup, Extension
2+
import os
23

3-
def main():
4-
setup(name="mscpylogparser",
5-
version="0.2.0",
6-
description="Python interface for parsing ModSecurity generated error.log lines",
7-
author="Ervin Hegedus",
8-
author_email="airween@digitalwave.hu",
9-
ext_modules=[
10-
Extension("mscpylogparser",
11-
sources = ["pybinding.c"],
12-
library_dirs = ["../src/.libs",],
13-
libraries = ['msclogparser'],
14-
extra_compile_args = ["-Wall", "-I../src"],
15-
)
16-
],
17-
)
4+
module = Extension(
5+
'mscpylogparser',
6+
sources=['pybinding.c'],
7+
libraries=['msclogparser'],
8+
include_dirs=['../src', '/usr/include', '/usr/local/include'],
9+
library_dirs=['../src/.libs', '/usr/lib', '/usr/local/lib'],
10+
)
11+
12+
setup(
13+
ext_modules=[module],
14+
)
1815

19-
if __name__ == "__main__":
20-
main()

configure

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ ac_config_headers="$ac_config_headers config.h"
29212921

29222922

29232923

2924-
VER_NUMBER=0:2:0
2924+
VER_NUMBER=0:3:0
29252925

29262926

29272927
ac_ext=c
@@ -14820,7 +14820,6 @@ printf "%s\n" "#define HAVE_PYTHON 1" >>confdefs.h
1482014820

1482114821
fi
1482214822
BINDING_ALL="${BINDING_ALL} all-py"
14823-
BINDING_INSTALL_EXEC="${BINDING_INSTALL_EXEC} install-exec-py"
1482414823
BINDING_CLEAN="${BINDING_CLEAN} clean-py"
1482514824

1482614825
else case e in #(

configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ AS_IF([test "x$wantpythonbinding" = xtrue],
104104
]
105105
)
106106
BINDING_ALL="${BINDING_ALL} all-py"
107-
BINDING_INSTALL_EXEC="${BINDING_INSTALL_EXEC} install-exec-py"
108107
BINDING_CLEAN="${BINDING_CLEAN} clean-py"
109108
],
110109
[AC_MSG_RESULT([no])]

0 commit comments

Comments
 (0)