Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move to z85base91 package #62

Merged
merged 3 commits into from
Jan 8, 2025
Merged

refactor: move to z85base91 package #62

merged 3 commits into from
Jan 8, 2025

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Jan 8, 2025

encoders moved to standalone package with optimized C implementation https://github.com/JarbasHiveMind/z85base91

closes #59

Summary by CodeRabbit

  • Dependency Changes

    • Added z85base91 package
    • Reintroduced py-cpuinfo
  • Encoding Module Updates

    • Deprecated current encoding implementations
    • Migrated encoding classes to z85base91 package
  • Workflow Changes

    • Removed GitHub Actions unit tests workflow
  • HTTP Client Updates

    • Added connection state management to HiveMindHTTPClient
  • Test Files

    • Removed test files for B91, Z85B, and Z85P encodings

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 48 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2ad8118 and 278a56e.

📒 Files selected for processing (2)
  • hivemind_bus_client/encodings/benchmark.py (1 hunks)
  • requirements.txt (1 hunks)

Walkthrough

This pull request involves a significant refactoring of the encoding modules within the hivemind_bus_client library. The primary change is migrating encoding implementations (Z85B, Z85P, B91) from the current library to an external package called z85base91. The changes include removing local encoding implementations, updating import statements across multiple files, adding deprecation warnings, and modifying the project's requirements. The unit test workflow and corresponding test files for these encodings have also been removed.

Changes

File Change Summary
.github/workflows/unit_tests.yml Removed GitHub Actions workflow for unit tests
hivemind_bus_client/encodings/__init__.py Updated imports with deprecation warning
hivemind_bus_client/encodings/b91.py Removed local implementation, imported from z85base91
hivemind_bus_client/encodings/z85b.py Removed local implementation, imported from z85base91
hivemind_bus_client/encodings/z85p.py Removed local implementation, imported from z85base91
hivemind_bus_client/encryption.py Updated encoding imports from z85base91
hivemind_bus_client/http_client.py Added self.connected threading event
requirements.txt Reintroduced py-cpuinfo, added z85base91
test/requirements.txt Removed test requirements file
test/test_b91.py, test/test_z85b.py, test/test_z85p.py Removed test files for encoding implementations

Assessment against linked issues

Objective Addressed Explanation
Adopt faster encodings from z85base91

Possibly related PRs

Poem

🐰 Hop, hop, encoding's new dance!
Z85base91 takes its stance
Old methods fade, new speed takes flight
Encodings leap with rabbit might
Swift and nimble, code transforms 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
hivemind_bus_client/encodings/z85b.py (1)

1-1: Unused import Z85B

The Z85B class is imported but not used within this module. This may lead to unnecessary resource usage and can be safely removed to clean up the code.

Apply this diff to remove the unused import:

-from z85base91 import Z85B

Alternatively, if you intend to re-export Z85B for backward compatibility, consider adding it to the module's public interface:

__all__ = ["Z85B"]
🧰 Tools
🪛 Ruff (0.8.2)

1-1: z85base91.Z85B imported but unused

Remove unused import: z85base91.Z85B

(F401)

hivemind_bus_client/encodings/z85p.py (1)

1-1: Unused import Z85P

The Z85P class is imported but not used within this module. Removing unused imports helps in maintaining clean code and optimizing resource usage.

Apply this diff to remove the unused import:

-from z85base91 import Z85P

If your intention is to re-export Z85P for backward compatibility, consider adding it to the module's public interface:

__all__ = ["Z85P"]
🧰 Tools
🪛 Ruff (0.8.2)

1-1: z85base91.Z85P imported but unused

Remove unused import: z85base91.Z85P

(F401)

hivemind_bus_client/z85b.py (1)

3-3: Unused import Z85B

The Z85B class is imported but not utilized within this module. It's advisable to remove unused imports to keep the codebase clean and efficient.

Apply this diff to remove the unused import:

-from z85base91 import Z85B

Alternatively, if you intend to re-export Z85B for backward compatibility, you can expose it through the module's public interface:

__all__ = ["Z85B"]

Or assign it directly for re-export:

Z85B = Z85B
🧰 Tools
🪛 Ruff (0.8.2)

3-3: z85base91.Z85B imported but unused

Remove unused import: z85base91.Z85B

(F401)

hivemind_bus_client/encodings/b91.py (1)

1-10: Consider adding migration guide documentation.

This refactoring to use the optimized C implementation in z85base91 is a good architectural decision. To ensure a smooth transition for users:

  1. Consider adding a migration guide in the README or documentation
  2. Include code examples showing how to update from the old to new package
  3. Document any performance improvements users can expect
🧰 Tools
🪛 Ruff (0.8.2)

1-1: z85base91.B91 imported but unused

Remove unused import: z85base91.B91

(F401)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89f4b2c and 2ad8118.

📒 Files selected for processing (14)
  • .github/workflows/unit_tests.yml (0 hunks)
  • hivemind_bus_client/encodings/__init__.py (1 hunks)
  • hivemind_bus_client/encodings/b91.py (1 hunks)
  • hivemind_bus_client/encodings/benchmark.py (2 hunks)
  • hivemind_bus_client/encodings/z85b.py (1 hunks)
  • hivemind_bus_client/encodings/z85p.py (1 hunks)
  • hivemind_bus_client/encryption.py (1 hunks)
  • hivemind_bus_client/http_client.py (4 hunks)
  • hivemind_bus_client/z85b.py (1 hunks)
  • requirements.txt (1 hunks)
  • test/requirements.txt (0 hunks)
  • test/test_b91.py (0 hunks)
  • test/test_z85b.py (0 hunks)
  • test/test_z85p.py (0 hunks)
