-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Python binding の提供
- Loading branch information
Showing
9 changed files
with
126 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
FROM alpine:latest | ||
|
||
RUN apk add --no-cache g++ | ||
RUN apk add --no-cache g++ make | ||
|
||
RUN apk add --no-cache bash | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
COPY scripts /app/scripts | ||
COPY src /app/src | ||
COPY Makefile /app/Makefile | ||
|
||
RUN bash build.sh | ||
RUN make build | ||
|
||
ENTRYPOINT [ "./docker-entrypoint.sh" ] | ||
ENTRYPOINT [ "scripts/docker-entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.PHONY: setup | ||
|
||
setup: | ||
bash scripts/setup.sh | ||
|
||
build: setup | ||
g++ -std=c++23 build/almo.cpp -o build/almo | ||
|
||
pybind: setup | ||
bash scripts/pybind.sh build/pyalmo.cpp almo.so | ||
|
||
all: build pybind | ||
|
||
clean: | ||
rm -rf build | ||
rm almo.so | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
#!/bin/sh | ||
|
||
exec /app/build/almo "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
if [ $# -ne 2 ]; then | ||
echo "引数の数が正しくありません" | ||
exit 1 | ||
fi | ||
|
||
input_file=$1 | ||
output_file=$2 | ||
|
||
g++ \ | ||
-O3 -shared -std=c++23 -undefined dynamic_lookup \ | ||
$(python3 -m pybind11 --includes) \ | ||
$input_file -o $output_file | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "almo.so をビルドしました" | ||
else | ||
echo "ビルドエラー" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
from pybind11.setup_helpers import Pybind11Extension, build_ext | ||
from setuptools import setup | ||
|
||
os.system("bash scripts/setup.sh") | ||
__version__ = "\"0.0.1\"" | ||
|
||
ext_modules = [ | ||
Pybind11Extension( | ||
"almo", | ||
["build/pyalmo.cpp"], | ||
cxx_std=23, | ||
define_macros=[("VERSION_INFO", __version__)], | ||
), | ||
] | ||
|
||
setup( | ||
name="almo", | ||
author=["abap34", "ebi-fly13", "noya2"], | ||
url="https://github.com/abap34/ALMO", | ||
ext_modules=ext_modules, | ||
cmdclass={"build_ext": build_ext}, | ||
zip_safe=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include "almo.cpp" | ||
|
||
|
||
std::string md_to_html(std::string md_content, std::map<std::string, std::string> meta_data) { | ||
almo::Block ast = almo::parse_rest(split(md_content, "\n")); | ||
return ast.render(meta_data); | ||
} | ||
|
||
|
||
std::string md_to_json(std::string md_content) { | ||
almo::Block ast = almo::parse_rest(split(md_content, "\n")); | ||
return ast.to_json(); | ||
} | ||
|
||
|
||
std::string md_to_dot(std::string md_content) { | ||
almo::Block ast = almo::parse_rest(split(md_content, "\n")); | ||
return ast.to_dot(true); | ||
} | ||
|
||
|
||
namespace py = pybind11; | ||
|
||
|
||
PYBIND11_MODULE(almo, m) { | ||
m.doc() = "almo interface for python."; | ||
|
||
m.def("md_to_html", &md_to_html, "md to html"); | ||
m.def("md_to_json", &md_to_json, "md to json"); | ||
m.def("md_to_dot", &md_to_dot, "md to dot"); | ||
|
||
|
||
#ifdef VERSION_INFO | ||
m.attr("__version__") = VERSION_INFO; | ||
#else | ||
m.attr("__version__") = "dev"; | ||
#endif | ||
} |