Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Drop Python 2 support
  • Loading branch information
filmor committed Jun 18, 2020
commit 705ba8349b9eed485a131b0c62980a2f6267e15e
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ python:
- 3.7
- 3.6
- 3.5
- 2.7

env:
matrix:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
### Added

### Changed
- Drop support for Python 2

### Fixed

Expand Down
5 changes: 1 addition & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build: off

image:
- Visual Studio 2017

platform:
- x86
- x64
Expand All @@ -23,13 +23,10 @@ environment:
BUILD_OPTS: --xplat
- PYTHON_VERSION: 3.5
BUILD_OPTS: --xplat
- PYTHON_VERSION: 2.7
BUILD_OPTS: --xplat
- PYTHON_VERSION: 3.8
- PYTHON_VERSION: 3.7
- PYTHON_VERSION: 3.6
- PYTHON_VERSION: 3.5
- PYTHON_VERSION: 2.7

init:
# Update Environment Variables based on matrix/platform
Expand Down
13 changes: 2 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,11 @@ def build_extension(self, ext):

# Up to Python 3.2 sys.maxunicode is used to determine the size of
# Py_UNICODE, but from 3.3 onwards Py_UNICODE is a typedef of wchar_t.
# TODO: Is this doing the right check for Py27?
if sys.version_info[:2] <= (3, 2):
unicode_width = 2 if sys.maxunicode < 0x10FFFF else 4
else:
import ctypes

unicode_width = ctypes.sizeof(ctypes.c_wchar)
import ctypes
unicode_width = ctypes.sizeof(ctypes.c_wchar)

defines = [
"PYTHON{0}{1}".format(PY_MAJOR, PY_MINOR),
"PYTHON{0}".format(PY_MAJOR), # Python Major Version
"UCS{0}".format(unicode_width),
]

Expand All @@ -274,7 +268,6 @@ def build_extension(self, ext):

if sys.platform != "win32" and (DEVTOOLS == "Mono" or DEVTOOLS == "dotnet"):
on_darwin = sys.platform == "darwin"
defines.append("MONO_OSX" if on_darwin else "MONO_LINUX")

# Check if --enable-shared was set when Python was built
enable_shared = sysconfig.get_config_var("Py_ENABLE_SHARED")
Expand Down Expand Up @@ -645,8 +638,6 @@ def run(self):
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: C#",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
Expand Down
13 changes: 0 additions & 13 deletions src/clrmodule/ClrModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@

public class clrModule
{
#if PYTHON3
[DllExport("PyInit_clr", CallingConvention.StdCall)]
public static IntPtr PyInit_clr()
#elif PYTHON2
[DllExport("initclr", CallingConvention.StdCall)]
public static void initclr()
#endif
{
DebugPrint("Attempting to load 'Python.Runtime' using standard binding rules.");
#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN
Expand Down Expand Up @@ -95,23 +90,15 @@ public static void initclr()
catch (InvalidOperationException)
{
DebugPrint("Could not load 'Python.Runtime'.");
#if PYTHON3
return IntPtr.Zero;
#elif PYTHON2
return;
#endif
}
}

// Once here, we've successfully loaded SOME version of Python.Runtime
// So now we get the PythonEngine and execute the InitExt method on it.
Type pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine");

#if PYTHON3
return (IntPtr)pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
#elif PYTHON2
pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
#endif
}

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions src/embed_tests/TestCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public void TestNoOverloadException() {
dynamic callWith42 = PythonEngine.Eval("lambda f: f([42])");
var error = Assert.Throws<PythonException>(() => callWith42(aFunctionThatCallsIntoPython.ToPython()));
Assert.AreEqual("TypeError", error.PythonTypeName);
string expectedArgTypes = Runtime.IsPython2
? "(<type 'list'>)"
: "(<class 'list'>)";
string expectedArgTypes = "(<class 'list'>)";
StringAssert.EndsWith(expectedArgTypes, error.Message);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/runtime/CustomMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ public static int GetUnicodeByteLength(IntPtr p)
/// </remarks>
public static IntPtr Py3UnicodePy2StringtoPtr(string s)
{
return Runtime.IsPython3
? Instance.MarshalManagedToNative(s)
: Marshal.StringToHGlobalAnsi(s);
return Instance.MarshalManagedToNative(s);
}

/// <summary>
Expand All @@ -137,9 +135,7 @@ public static IntPtr Py3UnicodePy2StringtoPtr(string s)
/// </returns>
public static string PtrToPy3UnicodePy2String(IntPtr p)
{
return Runtime.IsPython3
? PtrToStringUni(p)
: Marshal.PtrToStringAnsi(p);
return PtrToStringUni(p);
}
}

Expand Down
Loading