Skip to content

Commit 8f12cc0

Browse files
dralleylukash
authored andcommitted
Remove Python 2 support
closes rpm-software-management#65
1 parent 76bc005 commit 8f12cc0

28 files changed

+146
-299
lines changed

libcomps/src/python/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ if (ENABLE_TESTS)
33
endif ()
44

55
#include(pycopy.cmake)
6-
include(pversion.cmake)
7-
set(pycopy "py${pversion}-copy")
6+
set(pycopy "py3-copy")
87

98
set (pycomps_TESTSDIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/")
109

libcomps/src/python/docs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ add_dependencies(pydocs pycomps)
2626
include(../pycopy.cmake)
2727
add_custom_command(TARGET pydocs PRE_BUILD COMMAND set -E $ENV{LD_LIBRARY_PATH} "${LIBCOMPS_OUT}:$ENV{LD_LIBRARY_PATH}")
2828

29-
add_custom_command(TARGET pydocs COMMAND python${pversion} ${SPHINX_EXECUTABLE} -E -b html
29+
add_custom_command(TARGET pydocs COMMAND ${PYTHON_EXECUTABLE} ${SPHINX_EXECUTABLE} -E -b html
3030
"${CMAKE_CURRENT_SOURCE_DIR}/doc-sources/"
3131
"${CMAKE_CURRENT_BINARY_DIR}/html/"
3232
COMMENT "LDLP $ENV{LD_LIBRARY_PATH}")

libcomps/src/python/pversion.cmake

Lines changed: 0 additions & 11 deletions
This file was deleted.

libcomps/src/python/pycopy.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
include(${PROJECT_SOURCE_DIR}/src/python/tests/tests.cmake)
3-
include(${PROJECT_SOURCE_DIR}/src/python/pversion.cmake)
43

54
list(LENGTH TESTS_FILES len)
65
math (EXPR len "${len} - 1")

libcomps/src/python/src/CMakeLists.txt

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set (pycomps_SRC pycomps.c pycomps_sequence.c
1111
pycomps_gids.c pycomps_utils.c pycomps_dict.c pycomps_mdict.c
1212
pycomps_hash.c pycomps_exc.c pycomps_lbw.c)
1313

14-
set (pycomps_HEADERS pycomps_23macros.h pycomps_sequence.h
14+
set (pycomps_HEADERS pycomps_macros.h pycomps_sequence.h
1515
pycomps_envs.h pycomps_categories.h pycomps_groups.h
1616
pycomps_gids.h pycomps_utils.h pycomps_dict.h pycomps_mdict.h
1717
pycomps_hash.h pycomps_exc.h pycomps_lbw.h
@@ -43,12 +43,8 @@ foreach(i RANGE 0 ${pycomps_SRCLEN})
4343
endforeach(i)
4444

4545
if (NOT SKBUILD)
46-
if (${pversion} EQUAL 2)
47-
find_package (PythonInterp 2 EXACT REQUIRED)
48-
else ()
49-
find_package (PythonInterp 3 EXACT REQUIRED)
50-
endif ()
51-
find_package (PythonLibs)
46+
find_package (PythonLibs 3 EXACT)
47+
find_package (PythonInterp 3 EXACT REQUIRED)
5248
endif(NOT SKBUILD)
5349

5450
include_directories(${PYTHON_INCLUDE_PATH})
@@ -58,55 +54,26 @@ if (ENABLE_TESTS)
5854
configure_file(${pycomps_TESTSDIR}/run_tests.sh.in ./libcomps/run_tests.sh)
5955
endif ()
6056

61-
if (${pversion} EQUAL 2)
62-
add_library(pycomps SHARED ${pycomps_SRC})
63-
set_target_properties(pycomps PROPERTIES LIBRARY_OUTPUT_DIRECTORY "./libcomps")
64-
set_target_properties(pycomps PROPERTIES PREFIX "_lib")
65-
#set_target_properties(pycomps PROPERTIES LIBRARY_OUTPUT_NAME "_libpycomps")
66-
#add_dependencies(pycomps src-copy)
67-
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
68-
SET(CMAKE_SKIP_BUILD_RPATH TRUE)
69-
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
70-
else ()
71-
include(../pycopy.cmake)
72-
73-
add_library(pycomps SHARED ${pycomps_SRC})
74-
set_target_properties(pycomps PROPERTIES LIBRARY_OUTPUT_DIRECTORY "./libcomps")
75-
set_target_properties(pycomps PROPERTIES PREFIX "")
76-
set_target_properties(pycomps PROPERTIES LIBRARY_OUTPUT_NAME "_libpycomps")
77-
add_dependencies(pycomps src-copy)
78-
endif ()
57+
include(../pycopy.cmake)
58+
59+
add_library(pycomps SHARED ${pycomps_SRC})
60+
set_target_properties(pycomps PROPERTIES LIBRARY_OUTPUT_DIRECTORY "./libcomps")
61+
set_target_properties(pycomps PROPERTIES PREFIX "")
62+
set_target_properties(pycomps PROPERTIES LIBRARY_OUTPUT_NAME "_libpycomps")
63+
add_dependencies(pycomps src-copy)
7964

8065
target_link_libraries(pycomps libcomps)
8166
target_link_libraries(pycomps ${EXPAT_LIBRARIES})
8267
target_link_libraries(pycomps ${LIBXML2_LIBRARIES})
8368
target_link_libraries(pycomps ${PYTHON_LIBRARIES})
8469

85-
if ((${pversion} EQUAL 2) AND ENABLE_TESTS)
70+
if (ENABLE_TESTS)
8671
set(pycopy pytest_run)
8772

88-
add_custom_target(pytest_run)
89-
add_dependencies(pytest_run pycomps)
90-
91-
include(../pycopy.cmake)
92-
93-
add_custom_command(TARGET pytest_run COMMAND ./run_tests.sh
94-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libcomps/
95-
COMMENT "Running python binding tests")
96-
endif ()
97-
98-
if (ENABLE_TESTS)
9973
add_custom_target(pytest_run COMMAND ./run_tests.sh
100-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libcomps/
101-
COMMENT "Running python binding tests")
102-
endif ()
103-
104-
if (${pversion} EQUAL 2)
105-
if (ENABLE_TESTS)
106-
add_dependencies(pytest pytest_run)
107-
endif ()
108-
else ()
109-
add_dependencies(pycomps pycomps py3-copy)
74+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libcomps/
75+
COMMENT "Running python binding tests")
76+
add_dependencies(pytest_run pycomps py3-copy)
11077
endif ()
11178

11279
IF (SKBUILD)

libcomps/src/python/src/pycomps.c

Lines changed: 60 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,10 @@
2525

2626
#include <stdbool.h>
2727

28-
#include "pycomps_23macros.h"
28+
#include "pycomps_macros.h"
2929
#include "pycomps.h"
3030
#include "pycomps_exc.h"
3131

32-
#if PY_MAJOR_VERSION >= 3
33-
#define MODINIT_RET_NONE return NULL
34-
#define PY_OBJ_HEAD_INIT PyVarObject_HEAD_INIT(NULL, 0)
35-
#define IS_PY3K
36-
#else
37-
#define MODINIT_RET_NONE return
38-
#define PY_OBJ_HEAD_INIT PyObject_HEAD_INIT(NULL)\
39-
0,
40-
#endif
41-
4232
char __pycomps_dict_to_xml_opts(PyObject* pobj, void *cobj) {
4333
PyObject *val;
4434
COMPS_XMLOptions ** options = (COMPS_XMLOptions**)cobj;
@@ -281,7 +271,7 @@ PyObject* PyCOMPS_fromxml_f(PyObject *self, PyObject *args, PyObject* kwds) {
281271
PyErr_SetString(PyCOMPSExc_ParserError, "Fatal parser error");
282272
return NULL;
283273
}
284-
return PyINT_FROM_LONG((long)parsed_ret);
274+
return PyLong_FromLong((long)parsed_ret);
285275
}
286276

287277
PyObject* PyCOMPS_get_last_errors(PyObject *self, void *closure)
@@ -370,7 +360,7 @@ PyObject* PyCOMPS_fromxml_str(PyObject *self, PyObject *args, PyObject *kwds) {
370360
return NULL;
371361
}
372362

373-
return PyINT_FROM_LONG((long)parsed_ret);
363+
return PyLong_FromLong((long)parsed_ret);
374364
}
375365

376366
PyObject* PyCOMPS_get_(PyCOMPS *self, void *closure) {
@@ -881,7 +871,7 @@ PyNumberMethods PyCOMPS_Nums = {
881871
* */
882872

883873
PyTypeObject PyCOMPS_Type = {
884-
PY_OBJ_HEAD_INIT
874+
PyVarObject_HEAD_INIT(NULL, 0)
885875
"_libpycomps.Comps", /*tp_name*/
886876
sizeof(PyCOMPS), /*tp_basicsize*/
887877
0, /*tp_itemsize*/
@@ -971,95 +961,90 @@ static PyMethodDef LibcompsMethods[] = {
971961
"Return xml output default options"},
972962
{NULL, NULL, 0, NULL} /* Sentinel */
973963
};
974-
#if PY_MAJOR_VERSION >= 3
975-
static struct PyModuleDef moduledef = {
976-
PyModuleDef_HEAD_INIT,
977-
"_libpycomps",
978-
"libcomps module",
979-
-1,
980-
LibcompsMethods, //myextension_methods,
981-
NULL,
982-
NULL, //myextension_traverse,
983-
NULL, //myextension_clear,
984-
NULL
985-
};
986-
#endif
964+
965+
static struct PyModuleDef moduledef = {
966+
PyModuleDef_HEAD_INIT,
967+
"_libpycomps",
968+
"libcomps module",
969+
-1,
970+
LibcompsMethods, //myextension_methods,
971+
NULL,
972+
NULL, //myextension_traverse,
973+
NULL, //myextension_clear,
974+
NULL
975+
};
987976

988977
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
989978
#define PyMODINIT_FUNC void
990979
#endif
991980

992-
993981
PyMODINIT_FUNC
994-
PYINIT_FUNC(void) {
982+
PyInit__libpycomps(void)
983+
{
995984
PyObject *m;
996985
PyCOMPS_GroupType.tp_new = PyCOMPSGroup_new;
997986
PyCOMPS_Type.tp_new = PyCOMPS_new;
998-
if (PyType_Ready(&PyCOMPS_Type) < 0 ) {
999-
MODINIT_RET_NONE;
987+
if (PyType_Ready(&PyCOMPS_Type) < 0) {
988+
return NULL;
1000989
}
1001-
if (PyType_Ready(&PyCOMPS_CatType) < 0 ) {
1002-
MODINIT_RET_NONE;
990+
if (PyType_Ready(&PyCOMPS_CatType) < 0) {
991+
return NULL;
1003992
}
1004-
if (PyType_Ready(&PyCOMPS_CatsType) < 0 ) {
1005-
MODINIT_RET_NONE;
993+
if (PyType_Ready(&PyCOMPS_CatsType) < 0) {
994+
return NULL;
1006995
}
1007-
if (PyType_Ready(&PyCOMPS_GIDType) < 0 ) {
1008-
MODINIT_RET_NONE;
996+
if (PyType_Ready(&PyCOMPS_GIDType) < 0) {
997+
return NULL;
1009998
}
1010-
if (PyType_Ready(&PyCOMPS_GIDsType) < 0 ) {
1011-
MODINIT_RET_NONE;
999+
if (PyType_Ready(&PyCOMPS_GIDsType) < 0) {
1000+
return NULL;
10121001
}
1013-
if (PyType_Ready(&PyCOMPS_EnvsType) < 0 ) {
1014-
MODINIT_RET_NONE;
1002+
if (PyType_Ready(&PyCOMPS_EnvsType) < 0) {
1003+
return NULL;
10151004
}
1016-
if (PyType_Ready(&PyCOMPS_EnvType) < 0 ) {
1017-
MODINIT_RET_NONE;
1005+
if (PyType_Ready(&PyCOMPS_EnvType) < 0) {
1006+
return NULL;
10181007
}
1019-
if (PyType_Ready(&PyCOMPS_GroupType) < 0 ) {
1020-
MODINIT_RET_NONE;
1008+
if (PyType_Ready(&PyCOMPS_GroupType) < 0) {
1009+
return NULL;
10211010
}
1022-
if (PyType_Ready(&PyCOMPS_GroupsType) < 0 ) {
1023-
MODINIT_RET_NONE;
1011+
if (PyType_Ready(&PyCOMPS_GroupsType) < 0) {
1012+
return NULL;
10241013
}
1025-
if (PyType_Ready(&PyCOMPS_PacksType) < 0 ) {
1026-
MODINIT_RET_NONE;
1014+
if (PyType_Ready(&PyCOMPS_PacksType) < 0) {
1015+
return NULL;
10271016
}
1028-
if (PyType_Ready(&PyCOMPS_PackType) < 0 ) {
1029-
MODINIT_RET_NONE;
1017+
if (PyType_Ready(&PyCOMPS_PackType) < 0) {
1018+
return NULL;
10301019
}
1031-
if (PyType_Ready(&PyCOMPS_StrDictType) < 0 ) {
1032-
MODINIT_RET_NONE;
1020+
if (PyType_Ready(&PyCOMPS_StrDictType) < 0) {
1021+
return NULL;
10331022
}
1034-
if (PyType_Ready(&PyCOMPS_SeqIterType) < 0 ) {
1035-
MODINIT_RET_NONE;
1023+
if (PyType_Ready(&PyCOMPS_SeqIterType) < 0) {
1024+
return NULL;
10361025
}
1037-
if (PyType_Ready(&PyCOMPS_DictIterType) < 0 ) {
1038-
MODINIT_RET_NONE;
1026+
if (PyType_Ready(&PyCOMPS_DictIterType) < 0) {
1027+
return NULL;
10391028
}
1040-
if (PyType_Ready(&PyCOMPS_MDictType) < 0 ) {
1041-
MODINIT_RET_NONE;
1029+
if (PyType_Ready(&PyCOMPS_MDictType) < 0) {
1030+
return NULL;
10421031
}
1043-
if (PyType_Ready(&PyCOMPS_MDictIterType) < 0 ) {
1044-
MODINIT_RET_NONE;
1032+
if (PyType_Ready(&PyCOMPS_MDictIterType) < 0) {
1033+
return NULL;
10451034
}
1046-
if (PyType_Ready(&PyCOMPS_LangPacksType) < 0 ) {
1047-
MODINIT_RET_NONE;
1035+
if (PyType_Ready(&PyCOMPS_LangPacksType) < 0) {
1036+
return NULL;
10481037
}
1049-
if (PyType_Ready(&PyCOMPS_BlacklistType) < 0 ) {
1050-
MODINIT_RET_NONE;
1038+
if (PyType_Ready(&PyCOMPS_BlacklistType) < 0) {
1039+
return NULL;
10511040
}
1052-
if (PyType_Ready(&PyCOMPS_WhiteoutType) < 0 ) {
1053-
MODINIT_RET_NONE;
1041+
if (PyType_Ready(&PyCOMPS_WhiteoutType) < 0) {
1042+
return NULL;
10541043
}
1055-
if (PyType_Ready(&PyCOMPS_StrSeqType) < 0 ) {
1056-
MODINIT_RET_NONE;
1044+
if (PyType_Ready(&PyCOMPS_StrSeqType) < 0) {
1045+
return NULL;
10571046
}
1058-
#if PY_MAJOR_VERSION >= 3
1059-
m = PyModule_Create(&moduledef);
1060-
#else
1061-
m = Py_InitModule("_libpycomps", LibcompsMethods);
1062-
#endif
1047+
m = PyModule_Create(&moduledef);
10631048
Py_INCREF(&PyCOMPS_Type);
10641049
PyModule_AddObject(m, "Comps", (PyObject*) &PyCOMPS_Type);
10651050
Py_INCREF(&PyCOMPS_CatsType);
@@ -1110,7 +1095,5 @@ PYINIT_FUNC(void) {
11101095
PyModule_AddObject(m, "XMLGenError", PyCOMPSExc_XMLGenError);
11111096

11121097
//Py_AtExit(&pycomps_exit)
1113-
#if PY_MAJOR_VERSION >= 3
1114-
return m;
1115-
#endif
1098+
return m;
11161099
}

libcomps/src/python/src/pycomps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "libcomps/comps_dict.h"
2929
#include "libcomps/comps_log.h"
3030

31-
#include "pycomps_23macros.h"
31+
#include "pycomps_macros.h"
3232

3333
#include "pycomps_categories.h"
3434
#include "pycomps_groups.h"

libcomps/src/python/src/pycomps_categories.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ PyNumberMethods PyCOMPSCat_Nums = {
314314
};
315315

316316
PyTypeObject PyCOMPS_CatType = {
317-
PY_OBJ_HEAD_INIT
317+
PyVarObject_HEAD_INIT(NULL, 0)
318318
"libcomps.Category", /*tp_name*/
319319
sizeof(PyCOMPS_Category), /*tp_basicsize*/
320320
0, /*tp_itemsize*/
@@ -452,7 +452,7 @@ PyNumberMethods PyCOMPSCats_Nums = {
452452
};
453453

454454
PyTypeObject PyCOMPS_CatsType = {
455-
PY_OBJ_HEAD_INIT
455+
PyVarObject_HEAD_INIT(NULL, 0)
456456
"libcomps.CategoryList", /*tp_name*/
457457
sizeof(PyCOMPS_Sequence), /*tp_basicsize*/
458458
sizeof(PyCOMPS_Category), /*tp_itemsize*/

libcomps/src/python/src/pycomps_categories.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef PYCOMPS_CATEGORIES_H
2121
#define PYCOMPS_CATEGORIES_H
2222

23-
#include "pycomps_23macros.h"
23+
#include "pycomps_macros.h"
2424

2525
#include "libcomps/comps_doc.h"
2626
//#include "libcomps/comps_list.h"

0 commit comments

Comments
 (0)