Go from an empty directory to a passing dx test. The steps are for Linux.
rules_dx is not released yet. Install starts with the first BCR release.
Install Bazelisk, then install dx from the latest release.
curl -fsSL -o bazel https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64
chmod +x bazel
gh release download --repo devhusdk/rules_dx --pattern 'dx-linux-x86_64.tar.gz' --dir dx-release
mkdir -p ~/.local/bin
tar -xzf dx-release/dx-linux-x86_64.tar.gz -C ~/.local/bin dxPut bazel and ~/.local/bin on your PATH and open a new shell.
dx init --apply my-app
cd my-appA Bazel workspace is a directory with a MODULE.bazel. A module is the unit
Bazel builds and other modules depend on. dx init writes the file for you.
A package is a directory with a BUILD.bazel. Make one called hello.
mkdir helloCreate hello/hello.py.
"""Greeting helper."""
def greet(name):
"""Return a greeting for name."""
return f"Hello, {name}!"Create hello/hello_test.py.
"""Tests for the greeting helper."""
import unittest
from hello.hello import greet
class GreetTest(unittest.TestCase):
def test_greet(self):
self.assertEqual(greet("world"), "Hello, world!")
if __name__ == "__main__":
unittest.main()Let dx write the BUILD.bazel.
dx generate --applyhello/BUILD.bazel now lists targets. A target is one thing Bazel can build
or test. A label names it, like //hello:hello_test: the package path after
//, then the target name after :. //... means every target in the
workspace.
dx build //...
dx test //...dx check --apply //...Make a greeter package that depends on hello.
mkdir greeterCreate greeter/greeter.py.
"""Greets everyone."""
from hello.hello import greet
def greet_all(names):
"""Return one greeting per name."""
return [greet(name) for name in names]Create greeter/greeter_test.py.
"""Tests for greet_all."""
import unittest
from greeter.greeter import greet_all
class GreeterTest(unittest.TestCase):
def test_greet_all(self):
self.assertEqual(greet_all(["a"]), ["Hello, a!"])
if __name__ == "__main__":
unittest.main()dx generate --apply
dx test //...Commit your work, change hello/hello.py, then run only the affected tests.
Both packages run, because greeter depends on hello.
git init
git add .
git commit -m "hello"
dx test --affectedRun the same checks on every pull request. See GitHub CI.