Skip to content

Generating files from default preprocessed prompt name fails: could not determine language #8

@philippkolbe

Description

@philippkolbe

The default file name for preprocessing does not make sense <basename>_<language>_preprocessed.prompt because when generating this preprocessed file it is unable to automatically detect the language.

Reproduction

  1. Create a mock python file in config_example.py, e.g.:
from fastapi import FastAPI
from app.config import create_settings

def create_app() -> FastAPI:
    """
    Creates and configures the FastAPI application using environment-based settings.

    Returns:
        FastAPI: Configured FastAPI application instance.
    """
    app = FastAPI(
        title=settings.PROJECT_NAME,
        version=settings.VERSION
    )

    # Example usage of settings
    print("JWT Secret Key:", settings.JWT_SECRET_KEY)
    print("Allowed CORS Origins:", settings.CORS_ORIGINS)
    print("Token Expiry (minutes):", settings.ACCESS_TOKEN_EXPIRE_MINUTES)
    print("Rate Limit:", settings.RATE_LIMIT_PER_MINUTE)
    print("Log Level:", settings.LOG_LEVEL)

    @app.get("/health")
    def health_check() -> dict[str, str]:
        """
        Health check endpoint.

        Returns:
            dict: Application name and version.
        """
        return {
            "project": settings.PROJECT_NAME,
            "version": settings.VERSION
        }

    return app

settings = create_settings(env_file="example.env")
app = create_app()
  1. Create prompt in src/app/config_python.prompt with a value that requires preprocessing:
Create a configuration module that handles all application settings using Pydantic's BaseSettings.
It is located under app/config.py.

Requirements:
1. Settings Class:
- Create a Settings class that inherits from BaseSettings
- Use environment variables for all configuration
- Include type hints for all settings

2. Required Settings:
- PROJECT_NAME: Name of the project (used in FastAPI title)
- VERSION: Current version of the application (used in FastAPI and health check)
- JWT_SECRET_KEY: Secret key for JWT token generation
- JWT_ALGORITHM: Algorithm for JWT (default to "HS256")
- ACCESS_TOKEN_EXPIRE_MINUTES: Token expiration time
- CORS_ORIGINS: List of allowed CORS origins
- RATE_LIMIT_PER_MINUTE: Rate limit for authentication endpoints
- LOG_LEVEL: Application logging level

3. Environment Variables:
- All settings should be configurable via environment variables
- Use .env file for local development
- Include example .env file in documentation
- Default values should be provided where appropriate

4. Validation:
- Add validation for required settings
- Include reasonable defaults where appropriate
- Add validation for CORS origins format
- Validate JWT secret key length
- Validate version format (semantic versioning)
- Validate project name format

5. Documentation:
- Add docstrings for the Settings class
- Document each setting with its purpose and format
- Include example usage
- Document environment variable names
- Include example .env file

The module should be importable as 'config' and expose a 'settings' instance that can be used
throughout the application.

Example usage:

from config import settings

# Access settings
jwt_secret = settings.JWT_SECRET_KEY
cors_origins = settings.CORS_ORIGINS
project_name = settings.PROJECT_NAME
version = settings.VERSION

Example .env file:
PROJECT_NAME=pdd
VERSION=0.1.0
JWT_SECRET_KEY=your-secret-key-here
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
CORS_ORIGINS=["http://localhost:3000"]
RATE_LIMIT_PER_MINUTE=60
LOG_LEVEL=INFO


Make sure the code is executable via a unit test settings without side effects.
e.g. the following example should be executable without any side effects required.

<include>config_example.py</include>

Specifically, the `.env` file will not be available when executing the example. Adjust the interface so you can construct a new working example which will not require any side effects.

Please generate the complete config.py implementation following these requirements. 
  1. Run pdd --local preprocess config_change_python.prompt. This creates config_python_preprocessed.prompt.
  2. Run pdd --local generate config_python_preprocessed.prompt

Expected output

The config.py should be generated using the preprocessed prompt given.

Actual output

Error:

Could not determine language from input files or options.
Error during path construction: Could not determine language from input files or options.

Suggested Fix

If the prompt file ends with _preprocessed then you ignore that substring and try to read the language from the preceding substring.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions