Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0f45e4b
Integrated Native Python Proto Buf Pythons & Removed Maven/Java depen…
karthagokul Jul 5, 2025
d22fb5d
Added the base abstract class
karthagokul Jul 5, 2025
94f2fea
fixes to clean script & tests
karthagokul Jul 5, 2025
3a1af84
- Introduced git submodule to fetch the up-spec profo files
karthagokul Jul 5, 2025
a7ae94b
Fixes to the toml file
karthagokul Jul 5, 2025
7853fd0
Updated the script path
karthagokul Jul 5, 2025
264979f
removed friendly python script for runnign tests
karthagokul Jul 5, 2025
b33cf88
Fixes in the supported python minimum version to run pytest
karthagokul Jul 10, 2025
0b8d1cd
Updated the authors, email
karthagokul Jul 10, 2025
5412a79
Updated the authors, email
karthagokul Jul 10, 2025
2e2987f
Updated the authors, email
karthagokul Jul 10, 2025
547955b
Updated github workflow
karthagokul Jul 10, 2025
a17ede6
Updated license
karthagokul Jul 10, 2025
e7b3a0e
Updated license
karthagokul Jul 10, 2025
b40a92e
Updated the githubhook
karthagokul Jul 10, 2025
f505d8a
Updated the githubhook
karthagokul Jul 10, 2025
f9722f6
Updated the githubhook
karthagokul Jul 10, 2025
ff9b1ce
fixes in proto generation to support github action
karthagokul Jul 10, 2025
53a2c43
fixes
karthagokul Jul 10, 2025
e07d738
simplify the cleanup code
karthagokul Jul 10, 2025
a7f2a48
Fixing lint
karthagokul Jul 10, 2025
d6c20ef
Fixing the lint issues
karthagokul Jul 10, 2025
1c24a54
Fixes in the formatting
karthagokul Jul 10, 2025
24ee0da
added a global config
karthagokul Jul 10, 2025
749edc6
added a global config
karthagokul Jul 10, 2025
9497cd6
Fixes in the generation & cleanup scripts
karthagokul Jul 10, 2025
698bc43
fixes in lint
karthagokul Jul 10, 2025
672fa93
format fixes
karthagokul Jul 10, 2025
9f8eb1f
Reverting the original workflow
karthagokul Jul 10, 2025
c66d490
Removed unwanted init files in the .github
karthagokul Jul 10, 2025
d5c0f3c
Reverting the lint workflow
karthagokul Jul 10, 2025
fff3c0e
Reverting the lint workflow
karthagokul Jul 10, 2025
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
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[run]
omit = uprotocol/core/*,uprotocol/v1/*, uprotocol/uoptions_pb2.py, uprotocol/cloudevent/*_pb2.py, tests/*, */__init__.py
omit = uprotocol/core/*,uprotocol/v1/*, uprotocol/uoptions_pb2.py, uprotocol/uoptions_pb2_grpc.py, uprotocol/cloudevent/*_pb2.py, tests/*, */__init__.py
[report]
exclude_lines =
pragma: no cover
.*pass.*
.*pass.*
31 changes: 20 additions & 11 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,42 @@ jobs:
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.x'
python-version: '3.8'

- name: Install Poetry
run: |
python -m pip install --upgrade pip
python -m pip install poetry

- name: Install dependencies
- name: Checkout submodules
run: |
poetry install
git submodule update --init --recursive

- name: Run prebuild script
- name: Set up Python dependencies
run: |
cd scripts
# Run the script within the Poetry virtual environment
poetry run python pull_and_compile_protos.py
python -m pip install --upgrade pip
python -m pip install .[dev]

- name: Generate protobufs
run: |
python generate_proto.py

- name: Verify generated protobuf files
run: |
ls -lhR uprotocol/v1


- name: Run tests with coverage
run: |
set -o pipefail
poetry run coverage run --source=uprotocol -m pytest -x -o log_cli=true --timeout=300 2>&1 | tee test-output.log
poetry run coverage report > coverage_report.txt
coverage run --source=uprotocol -m pytest -x -o log_cli=true 2>&1 | tee test-output.log
coverage report > coverage_report.txt
export COVERAGE_PERCENTAGE=$(awk '/TOTAL/{print $4}' coverage_report.txt)
echo "COVERAGE_PERCENTAGE=$COVERAGE_PERCENTAGE" >> $GITHUB_ENV
echo "COVERAGE_PERCENTAGE: $COVERAGE_PERCENTAGE"
poetry run coverage html
timeout-minutes: 3 # Set a timeout of 3 minutes for this step
coverage html
timeout-minutes: 3


