Skip to content
Merged
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
37 changes: 37 additions & 0 deletions .github/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ruff.toml

line-length = 120

# Exclude specific files or directories.
exclude = [
"build/",
"dist/",
".venv/",
"__pycache__/",
"uprotocol/cloudevent/cloudevents_pb2.py",
"uprotocol/proto/*"
]

[lint]
# Enable all basic PEP 8 checks and other common linting rules.
select = [
"E", # PEP 8 rules (formatting issues)
"F", # Pyflakes rules (undefined names, etc.)
"W", # Additional PEP 8 rules (warning-level issues)
"I", # Import order checker (ensuring imports are ordered correctly)
"ERA", # flake8-eradicate (identifying commented-out code)
"N" # Naming convention rules
]

ignore = [
"F811", # Ignore the error for multimethod function
]

[lint.flake8-annotations]
allow-star-arg-any = true

[format]
quote-style = "preserve"
indent-style = "space"
docstring-code-format = true
docstring-code-line-length = 100
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Run Linter

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

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3


- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ruff

- name: Lint Python Code with Ruff
run: |
ruff check --config .github/ruff.toml

- name: Check Python Code Formatting with Ruff
run: |
ruff format --check --config .github/ruff.toml

2 changes: 1 addition & 1 deletion clean_project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
SPDX-FileCopyrightText: Copyright (c) 2023 Contributors to the
SPDX-FileCopyrightText: Copyright (c) 2023 Contributors to the
Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
Expand Down
32 changes: 19 additions & 13 deletions scripts/pull_and_compile_protos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
SPDX-FileCopyrightText: Copyright (c) 2023 Contributors to the
SPDX-FileCopyrightText: Copyright (c) 2023 Contributors to the
Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
Expand Down Expand Up @@ -34,36 +34,41 @@
PROTO_OUTPUT_DIR = os.path.abspath("../uprotocol/proto")


def clone_or_pull(repo_url, PROTO_REPO_DIR):
def clone_or_pull(repo_url, proto_repo_dir):
try:
repo = Repo.clone_from(repo_url, PROTO_REPO_DIR)
print(f"Repository cloned successfully from {repo_url} to {PROTO_REPO_DIR}")
repo = Repo.clone_from(repo_url, proto_repo_dir)
print(f"Repository cloned successfully from {repo_url} to {proto_repo_dir}")
# Checkout the specific tag
repo.git.checkout(TAG_NAME)
except git.exc.GitCommandError:
try:
git_pull_command = ["git", "pull", "origin", TAG_NAME]
subprocess.run(git_pull_command, cwd=PROTO_REPO_DIR, check=True)
subprocess.run(git_pull_command, cwd=proto_repo_dir, check=True)
print("Git pull successful after clone failure.")
except subprocess.CalledProcessError as pull_error:
print(f"Error during Git pull: {pull_error}")


def execute_maven_command(project_dir, command):
try:
with subprocess.Popen(command, cwd=os.path.join(os.getcwd(), project_dir), shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True) as process:
with subprocess.Popen(
command,
cwd=os.path.join(os.getcwd(), project_dir),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as process:
stdout, stderr = process.communicate()
print(stdout)

if process.returncode != 0:
print(f"Error: {stderr}")
else:
print("Maven command executed successfully.")
src_directory = os.path.join(os.getcwd(), project_dir, "target", "generated-sources", "protobuf",
"python")
# if not os.path.exists(PROTO_OUTPUT_DIR):
# os.makedirs(PROTO_OUTPUT_DIR)
src_directory = os.path.join(
os.getcwd(), project_dir, "target", "generated-sources", "protobuf", "python"
)

shutil.copytree(src_directory, PROTO_OUTPUT_DIR, dirs_exist_ok=True)
process_python_protofiles(PROTO_OUTPUT_DIR)
Expand All @@ -89,8 +94,9 @@ def process_python_protofiles(directory):
file_path = os.path.join(root, file)
replace_in_file(file_path, r'import uri_pb2', 'import uprotocol.proto.uri_pb2')
replace_in_file(file_path, r'import uuid_pb2', 'import uprotocol.proto.uuid_pb2')
replace_in_file(file_path, r'import uprotocol_options_pb2',
'import uprotocol.proto.uprotocol_options_pb2')
replace_in_file(
file_path, r'import uprotocol_options_pb2', 'import uprotocol.proto.uprotocol_options_pb2'
)
replace_in_file(file_path, r'import uattributes_pb2', 'import uprotocol.proto.uattributes_pb2')
replace_in_file(file_path, r'import upayload_pb2', 'import uprotocol.proto.upayload_pb2')
replace_in_file(file_path, r'import ustatus_pb2', 'import uprotocol.proto.ustatus_pb2')
Expand Down
Loading