How to specify config file location using environment variable?
cplager opened this issue · 4 comments
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'. )
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 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 toruff.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.
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.
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).