setup.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/usr/bin/env python
  2. # Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """psutil is a cross-platform library for retrieving information on
  6. running processes and system utilization (CPU, memory, disks, network)
  7. in Python.
  8. """
  9. import os
  10. import sys
  11. try:
  12. from setuptools import setup, Extension
  13. except ImportError:
  14. from distutils.core import setup, Extension
  15. HERE = os.path.abspath(os.path.dirname(__file__))
  16. def get_version():
  17. INIT = os.path.join(HERE, 'psutil/__init__.py')
  18. with open(INIT, 'r') as f:
  19. for line in f:
  20. if line.startswith('__version__'):
  21. ret = eval(line.strip().split(' = ')[1])
  22. assert ret.count('.') == 2, ret
  23. for num in ret.split('.'):
  24. assert num.isdigit(), ret
  25. return ret
  26. else:
  27. raise ValueError("couldn't find version string")
  28. def get_description():
  29. README = os.path.join(HERE, 'README.rst')
  30. with open(README, 'r') as f:
  31. return f.read()
  32. VERSION = get_version()
  33. VERSION_MACRO = ('PSUTIL_VERSION', int(VERSION.replace('.', '')))
  34. # POSIX
  35. if os.name == 'posix':
  36. libraries = []
  37. if sys.platform.startswith("sunos"):
  38. libraries.append('socket')
  39. posix_extension = Extension(
  40. 'psutil._psutil_posix',
  41. sources=['psutil/_psutil_posix.c'],
  42. libraries=libraries,
  43. )
  44. # Windows
  45. if sys.platform.startswith("win32"):
  46. def get_winver():
  47. maj, min = sys.getwindowsversion()[0:2]
  48. return '0x0%s' % ((maj * 100) + min)
  49. extensions = [Extension(
  50. 'psutil._psutil_windows',
  51. sources=[
  52. 'psutil/_psutil_windows.c',
  53. 'psutil/_psutil_common.c',
  54. 'psutil/arch/windows/process_info.c',
  55. 'psutil/arch/windows/process_handles.c',
  56. 'psutil/arch/windows/security.c',
  57. 'psutil/arch/windows/inet_ntop.c',
  58. ],
  59. define_macros=[
  60. VERSION_MACRO,
  61. # be nice to mingw, see:
  62. # http://www.mingw.org/wiki/Use_more_recent_defined_functions
  63. ('_WIN32_WINNT', get_winver()),
  64. ('_AVAIL_WINVER_', get_winver()),
  65. ('_CRT_SECURE_NO_WARNINGS', None),
  66. # see: https://github.com/giampaolo/psutil/issues/348
  67. ('PSAPI_VERSION', 1),
  68. ],
  69. libraries=[
  70. "psapi", "kernel32", "advapi32", "shell32", "netapi32", "iphlpapi",
  71. "wtsapi32", "ws2_32",
  72. ],
  73. # extra_compile_args=["/Z7"],
  74. # extra_link_args=["/DEBUG"]
  75. )]
  76. # OS X
  77. elif sys.platform.startswith("darwin"):
  78. extensions = [Extension(
  79. 'psutil._psutil_osx',
  80. sources=[
  81. 'psutil/_psutil_osx.c',
  82. 'psutil/_psutil_common.c',
  83. 'psutil/arch/osx/process_info.c'
  84. ],
  85. define_macros=[VERSION_MACRO],
  86. extra_link_args=[
  87. '-framework', 'CoreFoundation', '-framework', 'IOKit'
  88. ],
  89. ),
  90. posix_extension,
  91. ]
  92. # FreeBSD
  93. elif sys.platform.startswith("freebsd"):
  94. extensions = [Extension(
  95. 'psutil._psutil_bsd',
  96. sources=[
  97. 'psutil/_psutil_bsd.c',
  98. 'psutil/_psutil_common.c',
  99. 'psutil/arch/bsd/process_info.c'
  100. ],
  101. define_macros=[VERSION_MACRO],
  102. libraries=["devstat"]),
  103. posix_extension,
  104. ]
  105. # Linux
  106. elif sys.platform.startswith("linux"):
  107. extensions = [Extension(
  108. 'psutil._psutil_linux',
  109. sources=['psutil/_psutil_linux.c'],
  110. define_macros=[VERSION_MACRO]),
  111. posix_extension,
  112. ]
  113. # Solaris
  114. elif sys.platform.lower().startswith('sunos'):
  115. extensions = [Extension(
  116. 'psutil._psutil_sunos',
  117. sources=['psutil/_psutil_sunos.c'],
  118. define_macros=[VERSION_MACRO],
  119. libraries=['kstat', 'nsl', 'socket']),
  120. posix_extension,
  121. ]
  122. else:
  123. sys.exit('platform %s is not supported' % sys.platform)
  124. def main():
  125. setup_args = dict(
  126. name='psutil',
  127. version=VERSION,
  128. description=__doc__.replace('\n', '').strip(),
  129. long_description=get_description(),
  130. keywords=[
  131. 'ps', 'top', 'kill', 'free', 'lsof', 'netstat', 'nice', 'tty',
  132. 'ionice', 'uptime', 'taskmgr', 'process', 'df', 'iotop', 'iostat',
  133. 'ifconfig', 'taskset', 'who', 'pidof', 'pmap', 'smem', 'pstree',
  134. 'monitoring', 'ulimit', 'prlimit',
  135. ],
  136. author='Giampaolo Rodola',
  137. author_email='g.rodola <at> gmail <dot> com',
  138. url='https://github.com/giampaolo/psutil',
  139. platforms='Platform Independent',
  140. license='BSD',
  141. packages=['psutil'],
  142. # see: python setup.py register --list-classifiers
  143. classifiers=[
  144. 'Development Status :: 5 - Production/Stable',
  145. 'Environment :: Console',
  146. 'Environment :: Win32 (MS Windows)',
  147. 'Intended Audience :: Developers',
  148. 'Intended Audience :: Information Technology',
  149. 'Intended Audience :: System Administrators',
  150. 'License :: OSI Approved :: BSD License',
  151. 'Operating System :: MacOS :: MacOS X',
  152. 'Operating System :: Microsoft :: Windows :: Windows NT/2000',
  153. 'Operating System :: Microsoft',
  154. 'Operating System :: OS Independent',
  155. 'Operating System :: POSIX :: BSD :: FreeBSD',
  156. 'Operating System :: POSIX :: Linux',
  157. 'Operating System :: POSIX :: SunOS/Solaris',
  158. 'Operating System :: POSIX',
  159. 'Programming Language :: C',
  160. 'Programming Language :: Python :: 2',
  161. 'Programming Language :: Python :: 2.6',
  162. 'Programming Language :: Python :: 2.7',
  163. 'Programming Language :: Python :: 3',
  164. 'Programming Language :: Python :: 3.0',
  165. 'Programming Language :: Python :: 3.1',
  166. 'Programming Language :: Python :: 3.2',
  167. 'Programming Language :: Python :: 3.3',
  168. 'Programming Language :: Python :: 3.4',
  169. 'Programming Language :: Python :: Implementation :: CPython',
  170. 'Programming Language :: Python :: Implementation :: PyPy',
  171. 'Programming Language :: Python',
  172. 'Topic :: Software Development :: Libraries :: Python Modules',
  173. 'Topic :: Software Development :: Libraries',
  174. 'Topic :: System :: Benchmark',
  175. 'Topic :: System :: Hardware',
  176. 'Topic :: System :: Monitoring',
  177. 'Topic :: System :: Networking :: Monitoring',
  178. 'Topic :: System :: Networking',
  179. 'Topic :: System :: Systems Administration',
  180. 'Topic :: Utilities',
  181. ],
  182. )
  183. if extensions is not None:
  184. setup_args["ext_modules"] = extensions
  185. setup(**setup_args)
  186. if __name__ == '__main__':
  187. main()