File: setup.py

package info (click to toggle)
python-ethtool 0.14-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 324 kB
  • sloc: ansic: 1,770; python: 1,509; makefile: 24; sh: 16
file content (154 lines) | stat: -rw-r--r-- 4,769 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import print_function

from setuptools import setup, Extension
import sys
from io import open

try:
    import commands
except ImportError:
    import subprocess as commands

version = '0.14'


class PkgConfigExtension(Extension):
    '''Extension with lazy properties taken from pkg-config'''

    def __init__(self, *args, **kwargs):
        '''Behaves like Extension's __init__ but you should not use
        include_dirs, library_dirs and libraries arguments.

        Extra arguments:
          pkg : string
            The name of the pkg-config package to use for querying
          extra_libraris : [string]
            This will be added to the libraries attribute. Optional.
        '''
        self._pkg = kwargs['pkg']
        del kwargs['pkg']
        if 'extra_libraries' in kwargs:
            self._extra_libraries = kwargs['extra_libraries']
            del kwargs['extra_libraries']
        else:
            self._extra_libraries = []

        Extension.__init__(self, *args, **kwargs)

        try:
            # on Python 2 we need to delete those now
            del self.include_dirs
            del self.library_dirs
            del self.libraries
        except AttributeError:
            # on Python 3, that's not needed or possible
            pass

    @classmethod
    def _str2list(cls, pkgstr, onlystr):
        res = []
        for l in pkgstr.split(" "):
            if l.find(onlystr) == 0:
                res.append(l.replace(onlystr, "", 1))
        return res

    @classmethod
    def _run(cls, command_string):
        res, output = commands.getstatusoutput(command_string)
        if res != 0:
            print('Failed to query %s' % command_string)
            sys.exit(1)
        return output

    @property
    def include_dirs(self):
        includes = self._run('pkg-config --cflags-only-I %s' % self._pkg)
        return self._str2list(includes, '-I')

    @property
    def library_dirs(self):
        libdirs = self._run('pkg-config --libs-only-L %s' % self._pkg)
        return self._str2list(libdirs, '-L')

    @property
    def libraries(self):
        libs = self._run('pkg-config --libs-only-l %s' % self._pkg)
        return self._str2list(libs, '-l') + self._extra_libraries

    @include_dirs.setter
    def include_dirs(self, value):
        pass

    @library_dirs.setter
    def library_dirs(self, value):
        pass

    @libraries.setter
    def libraries(self, value):
        pass


with open('README.rst', encoding='utf-8') as f:
    long_description = f.read()

with open('CHANGES.rst', encoding='utf-8') as f:
    long_description += '\n\n'
    long_description += f.read()

setup(name='ethtool',
      version=version,
      description='Python module to interface with ethtool',
      long_description=long_description,

      author='Harald Hoyer, Arnaldo Carvalho de Melo, David Sommerseth',
      author_email='davids@redhat.com',

      maintainer='Lumír Balhar, Miro Hrončok, Charalampos Stratakis, Sanqui',
      maintainer_email='python-maint@redhat.com',

      url='https://github.com/fedora-python/python-ethtool',
      license='GPL-2.0',
      keywords='network networking ethernet tool ethtool',

      classifiers=[
          'Development Status :: 7 - Inactive',
          'Intended Audience :: Developers',
          'Intended Audience :: System Administrators',
          'Operating System :: POSIX :: Linux',
          'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
          'Programming Language :: Python',
          'Programming Language :: Python :: 2',
          'Programming Language :: Python :: 2.7',
          'Programming Language :: Python :: 3',
          'Programming Language :: Python :: 3.5',
          'Programming Language :: Python :: 3.6',
          'Programming Language :: Python :: 3.7',
          'Programming Language :: Python :: Implementation :: CPython',
          'Topic :: Software Development :: Libraries',
          'Topic :: System :: Networking',
      ],
      
      scripts=[
        'scripts/pethtool', 'scripts/pifconfig'
      ],
      
      ext_modules=[
          PkgConfigExtension(
              'ethtool',
              sources=[
                  'python-ethtool/ethtool.c',
                  'python-ethtool/etherinfo.c',
                  'python-ethtool/etherinfo_obj.c',
                  'python-ethtool/netlink.c',
                  'python-ethtool/netlink-address.c'],
              extra_compile_args=[
                  '-fno-strict-aliasing', '-Wno-unused-function'],
              define_macros=[('VERSION', '"%s"' % version)],
              pkg='libnl-3.0',
              extra_libraries=['nl-route-3'],
          )
      ]
      )