Skip to content

Commit

Permalink
Simplify environment loading
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeNaccarato committed Jan 17, 2025
1 parent f4a348c commit a98cc18
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/_dev/boilercv_dev/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cappa.subcommand import Subcommands


@command(invoke="boilercv_dev.tools.environment._sync_environment_variables")
@command(invoke="boilercv_dev.tools.environment.sync_environment_variables")
class SyncEnvironmentVariables:
"""Sync `.env` with `pyproject.toml`."""

Expand Down
24 changes: 9 additions & 15 deletions packages/_dev/boilercv_dev/tools/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class Constants(BaseModel):
"""Shell invocation for running arbitrary commands."""
uv_run_wrapper: str = "./Invoke-Uv.ps1"
"""Wrapper of `uv run` with extra setup."""
env: str = ".env"
"""Name of environment file."""
env: Path = (
Path(environ["GITHUB_ENV"])
if environ.get("GITHUB_ENV")
else rooted_paths.root / ".env"
)
"""Environment file path."""
pylance_version: str = (
(rooted_paths.root / ".pylance-version").read_text(encoding="utf-8").strip()
)
Expand All @@ -45,7 +49,7 @@ def sync_environment_variables(
path: Path | None = None,
pylance_version: str = const.pylance_version,
setenv: bool = True,
) -> str:
):
"""Sync `.env` with `pyproject.toml`, optionally setting environment variables."""
path = Path(path) if path else Path.cwd() / ".env"
config_env = Config().env
Expand All @@ -62,18 +66,8 @@ def sync_environment_variables(
dotenv[k] = v
if setenv:
load_dotenv(stream=StringIO("\n".join(f"{k}={v}" for k, v in dotenv.items())))
return "\n".join(f"{k}={v}" for k, v in dotenv.items())


def _sync_environment_variables(pylance_version: str = const.pylance_version):
"""Sync `.env` with `pyproject.toml`."""
if environ.get("GITHUB_ENV"):
env = Path(environ["GITHUB_ENV"])
else:
env = Path.cwd() / ".env"
env.write_text(
encoding="utf-8",
data=sync_environment_variables(pylance_version=pylance_version),
const.env.write_text(
encoding="utf-8", data="\n".join(f"{k}={v}" for k, v in dotenv.items())
)


Expand Down
2 changes: 1 addition & 1 deletion packages/pipeline/boilercv_pipeline/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def invoke(
parsed_command,
instance,
output=concrete_output,
state=state,
state=state, # pyright: ignore[reportCallIssue]
deps=deps,
)
for dep in global_deps:
Expand Down

0 comments on commit a98cc18

Please sign in to comment.