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

Skip to content

Commit 83ae857

Browse files
committed
Define PYTHON2 & PYTHON3 directives
Makes code more future proof as new python versions role out. We could otherwise use !PYTHON27 but it could be confused as a patch specific to that version of python instead of PYTHON3 compat.
1 parent 8fa699c commit 83ae857

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def build_extension(self, ext):
138138
unicode_width = ctypes.sizeof(ctypes.c_wchar)
139139

140140
defines = [
141-
"PYTHON%d%s" % (sys.version_info[:2]),
141+
"PYTHON%d%d" % (sys.version_info[:2]),
142+
"PYTHON%d" % (sys.version_info[:1]), # Python Major Version
142143
"UCS%d" % unicode_width,
143144
]
144145

src/clrmodule/ClrModule.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
public class clrModule
3131
{
32-
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
32+
#if PYTHON3
3333
[DllExport("PyInit_clr", CallingConvention.StdCall)]
3434
public static IntPtr PyInit_clr()
35-
#else
35+
#elif PYTHON2
3636
[DllExport("initclr", CallingConvention.StdCall)]
3737
public static void initclr()
3838
#endif
@@ -99,9 +99,9 @@ public static void initclr()
9999
#if DEBUG_PRINT
100100
Console.WriteLine("Could not load Python.Runtime");
101101
#endif
102-
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
102+
#if PYTHON3
103103
return IntPtr.Zero;
104-
#else
104+
#elif PYTHON2
105105
return;
106106
#endif
107107
}
@@ -111,9 +111,9 @@ public static void initclr()
111111
// So now we get the PythonEngine and execute the InitExt method on it.
112112
Type pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine");
113113

114-
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
114+
#if PYTHON3
115115
return (IntPtr)pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
116-
#else
116+
#elif PYTHON2
117117
pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
118118
#endif
119119
}

src/clrmodule/clrmodule.csproj

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x86'">
1919
<DebugSymbols>true</DebugSymbols>
2020
<OutputPath>bin\x86\DebugMono\</OutputPath>
21-
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
21+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
2222
<DebugType>full</DebugType>
2323
<PlatformTarget>x86</PlatformTarget>
2424
<ErrorReport>prompt</ErrorReport>
@@ -29,7 +29,7 @@
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugMono|x64'">
3030
<DebugSymbols>true</DebugSymbols>
3131
<OutputPath>bin\x64\DebugMono\</OutputPath>
32-
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
32+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
3333
<DebugType>full</DebugType>
3434
<PlatformTarget>x64</PlatformTarget>
3535
<ErrorReport>prompt</ErrorReport>
@@ -39,8 +39,7 @@
3939
</PropertyGroup>
4040
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseMono|x86'">
4141
<OutputPath>bin\x86\ReleaseMono\</OutputPath>
42-
<DefineConstants Condition="'$(DefineConstants)' == ''">
43-
</DefineConstants>
42+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
4443
<Optimize>true</Optimize>
4544
<DebugType>pdbonly</DebugType>
4645
<PlatformTarget>x86</PlatformTarget>
@@ -51,8 +50,7 @@
5150
</PropertyGroup>
5251
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseMono|x64'">
5352
<OutputPath>bin\x64\ReleaseMono\</OutputPath>
54-
<DefineConstants Condition="'$(DefineConstants)' == ''">
55-
</DefineConstants>
53+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
5654
<Optimize>true</Optimize>
5755
<DebugType>pdbonly</DebugType>
5856
<PlatformTarget>x64</PlatformTarget>
@@ -64,7 +62,7 @@
6462
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x86'">
6563
<DebugSymbols>true</DebugSymbols>
6664
<OutputPath>bin\x86\DebugWin\</OutputPath>
67-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;DEBUG_PRINT</DefineConstants>
65+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
6866
<DebugType>full</DebugType>
6967
<PlatformTarget>x86</PlatformTarget>
7068
<ErrorReport>prompt</ErrorReport>
@@ -75,7 +73,7 @@
7573
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugWin|x64'">
7674
<DebugSymbols>true</DebugSymbols>
7775
<OutputPath>bin\x64\DebugWin\</OutputPath>
78-
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
76+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
7977
<DebugType>full</DebugType>
8078
<PlatformTarget>x64</PlatformTarget>
8179
<ErrorReport>prompt</ErrorReport>
@@ -85,8 +83,7 @@
8583
</PropertyGroup>
8684
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseWin|x86'">
8785
<OutputPath>bin\x86\ReleaseWin\</OutputPath>
88-
<DefineConstants Condition="'$(DefineConstants)' == ''">
89-
</DefineConstants>
86+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
9087
<Optimize>true</Optimize>
9188
<DebugType>pdbonly</DebugType>
9289
<PlatformTarget>x86</PlatformTarget>
@@ -97,8 +94,7 @@
9794
</PropertyGroup>
9895
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseWin|x64'">
9996
<OutputPath>bin\x64\ReleaseWin\</OutputPath>
100-
<DefineConstants Condition="'$(DefineConstants)' == ''">
101-
</DefineConstants>
97+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
10298
<Optimize>true</Optimize>
10399
<DebugType>pdbonly</DebugType>
104100
<PlatformTarget>x64</PlatformTarget>

src/runtime/Python.Runtime.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|x86'">
1515
<OutputPath>bin\x86\ReleaseMono\</OutputPath>
16-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS4</DefineConstants>
16+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants>
1717
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1818
<Optimize>true</Optimize>
1919
<DebugType>pdbonly</DebugType>
@@ -23,7 +23,7 @@
2323
</PropertyGroup>
2424
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|x64'">
2525
<OutputPath>bin\x64\ReleaseMono\</OutputPath>
26-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS4</DefineConstants>
26+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants>
2727
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2828
<Optimize>true</Optimize>
2929
<DebugType>pdbonly</DebugType>
@@ -33,7 +33,7 @@
3333
</PropertyGroup>
3434
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWin|x86'">
3535
<OutputPath>bin\x86\ReleaseWin\</OutputPath>
36-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS2</DefineConstants>
36+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants>
3737
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3838
<Optimize>true</Optimize>
3939
<DebugType>pdbonly</DebugType>
@@ -43,7 +43,7 @@
4343
</PropertyGroup>
4444
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWin|x64'">
4545
<OutputPath>bin\x64\ReleaseWin\</OutputPath>
46-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS2</DefineConstants>
46+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants>
4747
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4848
<Optimize>true</Optimize>
4949
<DebugType>pdbonly</DebugType>
@@ -54,7 +54,7 @@
5454
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x86'">
5555
<DebugSymbols>true</DebugSymbols>
5656
<OutputPath>bin\x86\DebugMono\</OutputPath>
57-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS4</DefineConstants>
57+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS4</DefineConstants>
5858
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5959
<Optimize>false</Optimize>
6060
<DebugType>full</DebugType>
@@ -66,7 +66,7 @@
6666
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x64'">
6767
<DebugSymbols>true</DebugSymbols>
6868
<OutputPath>bin\x64\DebugMono\</OutputPath>
69-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS4</DefineConstants>
69+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS4</DefineConstants>
7070
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7171
<Optimize>false</Optimize>
7272
<DebugType>full</DebugType>
@@ -75,7 +75,7 @@
7575
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x86'">
7676
<DebugSymbols>true</DebugSymbols>
7777
<OutputPath>bin\x86\DebugWin\</OutputPath>
78-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
78+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS2</DefineConstants>
7979
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8080
<Optimize>false</Optimize>
8181
<DebugType>full</DebugType>
@@ -87,7 +87,7 @@
8787
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x64'">
8888
<DebugSymbols>true</DebugSymbols>
8989
<OutputPath>bin\x64\DebugWin\</OutputPath>
90-
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
90+
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS2</DefineConstants>
9191
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9292
<Optimize>false</Optimize>
9393
<DebugType>full</DebugType>

0 commit comments

Comments
 (0)