File: setup.py

package info (click to toggle)
pympler 0.9%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,172 kB
  • sloc: python: 9,943; javascript: 2,775; makefile: 21
file content (142 lines) | stat: -rw-r--r-- 4,484 bytes parent folder | download
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
"""Setup script for Pympler.

To build, install and test Pympler and to try Pympler
before building and installing it.

The HTML documentation is in the doc/ directory.  Point
your browser to the ./doc/html/index.html file.

"""
import sys
import pympler.metadata as metadata


def _not_supported(why):
    print('NotImplementedError: ' + why + '.')
    if 'try' in sys.argv:
        print(metadata.long_description)
    sys.exit(1)


if sys.hexversion < 0x2070000:
    _not_supported('Pympler requires Python 2.7 or newer')

import os
from distutils.command.install_lib import install_lib
from distutils.core import Command
from distutils.core import setup
from distutils.dist import Distribution
from distutils.errors import DistutilsExecError
from distutils.spawn import spawn  # raises DistutilsExecError

from shutil import rmtree


# Remove all already installed modules. Make sure old removed or renamed
# modules cannot be imported anymore.
class InstallCommand(install_lib):
    def run(self):
        target_path = os.path.join(self.install_dir, 'pympler')
        try:
            rmtree(target_path)
            print ("purging %s" % target_path)
        except OSError:
            pass
        install_lib.run(self)


class BaseTestCommand(Command):
    """Base class for the pre and the post installation commands. """
    user_options = []

    def initialize_options(self):
        self.param = None

    def finalize_options(self):
        pass

    def run(self):
        args = [sys.executable,  # this Python binary
                os.path.join('test', 'runtest.py'),
                self.param, '-verbose', '3']
        args.extend(sys.argv[2:])
        try:
            sys.exit(spawn(args))
        except DistutilsExecError:
            sys.exit(1)


class PreinstallTestCommand(BaseTestCommand):
    description = "run pre-installation tests"

    def initialize_options(self):
        self.param = '-pre-install'


class PostinstallTestCommand(BaseTestCommand):
    description = "run post-installation tests"

    def initialize_options(self):
        self.param = '-post-install'


def run_setup(include_tests=0):
    tests = []
    if include_tests:
        tests = ['test', 'test.asizeof', 'test.tracker', 'test.muppy',
                 'test.gui']

    setup(name=metadata.project_name,
          description=metadata.description,
          long_description=metadata.long_description,

          author=metadata.author,
          author_email=metadata.author_email,
          url=metadata.url,
          version=metadata.version,

          packages=['pympler', 'pympler.util'] + tests,

          package_data={'pympler': ['templates/*.html',
                                    'templates/*.tpl',
                                    'templates/*.js',
                                    'templates/*.css',
                                    'static/*.js']},

          license=metadata.license,
          platforms=['any'],
          classifiers=['Development Status :: 4 - Beta',
                       'Environment :: Console',
                       'Intended Audience :: Developers',
                       'License :: OSI Approved :: Apache Software License',
                       'Operating System :: OS Independent',
                       '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 :: 3.8',
                       'Programming Language :: Python :: 3.9',
                       'Topic :: Software Development :: Bug Tracking',
                       ],
          cmdclass={'try': PreinstallTestCommand,
                    'test': PostinstallTestCommand,
                    'install_lib': InstallCommand,
                    }
          )


try:  # hack Pympler commands into setup.py help output
    Distribution.common_usage += """
Pympler commands
  setup.py try     try Pympler before installation
  setup.py test    test Pympler after installation
"""
except AttributeError:
    pass

# Only include tests if creating a distribution package
# (i.e. do not install the tests).
run_setup('sdist' in sys.argv)