Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21cc289

Browse files
committed
Add a configure step to allow for easier testing
1 parentbf56f97 commit21cc289

File tree

6 files changed

+79
-25
lines changed

6 files changed

+79
-25
lines changed

‎.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Configuration data
2+
configured.props
3+
14
# General binaries and Build results
25
*.dll
36
*.exe

‎Directory.Build.props

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
<Project>
2-
<PropertyGroup>
3-
<VersionPrefix>3.0.0</VersionPrefix>
4-
<AssemblyCopyright>Copyright (c) 2006-2020 The Contributors of the Python.NET Project</AssemblyCopyright>
5-
<AssemblyCompany>pythonnet</AssemblyCompany>
6-
<AssemblyProduct>Python.NET</AssemblyProduct>
7-
<LangVersion>7.3</LangVersion>
8-
</PropertyGroup>
2+
<PropertyGroup>
3+
<VersionPrefix>3.0.0</VersionPrefix>
4+
<AssemblyCopyright>Copyright (c) 2006-2020 The Contributors of the Python.NET Project</AssemblyCopyright>
5+
<AssemblyCompany>pythonnet</AssemblyCompany>
6+
<AssemblyProduct>Python.NET</AssemblyProduct>
7+
<LangVersion>7.3</LangVersion>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReferenceInclude="Microsoft.CSharp"Version="4.7.0" />
11+
<PackageReferenceInclude="NonCopyableAnalyzer"Version="0.6.0">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
</ItemGroup>
16+
<ImportProject="$(MSBuildThisFileDirectory)configured.props"Condition="Exists('$(MSBuildThisFileDirectory)configured.props')" />
917
</Project>

‎setup.py

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
fromsetuptoolsimportsetup,find_packages,Command,Extension
44
fromwheel.bdist_wheelimportbdist_wheel
55
fromsetuptools.command.build_extimportbuild_ext
6+
importdistutils
67
fromsubprocessimportcheck_output,check_call
78

89
importsys,os
910

1011
PY_MAJOR=sys.version_info[0]
1112
PY_MINOR=sys.version_info[1]
1213

14+
CONFIGURED_PROPS="configured.props"
1315

1416

1517
def_get_interop_filename():
@@ -24,10 +26,11 @@ def _get_interop_filename():
2426
returnos.path.join("src","runtime",interop_filename)
2527

2628

27-
def_get_flags():
29+
def_write_configure_props():
2830
# Up to Python 3.2 sys.maxunicode is used to determine the size of
2931
# Py_UNICODE, but from 3.3 onwards Py_UNICODE is a typedef of wchar_t.
3032
importctypes
33+
3134
unicode_width=ctypes.sizeof(ctypes.c_wchar)
3235

