# fix\(env\): use repo-level env as source of truth \(\#35\) · flambo/atlantis

[View on GitCafe](https://git.cafe/flambo/atlantis/commit/8693f7eda7545d57604076e6686d1f0d0154ab36)

Repository: [flambo/atlantis](https://git.cafe/flambo/atlantis)

Visibility: public

Requested revision: 8693f7eda7545d57604076e6686d1f0d0154ab36

Requested commit: 8693f7eda7545d57604076e6686d1f0d0154ab36

Commit: 8693f7eda7545d57604076e6686d1f0d0154ab36

Tree: 5e5951bc04c52b492a9bf00a282e87a0eddc6f05

Author: oliver

Committer: GitHub

## Message

````
fix(env): use repo-level env as source of truth (#35)

<!-- greptile_comment -->

<h3>Greptile Summary</h3>

This PR fixes environment file resolution across all NetFlow pipeline scripts by replacing the CWD-relative default `'../.env'` with an absolute path anchored to each script's own location via `Path(__file__).resolve().parent.parent / '.env'`. This makes scripts runnable from any working directory (repo root or `netflow-db/`) without path resolution failures.

Key changes:
- `common.py`, `depr_ip_db.py`, `ip_time.py`: `load_env_file` now accepts `Optional[str]` (defaulting to `None`), and resolves to `DEFAULT_ENV_PATH` when no path is supplied. The error message now prints the fully-resolved `Path` object for easier debugging.
- `verify_ip_uniqueness.py`: Adds `DEFAULT_ENV_PATH` and wires it as the argparse default for `--env-path`. The error message prints the original `env_path` string rather than the resolved `env_file`, which is a minor inconsistency compared to the other files.
- `docs/pipeline-usage.md`: Updated to document that scripts work correctly from both `netflow-db/` and the repo root.
- The `load_env_file` implementation remains duplicated across three files (pre-existing design), which means future changes to this logic will need to be applied in multiple places.

<h3>Confidence Score: 4/5</h3>

- This PR is safe to merge; the core fix is correct and well-applied across all affected files.
- The path-resolution logic is sound and consistent. One minor inconsistency exists in `verify_ip_uniqueness.py`'s error message (printing the raw string instead of the resolved path), which is a cosmetic issue worth tidying up. No functional regressions introduced.
- netflow-db/verify_ip_uniqueness.py — minor error-message inconsistency worth tidying up.

<h3>Sequence Diagram</h3>

```mermaid
sequenceDiagram
    participant Script
    participant load_env_file
    participant FileSystem
    participant ProcessEnv

    Script->>load_env_file: invoke with optional path
    alt no path provided
        load_env_file->>load_env_file: use DEFAULT_ENV_PATH via __file__
    else custom path provided
        load_env_file->>load_env_file: apply expanduser to path
    end
    load_env_file->>FileSystem: check if dotenv file exists
    alt file found
        FileSystem-->>load_env_file: open handle
        load_env_file->>ProcessEnv: populate config entries
        load_env_file-->>Script: return successfully
    else file not found
        load_env_file-->>Script: print resolved path error, exit 1
    end
```

<sub>Last reviewed commit: 5f8adff</sub>

> Greptile also left **1 inline comment** on this PR.

<!-- /greptile_comment -->
````

## Parents

- [bc6f54b421451f0524b7b0a01df126adc41ec9aa](https://git.cafe/flambo/atlantis/commit/bc6f54b421451f0524b7b0a01df126adc41ec9aa?format=markdown)

- [f81c2c6829284089faa9380afe95a7f4ac0ddbbe](https://git.cafe/flambo/atlantis/commit/f81c2c6829284089faa9380afe95a7f4ac0ddbbe?format=markdown)

[Source at this commit](https://git.cafe/flambo/atlantis/tree/8693f7eda7545d57604076e6686d1f0d0154ab36?format=markdown)
