Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [Unreleased](https://github.com/dotenvx/python-dotenvx/compare/v0.2.6...main)
## [Unreleased](https://github.com/dotenvx/python-dotenvx/compare/v0.3.0...main)

## [0.3.0](https://github.com/dotenvx/dotenvx/compare/v0.2.6...v0.3.0)

### Added

* Add `dotenv_path` and `override` arguments ([#4](https://github.com/dotenvx/python-dotenvx/pull/4))

## [0.2.6](https://github.com/dotenvx/dotenvx/compare/v0.2.5...v0.2.6)

Expand Down
26 changes: 21 additions & 5 deletions src/dotenvx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,37 @@

ERROR_MISSING_BINARY = "[MISSING_BINARY] missing dotenvx binary\n[MISSING_BINARY] https://github.com/dotenvx/dotenvx/issues/576"

def load_dotenvx():
output = get()
def load_dotenvx(
dotenv_path=None,
override=False
):
output = dotenvx_get(
dotenv_path=dotenv_path,
override=override
)

try:
parsed = json.loads(output)
for key, value in parsed.items():
os.environ[key] = value
return parsed
return True
except Exception as e:
raise RuntimeError(f"Failed to parse dotenvx output: {e}")

def get():
def dotenvx_get(
dotenv_path=None,
override=False
):
binpath = binary()
cmd = [binpath, "get", "-pp"]

if dotenv_path:
cmd += ["-f", dotenv_path]
if override:
cmd.append("--overload")

output = subprocess.run(
[binpath, "get", "-pp"],
cmd,
capture_output=True,
text=True,
check=True
Expand Down