summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-05 17:56:06 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-05 17:56:06 +0200
commit3977de2616650c1ed2c9bf392c88eb2d0dd837d4 (patch)
tree818efb750576d4d3e3380d924049fa5e4dc5aa03
parent982f255b4a14c96482ad1ce455b0f2fb0275e144 (diff)
downloadpsutil-3977de2616650c1ed2c9bf392c88eb2d0dd837d4.tar.gz
make.bat: add -p opt
-rw-r--r--DEVGUIDE.rst22
-rw-r--r--make.bat2
-rw-r--r--psutil/_common.py8
-rwxr-xr-xscripts/internal/winmake.py35
-rwxr-xr-xsetup.py17
5 files changed, 68 insertions, 16 deletions
diff --git a/DEVGUIDE.rst b/DEVGUIDE.rst
index af34ee12..c00a3d5c 100644
--- a/DEVGUIDE.rst
+++ b/DEVGUIDE.rst
@@ -46,6 +46,28 @@ Some useful make commands::
$ make coverage # run test coverage
$ make flake8 # run PEP8 linter
+There are some differences between ``make`` on UNIX and Windows.
+For instance, to run a specific Python version. On UNIX::
+
+ make test PYTHON=python3.5
+
+On Windows:
+
+ set PYTHON=C:\python35\python.exe && make test
+
+ # ...or
+
+ make -p 35 test
+
+If you want to modify psutil and run a script on the fly which uses it do
+(on UNIX)::
+
+ make test TSCRIPT=foo.py
+
+On Windows:
+
+ set TSCRIPT=foo.py && make test
+
====================
Adding a new feature
====================
diff --git a/make.bat b/make.bat
index 98456457..cdabe3a6 100644
--- a/make.bat
+++ b/make.bat
@@ -29,4 +29,4 @@ if "%TSCRIPT%" == "" (
rem Needed to locate the .pypirc file and upload exes on PYPI.
set HOME=%USERPROFILE%
-%PYTHON% scripts\internal\winmake.py %1 %2
+%PYTHON% scripts\internal\winmake.py %1 %2 %3 %4 %5 %6
diff --git a/psutil/_common.py b/psutil/_common.py
index e6ba9dc3..38ffdc09 100644
--- a/psutil/_common.py
+++ b/psutil/_common.py
@@ -4,6 +4,9 @@
"""Common objects shared by __init__.py and _ps*.py modules."""
+# Note: this module is imported by setup.py so it should not import
+# psutil or third-party modules.
+
from __future__ import division
import contextlib
@@ -27,13 +30,14 @@ try:
except ImportError:
AF_UNIX = None
-from psutil._compat import PY3
-
if sys.version_info >= (3, 4):
import enum
else:
enum = None
+# can't take it from _common.py as this script is imported by setup.py
+PY3 = sys.version_info[0] == 3
+
__all__ = [
# OS constants
'FREEBSD', 'BSD', 'LINUX', 'NETBSD', 'OPENBSD', 'OSX', 'POSIX', 'SUNOS',
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index b8d111a4..05eae8a6 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -180,10 +180,11 @@ def recursive_rm(*patterns):
@cmd
def help():
"""Print this help"""
- safe_print('Run "make <target>" where <target> is one of:')
+ safe_print('Run "make [-p <PYTHON>] <target>" where <target> is one of:')
for name in sorted(_cmds):
safe_print(
" %-20s %s" % (name.replace('_', '-'), _cmds[name] or ''))
+ sys.exit(1)
@cmd
@@ -440,12 +441,42 @@ def bench_oneshot_2():
sh("%s scripts\\internal\\bench_oneshot_2.py" % PYTHON)
+def set_python(s):
+ global PYTHON
+ if os.path.isabs(s):
+ PYTHON = s
+ else:
+ # try to look for a python installation
+ orig = s
+ s = s.replace('.', '')
+ for v in ('26', '27', '33', '34', '35', '36', '37'):
+ if s == v:
+ path = 'C:\\python%s\python.exe' % s
+ if os.path.isfile(path):
+ print(path)
+ PYTHON = path
+ return
+ return sys.exit(
+ "can't find any python installation matching %r" % orig)
+
+
+def parse_cmdline():
+ if '-p' in sys.argv:
+ try:
+ pos = sys.argv.index('-p')
+ sys.argv.pop(pos)
+ py = sys.argv.pop(pos)
+ except IndexError:
+ return help()
+ set_python(py)
+
+
def main():
+ parse_cmdline()
try:
cmd = sys.argv[1].replace('-', '_')
except IndexError:
return help()
-
if cmd in _cmds:
fun = getattr(sys.modules[__name__], cmd)
fun()
diff --git a/setup.py b/setup.py
index d4fc4591..c4f3bcbc 100755
--- a/setup.py
+++ b/setup.py
@@ -22,6 +22,8 @@ except ImportError:
from distutils.core import setup, Extension
HERE = os.path.abspath(os.path.dirname(__file__))
+
+# ...so we can import _common.py
sys.path.insert(0, os.path.join(HERE, "psutil"))
from _common import BSD # NOQA
@@ -61,6 +63,10 @@ def get_version():
raise ValueError("couldn't find version string")
+VERSION = get_version()
+macros.append(('PSUTIL_VERSION', int(VERSION.replace('.', ''))))
+
+
def get_description():
README = os.path.join(HERE, 'README.rst')
with open(README, 'r') as f:
@@ -84,10 +90,6 @@ def silenced_output(stream_name):
setattr(sys, stream_name, orig)
-VERSION = get_version()
-macros.append(('PSUTIL_VERSION', int(VERSION.replace('.', ''))))
-
-# Windows
if WINDOWS:
def get_winver():
maj, min = sys.getwindowsversion()[0:2]
@@ -130,7 +132,6 @@ if WINDOWS:
# extra_link_args=["/DEBUG"]
)
-# OS X
elif OSX:
macros.append(("PSUTIL_OSX", 1))
ext = Extension(
@@ -144,7 +145,6 @@ elif OSX:
'-framework', 'CoreFoundation', '-framework', 'IOKit'
])
-# FreeBSD
elif FREEBSD:
macros.append(("PSUTIL_FREEBSD", 1))
ext = Extension(
@@ -157,7 +157,6 @@ elif FREEBSD:
define_macros=macros,
libraries=["devstat"])
-# OpenBSD
elif OPENBSD:
macros.append(("PSUTIL_OPENBSD", 1))
ext = Extension(
@@ -169,7 +168,6 @@ elif OPENBSD:
define_macros=macros,
libraries=["kvm"])
-# NetBSD
elif NETBSD:
macros.append(("PSUTIL_NETBSD", 1))
ext = Extension(
@@ -182,7 +180,6 @@ elif NETBSD:
define_macros=macros,
libraries=["kvm"])
-# Linux
elif LINUX:
def get_ethtool_macro():
# see: https://github.com/giampaolo/psutil/issues/659
@@ -218,7 +215,6 @@ elif LINUX:
sources=sources + ['psutil/_psutil_linux.c'],
define_macros=macros)
-# Solaris
elif SUNOS:
macros.append(("PSUTIL_SUNOS", 1))
ext = Extension(
@@ -230,7 +226,6 @@ elif SUNOS:
else:
sys.exit('platform %s is not supported' % sys.platform)
-# POSIX
if POSIX:
posix_extension = Extension(
'psutil._psutil_posix',