envlib 0.0.1__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.
envlib-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [год] [ваше имя или имя компании]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
envlib-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: envlib
3
+ Version: 0.0.1
4
+ Summary: Library to read .env files
5
+ Home-page: UNKNOWN
6
+ Author: Mansur Uldanov
7
+ Author-email: uldanovmansur2005@gmail.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.6
14
+ License-File: LICENSE
15
+
16
+ UNKNOWN
17
+
envlib-0.0.1/README.md ADDED
@@ -0,0 +1,11 @@
1
+ ```
2
+ # Пример использования
3
+ envModule = EnvModule('.env')
4
+
5
+ # Получение переменной окружения
6
+ api_key = envModule.get('API_KEY')
7
+ debug_mode = envModule.get('DEBUG', 'False')
8
+
9
+ print(f"API_KEY: {api_key}")
10
+ print(f"DEBUG_MODE: {debug_mode}")
11
+ ```
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: envlib
3
+ Version: 0.0.1
4
+ Summary: Library to read .env files
5
+ Home-page: UNKNOWN
6
+ Author: Mansur Uldanov
7
+ Author-email: uldanovmansur2005@gmail.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.6
14
+ License-File: LICENSE
15
+
16
+ UNKNOWN
17
+
@@ -0,0 +1,8 @@
1
+ LICENSE
2
+ README.md
3
+ envmodule.py
4
+ setup.py
5
+ envlib.egg-info/PKG-INFO
6
+ envlib.egg-info/SOURCES.txt
7
+ envlib.egg-info/dependency_links.txt
8
+ envlib.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ envmodule
@@ -0,0 +1,58 @@
1
+ import os
2
+
3
+ class EnvModule:
4
+ def __init__(self, env_file='.env'):
5
+ self.env_file = env_file
6
+ self.variables = {}
7
+ self._load_env()
8
+
9
+ def _find_env_file(self, current_directory):
10
+ """Рекурсивно ищет файл .env в текущей директории и выше"""
11
+ potential_path = os.path.join(current_directory, self.env_file)
12
+
13
+ if os.path.exists(potential_path):
14
+ return potential_path
15
+
16
+ # Если достигли корневой директории, прекращаем поиск
17
+ parent_directory = os.path.dirname(current_directory)
18
+ if current_directory == parent_directory:
19
+ return None
20
+
21
+ # Продолжаем искать в родительской директории
22
+ return self._find_env_file(parent_directory)
23
+
24
+ def _load_env(self):
25
+ """Чтение файла .env и сохранение переменных в словарь"""
26
+ current_directory = os.getcwd() # Текущая рабочая директория
27
+ env_path = self._find_env_file(current_directory)
28
+
29
+ if env_path is None:
30
+ raise FileNotFoundError(f"Файл {self.env_file} не найден в текущей или родительских директориях.")
31
+
32
+ with open(env_path, 'r') as file:
33
+ for line in file:
34
+ line = line.strip()
35
+ # Пропускаем пустые строки и комментарии
36
+ if not line or line.startswith('#'):
37
+ continue
38
+ key, value = line.split('=', 1)
39
+ self.variables[key.strip()] = value.strip()
40
+
41
+ def get(self, key, default=None):
42
+ """Возвращает значение переменной по ключу"""
43
+ return self.variables.get(key, default)
44
+
45
+ # Пример использования
46
+ envModule = EnvModule('.env')
47
+ api_key = envModule.get('API_KEY')
48
+ print(api_key)
49
+
50
+ # # Пример использования
51
+ # envModule = EnvModule('.env')
52
+
53
+ # # Получение переменной окружения
54
+ # api_key = envModule.get('API_KEY')
55
+ # debug_mode = envModule.get('DEBUG', 'False')
56
+
57
+ # print(f"API_KEY: {api_key}")
58
+ # print(f"DEBUG_MODE: {debug_mode}")
envlib-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
envlib-0.0.1/setup.py ADDED
@@ -0,0 +1,18 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='envlib',
5
+ version='0.0.1',
6
+ packages=find_packages(),
7
+ description='Library to read .env files',
8
+ author='Mansur Uldanov',
9
+ author_email='uldanovmansur2005@gmail.com',
10
+ url='', # ссылка на репозиторий (если есть)
11
+ py_modules=['envmodule'],
12
+ classifiers=[
13
+ 'Programming Language :: Python :: 3',
14
+ 'License :: OSI Approved :: MIT License',
15
+ 'Operating System :: OS Independent',
16
+ ],
17
+ python_requires='>=3.6',
18
+ )