3336
defines= [
@@ -44,18 +47,41 @@ def _get_flags():
4447
if"m"insys.abiflags:
4548
defines.append("PYTHON_WITH_PYMALLOC")
4649

47-
flags= []
48-
4950
# check the interop file exists, and create it if it doesn't
5051
interop_file=_get_interop_filename()
5152
ifnotos.path.exists(interop_file):
5253
print("Creating {0}".format(interop_file))
5354
geninterop=os.path.join("tools","geninterop","geninterop.py")
5455
check_call([sys.executable,geninterop,interop_file])
55-
56-
flags.append("-p:PythonInteropFile=\"{}\"".format(os.path.basename(interop_file)))
57-
flags.append("-p:DefineConstants=\"{}\"".format(" ".join(defines)))
58-
returnflags
56+
57+
importxml.etree.ElementTreeasET
58+
59+
proj=ET.Element("Project")
60+
props=ET.SubElement(proj,"PropertyGroup")
61+
f=ET.SubElement(props,"PythonInteropFile")
62+
f.text=os.path.basename(interop_file)
63+
64+
c=ET.SubElement(props,"ConfiguredConstants")
65+
c.text=" ".join(defines)
66+
67+
ET.ElementTree(proj).write(CONFIGURED_PROPS)
68+
69+
70+
classConfigure(Command):
71+
"""Configure command"""
72+
73+
description="Configure the pythonnet build"
74+
user_options= []
75+
76+
definitialize_options(self):
77+
pass
78+
79+
deffinalize_options(self):
80+
pass
81+
82+
defrun(self):
83+
self.announce("Writing configured.props...",level=distutils.log.INFO)
84+
_write_configure_props()
5985

6086

6187
classDotnetLib(Extension):
@@ -86,6 +112,13 @@ def run(self):
86112
dotnet_modules= [libforlibinorig_modulesifisinstance(lib,DotnetLib)]
87113
other_modules= [libforlibinorig_modulesifnotisinstance(lib,DotnetLib)]
88114

115+
ifdotnet_modules:
116+
ifos.path.isfile(CONFIGURED_PROPS):
117+
self.announce("Already configured",level=distutils.log.INFO)
118+
else:
119+
self.announce("Writing configured.props...",level=distutils.log.INFO)
120+
_write_configure_props()
121+
89122
forlibindotnet_modules:
90123
output=lib.args.pop("output")
91124
opts=sum(
@@ -97,7 +130,6 @@ def run(self):
97130
)
98131

99132
opts.extend(["--configuration",self.dotnet_config])
100-
opts.extend(_get_flags())
101133
opts.extend(["--output",os.path.join(self.build_lib,output)])
102134

103135
self.spawn(["dotnet","build",lib.path]+opts)
@@ -138,7 +170,9 @@ def finalize_options(self):
138170

139171
try:
140172
mono_libs=check_output("pkg-config --libs mono-2",shell=True,encoding="utf8")
141-
mono_cflags=check_output("pkg-config --cflags mono-2",shell=True,encoding="utf8")
173+
mono_cflags=check_output(
174+
"pkg-config --cflags mono-2",shell=True,encoding="utf8"
175+
)
142176
cflags=mono_cflags.strip()
143177
libs=mono_libs.strip()
144178

@@ -153,13 +187,14 @@ def finalize_options(self):
153187
ext_modules.append(clr_ext)
154188
exceptException:
155189
importtraceback
190+
156191
traceback.print_exc()
157192
print("Failed to find mono libraries via pkg-config, skipping the Mono CLR loader")
158193

159194

160195
setup(
161196
name="pythonnet",
162-
version="3.0.0-dev1",
197+
version="3.0.0.dev1",
163198
description=".Net and Mono integration for Python",
164199
url="https://pythonnet.github.io/",
165200
license="MIT",
@@ -168,7 +203,11 @@ def finalize_options(self):
168203
install_requires=["pycparser"],
169204
long_description=long_description,
170205
# data_files=[("{install_platlib}", ["{build_lib}/pythonnet"])],
171-
cmdclass={"build_ext":BuildDotnet,"bdist_wheel":bdist_wheel_patched},
206+
cmdclass={
207+
"build_ext":BuildDotnet,
208+
"bdist_wheel":bdist_wheel_patched,
209+
"configure":Configure,
210+
},
172211
ext_modules=ext_modules,
173212
classifiers=[
174213
"Development Status :: 5 - Production/Stable",

‎src/embed_tests/Python.EmbeddingTest.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
<ItemGroup>
88
<ProjectReferenceInclude="..\runtime\Python.Runtime.csproj" />
99
</ItemGroup>
10-
10+
1111
<ItemGroup>
1212
<PackageReferenceInclude="NUnit"Version="3.*" />
1313
<PackageReferenceInclude="NUnit3TestAdapter"Version="3.*">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
1717
<PackageReferenceInclude="Microsoft.NET.Test.Sdk"Version="16.*" />
18+
<PackageReferenceInclude="Microsoft.NETFramework.ReferenceAssemblies"Condition="$(MSBuildRuntimeType) == 'Core'">
19+
<Version>1.0.0</Version>
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
22+
</PackageReference>
1823
</ItemGroup>
1924

2025
</Project>

‎src/runtime/Python.Runtime.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
1616
</PropertyGroup>
1717

18+
<PropertyGroup>
19+
<DefineConstants>$(DefineConstants);$(ConfiguredConstants)</DefineConstants>
20+
</PropertyGroup>
21+
1822
<ItemGroupCondition=" '$(PythonInteropFile)' != ''">
1923
<CompileRemove="interop*.cs" />
2024
<CompileInclude="interop.cs" />
@@ -31,9 +35,5 @@
3135
<ItemGroup>
3236
<PackageReferenceInclude="System.Security.Permissions"Version="4.4.0" />
3337
<PackageReferenceInclude="System.Reflection.Emit"Version="4.3.0" />
34-
<PackageReferenceInclude="NonCopyableAnalyzer"Version="0.6.0">
35-
<PrivateAssets>all</PrivateAssets>
36-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
37-
</PackageReference>
3838
</ItemGroup>
3939
</Project>

‎src/testing/Python.Test.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0</TargetFrameworks>
44
</PropertyGroup>
5-
5+
66
<ItemGroup>
77
<ProjectReferenceInclude="..\runtime\Python.Runtime.csproj" />
8-
<PackageReferenceInclude="Microsoft.CSharp"Version="4.4.0" />
98
</ItemGroup>
109

1110
<TargetName="AfterBuild">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp