Skip to content

Commit

Permalink
[Dev] Add rules_lint (#23)
Browse files Browse the repository at this point in the history
* [Dev] Add rules_lint
  • Loading branch information
lshmouse authored Nov 11, 2024
1 parent 2fee993 commit a708081
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
blank_issues_enabled: true
blank_issues_enabled: true
10 changes: 4 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]

branches: [main]
jobs:
ci:
runs-on: ubuntu-latest
Expand All @@ -15,12 +13,12 @@ jobs:
with:
python-version: '3.10'
- uses: bazelbuild/setup-bazelisk@v3
- name: Mount bazel cache # Optional
- name: Mount bazel cache # Optional
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazel
- run: gcc --version
- run: bazel test --config=cpplint //...
- run: bazel build --config=cpu -- //...
- run: bazel test --config=cpu -- //...
- run: bazel test --config=cpu -- //...
7 changes: 7 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package(default_visibility = ["//visibility:public"])

alias(
name = "format",
actual = "//bazel/tools/format",
)

53 changes: 53 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,56 @@ opentelemetry_cpp_deps()
# # (required after v1.8.0) Load extra dependencies required for OpenTelemetry
load("@io_opentelemetry_cpp//bazel:extra_deps.bzl", "opentelemetry_extra_deps")
opentelemetry_extra_deps()



load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

# aspect_bazel_lib depends on bazel_skylib
aspect_bazel_lib_dependencies()

load(
"@aspect_rules_lint//format:repositories.bzl",
# Fetch additional formatter binaries you need:
"fetch_java_format",
"fetch_ktfmt",
"fetch_swiftformat",
"rules_lint_dependencies",
)

rules_lint_dependencies()

fetch_java_format()

fetch_ktfmt()

fetch_swiftformat()

load("@aspect_rules_lint//lint:checkstyle.bzl", "fetch_checkstyle")

fetch_checkstyle()

load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")

fetch_pmd()

load("@aspect_rules_lint//lint:vale.bzl", "fetch_vale")

fetch_vale()

load("@aspect_rules_lint//lint:ktlint.bzl", "fetch_ktlint")

fetch_ktlint()

########################
# Optional: multitool provides defaults for some tools such as yamlfmt
# If you do not set up multitool, you must provide these tools yourself
load("@rules_multitool//multitool:multitool.bzl", "multitool")

multitool(
name = "multitool",
lockfiles = [
"@aspect_rules_lint//format:multitool.lock.json",
"@aspect_rules_lint//lint:multitool.lock.json",
],
)
1 change: 1 addition & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
17 changes: 17 additions & 0 deletions bazel/tools/format/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package(default_visibility = ["//visibility:public"])
load("@aspect_rules_lint//format:defs.bzl", "format_multirun")

format_multirun(
name = "format",
c = "@llvm_toolchain_llvm//:bin/clang-format",
cc = "@llvm_toolchain_llvm//:bin/clang-format",
cuda = "@llvm_toolchain_llvm//:bin/clang-format",
# You can use standard gofmt instead of stricter gofumpt:
# go = "@go_sdk//:bin/gofmt",
go = "@aspect_rules_lint//format:gofumpt",
jsonnet = "@aspect_rules_lint//format:jsonnetfmt",
python = "@aspect_rules_lint//format:ruff",
shell = "@aspect_rules_lint//format:shfmt",
visibility = ["//:__subpackages__"],
yaml = "@aspect_rules_lint//format:yamlfmt",
)
3 changes: 3 additions & 0 deletions bazel/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ load("//third_party/rules_cuda:workspace.bzl", rules_cuda = "repo")
load("//third_party/rules_oci:workspace.bzl", rules_oci = "repo")
load("//third_party/rules_pkg:workspace.bzl", rules_pkg = "repo")

load("//third_party/rules_lint:workspace.bzl", rules_lint = "repo")
load("//third_party/cpplint:workspace.bzl", cpplint = "repo")

# compression libraries
Expand Down Expand Up @@ -65,6 +66,8 @@ def init_language_repos():
rules_oci()
rules_cuda()

rules_lint()

def init_compression_libs():
boringssl()
brotli()
Expand Down
2 changes: 1 addition & 1 deletion dev/docker/installers/install_developer_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# TODO: Install protoc compiler
# TODO: Install kubectl
# TODO: Install argo
# TODO: Install helm
# TODO: Install helm
28 changes: 14 additions & 14 deletions dev/docker/installers/install_minimal_environment.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/bash

apt-get -y update \
&& apt-get install -y software-properties-common \
&& add-apt-repository ppa:deadsnakes/ppa
apt-get -y update &&
apt-get install -y software-properties-common &&
add-apt-repository ppa:deadsnakes/ppa

apt install -y bash \
build-essential \
git \
git-lfs \
curl \
ca-certificates \
libsndfile1-dev \
libgl1 \
python3.10 \
python3-pip \
python3.10-venv && \
rm -rf /var/lib/apt/lists
build-essential \
git \
git-lfs \
curl \
ca-certificates \
libsndfile1-dev \
libgl1 \
python3.10 \
python3-pip \
python3.10-venv &&
rm -rf /var/lib/apt/lists

# TODO: Install bazel
2 changes: 1 addition & 1 deletion dev/docker/installers/install_training_support.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

pip install --upgrade numpy torch accelerate triton torchvision transformers huggingface_hub
pip install --upgrade numpy torch accelerate triton torchvision transformers huggingface_hub
9 changes: 5 additions & 4 deletions experimental/pybind11_example/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import example


class TestBasic(unittest.TestCase):
def test_add(self):
self.assertEqual(example.add(1, 2), 3)
self.assertEqual(example.add(2, 2), 4)

def test_add(self):
self.assertEqual(example.add(1, 2), 3)
self.assertEqual(example.add(2, 2), 4)

if __name__ == "__main__":
unittest.main()
unittest.main()
10 changes: 7 additions & 3 deletions experimental/python_example/python_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import time
import inspect


class ContextExample(ContextDecorator):
def __enter__(self):
self.start = time.time()
print('Starting')
print("Starting")
return self

def __exit__(self, *exc):
exec_time = time.time() - self.start
print(f'Finished in {exec_time:.2f} seconds')
print(f"Finished in {exec_time:.2f} seconds")
return False

def __call__(self, func):
Expand All @@ -21,16 +22,19 @@ def wrapper(*args, **kwargs):
print(f"Source code of the function: {source}")
with self as ctx:
return func(*args, **kwargs)

return wrapper


@ContextExample()
def say_hello():
print("Hello, world!")


if __name__ == "__main__":
print("======Using the context manager======")
with ContextExample() as ctx:
print("Inside the context")

print("======Using the decorator======")
say_hello()
say_hello()
50 changes: 28 additions & 22 deletions experimental/python_example/python_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,40 @@
import time
from inspect import getsource


def timer(func):
def wrapper(*args, **kwargs):
start = time.time()
ret = func(*args, **kwargs)
end = time.time()
exec_time = end - start
print(f"Function {func.__name__} took {exec_time:.2f} seconds to execute")
return ret
return wrapper
def wrapper(*args, **kwargs):
start = time.time()
ret = func(*args, **kwargs)
end = time.time()
exec_time = end - start
print(f"Function {func.__name__} took {exec_time:.2f} seconds to execute")
return ret

return wrapper


def tracing(func):
def wrapper(*args, **kwargs):
print("Something is happening before the function is called.")
print(f"Function name: {func.__name__}")
print(f"Arguments: {args}")
# print(f"Keyword arguments: {kwargs}")
source = getsource(func)
print(f"Source code: {source[9:]}")
ret = func(*args, **kwargs)
# ret = eval(source[9:])(*args, **kwargs)
print("Something is happening after the function is called.")
return ret
return wrapper
def wrapper(*args, **kwargs):
print("Something is happening before the function is called.")
print(f"Function name: {func.__name__}")
print(f"Arguments: {args}")
# print(f"Keyword arguments: {kwargs}")
source = getsource(func)
print(f"Source code: {source[9:]}")
ret = func(*args, **kwargs)
# ret = eval(source[9:])(*args, **kwargs)
print("Something is happening after the function is called.")
return ret

return wrapper


@tracing
@timer
def say_hello(name):
print("hello: " + name)
print("hello: " + name)


if __name__ == "__main__":
say_hello("world")
say_hello("world")
10 changes: 6 additions & 4 deletions experimental/python_example/python_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

app = Flask(__name__)

@app.route('/')

@app.route("/")
def hello():
return "hello world"
return "hello world"


if __name__ == '__main__':
app.run(host='0.0.0.0')
if __name__ == "__main__":
app.run(host="0.0.0.0")
22 changes: 13 additions & 9 deletions experimental/pytorch_example/pytorch_compile_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
from torch import _dynamo as torchdynamo
from typing import List


@torch.compile
def toy_example(a, b):
x = a / (torch.abs(a) + 1)
if b.sum() < 0:
b = b * -1
return x * b
x = a / (torch.abs(a) + 1)
if b.sum() < 0:
b = b * -1
return x * b


def main():
for _ in range(100):
toy_example(torch.randn(10), torch.randn(10))
for _ in range(100):
toy_example(torch.randn(10), torch.randn(10))


if __name__ == "__main__":
import depyf
with depyf.prepare_debug("depyf_debug_dir"):
main()
import depyf

with depyf.prepare_debug("depyf_debug_dir"):
main()
25 changes: 15 additions & 10 deletions experimental/ros2_example/ros_chatter.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
"""Launch a talker and a listener."""

import launch
import launch_ros.actions


def generate_launch_description():
"""Launch a talker and a listener."""
return launch.LaunchDescription([
launch_ros.actions.Node(
# Provide the rootpath for the node.
executable='chatter/talker',
output='screen',
name='talker'),
launch_ros.actions.Node(executable='chatter/listener',
output='screen',
name='listener'),
])
return launch.LaunchDescription(
[
launch_ros.actions.Node(
# Provide the rootpath for the node.
executable="chatter/talker",
output="screen",
name="talker",
),
launch_ros.actions.Node(
executable="chatter/listener", output="screen", name="listener"
),
]
)
Loading

0 comments on commit a708081

Please sign in to comment.