-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#118] Add example with python and bazel toolchain
- Loading branch information
1 parent
2d40c33
commit 4d9f408
Showing
15 changed files
with
160 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
test --test_output=errors | ||
|
||
# Do NOT implicitly create empty __init__.py files in the runfiles tree. | ||
# By default, these are created in every directory containing Python source code | ||
# or shared libraries, and every parent directory of those directories, | ||
# excluding the repo root directory. With this flag set, we are responsible for | ||
# creating (possibly empty) __init__.py files and adding them to the srcs of | ||
# Python targets as required. | ||
build --incompatible_default_to_explicit_init_py |
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 @@ | ||
6.2.0 |
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,3 @@ | ||
bazel-*/ | ||
pytest/ | ||
.pytest_cache/ |
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,9 @@ | ||
config: | ||
git: | ||
auto-push: false | ||
polling-period: 2s | ||
mob-timer: | ||
duration: 5m0s | ||
tcr: | ||
language: python | ||
toolchain: bazel |
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,9 @@ | ||
toolchains: | ||
default: bazel | ||
compatible-with: [ bazel ] | ||
source-files: | ||
directories: [ src ] | ||
patterns: [ '(?i)^.*\.py$' ] | ||
test-files: | ||
directories: [ tests ] | ||
patterns: [ '(?i)^.*\.py$' ] |
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,11 @@ | ||
build: | ||
- os: [ darwin, linux, windows ] | ||
arch: [ "386", amd64, arm64 ] | ||
command: bazel | ||
arguments: [ build, "..." ] | ||
test: | ||
- os: [ darwin, linux, windows ] | ||
arch: [ "386", amd64, arm64 ] | ||
command: bazel | ||
arguments: [ test, "..." ] | ||
test-result-dir: bazel-testlogs/src |
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,18 @@ | ||
load("@rules_python//python:defs.bzl", "py_library") | ||
load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") | ||
|
||
py_library( | ||
name = "hello_world", | ||
srcs = glob(["src/**/*.py"]), | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
py_pytest_test( | ||
name = "hello_world_test", | ||
size = "small", | ||
srcs = glob(["tests/*.py"]), | ||
imports = ["src"], | ||
deps = [ | ||
":hello_world", | ||
], | ||
) |
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,50 @@ | ||
# Using TCR with Python and Bazel | ||
|
||
## Prerequisites | ||
|
||
- macOS, Linux or Windows | ||
- [git](https://git-scm.com/) client | ||
- [curl](https://curl.se/download.html) command line utility | ||
- [python](https://www.python.org/downloads/) | ||
- [Bazel](https://bazel.build/) (previously installed and available from the command line) | ||
|
||
## Instructions | ||
|
||
### 1 - Open a terminal | ||
|
||
> ***Note to Windows users*** | ||
> | ||
> Use a **git bash** terminal for running the commands below. | ||
> _Windows CMD and PowerShell are not supported_ | ||
### 2 - Launch TCR | ||
|
||
> ***Reminder***: the command below should be run from | ||
> [examples/python-bazel](.) | ||
> directory | ||
From the built-in terminal: | ||
|
||
```shell | ||
./tcrw | ||
``` | ||
|
||
### Cheat Sheet | ||
|
||
Here are the main shortcuts available once TCR utility is running: | ||
|
||
| Shortcut | Description | | ||
|-----------|-----------------------------------------------| | ||
| `d` / `D` | Enter driver role (from main menu) | | ||
| `n` / `N` | Enter navigator role (from main menu) | | ||
| `p` / `P` | Toggle on/off git auto-push (from main menu) | | ||
| `l` / `L` | Pull from remote (from main menu) | | ||
| `s` / `S` | Push to remote (from main menu) | | ||
| `q` / `Q` | Quit current role - Quit TCR (from main menu) | | ||
| `t` / `T` | Query timer status (from driver role only) | | ||
| `?` | List available options | | ||
|
||
### Additional Details | ||
|
||
Refer to [tcr.md](../../doc/tcr.md) page for additional details and explanations about TCR | ||
available subcommands and options |
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 @@ | ||
workspace(name = "hello_world_python") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "rules_python", | ||
sha256 = "94750828b18044533e98a129003b6a68001204038dc4749f40b195b24c38f49f", | ||
strip_prefix = "rules_python-0.21.0", | ||
url = "https://github.com/bazelbuild/rules_python/releases/download/0.21.0/rules_python-0.21.0.tar.gz", | ||
) | ||
|
||
http_archive( | ||
name = "rules_python_pytest", | ||
sha256 = "334a0ac91a0d6a87df499cdf9b70b525754dc8ca4873763116d67177f759389f", | ||
strip_prefix = "rules_python_pytest-1.0.2", | ||
url = "https://github.com/caseyduquettesc/rules_python_pytest/archive/v1.0.2.tar.gz", | ||
) | ||
|
||
load("@rules_python//python:repositories.bzl", "py_repositories") | ||
load("@rules_python_pytest//python_pytest:repositories.bzl", "rules_python_pytest_dependencies") | ||
|
||
rules_python_pytest_dependencies() | ||
|
||
py_repositories() |
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,9 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.pytest.ini_options] | ||
addopts = "-vvs --junitxml=\"pytest/result.xml\"" | ||
testpaths = [ | ||
"tests" | ||
] |
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,2 @@ | ||
pytest == 7.0.1; python_version < '3.7' | ||
pytest == 7.3.1; python_version >= '3.7' |
Empty file.
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,2 @@ | ||
def say_hello(name: str) -> str: | ||
return f'Hello {name}!' |
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,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
base_dir="$(cd "$(dirname -- "$0")" && pwd)" | ||
. "${base_dir}/../tcr/tcr.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,9 @@ | ||
import pytest | ||
|
||
from hello_world.hello_world import say_hello | ||
|
||
|
||
class TestHelloWorld: | ||
|
||
def test_say_hello(self) -> None: | ||
assert ('Hello Sue!' == say_hello('Sue')) |