8
8
import os
9
9
import os .path
10
10
import sys
11
+ import logging
12
+ import tempfile
13
+ import platform
14
+ import shutil
11
15
12
16
13
17
try :
14
18
from setuptools import setup , find_packages
19
+ import distutils .command .build_scripts
15
20
except ImportError :
16
21
print ("install failed - requires setuptools" , file = sys .stderr )
17
22
sys .exit (1 )
@@ -51,6 +56,62 @@ def find_files(pattern, path=None, root="rez"):
51
56
long_description = f .read ()
52
57
53
58
59
+ SCRIPT_TEMPLATE = """#!/usr/bin/python -E
60
+ # -*- coding: utf-8 -*-
61
+ import re
62
+ import sys
63
+ from rez.cli._entry_points import {0}
64
+ if __name__ == '__main__':
65
+ sys.argv[0] = re.sub(r'(-script\\ .pyw|\\ .exe)?$', '', sys.argv[0])
66
+ sys.exit({0}())
67
+ """
68
+
69
+ class build_scripts (distutils .command .build_scripts .build_scripts ):
70
+ def finalize_options (self ):
71
+ super ().finalize_options ()
72
+ self .build_dir = os .path .join (self .build_dir , "rez" )
73
+
74
+ def run (self ):
75
+ logging .getLogger ().info ("running rez's customized build_scripts command" )
76
+
77
+ scripts = []
78
+ tmpdir = tempfile .mkdtemp ("rez-scripts" )
79
+
80
+ os .makedirs (self .build_dir )
81
+
82
+ for command in self .scripts :
83
+ spec = get_specifications ()[command ]
84
+
85
+ filename = "{0}.py" .format (command )
86
+ if platform .system () == "Windows" :
87
+ filename = "{0}-script.py" .format (command )
88
+
89
+ path = os .path .join (tmpdir , filename )
90
+ with open (path , "w" ) as fd :
91
+ fd .write (SCRIPT_TEMPLATE .format (spec ["func" ]))
92
+
93
+ scripts .append (path )
94
+
95
+ if platform .system () == "Windows" :
96
+ launcher = "t64.exe"
97
+ if spec ["type" ] == "window" :
98
+ launcher = "w64.exe"
99
+
100
+ self .copy_file (
101
+ os .path .join ("launcher" , launcher ),
102
+ os .path .join (self .build_dir , "{0}.exe" .format (command ))
103
+ )
104
+
105
+ prod_install_path = os .path .join (tmpdir , ".rez_production_install" )
106
+ with open (prod_install_path , "w" ) as fd :
107
+ fd .write ("# Production install installed with pip" )
108
+
109
+ scripts .append (prod_install_path )
110
+
111
+ self .scripts = scripts
112
+ return super ().run ()
113
+
114
+
54
115
setup (
55
116
name = "rez" ,
56
117
version = _rez_version ,
@@ -65,9 +126,7 @@ def find_files(pattern, path=None, root="rez"):
65
126
66
127
license = "Apache-2.0" ,
67
128
license_files = ["LICENSE" ],
68
- entry_points = {
69
- "console_scripts" : get_specifications ().values ()
70
- },
129
+ scripts = list (get_specifications ().keys ()),
71
130
include_package_data = True ,
72
131
zip_safe = False ,
73
132
package_dir = {'' : 'src' },
@@ -99,5 +158,6 @@ def find_files(pattern, path=None, root="rez"):
99
158
"Programming Language :: Python :: 3" ,
100
159
"Topic :: Software Development" ,
101
160
"Topic :: System :: Software Distribution"
102
- ]
161
+ ],
162
+ cmdclass = {"build_scripts" : build_scripts },
103
163
)
0 commit comments