diff --git a/hello-buck-python/.buckconfig b/hello-buck-python/.buckconfig new file mode 100644 index 0000000..2246f49 --- /dev/null +++ b/hello-buck-python/.buckconfig @@ -0,0 +1,3 @@ +[python] + interpreter = /usr/bin/python2.7 + path_to_pex_executer = /bin/bash \ No newline at end of file diff --git a/hello-buck-python/.gitignore b/hello-buck-python/.gitignore new file mode 100644 index 0000000..15fe75a --- /dev/null +++ b/hello-buck-python/.gitignore @@ -0,0 +1,12 @@ +# Buck +/buck-out +/buck-cache +/local.properties +/.buckconfig.local +/.buckd + +# OS X +.DS_Store + +# Python +/*.pyc diff --git a/hello-buck-python/BUCK b/hello-buck-python/BUCK new file mode 100644 index 0000000..d905fe3 --- /dev/null +++ b/hello-buck-python/BUCK @@ -0,0 +1,12 @@ +python_binary( + name = 'hello_buck_python', + main = 'hello_buck.py', + deps = [ + ':calc', + ], +) + +python_library( + name = 'calc', + srcs = glob(['calc.py']), +) diff --git a/hello-buck-python/README.md b/hello-buck-python/README.md new file mode 100644 index 0000000..fbfe3e4 --- /dev/null +++ b/hello-buck-python/README.md @@ -0,0 +1,10 @@ +# Hello Buck - Python + +A simple demo on how to setup Buck to build and execute Python code + +## Running + +``` +buck build //:hello_buck_python +./buck-out/gen/hello_buck_python.pex +``` \ No newline at end of file diff --git a/hello-buck-python/calc.py b/hello-buck-python/calc.py new file mode 100644 index 0000000..1ea8be4 --- /dev/null +++ b/hello-buck-python/calc.py @@ -0,0 +1,28 @@ +from __future__ import division +from __future__ import print_function + +import logging + +logger = logging.getLogger(__name__) + + +def add(a, b): + """Add two numbers.""" + return a+b + + +def divide(a, b): + """"Divide two numbers. Throw exception if division by zero.""" + if b == 0: + raise ZeroDivisionError() + return a/b + + +def subtract(a, b): + """Subtract two numbers""" + return a-b + + +def multiply(a, b): + """Multiply two numbers""" + return a*b diff --git a/hello-buck-python/hello_buck.py b/hello-buck-python/hello_buck.py new file mode 100644 index 0000000..6caeada --- /dev/null +++ b/hello-buck-python/hello_buck.py @@ -0,0 +1,9 @@ +from calc import add, multiply + + +def main(): + print add(1, 2) + print multiply(3, 4) + +if __name__ == '__main__': + main()