Skip to content

Commit

Permalink
dotenv compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Nov 27, 2024
1 parent 9ba8f2a commit cbf7d4b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = ">=3.8"
aiohttp = "*"
python-dotenv = "*"
py-dom-xpath-six = "*"
pyyaml = ">=4.2b1"
stpl = ">=1.13.2"
Expand Down
6 changes: 5 additions & 1 deletion reqman/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
#
# https://github.com/manatlan/reqman
# #############################################################################

import os
import re
import json
import datetime
import inspect
import urllib.parse
import hashlib
import logging
import dotenv; dotenv.load_dotenv()

from reqman.common import NotFound,decodeBytes,jdumps
import reqman.com as com
Expand Down Expand Up @@ -409,6 +410,9 @@ def get_var(self,vardef: str): # -> any or NotFound
value=self.run(callabl,value)
else:
return NotFound
else:
# FALLBACK to resolv from dotenv (new 27/12/2024)
value = os.environ.get(var,NotFound)

return value

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aiohttp
python-dotenv
py-dom-xpath-six
pyyaml >= 4.2b1
stpl >= 1.13.2
Expand Down
17 changes: 16 additions & 1 deletion tests/test__newcore_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import reqman.env
import reqman.com
import reqman.xlib
import json
import json,os

ENV=reqman.env.Scope(dict(
txt="hello",
Expand Down Expand Up @@ -212,9 +212,24 @@ def test_copy_dico():
assert e.get_var("user1.name") == "jo"


def test_dotenv():
if "ENV_VAR" in os.environ:
del os.environ["ENV_VAR"]

e=reqman.env.Scope( dict(
user="<<ENV_VAR>>",
))
assert e.get_var("ENV_VAR") == NotFound
assert e.get_var("user") == "<<ENV_VAR>>"


os.environ["ENV_VAR"]="dotenv_ready"

assert os.getenv("ENV_VAR") == "dotenv_ready"
assert os.environ["ENV_VAR"] == "dotenv_ready"

assert e.get_var("ENV_VAR") == "dotenv_ready"
assert e.get_var("user") == "dotenv_ready"


@pytest.mark.asyncio
Expand Down

0 comments on commit cbf7d4b

Please sign in to comment.