Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions python/prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ def gen_pyplot_functions(dub_root):
f.write("\n".join(functions))


def gen_backend_pdf_functions(dub_root):
'''
generate 'backend_pdf_functions.txt' for matplotlibd.backends.backends_pdf.
'''
import matplotlib.backends.backend_pdf
from string import lowercase

functions = filter(lambda i: i[0] != '_' or i[0] in lowercase,
extract_function_names(matplotlib.backends.backend_pdf))

with open(dub_root + "/views/backend_pdf_functions.txt", "w") as f:
f.write("\n".join(functions))



if __name__ == '__main__':
from sys import argv
gen_pyplot_functions(argv[1])
gen_backend_pdf_functions(argv[1])
49 changes: 49 additions & 0 deletions source/matplotlibd/backend_pdf.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module matplotlibd.backend_pdf;
import matplotlibd.core.pycall;
import matplotlibd.core.translate;

private:

string py_script = "import matplotlib.backends.backend_pdf\n";

immutable string backend_pdf_funcs = (){
import std.string: splitLines;

string[] method_names = import("backend_pdf_functions.txt").splitLines;
string backend_pdf_funcs;

foreach(name; method_names) {
backend_pdf_funcs ~=
"void " ~ name ~ "(T...)(T a)" ~
"{import std.format: format;" ~
"string p;if(a.length>0){foreach(i;a){p~=parseArgs(i);}" ~
"p = p[0..$-1];}py_script~=format(\"plt."~ name ~ "(%s)\n\",p);";

backend_pdf_funcs ~= "}\n";

}

return backend_pdf_funcs;
}();


public:

import matplotlibd.core.translate: False, True, None;


void clear() {
py_script = "import matplotlib.backends.backend_pdf\n";
}

mixin(backend_pdf_funcs);

/*unittest {
import std.string;
auto script = py_script ~ "plt.plot([1, 2],[2, 4],\"r-\",lw=2)\n";
plot([1, 2], [2, 4], "r-", ["lw": 2]);
assert(script == py_script);
clear();
assert(py_script == "import matplotlib.pyplot as plt\n");
}
*/