Skip to content

Conversation

@aditya-arolkar-swe
Copy link
Contributor

@aditya-arolkar-swe aditya-arolkar-swe commented Jan 26, 2026

Description

Refs: Requested by @aditya-arolkar-swe

Adds a generalized import_paths config option to the Python SDK generator that auto-loads user-defined files when the SDK is imported. This follows the same pattern as the Ruby SDK generator (PR #11264), but uses Pythonic naming (import_paths instead of requirePaths).

Link to Devin run: https://app.devin.ai/sessions/9e243bc5375e42018712dffa54f7546f

Changes Made

  • Added import_paths config option to SDKCustomConfig (array of strings)
  • Added _write_import_paths_hook() function in module_manager.py that writes import hooks at the end of root __init__.py
  • Updated Project class to pass import_paths and package_name to ModuleManager
  • Updated abstract_generator.py to read import_paths config and pass to Project
  • Added get_import_paths() method to CoreUtilities
  • Added test fixture exhaustive:import-paths to validate the feature
  • Added changelog entry for v4.53.0

Usage

Generator config:

generators:
  - name: fernapi/fern-python-sdk
    version: 4.53.0
    config:
      import_paths:
        - sentry_integration
        - custom_logging

Generated code in root __init__.py:

# Load user-defined files if present (e.g., for Sentry integration)
# Files are loaded from <package>/ if they exist
for _path in ["sentry_integration", "custom_logging"]:
    try:
        import_module(f".{_path}", "<package>")
    except ImportError:
        pass

Example user-defined sentry_integration.py:

# src/<your_package>/sentry_integration.py
# Add this file to .fernignore to preserve across regeneration

import sentry_sdk

def initialize_sentry():
    sentry_sdk.init(
        dsn="https://[email protected]/123456",
        traces_sample_rate=1.0,
    )

# Call at module level - runs once when SDK is first imported
initialize_sentry()

Human Review Checklist

  • Verify the generated __init__.py has the import hook at the end - check seed/python-sdk/exhaustive/import-paths/src/seed/__init__.py lines 64-70
  • Confirm this approach aligns with Ruby PR feat(ruby): add opt-in requirePaths config for auto-loading user files #11264 pattern (using try/except for graceful handling of missing files)
  • Verify the import_module import is available (already imported for lazy imports, conditionally added otherwise at line 236 of module_manager.py)
  • Verify package name computation handles package_path config correctly
  • Confirm config uses snake_case (import_paths) not kebab-case

Testing

  • Seed test exhaustive:import-paths passes
  • Pre-commit hooks pass (ruff formatting applied)
  • All CI checks pass
  • Generated SDK not fully tested (seed ran with --skip-scripts)

Updates Since Last Revision

  • Renamed require_paths to import_paths for more Pythonic naming (per reviewer feedback)
  • Removed kebab-case support (require-paths) - only snake_case (import_paths) is supported
  • Renamed fixture folder from require-paths to import-paths
  • Updated changelog to use import_paths terminology

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 2 commits January 26, 2026 22:07
Replace sentry-specific implementation with generalized require-paths config option.
This allows users to auto-load custom code files when the SDK is imported.

Changes:
- Add require_paths config option to SDKCustomConfig (array of strings)
- Add import hook at end of main __init__.py to auto-load specified files
- Remove sentry-specific code (SentryIntegrationConfig, sentry_integration.py template)
- Update test fixture from sentry-integration to require-paths
- Update versions.yml with changelog entry

Co-Authored-By: [email protected] <[email protected]>
@devin-ai-integration devin-ai-integration bot changed the title feat(python): add sentry-integration config option for error tracking feat(python): add require-paths config for custom code integration Jan 26, 2026
if generator_config.custom_config is not None:
# Support both hyphenated and underscored versions
require_paths = generator_config.custom_config.get(
"require_paths", generator_config.custom_config.get("require-paths")
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's remove all the kebab-case support. We don't do it elsewhere in the python generator so I think it's just confusing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think require_paths is the right term here? It was a bit confusing to me that we import from a require_path (require IMO is not a python term) and then idk how package_name relates

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point! I used require_paths to match the Ruby SDK's requirePaths config option for consistency across generators (as requested in the original task to duplicate Ruby PR #11264).

However, you're right that "require" is more of a Ruby term. A more Pythonic name would be import_paths or auto_import_paths.

Regarding package_name - it's used in the generated import statement: import_module(f".{_path}", "seed") where "seed" is the package name. The .{_path} is a relative import within that package.

Would you prefer I rename this to import_paths for better Python semantics? Happy to make that change if so.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, import_paths is PERFECT!!

Copy link
Contributor

Choose a reason for hiding this comment

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

Done! I've renamed require_paths to import_paths throughout the codebase:

  • Updated all Python generator files
  • Renamed the fixture folder from require-paths to import-paths
  • Updated the changelog to use import_paths

The config option is now import_paths (snake_case, Pythonic naming).

@devin-ai-integration devin-ai-integration bot changed the title feat(python): add require-paths config for custom code integration feat(python): add import_paths config for custom code integration Jan 27, 2026
@aditya-arolkar-swe aditya-arolkar-swe enabled auto-merge (squash) January 27, 2026 22:59
@aditya-arolkar-swe aditya-arolkar-swe merged commit de0cf0d into main Jan 27, 2026
127 checks passed
@aditya-arolkar-swe aditya-arolkar-swe deleted the devin/1769464083-sentry-integration branch January 27, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants