summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-02-09 14:33:38 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2015-02-09 14:33:38 +0100
commitea8853644e34ef3036912df77e8f1615e9251e87 (patch)
tree52854ac6e9241318c7d764e8d417edf58a31c2f8
parent39af7af7ca5438d7feac816b457b9ebe48747ddd (diff)
downloadpsutil-ea8853644e34ef3036912df77e8f1615e9251e87.tar.gz
fix #587: re-apply the relative import changes and use setup.py build_ext -i in order to fix the import error when using the interactive interpreter from within the root directory
-rw-r--r--Makefile6
-rw-r--r--psutil/__init__.py130
-rw-r--r--psutil/_psbsd.py16
-rw-r--r--[-rwxr-xr-x]psutil/_pslinux.py16
-rw-r--r--psutil/_psosx.py16
-rw-r--r--psutil/_psposix.py4
-rw-r--r--psutil/_pssunos.py18
-rw-r--r--psutil/_pswindows.py10
-rw-r--r--setup.py12
9 files changed, 116 insertions, 112 deletions
diff --git a/Makefile b/Makefile
index 542cc251..cb28b6fd 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,10 @@ clean:
build: clean
$(PYTHON) setup.py build
+ @# copies *.so files in ./psutil directory in order to allow
+ @# "import psutil" when using the interactive interpreter from within
+ @# this directory .
+ $(PYTHON) setup.py build_ext -i
install: build
$(PYTHON) setup.py install --user; \
@@ -47,7 +51,7 @@ test-memleaks: install
# Run a specific test by name; e.g. "make test-by-name disk_" will run
# all test methods containing "disk_" in their name.
# Requires "pip install nose".
-test-by-name:
+test-by-name: install
@$(PYTHON) -m nose test/test_psutil.py --nocapture -v -m $(filter-out $@,$(MAKECMDGOALS))
# requires "pip install pep8"
diff --git a/psutil/__init__.py b/psutil/__init__.py
index c92fe4a5..73ecccc7 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -25,67 +25,67 @@ try:
except ImportError:
pwd = None
-from psutil._common import memoize
-from psutil._compat import callable, long
-from psutil._compat import PY3 as _PY3
-from psutil._common import (deprecated_method as _deprecated_method,
- deprecated as _deprecated,
- sdiskio as _nt_sys_diskio,
- snetio as _nt_sys_netio)
-
-from psutil._common import (STATUS_RUNNING, # NOQA
- STATUS_SLEEPING,
- STATUS_DISK_SLEEP,
- STATUS_STOPPED,
- STATUS_TRACING_STOP,
- STATUS_ZOMBIE,
- STATUS_DEAD,
- STATUS_WAKING,
- STATUS_LOCKED,
- STATUS_IDLE, # bsd
- STATUS_WAITING, # bsd
+from ._common import memoize
+from ._compat import callable, long
+from ._compat import PY3 as _PY3
+from ._common import (deprecated_method as _deprecated_method,
+ deprecated as _deprecated,
+ sdiskio as _nt_sys_diskio,
+ snetio as _nt_sys_netio)
+
+from ._common import (STATUS_RUNNING, # NOQA
+ STATUS_SLEEPING,
+ STATUS_DISK_SLEEP,
+ STATUS_STOPPED,
+ STATUS_TRACING_STOP,
+ STATUS_ZOMBIE,
+ STATUS_DEAD,
+ STATUS_WAKING,
+ STATUS_LOCKED,
+ STATUS_IDLE, # bsd
+ STATUS_WAITING, # bsd
)
-from psutil._common import (CONN_ESTABLISHED,
- CONN_SYN_SENT,
- CONN_SYN_RECV,
- CONN_FIN_WAIT1,
- CONN_FIN_WAIT2,
- CONN_TIME_WAIT,
- CONN_CLOSE,
- CONN_CLOSE_WAIT,
- CONN_LAST_ACK,
- CONN_LISTEN,
- CONN_CLOSING,
- CONN_NONE)
+from ._common import (CONN_ESTABLISHED,
+ CONN_SYN_SENT,
+ CONN_SYN_RECV,
+ CONN_FIN_WAIT1,
+ CONN_FIN_WAIT2,
+ CONN_TIME_WAIT,
+ CONN_CLOSE,
+ CONN_CLOSE_WAIT,
+ CONN_LAST_ACK,
+ CONN_LISTEN,
+ CONN_CLOSING,
+ CONN_NONE)
if sys.platform.startswith("linux"):
- from psutil import _pslinux as _psplatform
- from psutil._pslinux import (phymem_buffers, # NOQA
- cached_phymem)
-
- from psutil._pslinux import (IOPRIO_CLASS_NONE, # NOQA
- IOPRIO_CLASS_RT,
- IOPRIO_CLASS_BE,
- IOPRIO_CLASS_IDLE)
+ from . import _pslinux as _psplatform
+ from ._pslinux import (phymem_buffers, # NOQA
+ cached_phymem)
+
+ from ._pslinux import (IOPRIO_CLASS_NONE, # NOQA
+ IOPRIO_CLASS_RT,
+ IOPRIO_CLASS_BE,
+ IOPRIO_CLASS_IDLE)
# Linux >= 2.6.36
if _psplatform.HAS_PRLIMIT:
- from _psutil_linux import (RLIM_INFINITY, # NOQA
- RLIMIT_AS,
- RLIMIT_CORE,
- RLIMIT_CPU,
- RLIMIT_DATA,
- RLIMIT_FSIZE,
- RLIMIT_LOCKS,
- RLIMIT_MEMLOCK,
- RLIMIT_NOFILE,
- RLIMIT_NPROC,
- RLIMIT_RSS,
- RLIMIT_STACK)
+ from ._psutil_linux import (RLIM_INFINITY, # NOQA
+ RLIMIT_AS,
+ RLIMIT_CORE,
+ RLIMIT_CPU,
+ RLIMIT_DATA,
+ RLIMIT_FSIZE,
+ RLIMIT_LOCKS,
+ RLIMIT_MEMLOCK,
+ RLIMIT_NOFILE,
+ RLIMIT_NPROC,
+ RLIMIT_RSS,
+ RLIMIT_STACK)
# Kinda ugly but considerably faster than using hasattr() and
# setattr() against the module object (we are at import time:
# speed matters).
- import _psutil_linux
+ from . import _psutil_linux
try:
RLIMIT_MSGQUEUE = _psutil_linux.RLIMIT_MSGQUEUE
except AttributeError:
@@ -109,25 +109,25 @@ if sys.platform.startswith("linux"):
del _psutil_linux
elif sys.platform.startswith("win32"):
- from psutil import _pswindows as _psplatform
- from _psutil_windows import (ABOVE_NORMAL_PRIORITY_CLASS, # NOQA
- BELOW_NORMAL_PRIORITY_CLASS,
- HIGH_PRIORITY_CLASS,
- IDLE_PRIORITY_CLASS,
- NORMAL_PRIORITY_CLASS,
- REALTIME_PRIORITY_CLASS)
- from psutil._pswindows import CONN_DELETE_TCB # NOQA
+ from . import _pswindows as _psplatform
+ from ._psutil_windows import (ABOVE_NORMAL_PRIORITY_CLASS, # NOQA
+ BELOW_NORMAL_PRIORITY_CLASS,
+ HIGH_PRIORITY_CLASS,
+ IDLE_PRIORITY_CLASS,
+ NORMAL_PRIORITY_CLASS,
+ REALTIME_PRIORITY_CLASS)
+ from ._pswindows import CONN_DELETE_TCB # NOQA
elif sys.platform.startswith("darwin"):
- from psutil import _psosx as _psplatform
+ from . import _psosx as _psplatform
elif sys.platform.startswith("freebsd"):
- from psutil import _psbsd as _psplatform
+ from . import _psbsd as _psplatform
elif sys.platform.startswith("sunos"):
- from psutil import _pssunos as _psplatform
- from psutil._pssunos import (CONN_IDLE, # NOQA
- CONN_BOUND)
+ from . import _pssunos as _psplatform
+ from ._pssunos import (CONN_IDLE, # NOQA
+ CONN_BOUND)
else:
raise NotImplementedError('platform %s is not supported' % sys.platform)
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 9204d927..cf2ee64c 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -12,12 +12,12 @@ import os
import sys
from collections import namedtuple
-from psutil import _common
-from psutil import _psposix
-from psutil._common import conn_tmap, usage_percent, sockfam_to_enum
-from psutil._common import socktype_to_enum
-import _psutil_bsd as cext
-import _psutil_posix
+from . import _common
+from . import _psposix
+from . import _psutil_bsd as cext
+from . import _psutil_posix as cext_posix
+from ._common import conn_tmap, usage_percent, sockfam_to_enum
+from ._common import socktype_to_enum
__extra__all__ = []
@@ -341,11 +341,11 @@ class Process(object):
@wrap_exceptions
def nice_get(self):
- return _psutil_posix.getpriority(self.pid)
+ return cext_posix.getpriority(self.pid)
@wrap_exceptions
def nice_set(self, value):
- return _psutil_posix.setpriority(self.pid, value)
+ return cext_posix.setpriority(self.pid, value)
@wrap_exceptions
def status(self):
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 2860ee94..bfea5625 100755..100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -19,12 +19,12 @@ import sys
import warnings
from collections import namedtuple, defaultdict
-from psutil import _common
-from psutil import _psposix
-from psutil._common import isfile_strict, usage_percent, deprecated
-from psutil._compat import PY3
-import _psutil_linux as cext
-import _psutil_posix
+from . import _common
+from . import _psposix
+from . import _psutil_linux as cext
+from . import _psutil_posix as cext_posix
+from ._common import isfile_strict, usage_percent, deprecated
+from ._compat import PY3
__extra__all__ = [
@@ -941,11 +941,11 @@ class Process(object):
# return int(data.split()[18])
# Use C implementation
- return _psutil_posix.getpriority(self.pid)
+ return cext_posix.getpriority(self.pid)
@wrap_exceptions
def nice_set(self, value):
- return _psutil_posix.setpriority(self.pid, value)
+ return cext_posix.setpriority(self.pid, value)
@wrap_exceptions
def cpu_affinity_get(self):
diff --git a/psutil/_psosx.py b/psutil/_psosx.py
index 68ba4d37..1fc6779f 100644
--- a/psutil/_psosx.py
+++ b/psutil/_psosx.py
@@ -11,12 +11,12 @@ import functools
import os
from collections import namedtuple
-from psutil import _common
-from psutil import _psposix
-from psutil._common import conn_tmap, usage_percent, isfile_strict
-from psutil._common import sockfam_to_enum, socktype_to_enum
-import _psutil_osx as cext
-import _psutil_posix
+from . import _common
+from . import _psposix
+from . import _psutil_osx as cext
+from . import _psutil_posix as cext_posix
+from ._common import conn_tmap, usage_percent, isfile_strict
+from ._common import sockfam_to_enum, socktype_to_enum
__extra__all__ = []
@@ -317,11 +317,11 @@ class Process(object):
@wrap_exceptions
def nice_get(self):
- return _psutil_posix.getpriority(self.pid)
+ return cext_posix.getpriority(self.pid)
@wrap_exceptions
def nice_set(self, value):
- return _psutil_posix.setpriority(self.pid, value)
+ return cext_posix.setpriority(self.pid, value)
@wrap_exceptions
def status(self):
diff --git a/psutil/_psposix.py b/psutil/_psposix.py
index 1f7dc96e..5bb16a38 100644
--- a/psutil/_psposix.py
+++ b/psutil/_psposix.py
@@ -12,8 +12,8 @@ import os
import sys
import time
-from psutil._common import sdiskusage, usage_percent, memoize
-from psutil._compat import PY3, unicode
+from ._common import sdiskusage, usage_percent, memoize
+from ._compat import PY3, unicode
class TimeoutExpired(Exception):
diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py
index 0c404147..907e216a 100644
--- a/psutil/_pssunos.py
+++ b/psutil/_pssunos.py
@@ -13,13 +13,13 @@ import subprocess
import sys
from collections import namedtuple
-from psutil import _common
-from psutil import _psposix
-from psutil._common import isfile_strict, socktype_to_enum, sockfam_to_enum
-from psutil._common import usage_percent
-from psutil._compat import PY3
-import _psutil_posix
-import _psutil_sunos as cext
+from . import _common
+from . import _psposix
+from . import _psutil_posix as cext_posix
+from . import _psutil_sunos as cext
+from ._common import isfile_strict, socktype_to_enum, sockfam_to_enum
+from ._common import usage_percent
+from ._compat import PY3
__extra__all__ = ["CONN_IDLE", "CONN_BOUND"]
@@ -295,7 +295,7 @@ class Process(object):
# Note: tested on Solaris 11; on Open Solaris 5 everything is
# fine.
try:
- return _psutil_posix.getpriority(self.pid)
+ return cext_posix.getpriority(self.pid)
except EnvironmentError as err:
if err.errno in (errno.ENOENT, errno.ESRCH):
if pid_exists(self.pid):
@@ -310,7 +310,7 @@ class Process(object):
# The process actually exists though, as it has a name,
# creation time, etc.
raise AccessDenied(self.pid, self._name)
- return _psutil_posix.setpriority(self.pid, value)
+ return cext_posix.setpriority(self.pid, value)
@wrap_exceptions
def ppid(self):
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index a97b4e0b..f0bf17b9 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -11,11 +11,11 @@ import functools
import os
from collections import namedtuple
-from psutil import _common
-from psutil._common import conn_tmap, usage_percent, isfile_strict
-from psutil._common import sockfam_to_enum, socktype_to_enum
-from psutil._compat import PY3, xrange, lru_cache
-import _psutil_windows as cext
+from . import _common
+from . import _psutil_windows as cext
+from ._common import conn_tmap, usage_percent, isfile_strict
+from ._common import sockfam_to_enum, socktype_to_enum
+from ._compat import PY3, xrange, lru_cache
# process priority constants, import from __init__.py:
diff --git a/setup.py b/setup.py
index 87218ee0..134af957 100644
--- a/setup.py
+++ b/setup.py
@@ -47,7 +47,7 @@ VERSION_MACRO = ('PSUTIL_VERSION', int(VERSION.replace('.', '')))
# POSIX
if os.name == 'posix':
posix_extension = Extension(
- '_psutil_posix',
+ 'psutil._psutil_posix',
sources=['psutil/_psutil_posix.c'],
)
# Windows
@@ -58,7 +58,7 @@ if sys.platform.startswith("win32"):
return '0x0%s' % ((maj * 100) + min)
extensions = [Extension(
- '_psutil_windows',
+ 'psutil._psutil_windows',
sources=[
'psutil/_psutil_windows.c',
'psutil/_psutil_common.c',
@@ -86,7 +86,7 @@ if sys.platform.startswith("win32"):
# OS X
elif sys.platform.startswith("darwin"):
extensions = [Extension(
- '_psutil_osx',
+ 'psutil._psutil_osx',
sources=[
'psutil/_psutil_osx.c',
'psutil/_psutil_common.c',
@@ -102,7 +102,7 @@ elif sys.platform.startswith("darwin"):
# FreeBSD
elif sys.platform.startswith("freebsd"):
extensions = [Extension(
- '_psutil_bsd',
+ 'psutil._psutil_bsd',
sources=[
'psutil/_psutil_bsd.c',
'psutil/_psutil_common.c',
@@ -115,7 +115,7 @@ elif sys.platform.startswith("freebsd"):
# Linux
elif sys.platform.startswith("linux"):
extensions = [Extension(
- '_psutil_linux',
+ 'psutil._psutil_linux',
sources=['psutil/_psutil_linux.c'],
define_macros=[VERSION_MACRO]),
posix_extension,
@@ -123,7 +123,7 @@ elif sys.platform.startswith("linux"):
# Solaris
elif sys.platform.lower().startswith('sunos'):
extensions = [Extension(
- '_psutil_sunos',
+ 'psutil._psutil_sunos',
sources=['psutil/_psutil_sunos.c'],
define_macros=[VERSION_MACRO],
libraries=['kstat', 'nsl'],),