Skip to content

How to specify config file location using environment variable? #604

Open
@cplager

Description

@cplager

Background: In most of my projects I have a pyproject.toml file that has the linting rules I use. I want to be able to use a similar file in my IDE settings so that unless overwritten by a project file, I use standard RUFF rules. The complication is that I sync my settings.json file accross many different computers, so having a "proper" absolute path will not work for me; I need to be able to use environment variables (or at least know where the "default" path is.

None of these seem to work.

    // try 1
    "ruff.lint.args": ["--config=%USERPROFILE%/pyproject.toml"],
    "ruff.format.args": ["--config=%USERPROFILE%/pyproject.toml"],
    // try 2
    "ruff.lint.args": ["--config=${env:USERPROFILE%|/pyproject.toml"],
    "ruff.format.args": ["--config=${env:USERPROFILE}/pyproject.toml"],
    // try 3
    "ruff.lint.args": ["--config=${USERPROFILE%|/pyproject.toml"],
    "ruff.format.args": ["--config=${USERPROFILE}/pyproject.toml"],

I get the following error:

Ruff: Lint failed (error: invalid value '${env:USERPROFILE%|/pyproject.toml' for '--config <CONFIG_OPTION>' tip: A `--config` flag must either be a path to a `.toml` configuration file or a TOML `<KEY> = <VALUE>` pair overriding a specific configuration option It looks like you were trying to pass a path to a configuration file. The path `${env:USERPROFILE%|/pyproject.toml` does not point to a configuration file For more information, try '--help'. )

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions