Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.
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
3 changes: 3 additions & 0 deletions hello-buck-python/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[python]
interpreter = /usr/bin/python2.7
path_to_pex_executer = /bin/bash
12 changes: 12 additions & 0 deletions hello-buck-python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Buck
/buck-out
/buck-cache
/local.properties
/.buckconfig.local
/.buckd

# OS X
.DS_Store

# Python
/*.pyc
12 changes: 12 additions & 0 deletions hello-buck-python/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
python_binary(
name = 'hello_buck_python',
main = 'hello_buck.py',
deps = [
':calc',
],
)

python_library(
name = 'calc',
srcs = glob(['calc.py']),
)
10 changes: 10 additions & 0 deletions hello-buck-python/README.md
Original file line number Diff line number Diff line change
@@ -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
```
28 changes: 28 additions & 0 deletions hello-buck-python/calc.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions hello-buck-python/hello_buck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from calc import add, multiply


def main():
print add(1, 2)
print multiply(3, 4)

if __name__ == '__main__':
main()