- name: Upload coverage report
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "up-spec"]
path = up-spec
url = https://github.com/eclipse-uprotocol/up-spec.git
30 changes: 14 additions & 16 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,35 @@ image:https://raw.githubusercontent.com/eclipse-uprotocol/up-spec/main/up_librar
=== Prerequisites
Before proceeding with the setup of this project, ensure that the following prerequisites are met:

* Maven is installed and configured in your environment. You can verify this by running the following command in your terminal:
[,bash]
----
mvn -version
----
If Maven is properly installed, you should see information about the Maven version and configuration. +
* `git` is installed and configured in your environment.

NOTE: Ensure you are using Java 17 with your Maven installation before continuing with the next steps. Other versions of Java may not be supported.
* Python 3.8+ is installed and configured in your environment.

=== Importing the Library

To set up SDK, follow the steps below:

. Clone the code from the GitHub repository:
. Clone the code from the GitHub repository , The repository contains the reference to up-spec main branch as the git submodule:
+
[source]
----
git clone https://github.com/eclipse-uprotocol/up-python.git
git clone --recurse-submodules https://github.com/eclipse-uprotocol/up-python.git
cd up-python
----

. Execute the `pull_and_compile_protos.py` script using the following commands:
If you have already cloned without `--recurse-submodules`, you can initialize and update using:
+
[source]
----
cd scripts
python pull_and_compile_protos.py
git submodule update --init --recursive
----
This script automates the following tasks:

1. **Cloning and Compilation of Protos:**
Clones the `up-core-api` protos from the `up-spec` repository, compiles them, and generates Python protofiles in the protos folder.
. Generate Python proto bindings using the provided script:
+
[source]
----
python generate_proto.py
----
This script will compile the `up-spec` protos locally and generate Python proto files under the appropriate package folders for local use in your environment.

. Install up-python
+
Expand Down
55 changes: 43 additions & 12 deletions 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) 2025 Contributors to the
Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
Expand All @@ -23,22 +23,53 @@
import os
import shutil

from config import TRACK_FILE


def clean_project():
# Remove build/ directory
if os.path.exists('build'):
shutil.rmtree('build')
# -----------------------------------
# Remove known build and cache folders
# -----------------------------------
directories_to_remove = ["build", "dist", "htmlcov", ".pytest_cache"]
directories_to_remove.extend([d for d in os.listdir() if d.endswith('.egg-info')])

for directory in directories_to_remove:
if os.path.exists(directory):
shutil.rmtree(directory)
print(f"Removed directory: {directory}/")

# -----------------------------------
# Remove generated proto files
# -----------------------------------
if os.path.exists(TRACK_FILE):
with open(TRACK_FILE, "r") as f:
files = [line.strip() for line in f if line.strip()]

for file in files:
# Normalize path to avoid './' issues
file_path = file.lstrip("./")
if os.path.exists(file_path):
os.remove(file_path)
print(f"Deleted file: {file_path}")
else:
print(f"File not found, skipping: {file_path}")

# Remove dist/ directory
if os.path.exists('dist'):
shutil.rmtree('dist')
# Remove the tracking file itself
os.remove(TRACK_FILE)
print(f"Removed tracking file: {TRACK_FILE}")
else:
print(f"No {TRACK_FILE} found, skipping proto cleanup.")

# Remove *.egg-info/ directories
egg_info_directories = [d for d in os.listdir() if d.endswith('.egg-info')]
for egg_info_directory in egg_info_directories:
shutil.rmtree(egg_info_directory)
# -----------------------------------
# Remove all __pycache__ directories
# -----------------------------------
for root, dirs, _ in os.walk("."):
for d in dirs:
if d == "__pycache__":
cache_path = os.path.join(root, d)
shutil.rmtree(cache_path)
print(f"Removed __pycache__: {cache_path}")


