python-flask-dev 0.0.7__py3-none-any.whl → 0.0.9__py3-none-any.whl

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.
@@ -3,23 +3,17 @@ import sys
3
3
  import importlib.util
4
4
  from pathlib import Path
5
5
  import site
6
+ import logging
6
7
 
7
8
 
8
- PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
9
- VIRTUAL_ENV = Path(os.getenv('VIRTUAL_ENV'))
10
-
11
- # opt for module in the local project directory, or module installed in the venv
12
-
13
- def get_imported_project_module(module_name, module_path = None, is_pkg_installation_required = False, add_to_import_system = False):
14
-
15
- if is_pkg_installation_required:
16
- module_path = f"{site.getsitepackages()[0]}/{module_name}"
17
- else:
18
- if module_path == None:
19
- raise Exception("ERROR: Module path is required for an installed package")
9
+ logger = logging.getLogger(__name__)
10
+ logging.basicConfig(level=logging.INFO)
20
11
 
12
+ def get_imported_project_module(module_name, module_path = None, add_to_import_system = False):
13
+ logger.info(f"##### module_path: {module_path}")
21
14
  # Create the module object from the spec
22
15
  module_spec = importlib.util.spec_from_file_location(module_name, Path(module_path))
16
+ logger.info(f"##### module_spec: {module_spec}")
23
17
  # Load the module
24
18
  custom_module = importlib.util.module_from_spec(module_spec)
25
19
 
@@ -32,13 +26,39 @@ def get_imported_project_module(module_name, module_path = None, is_pkg_install
32
26
  # The module is callable: `custom_module.some_function()`
33
27
  return custom_module
34
28
 
35
- # Note that, typically, this is not recommended for python projects
36
- def modify_venv_pythonpath(pkg_path, absolute_path=False):
37
- python_version = f"python{sys.version_info.major}.{sys.version_info.minor}"
29
+ # Note that, typically, this is not recommended for python projects; Modules located within the directory that is added to the search path can be imported.
30
+ def modify_venv_pythonpath(*, pth_filename = "imported-project-modules.pth", absolute_pkg_path = None, installed_pkg_name = None):
31
+ site_dir = site.getsitepackages()[0]
32
+ logger.info(f"########## site_dir: {site_dir}")
33
+
34
+ if absolute_pkg_path:
35
+ pkg_path = absolute_pkg_path
36
+ elif installed_pkg_name:
37
+ pkg_path = f"{site_dir}/{installed_pkg_name}"
38
+ else:
39
+ raise Exception("ERROR: absolute_pkg_path or installed_pkg_name is required")
40
+
41
+ # Create/write to a .pth file, listing the path of the package to import:
42
+ site_pkgs_pth_filepath = f"{site_dir}/{pth_filename}"
43
+ try:
44
+ with open(site_pkgs_pth_filepath, 'r') as file:
45
+ lines = [line.strip() for line in file]
46
+ except Exception as e:
47
+ logger.error(e)
48
+ lines = []
49
+
50
+ logger.info(f"########## pkg_path: {pkg_path}")
51
+ logger.info(f"########## lines: {lines}")
38
52
 
39
- site_pkgs_pth_file = f"{VIRTUAL_ENV}/lib/{python_version}/site-packages/{Path(PROJECT_ROOT).name}.pth"
53
+ if pkg_path not in lines:
54
+ with open(site_pkgs_pth_filepath, 'a') as file:
55
+ if pkg_path not in lines:
56
+ logger.info(f"########## writing to site-pkgs .pth; pkg_path: {pkg_path}")
57
+ file.write(pkg_path + '\n')
40
58
 
41
- print("site_pkgs_pth_file: ", site_pkgs_pth_file)
42
- with open(site_pkgs_pth_file, "w") as f:
43
- path = pkg_path if absolute_path else f"{PROJECT_ROOT}/{pkg_path}"
44
- f.write(path)
59
+ # Add the package:
60
+ known_paths = set(sys.path)
61
+ logger.info(f"########## known_paths: {known_paths}")
62
+ site.addpackage(site_dir, site_pkgs_pth_filepath, known_paths)
63
+ if pkg_path in os.listdir(site_dir):
64
+ logger.info(f"########## `{pkg_path}` package added to the Python packages search system path")
@@ -1,14 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-flask-dev
3
- Version: 0.0.7
4
- Summary: A small example package
5
- Author-email: Example Author <author@example.com>
3
+ Version: 0.0.9
4
+ Summary: Package containing modules with 'helper' functions to support the development of Python Flask applications.
5
+ Author-email: Dani <daniasestan@gmail.com>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/pypa/sampleproject
8
8
  Project-URL: Issues, https://github.com/pypa/sampleproject/issues
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.9
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Framework :: Flask
12
+ Requires-Python: >=3.12.3
12
13
  Description-Content-Type: text/markdown
13
14
  Requires-Dist: Flask==3.1.2
14
15
  Requires-Dist: numpy==2.4.2
@@ -6,9 +6,9 @@ python_flask_dev/custom_exceptions.py,sha256=VYcq3LAv-Xohe_EoP7YJsXQAIvDhiyHsyRA
6
6
  python_flask_dev/data_source.py,sha256=QtBSlleKoGqAq751xNh2G2ZIQwEIzHpre5jDvGzJszA,1109
7
7
  python_flask_dev/filtering_data.py,sha256=hB6M-anMztg1Nhi6ilxGBYMEpqUMKGmmGoS0vkeNx2o,8583
8
8
  python_flask_dev/formatting_data.py,sha256=bGTNnvRaACn_E44-03CoQ9Fc_oK3_aISROaLLJZLdKg,209
9
- python_flask_dev/importing_modules.py,sha256=-aQUBxmHXrW0BOyieiBESZFPoSqbVZLWPicpPxYQ3ZY,1673
9
+ python_flask_dev/importing_modules.py,sha256=rsRPM46WdeNGiVlp_xbpMucRWLLaE6fA37gFqo3Y9R0,2532
10
10
  python_flask_dev/path_retrieval.py,sha256=8jmSCJ5SKKvtjI6lQtr9gQH6RIFDU9_ouiL2GsaXb00,319
11
- python_flask_dev-0.0.7.dist-info/METADATA,sha256=PnmGCGZNnEKlsElfYZggup0532AprIsJkAvvwraJJFk,4791
12
- python_flask_dev-0.0.7.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
13
- python_flask_dev-0.0.7.dist-info/top_level.txt,sha256=LhLe2esd0pDfth_R0Ai8vfZMgucbwmfJAEpJla6Vk8w,35
14
- python_flask_dev-0.0.7.dist-info/RECORD,,
11
+ python_flask_dev-0.0.9.dist-info/METADATA,sha256=--rI9ef0yxvOIyJ_XLKYKcQeZ4EU1pQbxYRhzEG42rg,4902
12
+ python_flask_dev-0.0.9.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
13
+ python_flask_dev-0.0.9.dist-info/top_level.txt,sha256=LhLe2esd0pDfth_R0Ai8vfZMgucbwmfJAEpJla6Vk8w,35
14
+ python_flask_dev-0.0.9.dist-info/RECORD,,