-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(gemini-image): v0.2.0 major refactor with modular architecture #20
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
base: main
Are you sure you want to change the base?
Changes from all commits
c4e0e82
e786721
d1e7eca
ca1044d
228f081
f2b5793
c889da6
d665a68
b361162
40b52a8
5c2eba6
17943f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,31 @@ test_patterns = [ | |
| "**/*.spec.*", | ||
| ] | ||
|
|
||
| # ============================================================================ | ||
| # Issue Triage - Rule-level Ignores | ||
| # ============================================================================ | ||
| # Ignore Bandit B101 (assert_used) in test files - pytest uses assert statements | ||
| [[triage]] | ||
| match.plugins = ["bandit"] | ||
| match.rules = ["bandit:B101"] | ||
| match.file_patterns = [ | ||
| "**/tests/**", | ||
| "**/test_*.py", | ||
| "**/*_test.py", | ||
| ] | ||
| set.ignored = true | ||
|
|
||
| # Ignore Bandit B108 (hardcoded_tmp_directory) in test files - test fixtures use /tmp | ||
| [[triage]] | ||
| match.plugins = ["bandit"] | ||
| match.rules = ["bandit:B108"] | ||
| match.file_patterns = [ | ||
| "**/tests/**", | ||
| "**/test_*.py", | ||
| "**/*_test.py", | ||
| ] | ||
| set.ignored = true | ||
|
|
||
| # Default source for plugin definitions | ||
| [[source]] | ||
| name = "default" | ||
|
|
@@ -72,17 +97,8 @@ default = true | |
| [smells] | ||
| # Mode: comment (add PR comments) vs block (fail CI) | ||
| mode = "comment" | ||
|
|
||
| # Ignore complexity warnings for files with documented intentional complexity | ||
| [[smells.ignore]] | ||
| rules = [ | ||
| "function-complexity", | ||
| "function-parameters", | ||
| "nested-control-flow", | ||
| ] | ||
| file_patterns = [ | ||
| "**/gemini_image/generator.py", | ||
| ] | ||
| # Note: Complexity warnings for gemini_image/generator.py are intentional | ||
| # and documented in the file header. Use exclude_patterns at top level if needed. | ||
|
|
||
|
Comment on lines
97
to
102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Below is a concise recipe for configuring Qlty to exclude files, suppress/adjust smell (complexity) rules, and triage specific issues in .qlty/qlty.toml.
References
If you want, I can produce a ready-to-drop .qlty/qlty.toml example tailored to your repo (languages, complexity thresholds, and globs). Use Line 101–102 suggests using [[triage]]
match.file_patterns = ["gemini_image/generator.py"]
match.plugins = ["smells"]
set.ignored = trueThis suppresses smells for that file without removing it from other analyses. 🤖 Prompt for AI Agents |
||
| # Boolean logic complexity | ||
| [smells.boolean_logic] | ||
|
|
@@ -145,15 +161,6 @@ drivers = ["lint"] | |
| name = "bandit" | ||
| mode = "comment" | ||
|
|
||
| # Ignore B101 (assert_used) in test files - pytest uses assert statements | ||
| [[plugin.ignore]] | ||
| rule = "bandit:B101" | ||
| file_patterns = [ | ||
| "**/tests/**", | ||
| "**/test_*.py", | ||
| "**/*_test.py", | ||
| ] | ||
|
|
||
| # Shell script linting (comment mode - script styling preferences) | ||
| [[plugin]] | ||
| name = "shellcheck" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| # python-libs cloudflare-auth Package Fixes Needed | ||
|
|
||
| **Status**: Critical - Package cannot be used as a dependency | ||
| **Discovered**: 2025-12-06 during homelab-infra migration | ||
| **Reporter**: Claude Code (via ByronWilliams) | ||
|
|
||
| --- | ||
|
|
||
| ## Summary | ||
|
|
||
| The `byronwilliamscpa-cloudflare-auth` package has broken imports that prevent it from being used | ||
| as a dependency in other projects. This violates the core purpose of python-libs as a shared | ||
| library repository. | ||
|
|
||
| ## Issues Found | ||
|
|
||
| ### 1. ✅ FIXED LOCALLY: Incorrect Import Statements (21+ occurrences) | ||
|
|
||
| **Problem**: Module imports use `src.cloudflare_auth` instead of `cloudflare_auth` | ||
|
|
||
| **Status**: Fixed locally in this clone (not committed) | ||
|
|
||
| **Files Affected**: | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/__init__.py` | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/middleware.py` | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/middleware_enhanced.py` | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/validators.py` | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/redis_sessions.py` | ||
| - And potentially others | ||
|
|
||
| **Example**: | ||
|
|
||
| ```python | ||
| # Incorrect (current in repo) | ||
| from src.cloudflare_auth.models import CloudflareUser | ||
| from src.cloudflare_auth.middleware import CloudflareAuthMiddleware | ||
|
|
||
| # Correct (fixed locally) | ||
| from cloudflare_auth.models import CloudflareUser | ||
| from cloudflare_auth.middleware import CloudflareAuthMiddleware | ||
| ``` | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| **Fix Applied**: | ||
|
|
||
| ```bash | ||
| cd packages/cloudflare-auth | ||
| find src -name "*.py" -exec sed -i 's/from src\.cloudflare_auth/from cloudflare_auth/g' {} \; | ||
| find src -name "*.py" -exec sed -i 's/import src\.cloudflare_auth/import cloudflare_auth/g' {} \; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 2. ❌ NOT FIXED: Missing CloudflareSettings Module | ||
|
|
||
| **Problem**: Multiple files import from non-existent `src.config.settings` module | ||
|
|
||
| **Files Affected**: | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/validators.py:40` | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/middleware.py` | ||
| - `packages/cloudflare-auth/src/cloudflare_auth/middleware_enhanced.py` | ||
|
|
||
| **Import Statement**: | ||
|
|
||
| ```python | ||
| from src.config.settings import CloudflareSettings, get_cloudflare_settings | ||
| ``` | ||
|
|
||
| **Problem**: This module doesn't exist in the cloudflare-auth package | ||
|
|
||
| **Options for Resolution**: | ||
|
|
||
| #### Option A: Create CloudflareSettings within package (RECOMMENDED) | ||
|
|
||
| ```python | ||
| # packages/cloudflare-auth/src/cloudflare_auth/settings.py | ||
| from pydantic_settings import BaseSettings | ||
|
|
||
| class CloudflareSettings(BaseSettings): | ||
| """Cloudflare Access configuration settings.""" | ||
|
|
||
| cloudflare_team_domain: str | ||
| cloudflare_audience_tag: str | ||
| cloudflare_enabled: bool = True | ||
| service_token_enabled: bool = False | ||
| # ... other settings | ||
|
|
||
| class Config: | ||
| env_file = ".env" | ||
|
|
||
| def get_cloudflare_settings() -> CloudflareSettings: | ||
| """Get singleton CloudflareSettings instance.""" | ||
| return CloudflareSettings() | ||
| ``` | ||
|
|
||
| Then update imports: | ||
|
|
||
| ```python | ||
| # In validators.py, middleware.py, middleware_enhanced.py | ||
| from cloudflare_auth.settings import CloudflareSettings, get_cloudflare_settings | ||
| ``` | ||
|
|
||
| #### Option B: Make settings injectable (alternative) | ||
|
|
||
| Remove direct settings import and require settings to be passed as parameters: | ||
|
|
||
| ```python | ||
| # In validators.py | ||
| class CloudflareJWTValidator: | ||
| def __init__(self, team_domain: str, audience_tag: str): | ||
| self.team_domain = team_domain | ||
| self.audience_tag = audience_tag | ||
| ``` | ||
|
|
||
| **Recommendation**: Option A is preferred for backward compatibility and ease of use. | ||
|
|
||
| --- | ||
|
|
||
| ## Root Cause | ||
|
|
||
| The package appears to have been copied from a different project structure where it was nested under `src/` with a separate `src/config/` module. When moved to the python-libs monorepo structure, imports were not updated to reflect the new package structure. | ||
|
|
||
| --- | ||
|
|
||
| ## Impact | ||
|
|
||
| **Current State**: | ||
| - ❌ Package cannot be imported: `ModuleNotFoundError: No module named 'src.config'` | ||
| - ❌ Cannot be used as a dependency in other projects | ||
| - ❌ Forces code duplication instead of reuse | ||
| - ❌ Violates the stated purpose of python-libs repository | ||
|
|
||
| **Blocked Projects**: | ||
| - homelab-infra (PR #54) - waiting for these fixes before tests can run | ||
|
|
||
| --- | ||
|
|
||
| ## Action Items | ||
|
|
||
| ### Immediate (Required for PR #54) | ||
|
|
||
| 1. **Commit local import fixes**: | ||
|
|
||
| ```bash | ||
| cd packages/cloudflare-auth | ||
| git add src/cloudflare_auth/*.py | ||
| git commit -m "fix: correct all module imports from src.cloudflare_auth to cloudflare_auth" | ||
| ``` | ||
|
|
||
| 2. **Create CloudflareSettings module**: | ||
| - Create `src/cloudflare_auth/settings.py` | ||
| - Define `CloudflareSettings` and `get_cloudflare_settings` | ||
| - Update imports in affected files | ||
| - Test imports work correctly | ||
|
|
||
| 3. **Add import tests**: | ||
|
|
||
| ```python | ||
| # tests/test_imports.py | ||
| def test_public_imports(): | ||
| """Verify all public imports work correctly.""" | ||
| from cloudflare_auth import ( | ||
| CloudflareAuthMiddleware, | ||
| CloudflareUser, | ||
| setup_cloudflare_auth_enhanced, | ||
| ) | ||
| assert CloudflareAuthMiddleware is not None | ||
| ``` | ||
|
|
||
| 4. **Add CI check**: | ||
|
|
||
| ```yaml | ||
| # .github/workflows/ci.yml | ||
| - name: Test package imports | ||
| run: | | ||
| uv run python -c "from cloudflare_auth import CloudflareUser" | ||
| ``` | ||
|
|
||
| ### Follow-up (Before PyPI Publication) | ||
|
|
||
| 5. **Publish to PyPI**: | ||
| - Once fixes are complete and tests pass | ||
| - Follow semantic versioning (v0.1.1 for patch) | ||
| - Update homelab-infra to use PyPI package instead of path dependency | ||
|
|
||
| 6. **Update template**: | ||
| - Add import tests to cookiecutter-python-template | ||
| - Ensure packages in workspace members have validated imports | ||
|
|
||
| --- | ||
|
Comment on lines
+139
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, check the repository structure
git ls-files | head -20Repository: ByronWilliamsCPA/python-libs Length of output: 766 🏁 Script executed: # Verify the cloudflare-auth package directory structure
if [ -d "packages/cloudflare-auth" ]; then
echo "✓ cloudflare-auth package exists"
find packages/cloudflare-auth -type f -name "*.py" | head -20
else
echo "✗ cloudflare-auth package not found"
fiRepository: ByronWilliamsCPA/python-libs Length of output: 1204 🏁 Script executed: # Check for settings.py and examine FIXES_NEEDED.md
if [ -f "FIXES_NEEDED.md" ]; then
echo "✓ FIXES_NEEDED.md exists"
echo "Checking lines 139-189:"
sed -n '139,189p' FIXES_NEEDED.md
fiRepository: ByronWilliamsCPA/python-libs Length of output: 1526 🏁 Script executed: # Check if docs/secure.md exists and examine it
if [ -f "docs/secure.md" ]; then
echo "✓ docs/secure.md exists"
grep -n "CloudflareSettings" docs/secure.md | head -10
else
echo "✗ docs/secure.md not found"
fiRepository: ByronWilliamsCPA/python-libs Length of output: 481 🏁 Script executed: # Check the actual package structure
if [ -d "packages/cloudflare-auth/src/cloudflare_auth" ]; then
echo "Contents of packages/cloudflare-auth/src/cloudflare_auth:"
ls -la packages/cloudflare-auth/src/cloudflare_auth/
else
echo "✗ Expected directory not found"
fiRepository: ByronWilliamsCPA/python-libs Length of output: 1194 🏁 Script executed: # Check what's exported from __init__.py
echo "=== __init__.py contents ==="
cat -n packages/cloudflare-auth/src/cloudflare_auth/__init__.pyRepository: ByronWilliamsCPA/python-libs Length of output: 3720 🏁 Script executed: # Check if test_imports.py exists
if [ -f "packages/cloudflare-auth/tests/test_imports.py" ]; then
echo "✓ test_imports.py exists"
cat -n packages/cloudflare-auth/tests/test_imports.py
else
echo "✗ test_imports.py does not exist (action item 3 proposes creating it)"
fiRepository: ByronWilliamsCPA/python-libs Length of output: 141 🏁 Script executed: # Check settings.py to verify CloudflareSettings and get_cloudflare_settings are defined
echo "=== settings.py first 50 lines ==="
head -50 packages/cloudflare-auth/src/cloudflare_auth/settings.pyRepository: ByronWilliamsCPA/python-libs Length of output: 1714 🏁 Script executed: # Check existing CI workflows
if [ -d ".github/workflows" ]; then
echo "=== CI Workflow files ==="
ls -la .github/workflows/
else
echo "✗ .github/workflows not found"
fiRepository: ByronWilliamsCPA/python-libs Length of output: 1379 🏁 Script executed: # Check if the CI check already exists for imports
if [ -f ".github/workflows/ci.yml" ]; then
echo "=== Checking for 'Test package imports' in ci.yml ==="
grep -n "Test package imports" .github/workflows/ci.yml || echo "Not found"
fiRepository: ByronWilliamsCPA/python-libs Length of output: 135 🏁 Script executed: # Check ci.yml to understand the current test structure and find where the import test should be added
cat -n .github/workflows/ci.yml | head -100Repository: ByronWilliamsCPA/python-libs Length of output: 3968 🏁 Script executed: # Verify that CloudflareSettings and get_cloudflare_settings are actually exported and importable
grep -n "get_cloudflare_settings" packages/cloudflare-auth/src/cloudflare_auth/settings.pyRepository: ByronWilliamsCPA/python-libs Length of output: 128 🏁 Script executed: # Check if CloudflareSettings and get_cloudflare_settings are exported from __init__.py
grep "CloudflareSettings\|get_cloudflare_settings" packages/cloudflare-auth/src/cloudflare_auth/__init__.pyRepository: ByronWilliamsCPA/python-libs Length of output: 54 🏁 Script executed: # Verify test_settings.py already exists and what it covers
if [ -f "packages/cloudflare-auth/tests/test_settings.py" ]; then
echo "✓ test_settings.py exists"
wc -l packages/cloudflare-auth/tests/test_settings.py
head -40 packages/cloudflare-auth/tests/test_settings.py
fiRepository: ByronWilliamsCPA/python-libs Length of output: 1422 🏁 Script executed: # Check docs/secure.md to see what the intended migration path is for CloudflareSettings
echo "=== docs/secure.md sections about CloudflareSettings ==="
grep -B2 -A2 "CloudflareSettings" docs/secure.md | head -50Repository: ByronWilliamsCPA/python-libs Length of output: 859 🏁 Script executed: # Check if settings should be in __all__ by looking at the full settings.py
tail -20 packages/cloudflare-auth/src/cloudflare_auth/settings.pyRepository: ByronWilliamsCPA/python-libs Length of output: 705 🏁 Script executed: # Verify the actual line count of FIXES_NEEDED.md to understand the context
wc -l FIXES_NEEDED.mdRepository: ByronWilliamsCPA/python-libs Length of output: 91 🏁 Script executed: # Check the markdown line length guideline compliance for FIXES_NEEDED.md around lines 139-189
sed -n '139,189p' FIXES_NEEDED.md | awk '{print length, $0}' | sort -rn | head -10Repository: ByronWilliamsCPA/python-libs Length of output: 723 🏁 Script executed: # Check if the proposed test imports would actually work - verify CloudflareSettings is NOT exported
echo "=== Checking __all__ exports from __init__.py ==="
grep -A 50 "__all__" packages/cloudflare-auth/src/cloudflare_auth/__init__.pyRepository: ByronWilliamsCPA/python-libs Length of output: 899 🏁 Script executed: # Try to verify if importing the proposed items would work
python3 << 'EOF'
import sys
import os
# Simulate what the test would do
try:
# This should work
from cloudflare_auth import CloudflareUser
print("✓ Can import CloudflareUser")
except ImportError as e:
print(f"✗ Cannot import CloudflareUser: {e}")
try:
# This should work
from cloudflare_auth import CloudflareAuthMiddleware
print("✓ Can import CloudflareAuthMiddleware")
except ImportError as e:
print(f"✗ Cannot import CloudflareAuthMiddleware: {e}")
try:
# This should work
from cloudflare_auth import setup_cloudflare_auth_enhanced
print("✓ Can import setup_cloudflare_auth_enhanced")
except ImportError as e:
print(f"✗ Cannot import setup_cloudflare_auth_enhanced: {e}")
try:
# This might NOT work - check if CloudflareSettings is exported
from cloudflare_auth import CloudflareSettings
print("✓ Can import CloudflareSettings from cloudflare_auth")
except ImportError as e:
print(f"✗ Cannot import CloudflareSettings from cloudflare_auth: {e}")
try:
# This will work
from cloudflare_auth.settings import CloudflareSettings, get_cloudflare_settings
print("✓ Can import CloudflareSettings from cloudflare_auth.settings")
except ImportError as e:
print(f"✗ Cannot import from cloudflare_auth.settings: {e}")
EOFRepository: ByronWilliamsCPA/python-libs Length of output: 158 🏁 Script executed: # Look more carefully at the CI section to see if there's any import testing
grep -n "import\|Import\|test.*import" .github/workflows/ci.ymlRepository: ByronWilliamsCPA/python-libs Length of output: 54 🏁 Script executed: # Check if there are any remaining "src.cloudflare_auth" imports that should be "cloudflare_auth"
grep -r "from src\.cloudflare_auth\|from src\.config" packages/cloudflare-auth/src/ 2>/dev/null | grep -v ".pyc" || echo "No src. imports found"Repository: ByronWilliamsCPA/python-libs Length of output: 93 🏁 Script executed: # Check middleware.py and middleware_enhanced.py for import issues
head -30 packages/cloudflare-auth/src/cloudflare_auth/middleware.py | grep "^from\|^import"Repository: ByronWilliamsCPA/python-libs Length of output: 54 Action items 1–2 appear complete; items 3–4 (test_imports.py and CI check) remain pending. The steps correctly reference the cloudflare-auth package structure and align with docs/secure.md. Import fixes appear done (no However:
All referenced file paths and import statements match the actual module layout. Sequencing is sound and ready to implement. 🤖 Prompt for AI Agents |
||
|
|
||
| ## Files Changed Locally (Not Committed) | ||
|
|
||
| All files in `packages/cloudflare-auth/src/cloudflare_auth/`: | ||
| - `__init__.py` - Fixed imports and docstring | ||
| - `middleware.py` - Fixed imports | ||
| - `middleware_enhanced.py` - Fixed imports | ||
| - `validators.py` - Fixed imports | ||
| - `security_helpers.py` - Fixed imports | ||
| - `sessions.py` - Fixed imports | ||
| - `utils.py` - Fixed imports | ||
| - `whitelist.py` - Fixed imports | ||
| - `models.py` - Fixed imports | ||
| - `csrf.py` - Fixed imports | ||
| - `rate_limiter.py` - Fixed imports | ||
| - `redis_sessions.py` - Fixed imports | ||
|
|
||
| --- | ||
|
|
||
| ## Testing Verification | ||
|
|
||
| After fixes are applied, verify with: | ||
|
|
||
| ```bash | ||
| # 1. Clean install test | ||
| cd /tmp | ||
| uv venv test-env | ||
| source test-env/bin/activate | ||
| uv pip install /path/to/python-libs/packages/cloudflare-auth | ||
|
|
||
| # 2. Import test | ||
| python -c "from cloudflare_auth import CloudflareUser, setup_cloudflare_auth_enhanced" | ||
|
|
||
| # 3. Run package tests | ||
| cd /path/to/python-libs/packages/cloudflare-auth | ||
| uv run pytest tests/ -v | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Contact | ||
|
|
||
| For questions or to coordinate fixes: | ||
| - **Project**: homelab-infra (blocked PR #54) | ||
| - **Reporter**: Claude Code | ||
| - **Related**: [homelab-infra PR #54](https://github.com/ByronWilliamsCPA/homelab-infra/pull/54) | ||
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.
🧩 Analysis chain
🌐 Web query:
Qlty qlty.toml triage schema [[triage]] match.plugins match.rules match.file_patterns set.ignored💡 Result:
Short summary — meaning and usage of the qlty.toml triage keys you asked about:
Minimal example:
[[triage]]
[triage.match]
rules = ["eslint:react/prop-types"]
file_patterns = ["frontend/components/ui/**"]
[triage.set]
ignored = true
References:
🏁 Script executed:
Repository: ByronWilliamsCPA/python-libs
Length of output: 250
🏁 Script executed:
Repository: ByronWilliamsCPA/python-libs
Length of output: 242
🏁 Script executed:
Repository: ByronWilliamsCPA/python-libs
Length of output: 7460
🏁 Script executed:
Repository: ByronWilliamsCPA/python-libs
Length of output: 4215
Triage configuration has two issues: incorrect TOML syntax and ineffective rules due to Bandit excluding tests.
The
[[triage]]blocks use flat dot-notation keys (match.plugins,set.ignored) that don't match Qlty's documented schema, which requires nested[triage.match]and[triage.set]blocks. Additionally, these rules won't apply because Bandit is already configured inpyproject.tomlto exclude thetestsdirectory entirely (line 688:exclude_dirs = ["tests", ...]).Corrected triage syntax
📝 Committable suggestion
🤖 Prompt for AI Agents