FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/setup.py at d75cdccf22d7f6d49318cd0c82f63cd32daabb5f · askdaddy/pythonnet · GitHub
askdaddy
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
setup.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
230 lines (183 loc) · 6.77 KB
Breadcrumbs
pythonnet
/
setup.py
Copy path
File metadata and controls
230 lines (183 loc) · 6.77 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env python
from
setuptools
import
setup
,
Command
,
Extension
from
wheel
.
bdist_wheel
import
bdist_wheel
from
setuptools
.
command
.
build_ext
import
build_ext
import
distutils
from
subprocess
import
check_output
,
check_call
import
sys
,
os
PY_MAJOR
=
sys
.
version_info
[
0
]
PY_MINOR
=
sys
.
version_info
[
1
]
CONFIGURED_PROPS
=
"configured.props"
def
_get_interop_filename
():
"""interopXX.cs is auto-generated as part of the build.
For common windows platforms pre-generated files are included
as most windows users won't have Clang installed, which is
required to generate the file.
"""
interop_filename
=
"interop{0}{1}{2}.cs"
.
format
(
PY_MAJOR
,
PY_MINOR
,
getattr
(
sys
,
"abiflags"
,
""
)
)
return
os
.
path
.
join
(
"src"
,
"runtime"
,
interop_filename
)
def
_write_configure_props
():
defines
=
[
"PYTHON{0}{1}"
.
format
(
PY_MAJOR
,
PY_MINOR
),
]
if
sys
.
platform
==
"win32"
:
defines
.
append
(
"WINDOWS"
)
if
hasattr
(
sys
,
"abiflags"
):
if
"d"
in
sys
.
abiflags
:
defines
.
append
(
"PYTHON_WITH_PYDEBUG"
)
if
"m"
in
sys
.
abiflags
:
defines
.
append
(
"PYTHON_WITH_PYMALLOC"
)
# check the interop file exists, and create it if it doesn't
interop_file
=
_get_interop_filename
()
if
not
os
.
path
.
exists
(
interop_file
):
print
(
"Creating {0}"
.
format
(
interop_file
))
geninterop
=
os
.
path
.
join
(
"tools"
,
"geninterop"
,
"geninterop.py"
)
check_call
([
sys
.
executable
,
geninterop
,
interop_file
])
import
xml
.
etree
.
ElementTree
as
ET
proj
=
ET
.
Element
(
"Project"
)
props
=
ET
.
SubElement
(
proj
,
"PropertyGroup"
)
f
=
ET
.
SubElement
(
props
,
"PythonInteropFile"
)
f
.
text
=
os
.
path
.
basename
(
interop_file
)
c
=
ET
.
SubElement
(
props
,
"ConfiguredConstants"
)
c
.
text
=
" "
.
join
(
defines
)
ET
.
ElementTree
(
proj
).
write
(
CONFIGURED_PROPS
)
class
Configure
(
Command
):
"""Configure command"""
description
=
"Configure the pythonnet build"
user_options
=
[]
def
initialize_options
(
self
):
pass
def
finalize_options
(
self
):
pass
def
run
(
self
):
self
.
announce
(
"Writing configured.props..."
,
level
=
distutils
.
log
.
INFO
)
_write_configure_props
()
class
DotnetLib
(
Extension
):
def
__init__
(
self
,
name
,
path
,
**
kwargs
):
self
.
path
=
path
self
.
args
=
kwargs
super
().
__init__
(
name
,
sources
=
[])
class
BuildDotnet
(
build_ext
):
"""Build command for dotnet-cli based builds"""
description
=
"Build DLLs with dotnet-cli"
user_options
=
[(
"dotnet-config"
,
None
,
"dotnet build configuration"
)]
def
initialize_options
(
self
):
self
.
dotnet_config
=
"release"
super
().
initialize_options
()
def
finalize_options
(
self
):
super
().
finalize_options
()
def
get_source_files
(
self
):
return
super
().
get_source_files
()
def
run
(
self
):
orig_modules
=
self
.
distribution
.
ext_modules
dotnet_modules
=
[
lib
for
lib
in
orig_modules
if
isinstance
(
lib
,
DotnetLib
)]
other_modules
=
[
lib
for
lib
in
orig_modules
if
not
isinstance
(
lib
,
DotnetLib
)]
if
dotnet_modules
:
self
.
run_command
(
"configure"
)
for
lib
in
dotnet_modules
:
output
=
os
.
path
.
join
(
os
.
path
.
abspath
(
self
.
build_lib
),
lib
.
args
.
pop
(
"output"
))
rename
=
lib
.
args
.
pop
(
"rename"
, {})
opts
=
sum
(
[
[
"--"
+
name
.
replace
(
"_"
,
"-"
),
value
]
for
name
,
value
in
lib
.
args
.
items
()
],
[],
)
opts
.
extend
([
"--configuration"
,
self
.
dotnet_config
])
opts
.
extend
([
"--output"
,
output
])
self
.
announce
(
"Running dotnet build..."
,
level
=
distutils
.
log
.
INFO
)
self
.
spawn
([
"dotnet"
,
"build"
,
lib
.
path
]
+
opts
)
for
k
,
v
in
rename
.
items
():
source
=
os
.
path
.
join
(
output
,
k
)
dest
=
os
.
path
.
join
(
output
,
v
)
if
os
.
path
.
isfile
(
source
):
try
:
os
.
remove
(
dest
)
except
OSError
:
pass
self
.
move_file
(
src
=
source
,
dst
=
dest
,
level
=
distutils
.
log
.
INFO
)
else
:
self
.
warn
(
"Can't find file to rename: {}, current dir: {}"
.
format
(
source
,
os
.
getcwd
()))
if
other_modules
:
self
.
distribution
.
ext_modules
=
other_modules
super
().
run
()
self
.
distribution
.
ext_modules
=
orig_modules
# If no modules need to be compiled, skip
with
open
(
"README.rst"
,
"r"
)
as
f
:
long_description
=
f
.
read
()
ext_modules
=
[
DotnetLib
(
"python-runtime"
,
"src/runtime/Python.Runtime.csproj"
,
output
=
"pythonnet/runtime"
),
DotnetLib
(
"clrmodule-amd64"
,
"src/clrmodule/"
,
runtime
=
"win-x64"
,
output
=
"pythonnet/netfx/amd64"
,
rename
=
{
"clr.dll"
:
"clr.pyd"
},
),
DotnetLib
(
"clrmodule-x86"
,
"src/clrmodule/"
,
runtime
=
"win-x86"
,
output
=
"pythonnet/netfx/x86"
,
rename
=
{
"clr.dll"
:
"clr.pyd"
},
),
]
try
:
mono_libs
=
check_output
(
"pkg-config --libs mono-2"
,
shell
=
True
,
encoding
=
"utf8"
)
mono_cflags
=
check_output
(
"pkg-config --cflags mono-2"
,
shell
=
True
,
encoding
=
"utf8"
)
cflags
=
mono_cflags
.
strip
()
libs
=
mono_libs
.
strip
()
# build the clr python module
clr_ext
=
Extension
(
"clr"
,
language
=
"c++"
,
sources
=
[
"src/monoclr/clrmod.c"
],
extra_compile_args
=
cflags
.
split
(
" "
),
extra_link_args
=
libs
.
split
(
" "
),
)
ext_modules
.
append
(
clr_ext
)
except
Exception
:
print
(
"Failed to find mono libraries via pkg-config, skipping the Mono CLR loader"
)
setup
(
name
=
"pythonnet"
,
version
=
"3.0.0.dev1"
,
description
=
".Net and Mono integration for Python"
,
url
=
"https://pythonnet.github.io/"
,
license
=
"MIT"
,
author
=
"The Contributors of the Python.NET Project"
,
author_email
=
"pythonnet@python.org"
,
packages
=
[
"pythonnet"
],
setup_requires
=
[
"setuptools_scm"
],
install_requires
=
[
"pycparser"
],
long_description
=
long_description
,
# data_files=[("{install_platlib}", ["{build_lib}/pythonnet"])],
cmdclass
=
{
"build_ext"
:
BuildDotnet
,
"configure"
:
Configure
,
},
py_modules
=
[
"clr"
],
ext_modules
=
ext_modules
,
classifiers
=
[
"Development Status :: 5 - Production/Stable"
,
"Intended Audience :: Developers"
,
"License :: OSI Approved :: MIT License"
,
"Programming Language :: C#"
,
"Programming Language :: Python :: 3"
,
"Programming Language :: Python :: 3.6"
,
"Programming Language :: Python :: 3.7"
,
"Programming Language :: Python :: 3.8"
,
"Operating System :: Microsoft :: Windows"
,
"Operating System :: POSIX :: Linux"
,
"Operating System :: MacOS :: MacOS X"
,
],
zip_safe
=
False
,
)
Back
|
FazBrowse Home
|
New Git URL