From 6cf5bf2ca497fbe037a27d99662d5f946d1e4e06 Mon Sep 17 00:00:00 2001 From: Alexander Bezzubov Date: Sat, 1 Jun 2019 21:30:07 +0200 Subject: [PATCH] python: expose is_vendor() Signed-off-by: Alexander Bezzubov --- python/enry.py | 26 ++++++++++++++++++++++++-- python/enry_build.py | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/python/enry.py b/python/enry.py index 77830f8f..cd388ba2 100644 --- a/python/enry.py +++ b/python/enry.py @@ -4,6 +4,8 @@ from _c_enry import ffi, lib +## Helpers + def go_str_to_py(go_str): str_len = go_str.n @@ -19,6 +21,13 @@ def py_str_to_go(py_str): return go_str[0] +def go_bool_to_py(go_bool): + return go_bool == 1 + + +## API + + def language_by_extension(filename: str) -> str: fName = py_str_to_go(filename) guess = lib.GetLanguageByExtension(fName) @@ -33,11 +42,19 @@ def language_by_filename(filename: str) -> str: return lang -## Test +def is_vendor(filename: str) -> bool: + fName = py_str_to_go(filename) + guess = lib.IsVendor(fName) + return go_bool_to_py(guess) + + +## Tests def main(): - files = ["Parse.hs", "some.cpp", "and.go", "type.h", ".bashrc"] + files = [ + "Parse.hs", "some.cpp", "and.go", "type.h", ".bashrc", ".gitignore" + ] print("strategy: extension") for filename in files: @@ -49,6 +66,11 @@ def main(): lang = language_by_filename(filename) print("file: {:10s} language: '{}'".format(filename, lang)) + print("\ncheck: is vendor?") + for filename in files: + vendor = is_vendor(filename) + print("file: {:10s} vendor: '{}'".format(filename, vendor)) + if __name__ == "__main__": main() diff --git a/python/enry_build.py b/python/enry_build.py index 8e5d7763..96ca8f64 100644 --- a/python/enry_build.py +++ b/python/enry_build.py @@ -23,6 +23,8 @@ }; extern struct GetLanguageByFilename_return GetLanguageByFilename(GoString p0); + +extern GoUint8 IsVendor(GoString p0); """) # set_source() gives the name of the python extension module to