dotenvplus 0.0.2__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dotenvplus
3
- Version: 0.0.2
4
- Summary: Python library that handles interactions from Discord POST requests.
3
+ Version: 0.0.3
4
+ Summary: Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
5
5
  Author-email: AlexFlipnote <root@alexflipnote.dev>
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/AlexFlipnote/dotenvplus
8
8
  Project-URL: Repository, https://github.com/AlexFlipnote/dotenvplus
9
9
  Keywords: dotenv,env,config,environment,variables,key-value,parser
10
- Requires-Python: >=3.6.0
10
+ Requires-Python: >=3.7.0
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
13
  Provides-Extra: dev
14
14
  Requires-Dist: pyright; extra == "dev"
15
- Requires-Dist: flake8; extra == "dev"
15
+ Requires-Dist: ruff; extra == "dev"
16
16
  Requires-Dist: toml; extra == "dev"
17
17
  Provides-Extra: maintainer
18
18
  Requires-Dist: twine; extra == "maintainer"
@@ -23,12 +23,15 @@ Requires-Dist: build; extra == "maintainer"
23
23
  Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
24
24
 
25
25
  The values returned by the DotEnv object is treated like a dictionary, so you can use it like a normal dictionary.
26
+ # DotEnvPlus
27
+ Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
28
+
26
29
  Some of the usual dictionary methods are also supported like `.items()`, `.keys()`, `.values()`, etc.
27
30
 
28
31
  Goal is to make it easy to use environment variables in your code, while also supporting multiple values.
29
32
 
30
33
  ## Installing
31
- > You need **Python >=3.6** to use this library.
34
+ > You need **Python >=3.7** to use this library.
32
35
 
33
36
  ```bash
34
37
  pip install dotenvplus
@@ -2,12 +2,15 @@
2
2
  Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
3
3
 
4
4
  The values returned by the DotEnv object is treated like a dictionary, so you can use it like a normal dictionary.
5
+ # DotEnvPlus
6
+ Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
7
+
5
8
  Some of the usual dictionary methods are also supported like `.items()`, `.keys()`, `.values()`, etc.
6
9
 
7
10
  Goal is to make it easy to use environment variables in your code, while also supporting multiple values.
8
11
 
9
12
  ## Installing
10
- > You need **Python >=3.6** to use this library.
13
+ > You need **Python >=3.7** to use this library.
11
14
 
12
15
  ```bash
13
16
  pip install dotenvplus
@@ -2,7 +2,7 @@ import re
2
2
 
3
3
  from typing import Any, Iterator, Optional, Tuple, List, Dict
4
4
 
5
- __version__ = "0.0.2"
5
+ __version__ = "0.0.3"
6
6
 
7
7
 
8
8
  class ParsingError(Exception):
@@ -12,6 +12,7 @@ class ParsingError(Exception):
12
12
  class DotEnv:
13
13
  """
14
14
  DotEnv is a dotenv parser for Python with additional type support.
15
+
15
16
  It supports parsing of string, integer, float, and boolean values.
16
17
 
17
18
  Arguments
@@ -44,7 +45,7 @@ class DotEnv:
44
45
 
45
46
  # General values
46
47
  self.__env: Dict[str, Any] = {}
47
- self.__quotes: Tuple[str, ...] = ("\"", "'")
48
+ self.__quotes: Tuple[str, ...] = ('"', "'")
48
49
 
49
50
  # Config for the parser
50
51
  self.__path: str = path or ".env"
@@ -56,7 +57,7 @@ class DotEnv:
56
57
  def __repr__(self) -> str:
57
58
  return f"<DotEnv data={self.__env}>"
58
59
 
59
- def __getitem__(self, key: str) -> Any:
60
+ def __getitem__(self, key: str) -> Any: # noqa: ANN401
60
61
  if self.__handle_key_not_found:
61
62
  return self.__env.get(key, None)
62
63
  return self.__env[key]
@@ -83,7 +84,7 @@ class DotEnv:
83
84
  """ `list[Any]`: Returns a list of the values. """
84
85
  return list(self.__env.values())
85
86
 
86
- def get(self, key: str, default: Any = None) -> Any:
87
+ def get(self, key: str, default: Any = None) -> Any: # noqa: ANN401
87
88
  """ `Any`: Return the value for key if key is in the dictionary, else default. """
88
89
  return self.__env.get(key, default)
89
90
 
@@ -102,6 +103,7 @@ class DotEnv:
102
103
  def __parser(self) -> None:
103
104
  """
104
105
  Parse the .env file and store the values in a dictionary.
106
+
105
107
  The keys are accessible later by using the square bracket notation
