Browse Source
usage as such `-g dotenv` Should also be abble to make the PyCharmRunEnv generators absolete, but untested. PyCharm allows for setting a `.env` file for a script such as `cura_app.py` Contributes to NP-822pull/26/head
1 changed files with 22 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||||||
|
import os |
||||||
|
from conan.tools.env import VirtualRunEnv |
||||||
|
from conan.tools.files import copy, save, load |
||||||
|
|
||||||
|
class dotenv: |
||||||
|
|
||||||
|
def __init__(self, conanfile): |
||||||
|
self._conanfile = conanfile |
||||||
|
|
||||||
|
def generate(self): |
||||||
|
run_env = VirtualRunEnv(self._conanfile) |
||||||
|
env = run_env.environment() |
||||||
|
env_vars = env.vars(self._conanfile, scope="run") |
||||||
|
output_file = ".env" |
||||||
|
self._conanfile.output.info(f"Generating '{output_file}' with run environment variables...") |
||||||
|
|
||||||
|
content = "" |
||||||
|
for key, value in env_vars.items(): |
||||||
|
content += f"{key}={value}\n" |
||||||
|
self._conanfile.output.info(f"'{output_file}' generated successfully.") |
||||||
|
save(self._conanfile, output_file, content) |
||||||
|
self._conanfile.output.info(f"Saved '{output_file}' to the current directory.") |
||||||
Loading…
Reference in new issue