From d66b23b896851ebd0682d2f2f4627b075262f962 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Sun, 22 Feb 2015 22:45:04 +0000 Subject: [PATCH] Add support for running on PyPy. --- gnupg/_meta.py | 17 ++++++++++++++++- gnupg/_util.py | 3 +-- setup.py | 27 +++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/gnupg/_meta.py b/gnupg/_meta.py index 3f7ac5d..5efbd04 100644 --- a/gnupg/_meta.py +++ b/gnupg/_meta.py @@ -32,12 +32,18 @@ import encodings import locale import os import platform -import psutil import shlex import subprocess import sys import threading +## Using psutil is recommended, but since the extension doesn't run with the +## PyPy interpreter, we'll run even if it's not present. +try: + import psutil +except ImportError: + psutil = None + from . import _parsers from . import _util @@ -81,10 +87,19 @@ class GPGMeta(type): the same. (Sorry Windows users; maybe you should switch to anything else.) + .. note: This function will only run if the psutil_ Python extension + is installed. Because psutil won't run with the PyPy interpreter, + use of it is optional (although highly recommended). + + .. _psutil: https://pypi.python.org/pypi/psutil + :returns: True if there exists a gpg-agent process running under the same effective user ID as that of this program. Otherwise, returns False. """ + if not psutil: + return False + this_process = psutil.Process(os.getpid()) ownership_match = False diff --git a/gnupg/_util.py b/gnupg/_util.py index fff8c0c..8afece5 100644 --- a/gnupg/_util.py +++ b/gnupg/_util.py @@ -28,7 +28,6 @@ from time import mktime import codecs import encodings import os -import psutil import threading import random import re @@ -418,7 +417,7 @@ def _make_passphrase(length=None, save=False, file=None): passphrase = _make_random_string(length) if save: - ruid, euid, suid = psutil.Process(os.getpid()).uids + ruid, euid, suid = os.getresuid() gid = os.getgid() now = mktime(localtime()) diff --git a/setup.py b/setup.py index addfaa4..08cdfb8 100644 --- a/setup.py +++ b/setup.py @@ -22,11 +22,19 @@ from __future__ import absolute_import from __future__ import print_function +import platform import setuptools import sys import os import versioneer +try: + import __pypy__ +except ImportError: + _isPyPy = False +else: + _isPyPy = True + versioneer.versionfile_source = 'gnupg/_version.py' versioneer.versionfile_build = 'gnupg/_version.py' @@ -75,6 +83,13 @@ def get_requirements(): # Required to make `collections.OrderedDict` available on Python<=2.6 requirements.append('ordereddict==1.1#a0ed854ee442051b249bfad0f638bbec') + # Don't try to install psutil on PyPy: + if _isPyPy: + for line in requirements[:]: + if line.startswith('psutil'): + print("Not installing %s on PyPy..." % line) + requirements.remove(line) + return requirements, links @@ -89,8 +104,8 @@ This module allows easy access to GnuPG's key management, encryption and \ signature functionality from Python programs, by interacting with GnuPG \ through file descriptors. Input arguments are strictly checked and sanitised, \ and therefore this module should be safe to use in networked applications \ -requiring direct user input. It is intended for use with Python 2.6 or \ -greater. +requiring direct user input. It is intended for use on Windows, MacOS X, BSD, \ +or Linux, with Python 2.6, Python 2.7, Python 3.3, Python 3.4, or PyPy. """, license="GPLv3+", @@ -119,7 +134,13 @@ greater. classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", + "Intended Audience :: System Administrators", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + "Operating System :: Android", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: BSD", + "Operating System :: POSIX :: Linux", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", @@ -127,6 +148,8 @@ greater. "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Security :: Cryptography", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities",]