Skip to content

Commit

Permalink
python: expose is_vendor()
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
  • Loading branch information
bzz committed Oct 14, 2019
1 parent be583ca commit 6cf5bf2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 24 additions & 2 deletions python/enry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from _c_enry import ffi, lib

## Helpers


def go_str_to_py(go_str):
str_len = go_str.n
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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()
2 changes: 2 additions & 0 deletions python/enry_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6cf5bf2

Please sign in to comment.