-
Notifications
You must be signed in to change notification settings - Fork 0
Modernize packaging, tooling, and docs for ec_tools #10
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,3 @@ ec_tools.egg-info/ | |
|
|
||
| upload.sh | ||
| .*swp | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,25 @@ | ||
| repos: | ||
| # --- isort: import sorter --- | ||
| - repo: https://github.com/PyCQA/isort | ||
| rev: 5.13.2 | ||
| - repo: https://github.com/pycqa/isort | ||
| rev: 5.12.0 | ||
| hooks: | ||
| - id: isort | ||
| args: ["--profile", "black", "--line-length", "120"] | ||
| # --- autoflake: remove unused imports/vars --- | ||
| - repo: https://github.com/myint/autoflake | ||
| rev: v2.3.1 | ||
| args: ["--profile=black"] | ||
| name: isort (python) | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v5.0.0 | ||
| hooks: | ||
| - id: autoflake | ||
| args: [ | ||
| "--in-place", | ||
| "--remove-unused-variables", | ||
| "--remove-all-unused-imports", | ||
| ] | ||
| exclude: "__init__.py" | ||
| # --- Black: Python code formatter --- | ||
| - id: trailing-whitespace | ||
| - id: end-of-file-fixer | ||
| - id: check-yaml | ||
| - id: check-added-large-files | ||
| - repo: https://github.com/psf/black | ||
| rev: 24.8.0 # use a stable release | ||
| rev: 25.1.0 | ||
| hooks: | ||
| - id: black | ||
| language_version: python3 | ||
| args: ["--line-length=120"] | ||
| # --- YAML lint/format --- | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v5.0.0 | ||
| args: [--line-length=120] | ||
| - repo: https://github.com/myint/autoflake | ||
| rev: v2.3.1 | ||
| hooks: | ||
| - id: check-yaml | ||
|
|
||
| - id: autoflake | ||
| args: [ '--remove-all-unused-imports', '--in-place' ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| [MESSAGES CONTROL] | ||
| disable=missing-docstring,broad-exception-caught,too-many-return-statements,too-many-arguments,too-many-positional-arguments | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,76 @@ | ||
| # ec_tools | ||
|
|
||
| A lightweight Python toolbox for data modeling, SQLite DAOs, encrypted key-value storage, and small productivity utilities. | ||
|
|
||
| ## Highlights | ||
| - Data objects with JSON serialization and type-aware formatting. | ||
| - SQLite client + DAO layer with query generation. | ||
| - KV DAO with optional AES-backed encryption. | ||
| - Encryption helpers for bytes, chunks, and files. | ||
| - Utility helpers for IO, hashing, logging, and timing. | ||
|
|
||
| ## Requirements | ||
| - Python >= 3.12 | ||
|
|
||
| ## Install (from source) | ||
| ```bash | ||
| pip install -e . | ||
| ``` | ||
|
|
||
| ## Quick start | ||
| ### Encrypted KV storage with a KeyManager | ||
| ```python | ||
| from ec_tools.database import CipherKvDao, SqliteClient, SqliteKvDao | ||
| from ec_tools.tools.cipher import AesCipherGenerator | ||
| from ec_tools.tools.key_manager import KeyManager | ||
|
|
||
| sqlite_client = SqliteClient(":memory:") | ||
| kv_dao = SqliteKvDao(sqlite_client) | ||
| cipher_generator = AesCipherGenerator() | ||
| cipher_kv_dao = CipherKvDao(kv_dao, cipher_generator) | ||
|
|
||
| manager = KeyManager(cipher_kv_dao, "my-password") | ||
| manager.refresh_keys(["token", "cookie"]) | ||
| print(manager.get_key("token")) | ||
| ``` | ||
|
|
||
| ### Build headers from stored secrets | ||
| ```python | ||
| from ec_tools.tools.headers_manager import HeadersManager | ||
|
|
||
| headers = HeadersManager(manager, ["token"], {"User-Agent": "ec-tools"}).get() | ||
| print(headers) | ||
| ``` | ||
|
|
||
| ## Data objects | ||
| Define dataclasses that serialize to/from JSON with helpers for enums, lists, sets, and nested objects. | ||
| ```python | ||
| import dataclasses | ||
| from ec_tools.data import DataObject | ||
|
|
||
| @dataclasses.dataclass | ||
| class User(DataObject): | ||
| name: str | ||
| age: int | ||
|
|
||
| user = User.from_json({"name": "Ada", "age": "42"}) | ||
| print(user.to_json()) | ||
| ``` | ||
|
|
||
| ## Encryption helpers | ||
| - `AesCipher` for encrypting/decrypting bytes. | ||
| - Chunked and file-level encryption utilities in `ec_tools.tools.cipher`. | ||
|
|
||
| ## Project layout | ||
| - `ec_tools/data`: data-object helpers and JSON formatting. | ||
| - `ec_tools/database`: SQLite client, DAO, and KV DAO. | ||
| - `ec_tools/tools`: key/headers managers, cipher tools, thread pool. | ||
| - `ec_tools/utils`: IO, hashing, logging, and timing helpers. | ||
|
|
||
| ## Development | ||
| ```bash | ||
| pytest | ||
| ``` | ||
|
|
||
| ## License | ||
| MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,9 @@ | ||
| from .data_object import CustomizedJsonEncoder, DataObject, Formatter | ||
| from .json_type import JsonType | ||
|
|
||
| __all__ = [ | ||
| "CustomizedJsonEncoder", | ||
| "DataObject", | ||
| "Formatter", | ||
| "JsonType", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| from .thread_pool import CustomThreadPoolExecutor | ||
|
|
||
| __all__ = [ | ||
| "CustomThreadPoolExecutor", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| [build-system] | ||
| requires = [ | ||
| "setuptools>=61.0", | ||
| "wheel" | ||
| ] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "ec_tools" | ||
| version = "0.3.0" | ||
| description = "A collection of tool for EC." | ||
| readme = "README.md" | ||
| requires-python = ">=3.12" | ||
| license = { text = "MIT" } | ||
| dependencies = [ | ||
| "colorama==0.4.6", | ||
| "pycryptodome==3.20.0", | ||
| "setuptools==69.5.1", | ||
| ] | ||
| classifiers = [ | ||
| "Programming Language :: Python :: 3", | ||
| "License :: OSI Approved :: MIT License", | ||
| "Operating System :: OS Independent" | ||
| ] | ||
|
|
||
| [project.optional-dependencies] | ||
| dev = ["black"] | ||
|
|
||
| [tool.black] | ||
| line-length = 120 | ||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "pre-commit>=4.5.1", | ||
| ] | ||
|
|
||
| [tool.pytest.ini_options] | ||
| pythonpath = ["."] | ||
| testpaths = [ | ||
| "tests/" | ||
| ] | ||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["ec_tools"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| colorama==0.4.6 | ||
| pycryptodome==3.20.0 | ||
| setuptools==69.5.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
where = ["ec_tools"]makes setuptools search inside theec_tools/directory as the package root, so the built distribution will not include the top-levelec_toolspackage (it resolves subpackages likedata,database, etc. as top-level names instead). In an installed wheel/sdist, imports used throughout this repo and README (for exampleimport ec_tools.database) will fail, which breaks consumers after publishing.Useful? React with 👍 / 👎.