diff --git a/python-pyalpm/0001-Python2-compat-Module-initialization.patch b/python-pyalpm/0001-Python2-compat-Module-initialization.patch new file mode 100644 index 00000000..b14b79b1 --- /dev/null +++ b/python-pyalpm/0001-Python2-compat-Module-initialization.patch @@ -0,0 +1,108 @@ +From a5e026eb17fd6c32ecb92aa40b71b5c6900fdabe Mon Sep 17 00:00:00 2001 +From: Ray Donnelly +Date: Fri, 11 Mar 2016 11:55:59 +0000 +Subject: [PATCH 1/5] Python2 compat: Module initialization + +From https://docs.python.org/3/howto/cporting.html +--- + src/pyalpm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- + 1 file changed, 57 insertions(+), 5 deletions(-) + +diff --git src/pyalpm.c src/pyalpm.c +index 507f564..47c48cc 100644 +--- src/pyalpm.c ++++ src/pyalpm.c +@@ -78,6 +78,28 @@ static PyObject *pyalpm_vercmp(PyObject *self, PyObject *args) { + return PyLong_FromLong(result); + } + ++/* ++ https://docs.python.org/3/howto/cporting.html ++*/ ++ ++struct module_state { ++ PyObject *error; ++}; ++ ++#if PY_MAJOR_VERSION >= 3 ++#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) ++#else ++#define GETSTATE(m) (&_state) ++static struct module_state _state; ++#endif ++ ++static PyObject * ++error_out(PyObject *m) { ++ struct module_state *st = GETSTATE(m); ++ PyErr_SetString(st->error, "something bad happened"); ++ return NULL; ++} ++ + static PyMethodDef methods[] = { + {"version", version_alpm, METH_NOARGS, "returns pyalpm version."}, + {"alpmversion", alpmversion_alpm, METH_NOARGS, "returns alpm version."}, +@@ -101,26 +123,56 @@ static PyMethodDef methods[] = { + {NULL, NULL, 0, NULL} + }; + ++#if PY_MAJOR_VERSION >= 3 ++ ++static int pyalpm_traverse(PyObject *m, visitproc visit, void *arg) { ++ Py_VISIT(GETSTATE(m)->error); ++ return 0; ++} ++ ++static int pyalpm_clear(PyObject *m) { ++ Py_CLEAR(GETSTATE(m)->error); ++ return 0; ++} ++ + static struct PyModuleDef pyalpm_def = { + PyModuleDef_HEAD_INIT, + "alpm", + "This module wraps the libalpm library", +- -1, ++ sizeof(struct module_state), + methods, +- NULL, NULL, NULL, NULL, ++ NULL, ++ pyalpm_traverse, ++ pyalpm_clear, ++ NULL, + }; + +-PyMODINIT_FUNC PyInit_pyalpm(void) +-{ +- PyObject* m = PyModule_Create(&pyalpm_def); ++#define INITERROR return NULL + ++PyMODINIT_FUNC ++PyInit_pyalpm(void) ++ ++#else ++#define INITERROR return ++ ++void ++initpyalpm(void) ++#endif ++{ ++#if PY_MAJOR_VERSION >= 3 ++ PyObject *m = PyModule_Create(&pyalpm_def); ++#else ++ PyObject *m = Py_InitModule("pyalpm", methods); ++#endif + init_pyalpm_error(m); + init_pyalpm_handle(m); + init_pyalpm_package(m); + init_pyalpm_db(m); + init_pyalpm_transaction(m); + ++#if PY_MAJOR_VERSION >= 3 + return m; ++#endif + } + + /* vim: set ts=2 sw=2 et: */ +-- +2.7.1 + diff --git a/python-pyalpm/0002-Python2-compat-Use-Py_BuildValue-s-file-name.patch b/python-pyalpm/0002-Python2-compat-Use-Py_BuildValue-s-file-name.patch new file mode 100644 index 00000000..258a425f --- /dev/null +++ b/python-pyalpm/0002-Python2-compat-Use-Py_BuildValue-s-file-name.patch @@ -0,0 +1,29 @@ +From c9bd0894ab16050c318a61e96f5e65b6cd58322c Mon Sep 17 00:00:00 2001 +From: Ray Donnelly +Date: Fri, 11 Mar 2016 11:56:57 +0000 +Subject: [PATCH 2/5] Python2 compat: Use Py_BuildValue("s", file->name) + +.. since PyUnicode_DecodeFSDefault() isn't available +--- + src/package.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git src/package.c src/package.c +index d4ab941..909cb0d 100644 +--- src/package.c ++++ src/package.c +@@ -213,7 +213,11 @@ static PyObject* pyalpm_package_get_files(AlpmPackage *self, void *closure) { + result = PyList_New((Py_ssize_t)flist->count); + for (i = 0; i < (ssize_t)flist->count; i++) { + const alpm_file_t *file = flist->files + i; ++#if PY_MAJOR_VERSION >= 3 + PyObject *filename = PyUnicode_DecodeFSDefault(file->name); ++#else ++ PyObject *filename = Py_BuildValue("s", file->name); ++#endif + PyObject *filesize = PyLong_FromLongLong(file->size); + PyObject *filemode = PyLong_FromUnsignedLong(file->mode); + PyObject *item = PyTuple_New(3); +-- +2.7.1 + diff --git a/python-pyalpm/0003-Python2-compat-pycman-from-__future__-import-print_f.patch b/python-pyalpm/0003-Python2-compat-pycman-from-__future__-import-print_f.patch new file mode 100644 index 00000000..00d43ebe --- /dev/null +++ b/python-pyalpm/0003-Python2-compat-pycman-from-__future__-import-print_f.patch @@ -0,0 +1,103 @@ +From 5232589a05a30db625c10a1278cd4f0cbf66b294 Mon Sep 17 00:00:00 2001 +From: Ray Donnelly +Date: Fri, 11 Mar 2016 11:58:17 +0000 +Subject: [PATCH 3/5] Python2 compat: pycman: from __future__ import + print_function + +--- + pycman/action_database.py | 1 + + pycman/action_deptest.py | 1 + + pycman/action_query.py | 1 + + pycman/action_remove.py | 1 + + pycman/action_sync.py | 1 + + pycman/action_upgrade.py | 1 + + pycman/action_version.py | 1 + + 7 files changed, 7 insertions(+) + +diff --git pycman/action_database.py pycman/action_database.py +index 6774ea7..5cecc65 100755 +--- pycman/action_database.py ++++ pycman/action_database.py +@@ -25,6 +25,7 @@ This script allows to modify install reasons for packages in local + database. + """ + ++from __future__ import print_function + import sys + import pyalpm + from pycman import config +diff --git pycman/action_deptest.py pycman/action_deptest.py +index c9c4ccf..16a8c2e 100755 +--- pycman/action_deptest.py ++++ pycman/action_deptest.py +@@ -25,6 +25,7 @@ This script checks whether specified dependencies are satisfied + and prints out a list of those which are missing. + """ + ++from __future__ import print_function + import sys + import pyalpm + from pycman import config +diff --git pycman/action_query.py pycman/action_query.py +index a8fb41b..7fb2642 100755 +--- pycman/action_query.py ++++ pycman/action_query.py +@@ -24,6 +24,7 @@ A Python implementation of pacman -Q + This script displays information about installed packages. + """ + ++from __future__ import print_function + import os + import sys + +diff --git pycman/action_remove.py pycman/action_remove.py +index 62303c1..53c6c16 100755 +--- pycman/action_remove.py ++++ pycman/action_remove.py +@@ -25,6 +25,7 @@ This script uninstalls packages. Various options control + the effect on dependencies of/on given targets. + """ + ++from __future__ import print_function + import sys + import traceback + import pyalpm +diff --git pycman/action_sync.py pycman/action_sync.py +index 82fda91..e5845d4 100755 +--- pycman/action_sync.py ++++ pycman/action_sync.py +@@ -25,6 +25,7 @@ This script displays information about packages available in repositories, + and is also used to install/upgrade/remove them. + """ + ++from __future__ import print_function + import sys + + import pyalpm +diff --git pycman/action_upgrade.py pycman/action_upgrade.py +index fc3b8df..4d064fd 100755 +--- pycman/action_upgrade.py ++++ pycman/action_upgrade.py +@@ -25,6 +25,7 @@ This script installs packages from tarballs. Various options control + the effect of the transaction. + """ + ++from __future__ import print_function + import sys + import traceback + import pyalpm +diff --git pycman/action_version.py pycman/action_version.py +index 05135cd..409137e 100755 +--- pycman/action_version.py ++++ pycman/action_version.py +@@ -24,6 +24,7 @@ A Python implementation of pacman -V + This script prints version information about pycman and pyalpm. + """ + ++from __future__ import print_function + import pyalpm + + VERSION_STRING = """ +-- +2.7.1 + diff --git a/python-pyalpm/0004-Python2-compat-python3-python-coding-utf-8.patch b/python-pyalpm/0004-Python2-compat-python3-python-coding-utf-8.patch new file mode 100644 index 00000000..8641a350 --- /dev/null +++ b/python-pyalpm/0004-Python2-compat-python3-python-coding-utf-8.patch @@ -0,0 +1,143 @@ +From 87a81fa3ab0c00aa6097c9adaed6e3b24b9f0a89 Mon Sep 17 00:00:00 2001 +From: Ray Donnelly +Date: Fri, 11 Mar 2016 16:52:40 +0000 +Subject: [PATCH 4/5] Python2 compat: python3 -> python, coding: utf-8 + +--- + pycman/__init__.py | 3 ++- + pycman/action_database.py | 3 ++- + pycman/action_deptest.py | 3 ++- + pycman/action_query.py | 3 ++- + pycman/action_remove.py | 3 ++- + pycman/action_sync.py | 3 ++- + pycman/action_upgrade.py | 3 ++- + pycman/action_version.py | 3 ++- + pycman/config.py | 3 ++- + pycman/pkginfo.py | 3 ++- + pycman/transaction.py | 3 ++- + 11 files changed, 22 insertions(+), 11 deletions(-) + +diff --git pycman/__init__.py pycman/__init__.py +index 19e3c9d..b43cf75 100644 +--- pycman/__init__.py ++++ pycman/__init__.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/action_database.py pycman/action_database.py +index 5cecc65..0bd9c5a 100755 +--- pycman/action_database.py ++++ pycman/action_database.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman-deptest - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/action_deptest.py pycman/action_deptest.py +index 16a8c2e..52058ed 100755 +--- pycman/action_deptest.py ++++ pycman/action_deptest.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman-deptest - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/action_query.py pycman/action_query.py +index 7fb2642..d6e3dc7 100755 +--- pycman/action_query.py ++++ pycman/action_query.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman-query - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/action_remove.py pycman/action_remove.py +index 53c6c16..b7f904f 100755 +--- pycman/action_remove.py ++++ pycman/action_remove.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman-remove - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/action_sync.py pycman/action_sync.py +index e5845d4..bade0ad 100755 +--- pycman/action_sync.py ++++ pycman/action_sync.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman-sync - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/action_upgrade.py pycman/action_upgrade.py +index 4d064fd..9f93a1a 100755 +--- pycman/action_upgrade.py ++++ pycman/action_upgrade.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman-upgrade - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/action_version.py pycman/action_version.py +index 409137e..8435032 100755 +--- pycman/action_version.py ++++ pycman/action_version.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman-version - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/config.py pycman/config.py +index 1543ce1..65028de 100644 +--- pycman/config.py ++++ pycman/config.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/pkginfo.py pycman/pkginfo.py +index a120d5f..9efd8d5 100644 +--- pycman/pkginfo.py ++++ pycman/pkginfo.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman.pkginfo - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +diff --git pycman/transaction.py pycman/transaction.py +index 143d1a3..926aebf 100644 +--- pycman/transaction.py ++++ pycman/transaction.py +@@ -1,4 +1,5 @@ +-#!/usr/bin/env python3 ++#!/usr/bin/env python ++# -- coding: utf-8 -- + # + # pycman - A Python implementation of Pacman + # Copyright (C) 2011 Rémy Oudompheng +-- +2.7.1 + diff --git a/python-pyalpm/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch b/python-pyalpm/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch new file mode 100644 index 00000000..cad08ced --- /dev/null +++ b/python-pyalpm/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch @@ -0,0 +1,60 @@ +From 7cfc7fd75c2c93085f7426d4f3cc9b893686b0b8 Mon Sep 17 00:00:00 2001 +From: Ray Donnelly +Date: Sat, 12 Mar 2016 12:10:52 +0000 +Subject: [PATCH 5/5] Use pkg-config, add LIBALPM_STATIC env. var + +--- + setup.py | 21 +++++++++++++++++---- + 1 file changed, 17 insertions(+), 4 deletions(-) + +diff --git setup.py setup.py +index 44507a9..49adf99 100644 +--- setup.py ++++ setup.py +@@ -1,6 +1,7 @@ + # -*- coding: utf-8 -*- + import os + from distutils.core import Extension, setup ++import commands + + os.putenv('LC_CTYPE', 'en_US.UTF-8') + +@@ -12,11 +13,21 @@ cflags = ['-Wall', '-Wextra', + '-Wno-unused-function', + '-Wno-format', + '-Wdeclaration-after-statement', +- '-ansi', '-D_FILE_OFFSET_BITS=64'] ++ '-ansi', '-D_FILE_OFFSET_BITS=64', ++ '-DVERSION="%s"' % pyalpm_version] ++ ++# From: http://code.activestate.com/recipes/502261-python-distutils-pkg-config/ ++def pkg_config(*pkg_config_flags, **kw): ++ flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} ++ kw['extra_compile_args'] = cflags ++ for token in commands.getoutput("pkg-config --libs --cflags %s" % ' '.join(pkg_config_flags)).split(): ++ if token[:2] in flag_map: ++ kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) ++ else: ++ kw['extra_compile_args'].append(token) ++ return kw + + alpm = Extension('pyalpm', +- libraries = ['alpm'], +- extra_compile_args = cflags + ['-DVERSION="%s"' % pyalpm_version], + language = 'C', + sources = [ + 'src/pyalpm.c', +@@ -34,7 +45,9 @@ alpm = Extension('pyalpm', + 'src/package.h', + 'src/pyalpm.h', + 'src/util.h', +- ]) ++ ], ++ **pkg_config('libalpm', '--static' if os.getenv('LIBALPM_STATIC') else '') ++ ) + + setup(name = 'pyalpm', + version = pyalpm_version, +-- +2.7.1 + diff --git a/python-pyalpm/PKGBUILD b/python-pyalpm/PKGBUILD new file mode 100644 index 00000000..9fb31b8a --- /dev/null +++ b/python-pyalpm/PKGBUILD @@ -0,0 +1,66 @@ +# Maintainer: Ray Donnelly + +pkgbase=pyalpm +pkgname=("python3-${pkgbase}" "python2-${pkgbase}") +pkgver=0.8 +pkgrel=1 +pkgdesc="Pycman arch linux package manager python bindings" +arch=('i686' 'x86_64') +license=('GPL') +url="https://nose.readthedocs.org/" +depends=("libarchive-devel") +makedepends=("python2-setuptools" + "python3-setuptools" + 'gettext-devel' + 'heimdal-devel' + 'libarchive-devel' + 'libcurl-devel' + 'libgpgme-devel' + 'pacman') +source=("https://sources.archlinux.org/other/${pkgbase}/${pkgbase}-${pkgver}.tar.gz" + "0001-Python2-compat-Module-initialization.patch" + "0002-Python2-compat-Use-Py_BuildValue-s-file-name.patch" + "0003-Python2-compat-pycman-from-__future__-import-print_f.patch" + "0004-Python2-compat-python3-python-coding-utf-8.patch" + "0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch") +sha256sums=('b83b50a8a03b38954c84a280ea627e7c5a750cd6451530e0418c097ab0476e22' + '489a3556bea9e22e809d7be31beb2dcaa74a3f776acd304d4a31cc1cfc2c547a' + '37f510ad8b66317b68125e7b2c4d7fee8396a0e795c145c443bfb3770187bed4' + '4b64a72f86cb6df75f37acf96de50148314ae1f44ae5ebd011b4631a7b5abcb8' + 'cd8aea9eeb69d740d8b32514560371f163be02717ce0de9c1dc0509e69bd680b' + 'ba2a5fa68bd90621efc8c69897abb623a8ec8347ddf00f75f92124876817f76b') + +prepare() { + cd "${srcdir}"/${pkgbase}-${pkgver} + patch -p0 -i "${srcdir}"/0001-Python2-compat-Module-initialization.patch + patch -p0 -i "${srcdir}"/0002-Python2-compat-Use-Py_BuildValue-s-file-name.patch + patch -p0 -i "${srcdir}"/0003-Python2-compat-pycman-from-__future__-import-print_f.patch + patch -p0 -i "${srcdir}"/0004-Python2-compat-python3-python-coding-utf-8.patch + patch -p0 -i "${srcdir}"/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch +} + +build() { + cd "$srcdir" + rm -rf python{2,3}-build + for builddir in python{2,3}-build; do + cp -r ${pkgbase}-${pkgver} ${builddir} + pushd ${builddir} + LIBALPM_STATIC=1 \ + /usr/bin/${builddir%-build} setup.py build + popd + done +} + +package_python3-pyalpm() { + depends=("python3-setuptools") + + cd "$srcdir/python3-build" + /usr/bin/python3 setup.py install --prefix=/usr --root="$pkgdir" -O1 +} + +package_python2-pyalpm() { + depends=("python2-setuptools") + + cd "$srcdir/python2-build" + /usr/bin/python2 setup.py install --prefix=/usr --root="$pkgdir" -O1 +}