Skip to content

Commit ff7d4ac

Browse files
committed
Merge branch 'pythonnet-develop' into python3
2 parents 9d96da5 + aad52dc commit ff7d4ac

File tree

1 file changed

+56
-19
lines changed

1 file changed

+56
-19
lines changed

setup.py

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
"""
55
from setuptools import setup, Extension
66
from distutils.command.build_ext import build_ext
7-
from distutils.command.build_scripts import build_scripts
87
from distutils.command.install_lib import install_lib
8+
from distutils.command.install_data import install_data
99
from distutils.sysconfig import get_config_var
10-
from distutils.util import convert_path
11-
from distutils.dep_util import newer
12-
from distutils import log
1310
from platform import architecture
1411
from subprocess import Popen, CalledProcessError, PIPE, check_call
1512
from glob import glob
16-
import stat
13+
import fnmatch
1714
import sys
1815
import os
1916

20-
CONFIG = "Release" # Release or Debug
17+
CONFIG = "Release" # Release or Debug
2118
DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono"
22-
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
19+
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
2320
PLATFORM = "x64" if architecture()[0] == "64bit" else "x86"
2421

2522

@@ -167,7 +164,6 @@ def build_extension(self, ext):
167164
if DEVTOOLS == "Mono":
168165
self._build_monoclr(ext)
169166

170-
171167
def _get_manifest(self, build_dir):
172168
if DEVTOOLS == "MsDev" and sys.version_info[:2] > (2,5):
173169
mt = _find_msbuild_tool("mt.exe", use_windows_sdk=True)
@@ -177,7 +173,6 @@ def _get_manifest(self, build_dir):
177173
check_call(" ".join(cmd), shell=False)
178174
return manifest
179175

180-
181176
def _build_monoclr(self, ext):
182177
mono_libs = _check_output("pkg-config --libs mono-2", shell=True)
183178
mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True)
@@ -197,7 +192,6 @@ def _build_monoclr(self, ext):
197192

198193
build_ext.build_extension(self, clr_ext)
199194

200-
201195
def _install_packages(self):
202196
"""install packages using nuget"""
203197
nuget = os.path.join("tools", "nuget", "nuget.exe")
@@ -222,12 +216,31 @@ def install(self):
222216
if not os.path.exists(self.install_dir):
223217
self.mkpath(self.install_dir)
224218

225-
# only copy clr.pyd and its dependencies
226-
for pattern in ("clr.*", "Python.Runtime.*"):
227-
for srcfile in glob(os.path.join(self.build_dir, pattern)):
228-
destfile = os.path.join(self.install_dir, os.path.basename(srcfile))
229-
self.copy_file(srcfile, destfile)
230-
219+
# only copy clr.pyd/.so
220+
for srcfile in glob(os.path.join(self.build_dir, "clr.*")):
221+
destfile = os.path.join(self.install_dir, os.path.basename(srcfile))
222+
self.copy_file(srcfile, destfile)
223+
224+
225+
class PythonNET_InstallData(install_data):
226+
227+
def run(self):
228+
build_cmd = self.get_finalized_command("build_ext")
229+
install_cmd = self.get_finalized_command("install")
230+
build_lib = os.path.abspath(build_cmd.build_lib)
231+
install_platlib = os.path.relpath(install_cmd.install_platlib, self.install_dir)
232+
233+
for i, data_files in enumerate(self.data_files):
234+
if isinstance(data_files, str):
235+
self.data_files[i] = data_files[i].format(build_lib=build_lib)
236+
else:
237+
for j, filename in enumerate(data_files[1]):
238+
data_files[1][j] = filename.format(build_lib=build_lib)
239+
dest = data_files[0].format(install_platlib=install_platlib)
240+
self.data_files[i] = dest, data_files[1]
241+
242+
return install_data.run(self)
243+
231244

232245
def _check_output(*popenargs, **kwargs):
233246
"""subprocess.check_output from python 2.7.
@@ -248,6 +261,24 @@ def _check_output(*popenargs, **kwargs):
248261

249262

250263
if __name__ == "__main__":
264+
setupdir = os.path.dirname(__file__)
265+
if setupdir:
266+
os.chdir(setupdir)
267+
268+
sources = []
269+
for ext in (".sln", ".snk", ".config"):
270+
sources.extend(glob("*" + ext))
271+
272+
for root, dirnames, filenames in os.walk("src"):
273+
for ext in (".cs", ".csproj", ".sln", ".snk", ".config", ".il", ".py", ".c", ".h", ".ico"):
274+
for filename in fnmatch.filter(filenames, "*" + ext):
275+
sources.append(os.path.join(root, filename))
276+
277+
for root, dirnames, filenames in os.walk("tools"):
278+
for ext in (".exe"):
279+
for filename in fnmatch.filter(filenames, "*" + ext):
280+
sources.append(os.path.join(root, filename))
281+
251282
setup(
252283
name="pythonnet",
253284
version="2.0.0.dev1",
@@ -258,12 +289,18 @@ def _check_output(*popenargs, **kwargs):
258289
'Development Status :: 3 - Alpha',
259290
'Intended Audience :: Developers'],
260291
ext_modules=[
261-
Extension("clr", sources=[])
292+
Extension("clr", sources=sources)
293+
],
294+
data_files=[
295+
("{install_platlib}", [
296+
"{build_lib}/Python.Runtime.dll",
297+
"Python.Runtime.dll.config"]),
262298
],
263299
zip_safe=False,
264300
cmdclass={
265-
"build_ext": PythonNET_BuildExt,
266-
"install_lib": PythonNET_InstallLib,
301+
"build_ext" : PythonNET_BuildExt,
302+
"install_lib" : PythonNET_InstallLib,
303+
"install_data": PythonNET_InstallData,
267304
}
268305
)
269306

0 commit comments

Comments
 (0)