Skip to content

Commit e8bcd79

Browse files
authored
chore: Restructure dependencies and add optional extras (hiero-ledger#1679)
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent f288a3a commit e8bcd79

13 files changed

Lines changed: 374 additions & 20 deletions

File tree

.github/workflows/deps-check.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Dependency Compatibility Check
2+
3+
on:
4+
push:
5+
paths:
6+
- "pyproject.toml"
7+
pull_request:
8+
paths:
9+
- "pyproject.toml"
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
min-deps:
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
python-version: ["3.10", "3.14"]
23+
24+
steps:
25+
- name: Harden the runner (Audit all outbound calls)
26+
uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
27+
with:
28+
egress-policy: audit
29+
30+
- name: Checkout repository
31+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
32+
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
cache: "pip"
38+
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@803947b9bd8e9f986429fa0c5a41c367cd732b41 # v7.2.1
41+
42+
- name: Create virtual environment
43+
run: uv venv
44+
45+
- name: Install minimum dependencies and tooling
46+
run: |
47+
uv sync --all-extras --resolution=lowest-direct
48+
49+
- name: Show resolved core dependency versions
50+
run: |
51+
echo "Resolved core dependency versions:"
52+
PATTERN='^(
53+
protobuf|
54+
grpcio|
55+
cryptography|
56+
requests|
57+
pycryptodome|
58+
eth-abi|
59+
python-dotenv|
60+
eth-keys|
61+
rlp|
62+
grpcio-tools|
63+
ruff|
64+
mypy|
65+
typing-extensions|
66+
pytest
67+
)\s'
68+
uv pip list | grep -E "$(echo "$PATTERN" | tr -d '\n ')"
69+
70+
- name: Generate Proto Files
71+
run: |
72+
uv run python generate_proto.py
73+
74+
- name: Run unit tests (min deps)
75+
run: |
76+
uv run pytest tests/unit -v

.github/workflows/pr-check-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
uses: astral-sh/setup-uv@803947b9bd8e9f986429fa0c5a41c367cd732b41
2828

2929
- name: Install dependencies
30-
run: uv sync
30+
run: uv sync --all-extras
3131

3232
- name: Generate Proto Files
3333
run: uv run python generate_proto.py

.github/workflows/pr-check-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
python-version: ["3.10", "3.11", "3.12", "3.13"]
21+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
2222