if __name__ == "__main__":
clean_project()
print("Cleanup complete.")
30 changes: 30 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
SPDX-FileCopyrightText: Copyright (c) 2025 Contributors to the
Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-FileType: SOURCE
SPDX-License-Identifier: Apache-2.0
"""

# Input location of protofile
PROTO_DIR = "up-spec/up-core-api"

# Output location of the proto
OUTPUT_DIR = "."

# The list of generated files
TRACK_FILE = "generated_proto_files.txt"
78 changes: 78 additions & 0 deletions generate_proto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
SPDX-FileCopyrightText: 2025 Contributors to the Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.

This program and the accompanying materials are made available under the
terms of the Apache License Version 2.0 which is available at

http://www.apache.org/licenses/LICENSE-2.0

SPDX-License-Identifier: Apache-2.0
"""

import os

import pkg_resources
from grpc_tools import protoc

from config import OUTPUT_DIR, PROTO_DIR, TRACK_FILE

# Add google protobuf include path
PROTOBUF_INCLUDE = pkg_resources.resource_filename('grpc_tools', '_proto')


def generate_all_protos():
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)

generated_files = []

for root, _, files in os.walk(PROTO_DIR):
for file in files:
if file.endswith(".proto"):
proto_file = os.path.join(root, file)
print(f"Compiling {proto_file}...")

result = protoc.main(
[
'',
f'-I{PROTO_DIR}',
f'-I{PROTOBUF_INCLUDE}',
f'--python_out={OUTPUT_DIR}',
f'--grpc_python_out={OUTPUT_DIR}',
proto_file,
]
)

if result != 0:
print(f"Failed to compile {proto_file}")
else:
print(f"Compiled {proto_file} successfully.")
base_name = os.path.splitext(file)[0]
rel_dir = os.path.relpath(root, PROTO_DIR)
output_dir = os.path.join(OUTPUT_DIR, rel_dir)

generated_files.append(os.path.join(output_dir, f"{base_name}_pb2.py"))
generated_files.append(os.path.join(output_dir, f"{base_name}_pb2_grpc.py"))

# Ensure __init__.py in all generated proto folders
for root, dirs, _ in os.walk(OUTPUT_DIR):
if '.git' in root or os.path.commonpath([root, PROTO_DIR]) == PROTO_DIR:
continue
init_file = os.path.join(root, '__init__.py')
if not os.path.exists(init_file):
open(init_file, 'a').close()
print(f"Created {init_file}")
generated_files.append(init_file)

# Write generated files to track file
with open(TRACK_FILE, "w") as f:
for path in generated_files:
f.write(f"{path}\n")
print(f"Tracked {len(generated_files)} generated files in {TRACK_FILE}")


if __name__ == "__main__":
generate_all_protos()
46 changes: 25 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
[tool.poetry]
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "up-python"
version = "0.2.0-dev"
description = "Language specific uProtocol library for building and using UUri, UUID, UAttributes, UTransport, and more."
authors = ["Neelam Kushwah <neelam.kushwah@gm.com>"]
license = "The Apache License, Version 2.0"
readme = "README.adoc"
repository = "https://github.com/eclipse-uprotocol/up-python"
packages = [{ include = "uprotocol" },
{ include = "tests" },
{ include = "scripts" }
authors = [{ name = "Eclipse Foundation uProtocol Project", email = "uprotocol-dev@eclipse.org" }]
license = { file = "LICENSE" }
readme = { file = "README.adoc", content-type = "text/asciidoc" }

dependencies = [
"cloudevents",
"googleapis-common-protos>=1.56.4",
"protobuf>=4.24.2",
"grpcio>=1.60.0",
"grpcio-tools>=1.60.0"
]

[tool.poetry.dependencies]
python = "^3.8"
cloudevents = "*"
gitpython = ">=3.1.41"
googleapis-common-protos = ">=1.56.4"
protobuf = "4.24.2"
pytest = ">=6.2.5"
pytest-asyncio = ">=0.15.1"
coverage = ">=6.5.0"
pytest-timeout = ">=1.4.2"
[project.urls]
Repository = "https://github.com/eclipse-uprotocol/up-python"

[project.optional-dependencies]
dev = [
"pytest>=6.2.5",
"pytest-asyncio>=0.15.1",
"coverage>=6.5.0",
"pytest-timeout>=1.4.2"
]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.setuptools.packages.find]
include = ["uprotocol*", "tests*", "scripts*"]
Loading