1
1
#!/usr/bin/env python
2
2
3
3
from setuptools import setup , Command , Extension
4
- from wheel .bdist_wheel import bdist_wheel
5
4
from setuptools .command .build_ext import build_ext
6
5
import distutils
7
6
from distutils .command import build
8
7
from subprocess import check_output , check_call
9
8
10
9
import sys , os
11
10
11
+ BUILD_MONO = True
12
+ BUILD_NETFX = True
13
+
12
14
PY_MAJOR = sys .version_info [0 ]
13
15
PY_MINOR = sys .version_info [1 ]
14
16
@@ -91,26 +93,40 @@ class build_dotnet(Command):
91
93
"""Build command for dotnet-cli based builds"""
92
94
93
95
description = "Build DLLs with dotnet-cli"
94
- user_options = [("dotnet-config" , None , "dotnet build configuration" )]
96
+ user_options = [
97
+ ("dotnet-config" , None , "dotnet build configuration" ),
98
+ (
99
+ "inplace" ,
100
+ "i" ,
101
+ "ignore build-lib and put compiled extensions into the source "
102
+ + "directory alongside your pure Python modules" ,
103
+ ),
104
+ ]
95
105
96
106
def initialize_options (self ):
97
107
self .dotnet_config = None
98
108
self .build_lib = None
109
+ self .inplace = False
99
110
100
111
def finalize_options (self ):
101
112
if self .dotnet_config is None :
102
113
self .dotnet_config = "release"
103
-
114
+
104
115
build = self .distribution .get_command_obj ("build" )
105
116
build .ensure_finalized ()
106
- self .build_lib = build .build_lib
117
+ if self .inplace :
118
+ self .build_lib = "."
119
+ else :
120
+ self .build_lib = build .build_lib
107
121
108
122
def run (self ):
109
123
dotnet_modules = self .distribution .dotnet_libs
110
124
self .run_command ("configure" )
111
125
112
126
for lib in dotnet_modules :
113
- output = os .path .join (os .path .abspath (self .build_lib ), lib .args .pop ("output" ))
127
+ output = os .path .join (
128
+ os .path .abspath (self .build_lib ), lib .args .pop ("output" )
129
+ )
114
130
rename = lib .args .pop ("rename" , {})
115
131
116
132
opts = sum (
@@ -139,75 +155,105 @@ def run(self):
139
155
140
156
self .move_file (src = source , dst = dest , level = distutils .log .INFO )
141
157
else :
142
- self .warn ("Can't find file to rename: {}, current dir: {}" .format (source , os .getcwd ()))
158
+ self .warn (
159
+ "Can't find file to rename: {}, current dir: {}" .format (
160
+ source , os .getcwd ()
161
+ )
162
+ )
163
+
143
164
144
165
# Add build_dotnet to the build tasks:
145
166
from distutils .command .build import build as _build
167
+ from setuptools .command .develop import develop as _develop
146
168
from setuptools import Distribution
169
+ import setuptools
170
+
147
171
148
172
class build (_build ):
149
- sub_commands = _build .sub_commands + [(' build_dotnet' , None )]
173
+ sub_commands = _build .sub_commands + [(" build_dotnet" , None )]
150
174
175
+
176
+ class develop (_develop ):
177
+ def install_for_development (self ):
178
+ # Build extensions in-place
179
+ self .reinitialize_command ("build_dotnet" , inplace = 1 )
180
+ self .run_command ("build_dotnet" )
181
+
182
+ return super ().install_for_development ()
183
+
184
+
185
+ # Monkey-patch Distribution s.t. it supports the dotnet_libs attribute
151
186
Distribution .dotnet_libs = None
152
187
188
+ cmdclass = {
189
+ "build" : build ,
190
+ "build_dotnet" : build_dotnet ,
191
+ "configure" : configure ,
192
+ "develop" : develop ,
193
+ }
194
+
153
195
154
196
with open ("README.rst" , "r" ) as f :
155
197
long_description = f .read ()
156
198
157
-
158
199
dotnet_libs = [
159
200
DotnetLib (
160
201
"python-runtime" ,
161
202
"src/runtime/Python.Runtime.csproj" ,
162
- output = "pythonnet/runtime"
163
- ),
164
- DotnetLib (
165
- "clrmodule-amd64" ,
166
- "src/clrmodule/" ,
167
- runtime = "win-x64" ,
168
- output = "pythonnet/netfx/amd64" ,
169
- rename = {"clr.dll" : "clr.pyd" },
170
- ),
171
- DotnetLib (
172
- "clrmodule-x86" ,
173
- "src/clrmodule/" ,
174
- runtime = "win-x86" ,
175
- output = "pythonnet/netfx/x86" ,
176
- rename = {"clr.dll" : "clr.pyd" },
177
- ),
203
+ output = "pythonnet/runtime" ,
204
+ )
178
205
]
179
206
180
- ext_modules = []
181
-
182
- try :
183
- mono_libs = check_output ("pkg-config --libs mono-2" , shell = True , encoding = "utf8" )
184
- mono_cflags = check_output (
185
- "pkg-config --cflags mono-2" , shell = True , encoding = "utf8"
207
+ if BUILD_NETFX :
208
+ dotnet_libs .extend (
209
+ [
210
+ DotnetLib (
211
+ "clrmodule-amd64" ,
212
+ "src/clrmodule/" ,
213
+ runtime = "win-x64" ,
214
+ output = "pythonnet/netfx/amd64" ,
215
+ rename = {"clr.dll" : "clr.pyd" },
216
+ ),
217
+ DotnetLib (
218
+ "clrmodule-x86" ,
219
+ "src/clrmodule/" ,
220
+ runtime = "win-x86" ,
221
+ output = "pythonnet/netfx/x86" ,
222
+ rename = {"clr.dll" : "clr.pyd" },
223
+ ),
224
+ ]
186
225
)
187
- cflags = mono_cflags .strip ()
188
- libs = mono_libs .strip ()
189
-
190
- # build the clr python module
191
- clr_ext = Extension (
192
- "clr" ,
193
- language = "c++" ,
194
- sources = ["src/monoclr/clrmod.c" ],
195
- extra_compile_args = cflags .split (" " ),
196
- extra_link_args = libs .split (" " ),
197
- )
198
- ext_modules .append (clr_ext )
199
- except Exception :
200
- print ("Failed to find mono libraries via pkg-config, skipping the Mono CLR loader" )
201
226
227
+ ext_modules = []
202
228
229
+ if BUILD_MONO :
230
+ try :
231
+ mono_libs = check_output (
232
+ "pkg-config --libs mono-2" , shell = True , encoding = "utf8"
233
+ )
234
+ mono_cflags = check_output (
235
+ "pkg-config --cflags mono-2" , shell = True , encoding = "utf8"
236
+ )
237
+ cflags = mono_cflags .strip ()
238
+ libs = mono_libs .strip ()
239
+
240
+ # build the clr python module
241
+ clr_ext = Extension (
242
+ "pythonnet.mono.clr" ,
243
+ language = "c++" ,
244
+ sources = ["src/monoclr/clrmod.c" ],
245
+ extra_compile_args = cflags .split (" " ),
246
+ extra_link_args = libs .split (" " ),
247
+ )
248
+ ext_modules .append (clr_ext )
249
+ except Exception :
250
+ print (
251
+ "Failed to find mono libraries via pkg-config, skipping the Mono CLR loader"
252
+ )
203
253
204
- setup (
205
- cmdclass = {
206
- "build" : build ,
207
- "build_dotnet" : build_dotnet ,
208
- "configure" : configure ,
209
- },
210
254
255
+ setup (
256
+ cmdclass = cmdclass ,
211
257
name = "pythonnet" ,
212
258
version = "3.0.0.dev1" ,
213
259
description = ".Net and Mono integration for Python" ,
@@ -216,11 +262,9 @@ class build(_build):
216
262
author = "The Contributors of the Python.NET Project" ,
217
263
author_email = "pythonnet@python.org" ,
218
264
packages = ["pythonnet" ],
219
- setup_requires = ["setuptools_scm" ],
220
265
install_requires = ["pycparser" ],
221
266
long_description = long_description ,
222
267
# data_files=[("{install_platlib}", ["{build_lib}/pythonnet"])],
223
-
224
268
py_modules = ["clr" ],
225
269
ext_modules = ext_modules ,
226
270
dotnet_libs = dotnet_libs ,
0 commit comments