💤 Files with no reviewable changes (5)
  • test/requirements.txt
  • test/test_b91.py
  • .github/workflows/unit_tests.yml
  • test/test_z85b.py
  • test/test_z85p.py
✅ Files skipped from review due to trivial changes (1)
  • hivemind_bus_client/encryption.py
🧰 Additional context used
🪛 Ruff (0.8.2)
hivemind_bus_client/z85b.py

3-3: z85base91.Z85B imported but unused

Remove unused import: z85base91.Z85B

(F401)

hivemind_bus_client/encodings/z85b.py

1-1: z85base91.Z85B imported but unused

Remove unused import: z85base91.Z85B

(F401)

hivemind_bus_client/encodings/__init__.py

1-1: z85base91.Z85B imported but unused

(F401)


1-1: z85base91.Z85P imported but unused

(F401)


1-1: z85base91.B91 imported but unused

(F401)

hivemind_bus_client/encodings/z85p.py

1-1: z85base91.Z85P imported but unused

Remove unused import: z85base91.Z85P

(F401)

hivemind_bus_client/encodings/b91.py

1-1: z85base91.B91 imported but unused

Remove unused import: z85base91.B91

(F401)

🔇 Additional comments (12)
hivemind_bus_client/encodings/z85b.py (1)

5-10: Deprecation warning is properly implemented

The deprecation warning correctly informs users about the deprecation and advises them to use the new package z85base91. The use of stacklevel=2 ensures that the warning points to the user's code, which is good practice.

hivemind_bus_client/encodings/z85p.py (1)

5-10: Deprecation warning is properly implemented

The deprecation warning appropriately notifies users about the deprecation and guides them to use the new package z85base91. Including stacklevel=2 in the warning ensures that the warning points to the user's code.

hivemind_bus_client/z85b.py (1)

8-8: Deprecation warning message updated correctly

The deprecation warning message has been updated to inform users about the deprecation and advise them to use the new package z85base91. This helps in a smooth transition for users relying on the old import path.

hivemind_bus_client/encodings/__init__.py (2)

1-1: LGTM! Import statement updated correctly.

The encoders are now imported from the z85base91 package as intended.

🧰 Tools
🪛 Ruff (0.8.2)

1-1: z85base91.Z85B imported but unused

(F401)


1-1: z85base91.Z85P imported but unused

(F401)


1-1: z85base91.B91 imported but unused

(F401)


5-10: Well-structured deprecation warning.

The warning effectively communicates the deprecation and provides clear guidance for users to update their code.

hivemind_bus_client/encodings/benchmark.py (2)

182-182: Increased iterations for more accurate benchmarking.

Changing default iterations from 20 to 1000 will provide more statistically significant results.


266-276: Review benchmark results showing performance tradeoffs.

The benchmark results show:

  • JSON-B64 variants lead in performance but have higher size overhead
  • z85base91 implementations (B91, Z85B, Z85P) offer better bandwidth efficiency but lower performance
  • This aligns with the PR objective of providing optimized implementations with different tradeoffs
hivemind_bus_client/http_client.py (3)

76-76: Good addition of connection state management.

Using threading.Event for connection state tracking improves thread safety and robustness.


257-258: Connection state validation added consistently.

Connection checks are properly added to emit, get_messages, and get_binary_messages methods with clear error messages.

Also applies to: 350-351, 360-361


337-337: TODO comment needs implementation.

The TODO comment indicates that the connection state is set without validating the POST request response.

Would you like me to provide an implementation for proper connection state validation based on the response?

hivemind_bus_client/encodings/b91.py (2)

4-10: Well-implemented deprecation warning!

The deprecation warning is clear, informative, and follows best practices:

  • Clearly indicates what's deprecated
  • Provides migration instructions
  • Uses correct warning category
  • Sets appropriate stacklevel

1-2: Verify the purpose of importing B91.

While static analysis flags B91 as unused, this import might be necessary for maintaining backward compatibility during the transition period. Please confirm if this is intentional.

Run this script to check if this module is re-exporting B91:

✅ Verification successful

The B91 import is correctly used as part of the deprecation strategy

The import is intentional and serves as part of the transition to the z85base91 package. The module re-exports B91 through __init__.py while warning users to update their imports. This maintains backward compatibility for existing code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if B91 is re-exported in __init__.py
rg -l "from.*b91.*import.*B91" "hivemind_bus_client/encodings/__init__.py"

# Check for any direct imports of B91 from this module
rg -l "from.*hivemind_bus_client.encodings.b91.*import.*B91" 

Length of output: 137


Script:

#!/bin/bash
# View complete content of b91.py
cat hivemind_bus_client/encodings/b91.py

# Search for any B91-related patterns
rg "B91" --type py

# Check __init__.py content for any re-exports
cat hivemind_bus_client/encodings/__init__.py

Length of output: 2084

🧰 Tools
🪛 Ruff (0.8.2)

1-1: z85base91.B91 imported but unused

Remove unused import: z85base91.B91

(F401)

requirements.txt Outdated Show resolved Hide resolved
@JarbasAl JarbasAl merged commit c6febbf into dev Jan 8, 2025
1 check passed
@JarbasAl JarbasAl deleted the z85base91 branch January 8, 2025 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faster encodings
1 participant