File: setup.py

package info (click to toggle)
deken 0.10.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 668 kB
  • sloc: tcl: 2,945; python: 422; sh: 417; makefile: 33
file content (207 lines) | stat: -rwxr-xr-x 6,079 bytes parent folder | download | duplicates (3)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
from setuptools import setup


def check_pyversions(versions):
    """checks if the python-version is within the list of versions

    to check is we are running py2 or py3:
        check_pyversions(((2,), (3,)))

    to check if we are running either py2 or py3.4.2 (but no other py3 version)
        check_pyversions(((2,), (3,4,2)))
    """
    for v in versions:
        if all([x == y for x, y in zip(v, sys.version_info)]):
            return True
    return False


# ModuleFinder can't handle runtime changes to __path__, but win32com uses them
try:
    # py2exe 0.6.4 introduced a replacement modulefinder.
    # This means we have to add package paths there, not to the built-in
    # one.  If this new modulefinder gets integrated into Python, then
    # we might be able to revert this some day.
    # if this doesn't work, try import modulefinder
    try:
        import py2exe.mf as modulefinder
    except ImportError:
        import modulefinder
    import win32com

    for p in win32com.__path__[1:]:
        modulefinder.AddPackagePath("win32com", p)
    for extra in ["win32com.shell"]:  # ,"win32com.mapi"
        __import__(extra)
        m = sys.modules[extra]
        for p in m.__path__[1:]:
            modulefinder.AddPackagePath(extra, p)
    import py2exe
except ImportError:
    # no build path setup, no worries.
    pass


# This is a list of files to install, and where
# (relative to the 'root' dir, where setup.py is)
# You could be more specific.
files = [
    "pydeken.py",
]
data_files = [
    "deken.hy",
]
setup_requires = []
dist_dir = ""
dist_file = None

options = {}
setupargs = {
    "name": "deken",
    "version": "0.2.4",
    "description": """Pure Data externals wrangler""",
    "author": "Chris McCormick, IOhannes m zmölnig et al.",
    "author_email": "pd-list@lists.puredata.info",
    "url": "https://git.iem.at/pure-data/deken",
    # Name the folder where your packages live:
    # (If you have other packages (dirs) or modules (py files) then
    # put them into the package directory - they will be found
    # recursively.)
    # 'packages': ['deken', ],
    # This dict maps the package name =to=> directories
    # It says, package *needs* these files.
    "package_data": {"deken": files},
    "data_files": data_files,
    "install_requires": [
        # 'PySide',
    ],
    "scripts": ["deken", "pydeken.py"],
    "long_description": """
a tool to create and upload dek packages to puredata.info,
so they can be installed by Pd's built-in package manager
""",
    #
    # https://pypi.python.org/pypi?%3Aaction=list_classifiers
    "classifiers": [
        "Development Status :: 3 - Alpha",
        "Environment :: Console",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: BSD 3 clause",
        "Natural Language :: English",
        # "Topic :: Internet :: WWW/HTTP :: Site Management",
    ],
    "options": options,
    "setup_requires": setup_requires,
}

if "py2exe" in sys.argv:
    dist_dir = "%s-%s" % (setupargs["name"], setupargs["version"])
    dist_file = "%s.exe-%s.zip" % (setupargs["name"], setupargs["version"])
    setup_requires += [
        "py2exe",
    ]

    def getMSVCfiles():
        # urgh, find the msvcrt redistributable DLLs
        # either it's in the MSVC90 application folder
        # or in some winsxs folder
        from glob import glob

        program_path = os.path.expandvars("%ProgramFiles%")
        winsxs_path = os.path.expandvars("%SystemRoot%\WinSXS")
        msvcrt_paths = [
            (
                r"%s\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT"
                % program_path
            )
        ]

        if check_pyversions(((2, 7),)):
            # python2.7 seems to be built against VC90 (9.0.21022),
            # so let's try that
            msvcrt_paths += glob(
                r"%s\x86_microsoft.vc90.crt_*_9.0.21022.8_*_*" "\\" % winsxs_path
            )
            for p in msvcrt_paths:
                if os.path.exists(os.path.join(p, "msvcp90.dll")):
                    sys.path.append(p)
                    f = glob(r"%s\*.*" % p)
                    if f:
                        return [("Microsoft.VC90.CRT", f)]
                    return None

        return None

    def getRequestsCerts():
        import requests.certs

        f = requests.certs.where()
        if f:
            return [(".", [f])]

    data_files += getMSVCfiles() or []
    data_files += getRequestsCerts() or []
    print(data_files)

    setupargs["windows"] = [
        {
            # 'icon_resources': [(1, "media\deken.ico")],
            "script": "pydeken.py",
        }
    ]
    setupargs["zipfile"] = None

    options["py2exe"] = {
        "includes": [
            "deken.hy",
        ],
        "packages": [
            "requests",
        ],
        "bundle_files": 3,
        "dist_dir": os.path.join("dist", dist_dir),
    }

if "py2app" in sys.argv:
    dist_dir = "%s.app" % (setupargs["name"],)
    dist_file = "%s.app-%s.zip" % (setupargs["name"], setupargs["version"])
    setup_requires += [
        "py2app",
    ]
    setupargs["app"] = [
        "pydeken.py",
    ]
    options["py2app"] = {
        "packages": [
            "requests",
        ],
    }

if dist_dir:
    try:
        os.makedirs(os.path.join("dist", dist_dir))
    except FileExistsError:
        pass

setup(**setupargs)

if dist_dir and dist_file:
    import zipfile

    def zipdir(path, ziph):
        # ziph is zipfile handle
        for root, dirs, files in os.walk(path):
            for f in files:
                fullname = os.path.join(root, f)
                archname = os.path.relpath(fullname, os.path.join(path, ".."))
                if ziph:
                    ziph.write(fullname, archname)
                else:
                    print("%s -> %s" % (fullname, archname))

    with zipfile.ZipFile(dist_file, "w", compression=zipfile.ZIP_DEFLATED) as myzip:
        zipdir(os.path.join("dist", dist_dir), myzip)