4
4
from wheel .bdist_wheel import bdist_wheel
5
5
from setuptools .command .build_ext import build_ext
6
6
import distutils
7
+ from distutils .command import build
7
8
from subprocess import check_output , check_call
8
9
9
10
import sys , os
@@ -26,6 +27,8 @@ def _get_interop_filename():
26
27
return os .path .join ("src" , "runtime" , interop_filename )
27
28
28
29
30
+ # Write configuration to configured.props. This will go away once all of these
31
+ # can be decided at runtime.
29
32
def _write_configure_props ():
30
33
defines = [
31
34
"PYTHON{0}{1}" .format (PY_MAJOR , PY_MINOR ),
@@ -60,7 +63,7 @@ def _write_configure_props():
60
63
ET .ElementTree (proj ).write (CONFIGURED_PROPS )
61
64
62
65
63
- class Configure (Command ):
66
+ class configure (Command ):
64
67
"""Configure command"""
65
68
66
69
description = "Configure the pythonnet build"
@@ -77,36 +80,34 @@ def run(self):
77
80
_write_configure_props ()
78
81
79
82
80
- class DotnetLib ( Extension ) :
83
+ class DotnetLib :
81
84
def __init__ (self , name , path , ** kwargs ):
85
+ self .name = name
82
86
self .path = path
83
87
self .args = kwargs
84
- super ().__init__ (name , sources = [])
85
88
86
89
87
- class BuildDotnet ( build_ext ):
90
+ class build_dotnet ( Command ):
88
91
"""Build command for dotnet-cli based builds"""
89
92
90
93
description = "Build DLLs with dotnet-cli"
91
94
user_options = [("dotnet-config" , None , "dotnet build configuration" )]
92
95
93
96
def initialize_options (self ):
94
- self .dotnet_config = "release"
95
- super (). initialize_options ()
97
+ self .dotnet_config = None
98
+ self . build_lib = None
96
99
97
100
def finalize_options (self ):
98
- super ().finalize_options ()
99
-
100
- def get_source_files (self ):
101
- return super ().get_source_files ()
101
+ if self .dotnet_config is None :
102
+ self .dotnet_config = "release"
103
+
104
+ build = self .distribution .get_command_obj ("build" )
105
+ build .ensure_finalized ()
106
+ self .build_lib = build .build_lib
102
107
103
108
def run (self ):
104
- orig_modules = self .distribution .ext_modules
105
- dotnet_modules = [lib for lib in orig_modules if isinstance (lib , DotnetLib )]
106
- other_modules = [lib for lib in orig_modules if not isinstance (lib , DotnetLib )]
107
-
108
- if dotnet_modules :
109
- self .run_command ("configure" )
109
+ dotnet_modules = self .distribution .dotnet_libs
110
+ self .run_command ("configure" )
110
111
111
112
for lib in dotnet_modules :
112
113
output = os .path .join (os .path .abspath (self .build_lib ), lib .args .pop ("output" ))
@@ -140,18 +141,21 @@ def run(self):
140
141
else :
141
142
self .warn ("Can't find file to rename: {}, current dir: {}" .format (source , os .getcwd ()))
142
143
143
- if other_modules :
144
- self .distribution .ext_modules = other_modules
145
- super ().run ()
146
- self .distribution .ext_modules = orig_modules
147
- # If no modules need to be compiled, skip
144
+ # Add build_dotnet to the build tasks:
145
+ from distutils .command .build import build as _build
146
+ from setuptools import Distribution
147
+
148
+ class build (_build ):
149
+ sub_commands = _build .sub_commands + [('build_dotnet' , None )]
150
+
151
+ Distribution .dotnet_libs = None
148
152
149
153
150
154
with open ("README.rst" , "r" ) as f :
151
155
long_description = f .read ()
152
156
153
157
154
- ext_modules = [
158
+ dotnet_libs = [
155
159
DotnetLib (
156
160
"python-runtime" ,
157
161
"src/runtime/Python.Runtime.csproj" ,
@@ -173,6 +177,8 @@ def run(self):
173
177
),
174
178
]
175
179
180
+ ext_modules = []
181
+
176
182
try :
177
183
mono_libs = check_output ("pkg-config --libs mono-2" , shell = True , encoding = "utf8" )
178
184
mono_cflags = check_output (
@@ -194,7 +200,14 @@ def run(self):
194
200
print ("Failed to find mono libraries via pkg-config, skipping the Mono CLR loader" )
195
201
196
202
203
+
197
204
setup (
205
+ cmdclass = {
206
+ "build" : build ,
207
+ "build_dotnet" : build_dotnet ,
208
+ "configure" : configure ,
209
+ },
210
+
198
211
name = "pythonnet" ,
199
212
version = "3.0.0.dev1" ,
200
213
description = ".Net and Mono integration for Python" ,
@@ -207,12 +220,10 @@ def run(self):
207
220
install_requires = ["pycparser" ],
208
221
long_description = long_description ,
209
222
# data_files=[("{install_platlib}", ["{build_lib}/pythonnet"])],
210
- cmdclass = {
211
- "build_ext" : BuildDotnet ,
212
- "configure" : Configure ,
213
- },
223
+
214
224
py_modules = ["clr" ],
215
225
ext_modules = ext_modules ,
226
+ dotnet_libs = dotnet_libs ,
216
227
classifiers = [
217
228
"Development Status :: 5 - Production/Stable" ,
218
229
"Intended Audience :: Developers" ,
0 commit comments