106
108
  directly on the DotEnv object.
107
109
 
@@ -112,7 +114,7 @@ class DotEnv:
112
114
  `ParsingError`
113
115
  If one of the values cannot be parsed.
114
116
  """
115
- with open(self.__path, "r", encoding="utf-8") as f:
117
+ with open(self.__path, encoding="utf-8") as f:
116
118
  data: List[str] = f.readlines()
117
119
 
118
120
  for line in data:
@@ -122,12 +124,12 @@ class DotEnv:
122
124
  # Ignore comment or empty line
123
125
  continue
124
126
 
125
- _find_kv = self.__re_keyvar.search(line)
126
- if not _find_kv:
127
+ find_kv = self.__re_keyvar.search(line)
128
+ if not find_kv:
127
129
  raise ParsingError(f"Expected key=value format, got '{line}'")
128
130
 
129
- key, value = _find_kv.groups()
130
- _force_string = False
131
+ key, value = find_kv.groups()
132
+ force_string = False
131
133
 
132
134
  # Replace any variables in the value
133
135
  value = self.__re_var_call.sub(
@@ -141,9 +143,9 @@ class DotEnv:
141
143
  value.endswith(self.__quotes)
142
144
  ):
143
145
  value = value[1:-1]
144
- _force_string = True
146
+ force_string = True
145
147
 
146
- if not _force_string:
148
+ if not force_string:
147
149
 
148
150
  if self.__re_isdigit.search(value):
149
151
  value = int(value)
@@ -158,6 +160,7 @@ class DotEnv:
158
160
  value = None
159
161
 
160
162
  else:
161
- value = value
163
+ # Remove comment on the value itself too (if any)
164
+ value = value.split("#")[0].strip()
162
165
 
163
166
  self.__env[key] = value
@@ -1,18 +1,18 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dotenvplus
3
- Version: 0.0.2
4
- Summary: Python library that handles interactions from Discord POST requests.
3
+ Version: 0.0.3
4
+ Summary: Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
5
5
  Author-email: AlexFlipnote <root@alexflipnote.dev>
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/AlexFlipnote/dotenvplus
8
8
  Project-URL: Repository, https://github.com/AlexFlipnote/dotenvplus
9
9
  Keywords: dotenv,env,config,environment,variables,key-value,parser
10
- Requires-Python: >=3.6.0
10
+ Requires-Python: >=3.7.0
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
13
  Provides-Extra: dev
14
14
  Requires-Dist: pyright; extra == "dev"
15
- Requires-Dist: flake8; extra == "dev"
15
+ Requires-Dist: ruff; extra == "dev"
16
16
  Requires-Dist: toml; extra == "dev"
17
17
  Provides-Extra: maintainer
18
18
  Requires-Dist: twine; extra == "maintainer"
@@ -23,12 +23,15 @@ Requires-Dist: build; extra == "maintainer"
23
23
  Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
24
24
 
25
25
  The values returned by the DotEnv object is treated like a dictionary, so you can use it like a normal dictionary.
26
+ # DotEnvPlus
27
+ Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation.
28
+
26
29
  Some of the usual dictionary methods are also supported like `.items()`, `.keys()`, `.values()`, etc.
27
30
 
28
31
  Goal is to make it easy to use environment variables in your code, while also supporting multiple values.
29
32
 
30
33
  ## Installing
31
- > You need **Python >=3.6** to use this library.
34
+ > You need **Python >=3.7** to use this library.
32
35
 
33
36
  ```bash
34
37
  pip install dotenvplus
@@ -1,7 +1,7 @@
1
1
 
2
2
  [dev]
3
3
  pyright
4
- flake8
4
+ ruff
5
5
  toml
6
6
 
7
7
  [maintainer]
@@ -0,0 +1,168 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.pdm.source]
6
+ name = "public"
7
+ url = "https://github.com/AlexFlipnote/dotenvplus"
8
+
9
+ [project]
10
+ name = "dotenvplus"
11
+ description = "Reads key-value pairs from a .env file and supports multiple values with dynamic interpolation."
12
+ requires-python = ">=3.7.0"
13
+ license = {text = "MIT"}
14
+
15
+ dynamic = ["version"]
16
+ readme = "README.md"
17
+ keywords = ["dotenv", "env", "config", "environment", "variables", "key-value", "parser"]
18
+ authors = [{name = "AlexFlipnote", email = "root@alexflipnote.dev"}]
19
+
20
+ dependencies = []
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/AlexFlipnote/dotenvplus"
24
+ Repository = "https://github.com/AlexFlipnote/dotenvplus"
25
+
26
+ [project.optional-dependencies]
27
+ dev = ["pyright", "ruff", "toml"]
28
+ maintainer = ["twine", "wheel", "build"]
29
+
30
+ [tool.setuptools]
31
+ packages = [
32
+ "dotenvplus",
33
+ ]
34
+
35
+ [tool.setuptools.dynamic]
36
+ version = {attr = "dotenvplus.__version__"}
37
+ readme = {file = ["README.md"]}
38
+
39
+ [tool.ruff]
40
+ target-version = "py37"
41
+ indent-width = 4
42
+ line-length = 256 # Debating to change this.. not sure yet
43
+ output-format = "concise"
44
+
45
+ # Files to include/exclude
46
+ include = [
47
+ "dotenvplus/*",
48
+ ]
49
+ exclude = [
50
+ "**/__pycache__",
51
+ "**/*.pyc",
52
+ "*.egg-info",
53
+ ".venv",
54
+ "build",
55
+ "docs",
56
+ "dist",
57
+ "tests",
58
+ "examples",
59
+ ]
60
+
61
+ [tool.ruff.lint]
62
+ select = [
63
+ "A", # flake8-builtins
64
+ "ANN", # Annotations
65
+ "ARG", # flake8-unused-arguments
66
+ "B", # flake8-bugbear
67
+ "D", # pydocstyle
68
+ "DTZ", # flake8-datetimez
69
+ "E", # Error
70
+ "ERA", # eradicate
71
+ "F", # Pyflakes
72
+ "FIX", # flake8-fixme
73
+ "FLY", # flynt
74
+ "FURB", # refurb
75
+ "ICN", # flake8-import-conventions
76
+ "ISC", # flake8-implicit-str-concat
77
+ "N", # pep8-naming
78
+ "PIE", # flake8-pie
79
+ "PLE", # Pylint Errors
80
+ "PLW", # Pylint Warnings
81
+ "Q", # flake8-quotes
82
+ "RET", # flake8-return
83
+ "RUF", # Ruff-specific rules
84
+ "SIM", # flake8-simplify
85
+ "T", # flake8-print
86
+ "TC", # type-checking
87
+ "UP", # pyupgrade
88
+ "W", # Warning
89
+ ]
90
+
91
+ extend-select = ["W", "E"]
92
+ preview = true
93
+
94
+ ignore = [
95
+ # Docstring: function
96
+ "D100", # docstring in public module
97
+ "D104", # Missing docstring in public package
98
+ "D203", # 1 blank line required before class docstring
99
+ "D204", # 1 blank line required after class docstring
100
+ "D210", # No whitespaces surrounding docstring text
101
+ "D212", # Multi-line docstring start at first line
102
+ "D400", # Strictly must end with a period
103
+ "D401", # First line should be in imperative mood
104
+ "D413", # Missing blank line after last section
105
+ "D416", # Section name should end with a colon
106
+
107
+ # Annotations
108
+ "ANN003", # Missing type annotation for **kwargs
109
+ "ANN204", # Missing for __init__ method
110
+
111
+ # Type-checking
112
+ "TC001", "TC002", "TC003", "TC004", # Moving imports
113
+
114
+ # Docstring: Missing docs
115
+ "D101", # class
116
+ "D105", # magic method docstring required (__str__, __int__, etc)
117
+ "D107", # __init__ docstring required
118
+
119
+ # Except cases
120
+ "B904", # raise in except
121
+
122
+ # Simplify
123
+ "SIM105", # Use contextlib.suppress
124
+ "SIM114", # Merge if-else to one-liner
125
+
126
+ # Refurb
127
+ "FURB101", # read-whole-file
128
+ "FURB103", # write-whole-file
129
+
130
+ # Pylint Warnings
131
+ "PLW2901", # Overwrite loop control variable
132
+
133
+ # Type hints
134
+ "UP037", # type hints with quotes
135
+
136
+ # Variable shadowing
137
+ "A005", # Files
138
+ ]
139
+
140
+ [tool.ruff.format]
141
+ quote-style = "double"
142
+ indent-style = "space"
143
+ line-ending = "auto"
144
+
145
+ [tool.pyright]
146
+ reportOptionalOperand = "none"
147
+ reportOptionalSubscript = "none"
148
+ reportOptionalMemberAccess = "none"
149
+ reportUnnecessaryTypeIgnoreComment = "warning"
150
+ typeCheckingMode = "basic"
151
+ pythonVersion = "3.11"
152
+
153
+ include = [
154
+ "index.py", # Usually my main file name scheme
155
+ "main.py",
156
+ ]
157
+
158
+ exclude = [
159
+ "**/__pycache__",
160
+ "**/*.pyc",
161
+ "*.egg-info",
162
+ ".venv",
163
+ "build",
164
+ "docs",
165
+ "dist",
166
+ "tests",
167
+ "examples",
168
+ ]
@@ -11,9 +11,11 @@ class TestDotEnv(unittest.TestCase):
11
11
  "# Comment line\n"
12
12
  "STRING_KEY=HelloWorld\n"
13
13
  "INT_KEY=1234\n"
14
+ "STR_INT_KEY='1234'\n"
14
15
  "FLOAT_KEY=12.34\n"
15
16
  "BOOL_TRUE_KEY=true\n"
16
17
  "BOOL_FALSE_KEY=false\n"
18
+ "COMMENT_KEY=comment # Comment here\n"
17
19
  "NULL_KEY=null\n"
18
20
  "NONE_KEY=none\n"
19
21
  "NIL_KEY=nil\n"
@@ -35,6 +37,7 @@ class TestDotEnv(unittest.TestCase):
35
37
  self.assertIsInstance(dotenv, DotEnv)
36
38
  self.assertIsInstance(dotenv.get("STRING_KEY"), str)
37
39
  self.assertIsInstance(dotenv.get("INT_KEY"), int)
40
+ self.assertIsInstance(dotenv.get("STR_INT_KEY"), str)
38
41
  self.assertIsInstance(dotenv.get("FLOAT_KEY"), float)
39
42
  self.assertIsInstance(dotenv.get("BOOL_TRUE_KEY"), bool)
40
43
  self.assertIsInstance(dotenv.get("BOOL_FALSE_KEY"), bool)
@@ -42,6 +45,10 @@ class TestDotEnv(unittest.TestCase):
42
45
  self.assertIsInstance(dotenv.get("NONE_KEY"), type(None))
43
46
  self.assertIsInstance(dotenv.get("NIL_KEY"), type(None))
44
47
 
48
+ def test_comment_removed(self):
49
+ dotenv = DotEnv(self.file_path)
50
+ self.assertNotIn("#", dotenv.get("COMMENT_KEY"))
51
+
45
52
  def test_raises_error_on_missing_file(self):
46
53
  with self.assertRaises(FileNotFoundError):
47
54
  DotEnv("missing_file.env")
@@ -1,62 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools", "wheel"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [tool.pdm.source]
6
- name = "public"
7
- url = "https://github.com/AlexFlipnote/dotenvplus"
8
-
9
- [project]
10
- name = "dotenvplus"
11
- description = "Python library that handles interactions from Discord POST requests."
12
- requires-python = ">=3.6.0"
13
- license = {text = "MIT"}
14
-
15
- dynamic = ["version"]
16
- readme = "README.md"
17
- keywords = ["dotenv", "env", "config", "environment", "variables", "key-value", "parser"]
18
- authors = [{name = "AlexFlipnote", email = "root@alexflipnote.dev"}]
19
-
20
- dependencies = []
21
-
22
- [project.urls]
23
- Homepage = "https://github.com/AlexFlipnote/dotenvplus"
24
- Repository = "https://github.com/AlexFlipnote/dotenvplus"
25
-
26
- [project.optional-dependencies]
27
- dev = ["pyright", "flake8", "toml"]
28
- maintainer = ["twine", "wheel", "build"]
29
-
30
- [tool.setuptools]
31
- packages = [
32
- "dotenvplus",
33
- ]
34
-
35
- [tool.setuptools.dynamic]
36
- version = {attr = "dotenvplus.__version__"}
37
- readme = {file = ["README.md"]}
38
-
39
- [tool.flake8]
40
- max-line-length = 128
41
- ignore = [
42
- "D210", "D400", "D401", "D100", "D202", "D413", "D107",
43
- "D101", "D103", "D102", "E121", "D205", "D209", "D105",
44
- "E252", "W605", "W504", "E128", "E124", "E999", "W504"
45
- ]
46
-
47
- [tool.pyright]
48
- reportOptionalOperand = "none"
49
- reportOptionalSubscript = "none"
50
- reportOptionalMemberAccess = "none"
51
- reportUnnecessaryTypeIgnoreComment = "warning"
52
- typeCheckingMode = "basic"
53
- pythonVersion = "3.6"
54
-
55
- include = [
56
- "dotenvplus",
57
- ]
58
-
59
- exclude = [
60
- "**/__pycache__", "**/*.pyc", "*.egg-info",
61
- ".venv", "build", "docs", "dist",
62
- ]
File without changes
File without changes