Skip to content
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

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

Open
cplager opened this issue Sep 7, 2024 · 4 comments
Open

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

cplager opened this issue Sep 7, 2024 · 4 comments
Labels
question Asking for support or clarification

Comments

@cplager
Copy link

cplager commented Sep 7, 2024

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'. )
@dhruvmanila
Copy link
Member

I think the settings in your version 2 should work except that the value in ruff.lint.args is incorrect. Can you change that to be similar to ruff.format.args and try? So,

    "ruff.lint.args": ["--config=${env:USERPROFILE}/pyproject.toml"],
    "ruff.format.args": ["--config=${env:USERPROFILE}/pyproject.toml"],

@cplager
Copy link
Author

cplager commented Sep 10, 2024

I think the settings in your version 2 should work except that the value in ruff.lint.args is incorrect. Can you change that to be similar to ruff.format.args and try? So,

    "ruff.lint.args": ["--config=${env:USERPROFILE}/pyproject.toml"],
    "ruff.format.args": ["--config=${env:USERPROFILE}/pyproject.toml"],

I updated to what you have. I still see the problem:

2024-09-09 11:04:22.085 [info] [Error - 11:04:22 AM] 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'.
)

In file explorer, I have verified that %USERPROFILE%\pyproject.toml opens my toml file in VSCode as expected.

@dhruvmanila
Copy link
Member

Could it be that the environment variable itself isn't available in that environment where VS Code is opened? Because, I think ${env:USERPROFILE} should work although I don't have a Windows machine to check this.

@cplager
Copy link
Author

cplager commented Sep 10, 2024

I don't think so (but it's not impossible).

If I open a terminal inside of VSCode I can access it (where as if you open VSCode, then create an environment variable, and then open a terminal, that variable will NOT be present).

@dhruvmanila dhruvmanila added the question Asking for support or clarification label Oct 25, 2024
@dhruvmanila dhruvmanila changed the title Want to specify pyproject.toml file location using environment variable. How to specify config file location using environment variable? Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

2 participants