Skip to content

Commit

Permalink
Merge pull request symmetryinvestments#267 from atilaneves/no-more-py…
Browse files Browse the repository at this point in the history
…thon2

Remove support for Python2
  • Loading branch information
atilaneves committed Sep 22, 2020
2 parents e96e35c + d21b02c commit b1b2d4b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 46 deletions.
32 changes: 3 additions & 29 deletions pynih/source/autowrap/pynih/wrap.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public import std.typecons: Yes, No;
public import autowrap.types: Modules, Module, isModule,
LibraryName, PreModuleInitCode, PostModuleInitCode, RootNamespace, Ignore;
static import python.boilerplate;
import python.raw: isPython2, isPython3;
import std.meta: allSatisfy;


Expand Down Expand Up @@ -67,17 +66,9 @@ string createPythonModuleMixin(LibraryName libraryName, Modules modules)


private string pyInitFuncName(LibraryName libraryName) @safe pure nothrow {

string prefix() {
static if(isPython2)
return "init";
else static if(isPython3)
return "PyInit_";
else
static assert(false);
}

return prefix ~ libraryName.value;
import python.raw: isPython3;
static assert(isPython3, "Python2 no longer supported");
return "PyInit_" ~ libraryName.value;
}


Expand Down Expand Up @@ -144,7 +135,6 @@ auto createPythonModule(LibraryName libraryName, modules...)()


mixin template createPythonModule(python.boilerplate.Module module_, alias cfunctions, alias aggregates)
if(isPython3)
{
static extern(C) export auto _py_init_impl() { // -> ModuleInitRet
import python.raw: pyDateTimeImport;
Expand All @@ -157,19 +147,3 @@ mixin template createPythonModule(python.boilerplate.Module module_, alias cfunc
return createModule!(module_, cfunctions, aggregates);
}
}


mixin template createPythonModule(python.boilerplate.Module module_, alias cfunctions, alias aggregates)
if(isPython2)
{
static extern(C) export void _py_init_impl() {
import python.raw: pyDateTimeImport;
import python.cooked: initModule;
import core.runtime: rt_init;

rt_init;

pyDateTimeImport;
initModule!(module_, cfunctions, aggregates);
}
}
1 change: 0 additions & 1 deletion pynih/source/python/boilerplate.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module python.boilerplate;


import python.raw: isPython2, isPython3;
import std.traits: isFunction;


Expand Down
20 changes: 4 additions & 16 deletions pynih/source/python/cooked.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import python.boilerplate: Module, CFunctions, Aggregates;
Each function has the same name in Python.
*/
auto createModule(Module module_, alias cfunctions, alias aggregates = Aggregates!())()
if(isPython3 &&
is(cfunctions == CFunctions!F, F...) &&
if(is(cfunctions == CFunctions!F, F...) &&
is(aggregates == Aggregates!T, T...))
{
static assert(isPython3, "Python2 no longer supported");

static PyModuleDef moduleDef;

auto pyMethodDefs = cFunctionsToPyMethodDefs!(cfunctions);
Expand All @@ -29,19 +30,6 @@ auto createModule(Module module_, alias cfunctions, alias aggregates = Aggregate
}


/**
Calls Py_InitModule. It's the Python2 way of creating a new Python module.
Each function has the same name in Python.
*/
void initModule(Module module_, alias cfunctions, alias aggregates)()
if(isPython2 &&
is(cfunctions == CFunctions!F, F...) &&
is(aggregates == Aggregates!T, T...))
{
auto module_ = pyInitModule(&module_.name[0], cFunctionsToPyMethodDefs!(cfunctions));
addModuleTypes!aggregates(module_);
}

private void addModuleTypes(alias aggregates)(PyObject* module_) {
import autowrap.common: AlwaysTry;
import python.type: PythonType;
Expand Down Expand Up @@ -85,7 +73,7 @@ private PyMethodDef* cFunctionsToPyMethodDefs(alias cfunctions)()
Helper function to get around the C syntax problem with
PyModuleDef_HEAD_INIT - it doesn't compile in D.
*/
private auto pyModuleDef(A...)(auto ref A args) if(isPython3) {
private auto pyModuleDef(A...)(auto ref A args) {
import std.functional: forward;

return PyModuleDef(
Expand Down

0 comments on commit b1b2d4b

Please sign in to comment.