Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a53380

Browse files
committed
Fix sdist build and uninstalling.
Include all source files in the sdist wheel. Add Python.Runtime.dll as a data file so it gets added to the manifest and cleaned up correctly when the package is uninstalled.
1 parent 80fcbc4 commit 4a53380

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

setup.py

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from distutils.command.build_ext import build_ext
77
from distutils.command.build_scripts import build_scripts
88
from distutils.command.install_lib import install_lib
9+
from distutils.command.install_data import install_data
910
from distutils.sysconfig import get_config_var
1011
from platform import architecture
1112
from subprocess import Popen, CalledProcessError, PIPE, check_call
1213
from glob import glob
14+
import fnmatch
1315
import shutil
1416
import sys
1517
import os
@@ -229,16 +231,35 @@ def install(self):
229231
if not os.path.exists(self.install_dir):
230232
self.mkpath(self.install_dir)
231233

232-
# only copy clr.pyd and its dependencies
233-
for pattern in ("clr.*", "Python.Runtime.*"):
234-
for srcfile in glob(os.path.join(self.build_dir, pattern)):
235-
destfile = os.path.join(self.install_dir, os.path.basename(srcfile))
236-
self.copy_file(srcfile, destfile)
237-
234+
# only copy clr.pyd/.so
235+
for srcfile in glob(os.path.join(self.build_dir, "clr.*")):
236+
destfile = os.path.join(self.install_dir, os.path.basename(srcfile))
237+
self.copy_file(srcfile, destfile)
238+
239+
240+
class PythonNET_InstallData(install_data):
241+
242+
def run(self):
243+
build_cmd = self.get_finalized_command("build_ext")
244+
install_cmd = self.get_finalized_command("install")
245+
build_lib = os.path.abspath(build_cmd.build_lib)
246+
install_platlib = os.path.relpath(install_cmd.install_platlib, self.install_dir)
247+
248+
for i, data_files in enumerate(self.data_files):
249+
if isinstance(data_files, str):
250+
self.data_files[i] = data_files[i].format(build_lib=build_lib)
251+
else:
252+
for j, filename in enumerate(data_files[1]):
253+
data_files[1][j] = filename.format(build_lib=build_lib)
254+
dest = data_files[0].format(install_platlib=install_platlib)
255+
self.data_files[i] = dest, data_files[1]
256+
257+
return install_data.run(self)
258+
238259

239260
class PythonNET_BuildScripts(build_scripts):
240261

241-
def finalize_options(self):
262+
def run(self):
242263
build_scripts.finalize_options(self)
243264

244265
# fixup scripts to look in the build_ext output folder
@@ -252,6 +273,8 @@ def finalize_options(self):
252273
scripts.append(script)
253274
self.scripts = scripts
254275

276+
return build_scripts.run(self)
277+
255278

256279
def _check_output(*popenargs, **kwargs):
257280
"""subprocess.check_output from python 2.7.
@@ -270,6 +293,24 @@ def _check_output(*popenargs, **kwargs):
270293

271294

272295
if __name__ == "__main__":
296+
setupdir = os.path.dirname(__file__)
297+
if setupdir:
298+
os.chdir(setupdir)
299+
300+
sources = []
301+
for ext in (".sln", ".snk"):
302+
sources.extend(glob("*" + ext))
303+
304+
for root, dirnames, filenames in os.walk("src"):
305+
for ext in (".cs", ".csproj", ".sln", ".snk", ".config", ".il", ".py", ".c", ".h", ".ico"):
306+
for filename in fnmatch.filter(filenames, "*" + ext):
307+
sources.append(os.path.join(root, filename))
308+
309+
for root, dirnames, filenames in os.walk("tools"):
310+
for ext in (".exe"):
311+
for filename in fnmatch.filter(filenames, "*" + ext):
312+
sources.append(os.path.join(root, filename))
313+
273314
setup(
274315
name="pythonnet",
275316
version="2.0.0.dev1",
@@ -280,14 +321,18 @@ def _check_output(*popenargs, **kwargs):
280321
'Development Status :: 3 - Alpha',
281322
'Intended Audience :: Developers'],
282323
ext_modules=[
283-
Extension("clr", sources=[])
324+
Extension("clr", sources=sources)
325+
],
326+
data_files=[
327+
("{install_platlib}", ["{build_lib}/Python.Runtime.dll"]),
284328
],
285329
scripts=[_npython_exe],
286330
zip_safe=False,
287331
cmdclass={
288332
"build_ext" : PythonNET_BuildExt,
289333
"build_scripts" : PythonNET_BuildScripts,
290-
"install_lib" : PythonNET_InstallLib
334+
"install_lib" : PythonNET_InstallLib,
335+
"install_data": PythonNET_InstallData,
291336
}
292337
)
293338

0 commit comments

Comments
 (0)