Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
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
16 changes: 5 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?
Comment thread
filmor marked this conversation as resolved.
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 All @@ -288,6 +281,9 @@ def build_extension(self, ext):
if not enable_shared:
defines.append("PYTHON_WITHOUT_ENABLE_SHARED")

if sys.platform == "win32":
defines.append("WINDOWS")

if hasattr(sys, "abiflags"):
if "d" in sys.abiflags:
defines.append("PYTHON_WITH_PYDEBUG")
Expand Down Expand Up @@ -645,8 +641,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
26 changes: 0 additions & 26 deletions src/embed_tests/TestPythonEngineProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ public void SetProgramName()
[Test]
public void SetPythonPath()
{
if (Runtime.Runtime.pyversion == "2.7")
{
// Assert.Skip outputs as a warning (ie. pending to fix)
Assert.Pass();
}

PythonEngine.Initialize();
string path = PythonEngine.PythonPath;
PythonEngine.Shutdown();
Expand All @@ -196,25 +190,5 @@ public void SetPythonPath()
Assert.AreEqual(path, PythonEngine.PythonPath);
PythonEngine.Shutdown();
}

[Test]
public void SetPythonPathExceptionOn27()
{
if (Runtime.Runtime.pyversion != "2.7")
{
Assert.Pass();
}

PythonEngine.Initialize();
string path = PythonEngine.PythonPath;
PythonEngine.Shutdown();

var ex = Assert.Throws<NotSupportedException>(() => PythonEngine.PythonPath = "foo");
Assert.AreEqual("Set PythonPath not supported on Python 2", ex.Message);

PythonEngine.Initialize();
Assert.AreEqual(path, PythonEngine.PythonPath);
PythonEngine.Shutdown();
}
}
}
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