2323
steps:
2424
- name: Harden the runner (Audit all outbound calls)

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
151151
- Added `/working` command to reset the inactivity timer on issues and PRs. ([#1552](https://github.com/hiero-ledger/hiero-sdk-python/issues/1552))
152152
- Added `grpc_deadline` support for transaction and query execution.
153153
- Type hints to exception classes (`PrecheckError`, `MaxAttemptsError`, `ReceiptStatusError`) constructors and string methods.
154+
- Added `__eq__` and `__hash__` functions for Keys.
154155

155156
### Documentation
156157
- Fix relative links in `testing.md`, clean up `CONTRIBUTING.md` TOC, and normalize test file naming and paths (`#1706`)
@@ -258,6 +259,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
258259
- chore: update merge conflict bot message with web editor tips (#1592)
259260
- chore: update MAINTAINERS.md to include new maintainer Manish Dait and sort maintainers by GitHub ID. (#1691)
260261
- chore: clarify wording in the bot-assignment-check.sh (#1748)
262+
- Refactored SDK dependencies to use version ranges, moved build-only deps out of runtime, removed unused core deps and added optional extras.
263+
261264

262265
### Fixed
263266
- Corrected broken documentation links in SDK developer training files.(#1707)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
A Python SDK for interacting with the Hedera Hashgraph platform.
88

9+
>**Python compatibility:**
10+
> The SDK supports Python ≥ 3.10 and is tested on Python 3.10–3.14. Newer Python versions may work but have not yet been validated.
911
1012
## Quick Start
1113

docs/sdk_developers/examples.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ python examples/name_of_file.py
2424
python -m examples.name_of_module
2525
```
2626

27+
### Optional Dependencies for Examples
28+
29+
Some example scripts (notably those related to Ethereum / EVM functionality) require **optional dependencies** that are not installed by default.
30+
31+
If you encounter import errors related to Ethereum libraries, install the ETH extra before running those examples.
32+
33+
#### Using uv (recommended)
34+
35+
```bash
36+
uv sync --dev --extra eth
37+
```
38+
39+
#### Using pip
40+
41+
```bash
42+
pip install -e ".[eth]"
43+
```
44+
2745
You'll need your environment variables and uv set up as outlined in /README.md [README](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/README.md)
2846

2947

docs/sdk_developers/setup.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,35 @@ pip install -e .
144144

145145
**Note:** This method requires you to have Python 3.10+ already installed on your system. Changes to your local code will be immediately reflected when you import the SDK.
146146

147+
## Installing Optional Dependencies
148+
Some SDK features (such as Ethereum-related functionality) rely on optional dependencies that are not installed by default.
149+
150+
These optional dependencies are required for:
151+
- Integration tests covering ETH-specific features
152+
- Running ETH-related example scripts
153+
154+
Optional dependencies are provided via **extras**.
155+
156+
#### Using pip
157+
To install the SDK for local development with Ethereum support enabled:
158+
```bash
159+
pip install -e ".[eth]"
160+
```
161+
162+
#### Using uv (recommended)
163+
For most contributors, start with the standard development environment:
164+
```bash
165+
uv sync
166+
```
167+
If you are working on ETH functionality, running ETH-related tests, or executing ETH examples, install the ETH extra explicitly:
168+
```bash
169+
uv sync --dev --extra eth
170+
```
171+
172+
Optional: To install all available extras (useful full-matrix testing):
173+
```bash
174+
uv sync --dev --all-extras
175+
```
147176

148177
## Generate Protocol Buffers
149178

docs/sdk_developers/testing.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,36 @@ TOPIC_ID=0.0.1234569
235235

236236
---
237237

238+
### Optional Dependencies for Tests
239+
240+
Some unit and integration tests (notably those covering Ethereum / EVM
241+
functionality) rely on **optional ETH-related dependencies**. These
242+
dependencies are **not installed by default**.
243+
244+
If these dependencies are missing ETH-related unit tests may fail with import errors.
245+
246+
These dependencies are provided via the `eth` extra.
247+
248+
#### Using uv (recommended)
249+
250+
When working on the SDK locally and running the full test suite:
251+
252+
```bash
253+
uv sync --dev --extra eth
254+
```
255+
This installs:
256+
- All standard development dependencies (pytest, ruff, mypy, etc.)
257+
- All ETH-related optional dependencies required for tests and examples
258+
259+
#### Using pip
260+
If you are using pip instead of uv:
261+
262+
```bash
263+
pip install -e ".[eth]"
264+
```
265+
266+
This ensures all ETH-related test code paths execute correctly during development.
267+
238268
### VS Code Setup
239269

240270
VS Code provides excellent Python testing support with built-in test discovery and debugging.

pyproject.toml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ authors = [
1212
]
1313
license = { file = "LICENSE" }
1414
readme = "README.md"
15-
requires-python = ">=3.10, <3.14"
15+
requires-python = ">=3.10, <4"
1616
dependencies = [
17-
"grpcio-tools==1.76.0",
18-
"protobuf==6.33.2",
19-
"grpcio==1.76.0",
20-
"cryptography==44.0.0",
21-
"python-dotenv==1.2.1",
22-
"requests>=2.32.4",
23-
"pycryptodome==3.23.0",
24-
"eth-abi==5.2.0",
25-
"rlp>=4.0.0",
26-
"eth-keys==0.7.0",
17+
"protobuf>=4.21.12,<7",
18+
"grpcio>=1.76.0,<2",
19+
"cryptography>=44.0.1,<47",
20+
"requests>=2.31.0,<3",
21+
"pycryptodome>=3.18.0,<4",
22+
"eth-abi>=5.1.0,<6",
23+
"python-dotenv>=1.2.1,<3",
2724
]
2825
classifiers = [
2926
"Development Status :: 2 - Pre-Alpha",
@@ -32,27 +29,36 @@ classifiers = [
3229
"Programming Language :: Python :: 3.11",
3330
"Programming Language :: Python :: 3.12",
3431
"Programming Language :: Python :: 3.13",
32+
"Programming Language :: Python :: 3.14",
3533
"Operating System :: OS Independent",
3634
"Intended Audience :: Developers",
3735
"Topic :: Software Development :: Libraries",
3836
]
3937

38+
[project.optional-dependencies]
39+
eth = [
40+
"eth-keys>=0.7.0,<0.8",
41+
"rlp>=4.0.1,<5",
42+
]
43+
4044
[dependency-groups]
4145
dev = [
42-
"pytest>=8.3.4",
43-
"pytest-cov>=7.0.0",
46+
"grpcio-tools>=1.76.0,<2",
47+
"pytest>=8.3.4,<9",
48+
"pytest-cov>=7.0.0,<8",
4449
]
50+
4551
lint = [
46-
"ruff>=0.14.9",
47-
"mypy>=1.18.2",
48-
"typing-extensions>=4.15.0",
52+
"ruff>=0.14.9,<1",
53+
"mypy>=1.18.2,<2",
54+
"typing-extensions>=4.15.0,<5",
4955
]
5056

5157
[tool.uv]
5258
default-groups = ["dev", "lint"]
5359

5460
[build-system]
55-
requires = ["pdm-backend", "setuptools", "setuptools_scm"]
61+
requires = ["pdm-backend", "setuptools", "setuptools_scm", "grpcio-tools"]
5662
build-backend = "pdm.backend"
5763

5864
[tool.setuptools_scm]
@@ -72,7 +78,7 @@ testpaths = ["tests"]
7278

7379
[tool.ruff]
7480
line-length = 120
75-
target-version = "py310"
81+
target-version = "py314"
7682

7783
[tool.ruff.lint]
7884
select = [

src/hiero_sdk_python/crypto/private_key.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,20 @@ def _parse_legacy_ecdsa_der_key(key_bytes: bytes) -> "ec.EllipticCurvePrivateKey
469469
return ec.derive_private_key(private_int, ec.SECP256K1())
470470
except Exception as exc:
471471
raise ValueError(f"Failed to derive ECDSA private key: {exc}") from exc
472+
473+
def __eq__(self, other: object) -> bool:
474+
"""
475+
Compare two PrivateKey objects for equality.
476+
"""
477+
if not isinstance(other, PrivateKey):
478+
return NotImplemented
479+
480+
# Different algorithms can never be equal
481+
if self.is_ed25519() != other.is_ed25519():
482+
return False
483+
484+
return self.to_bytes_raw() == other.to_bytes_raw()
485+
486+
def __hash__(self) -> int:
487+
"""Returns the hash value for the private key."""
488+
return hash((self.is_ed25519(), self.to_bytes_raw()))

0 commit comments

Comments
 (0)