Skip to content

[GOOD FIRST ISSUE] Refactor AdapterFactory: Move plugin namespace check to a helper function #182

Description

@raphael-intugle

name: Good First Issue
about: A beginner-friendly task perfect for first-time contributors
title: '[GOOD FIRST ISSUE] Refactor AdapterFactory: Move plugin namespace check to a helper function'
labels: 'good first issue'
assignees: ''


Welcome! 👋

This is a beginner-friendly issue perfect for first-time contributors to the Intugle project. We've designed this task to help you get familiar with our codebase while making a meaningful contribution.

Task Description

Refactor the AdapterFactory class in src/intugle/adapters/factory.py to move the plugin namespace check logic into a dedicated helper function.

Currently, the __init__ method of AdapterFactory contains an inline check to ensure that plugin names start with "intugle.adapters.types.". For better readability and maintainability, this logic should be extracted into a separate function (e.g., is_safe_plugin_name(plugin_name: str) -> bool).

Why This Matters

  • Improves code readability and maintainability
  • Makes the plugin safety check reusable and easier to test
  • Encourages clean code practices for future contributors

What You'll Learn

  • How to refactor Python code for clarity
  • How to write and use helper functions
  • How to improve code maintainability in a real-world codebase

Step-by-Step Guide

Prerequisites

  • Python 3.10+ installed
  • Git basics (clone, commit, push, pull request)
  • Read our CONTRIBUTING.md guide

Setup Instructions

  1. Fork and clone the repository

    git clone https://github.com/YOUR_USERNAME/data-tools.git
    cd data-tools
  2. Create a virtual environment

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install dependencies

    pip install -e ".[dev]"
  4. Create a new branch

    git checkout -b fix/issue-XX-adapterfactory-plugin-helper

Implementation Steps

  1. In src/intugle/adapters/factory.py, define a new helper function (e.g., is_safe_plugin_name(plugin_name: str) -> bool) near the top of the file.
  2. Move the logic that checks if a plugin name starts with "intugle.adapters.types." into this function.
  3. Replace the inline check in the AdapterFactory.__init__ method with a call to this helper function.
  4. (Optional) Add a simple test for this helper function in the appropriate test file (if tests exist for this module).
  5. Ensure all existing tests pass.

Files to Modify

  • File: src/intugle/adapters/factory.py
    • Change: Extract plugin namespace check into a helper function and use it in AdapterFactory.__init__
    • Line(s): Around the __init__ method, and top-level for the new function

Testing Your Changes

# Run tests
pytest tests/

# Or run specific test
pytest tests/adapters/test_factory.py

Submitting Your Work

  1. Commit your changes

    git add .
    git commit -m "Refactor: move plugin namespace check to helper function in AdapterFactory"
  2. Push to your fork

    git push origin fix/issue-XX-adapterfactory-plugin-helper
  3. Create a Pull Request

    • Go to the original repository
    • Click "Pull Requests" → "New Pull Request"
    • Select your branch
    • Fill out the PR template
    • Reference this issue with "Fixes #XX"

Example Code

# Before
for _plugin in plugins:
    # Security check: Ensure the plugin is in the correct namespace
    if not _plugin.startswith("intugle.adapters.types."):
        print(f"Warning: Skipping potentially unsafe plugin '{_plugin}'.")
        continue

# After
def is_safe_plugin_name(plugin_name: str) -> bool:
    return plugin_name.startswith("intugle.adapters.types.")

for _plugin in plugins:
    if not is_safe_plugin_name(_plugin):
        print(f"Warning: Skipping potentially unsafe plugin '{_plugin}'.")
        continue

Expected Outcome

  • The plugin namespace check is now in a helper function.
  • The AdapterFactory code is cleaner and easier to understand.
  • All tests pass.

Definition of Done

  • Code changes implemented
  • Tests added/updated
  • Tests passing locally
  • Code follows project style guidelines
  • No new linter warnings
  • Documentation updated (if needed)
  • Pull request submitted

Resources

Need Help?

Don't hesitate to ask questions! We're here to help you succeed.

Skills You'll Use

  • Python basics
  • Git and GitHub
  • Testing with pytest (optional)
  • Other: Refactoring

Thank you for contributing to Intugle!

Tips for Success:

  • Take your time and read through everything carefully
  • Don't be afraid to ask questions
  • Test your changes before submitting
  • Have fun! 🎉

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions