yta-programming-env 0.3.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yta-programming-env
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Youtube Autonomous Programming Dependencies Module
5
5
  License-File: LICENSE
6
6
  Author: danialcala94
@@ -13,9 +13,9 @@ Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
- Requires-Dist: python-dotenv (>=1.0.0,<9.0.0)
17
- Requires-Dist: yta_programming_path (>=0.0.1,<1.0.0)
18
- Requires-Dist: yta_validation (>=0.0.1,<1.0.0)
16
+ Requires-Dist: python-dotenv (>=1.0.1,<9999.0.0)
17
+ Requires-Dist: yta_programming_path (>=0.3.0,<1.0.0)
18
+ Requires-Dist: yta_validation (>=0.2.1,<1.0.0)
19
19
  Description-Content-Type: text/markdown
20
20
 
21
21
  # Youtube Autonomous Programming Environment add-on
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "yta-programming-env"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Youtube Autonomous Programming Dependencies Module"
5
5
  authors = [
6
6
  {name = "danialcala94",email = "danielalcalavalera@gmail.com"}
@@ -10,9 +10,9 @@ requires-python = ">=3.8,<3.14"
10
10
 
11
11
  [tool.poetry.dependencies]
12
12
  # Mandatory
13
- yta_validation = { version = ">=0.0.1,<1.0.0", optional = false }
14
- yta_programming_path = { version = ">=0.0.1,<1.0.0", optional = false }
15
- python-dotenv = { version = ">=1.0.0,<9.0.0", optional = false }
13
+ yta_validation = { version = ">=0.2.1,<1.0.0", optional = false }
14
+ yta_programming_path = { version = ">=0.3.0,<1.0.0", optional = false }
15
+ python-dotenv = { version = ">=1.0.1,<9999.0.0", optional = false }
16
16
  # Optional
17
17
 
18
18
  [tool.poetry]
@@ -0,0 +1,74 @@
1
+ from yta_programming_path import DevPathHandler
2
+ from yta_validation.parameter import ParameterValidator
3
+ from dotenv import load_dotenv, dotenv_values
4
+ from typing import Union
5
+
6
+ import os
7
+
8
+
9
+ class Environment:
10
+ """
11
+ Class to handle the environment of the project in
12
+ which you are executing this code perfectly.
13
+ """
14
+
15
+ @staticmethod
16
+ def load_current_project_dotenv(
17
+ env_filename: str = '.env',
18
+ do_override: bool = True
19
+ ):
20
+ """
21
+ Load the `env_filename` (by default '.env')
22
+ environment configuration file from the current
23
+ project. The current project is the one in which
24
+ the code is being executed, not the library in which
25
+ it is written.
26
+
27
+ The `env_filename` will be read and the variables on
28
+ it will be loaded and ready to be accessed.
29
+
30
+ If the `do_override` is `True`, the previously
31
+ existing configuration variables will be overriden by
32
+ the new values.
33
+ """
34
+ load_dotenv(
35
+ dotenv_path = os.path.join(DevPathHandler.get_project_abspath(), env_filename),
36
+ override = do_override
37
+ )
38
+
39
+ @staticmethod
40
+ def get_current_project_env_dict(
41
+ env_filename: str = '.env'
42
+ ) -> dict:
43
+ """
44
+ Get the variables of the `env_filename` environment
45
+ configuration file as a dict.
46
+
47
+ This method doesn't load the variables in memory, it
48
+ just read the values from the file.
49
+ """
50
+ return dotenv_values(
51
+ dotenv_path = os.path.join(
52
+ DevPathHandler.get_project_abspath(),
53
+ env_filename
54
+ )
55
+ )
56
+
57
+
58
+ @staticmethod
59
+ def get_current_project_env(
60
+ variable: str,
61
+ default_value: Union[str, bool, float, int, None] = None,
62
+ env_filename: str = '.env'
63
+ ):
64
+ """
65
+ Load the `env_filename` environment configuration file
66
+ and get the value of the `variable`, if existing.
67
+
68
+ This method will do a `load_dotenv` call, which will
69
+ try to load the `env_filename` in memory and then use
70
+ the `os.getenv` method.
71
+ """
72
+ ParameterValidator.validate_mandatory_string('variable', variable, do_accept_empty = False)
73
+
74
+ return Environment.get_current_project_env_dict(env_filename).get(variable, default_value)
@@ -1,49 +0,0 @@
1
- from yta_programming_path import DevPathHandler
2
- from yta_validation.parameter import ParameterValidator
3
- from dotenv import load_dotenv
4
- from typing import Union
5
-
6
- import os
7
-
8
-
9
- class Environment:
10
- """
11
- Class to handle the environment of the project in
12
- which you are executing this code perfectly.
13
- """
14
-
15
- @staticmethod
16
- def load_current_project_dotenv(
17
- ):
18
- """
19
- Load the current project environment '.env' configuration
20
- file. The current project is the one in which the code
21
- is being executed (the code in which you call this method,
22
- not the library in which it is written).
23
-
24
- Any project in which you are importing this library, the
25
- '.env' file on its main folder will be loaded.
26
- """
27
- load_dotenv(os.path.join(DevPathHandler.get_project_abspath(), '.env'))
28
-
29
- @staticmethod
30
- def get_current_project_env(
31
- variable: str,
32
- default_value: Union[str, bool, float, int, None] = None
33
- ):
34
- """
35
- Load the current project environment '.env' configuration
36
- file and get the value of the 'variable' if existing.
37
-
38
- This method makes a 'load_dotenv' call within the current
39
- project absolute path any time you call it, so it ensures
40
- the value is correctly loaded if available.
41
-
42
- You don't need to do 'load_dotenv()' to call this method,
43
- it will do for you =).
44
- """
45
- ParameterValidator.validate_mandatory_string('variable', variable, do_accept_empty = False)
46
-
47
- Environment.load_current_project_dotenv()
48
-
49
- return os.getenv(variable, default_value)