rapidframework-lib 1.0.9__tar.gz → 1.1.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.
Files changed (47) hide show
  1. {rapidframework_lib-1.0.9/rapidframework_lib.egg-info → rapidframework_lib-1.1.1}/PKG-INFO +2 -2
  2. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/README.md +1 -1
  3. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/config.py +24 -19
  4. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/configs/managers.json +12 -13
  5. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/django.py +4 -4
  6. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/fastapi.py +1 -2
  7. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/main.py +13 -18
  8. rapidframework_lib-1.1.1/rapidframework/template.py +80 -0
  9. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1/rapidframework_lib.egg-info}/PKG-INFO +2 -2
  10. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/setup.py +1 -1
  11. rapidframework_lib-1.0.9/rapidframework/template.py +0 -88
  12. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/LICENSE +0 -0
  13. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/pyproject.toml +0 -0
  14. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/__init__.py +0 -0
  15. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/__pycache__/main.cpython-313.pyc +0 -0
  16. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/__init__.py +0 -0
  17. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/__init__.py +0 -0
  18. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/bottle_1.py +0 -0
  19. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/cherrypy_1.py +0 -0
  20. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/manage.py-tpl +0 -0
  21. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/__init__.py-tpl +0 -0
  22. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/asgi.py-tpl +0 -0
  23. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/settings.py-tpl +0 -0
  24. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/urls.py-tpl +0 -0
  25. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/users/__init__.py-tpl +0 -0
  26. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/users/admin.py-tpl +0 -0
  27. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/users/migrations/0001_initial.py-tpl +0 -0
  28. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/users/migrations/__init__.py-tpl +0 -0
  29. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/users/models.py-tpl +0 -0
  30. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/django_1/project_name/wsgi.py-tpl +0 -0
  31. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/fastapi_1.py +0 -0
  32. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/flask_1.py +0 -0
  33. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/grok_1.py +0 -0
  34. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/litestar_1.py +0 -0
  35. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/pyramid_1.py +0 -0
  36. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/socketify_1.py +0 -0
  37. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/starlette_1.py +0 -0
  38. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/tornado_1.py +0 -0
  39. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/turbogears2_1.py +0 -0
  40. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/examples/web2py_1.py +0 -0
  41. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework/frameworks/simple_frameworks.py +0 -0
  42. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework_lib.egg-info/SOURCES.txt +0 -0
  43. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework_lib.egg-info/dependency_links.txt +0 -0
  44. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework_lib.egg-info/entry_points.txt +0 -0
  45. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework_lib.egg-info/requires.txt +0 -0
  46. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/rapidframework_lib.egg-info/top_level.txt +0 -0
  47. {rapidframework_lib-1.0.9 → rapidframework_lib-1.1.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rapidframework-lib
3
- Version: 1.0.9
3
+ Version: 1.1.1
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Requires-Dist: msgspec
@@ -13,7 +13,7 @@ Dynamic: requires-dist
13
13
 
14
14
  > **RapidFramework** is a Python library for quickly creating and setting up projects from templates.
15
15
 
16
- ## https://pypi.org/project/rapidframework-lib/1.0.9/
16
+ ## https://pypi.org/project/rapidframework-lib/1.1.1/
17
17
 
18
18
  ## Installation
19
19
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  > **RapidFramework** is a Python library for quickly creating and setting up projects from templates.
4
4
 
5
- ## https://pypi.org/project/rapidframework-lib/1.0.9/
5
+ ## https://pypi.org/project/rapidframework-lib/1.1.1/
6
6
 
7
7
  ## Installation
8
8
 
@@ -1,8 +1,8 @@
1
- from os import getcwd, listdir, path, makedirs
2
- from typing import Self, Dict
1
+ from pathlib import Path
2
+ from typing import Optional, Self, Dict, List
3
3
  import pkgutil
4
- from msgspec import json, Struct, field, DecodeError
5
- from subprocess import run
4
+ from msgspec import json, Struct, DecodeError
5
+ from subprocess import run, CalledProcessError
6
6
  from importlib.metadata import distribution
7
7
  from re import sub
8
8
 
@@ -17,9 +17,9 @@ class Config:
17
17
 
18
18
  def __init__(self) -> None:
19
19
  if not hasattr(self, "_initialized"):
20
- self.source_dir = getcwd()
21
- self.project_name = path.basename(self.source_dir)
22
- self.source_files = listdir()
20
+ self.source_dir = Path.cwd()
21
+ self.source_files = self.source_dir.iterdir()
22
+ self.project_name = Path(self.source_dir).name
23
23
  self.dirs_to_create = [
24
24
  "tests",
25
25
  "templates",
@@ -28,27 +28,28 @@ class Config:
28
28
  "static/js",
29
29
  "static/images",
30
30
  ]
31
- self.install = AutoManager().get_config_managers()
32
- self.pkg_manager = AutoManager().get_pkg_manager()
31
+ manager = AutoManager()
32
+ self.install = manager.get_config_managers()
33
+ self.pkg_manager = manager.get_pkg_manager()
33
34
  self._initialized = True
34
35
 
35
36
 
36
- def create_dirs(self, app_path, extra_dirs=[]) -> None:
37
+ def create_dirs(self, _dirs_to_create: Optional[List[str]] = None) -> None:
37
38
  dirs_to_create: list = self.dirs_to_create.copy()
38
- dirs_to_create.extend(extra_dirs)
39
+ if _dirs_to_create:
40
+ dirs_to_create.extend(_dirs_to_create)
39
41
  #
40
42
  for _dir in dirs_to_create:
41
- makedirs(path.join(app_path, _dir), exist_ok=True)
43
+ (self.source_dir / _dir).mkdir(exist_ok=True)
42
44
 
43
- def create_files(self, file_paths) -> None:
44
- for file_path in file_paths:
45
- with open(path.join(self.source_dir, file_path), "w"): ...
45
+ def create_files(self, relative_file_paths: List[str]) -> None:
46
+ for _relative_path in relative_file_paths:
47
+ with open(self.source_dir / _relative_path, "w"): ...
46
48
 
47
49
 
48
50
  class _ConfigCommands(Struct):
49
51
  install: str
50
52
  uninstall: str
51
- list_: str = field(name="list")
52
53
 
53
54
  class _ConfigFormat(Struct):
54
55
  managers: Dict[str, _ConfigCommands]
@@ -57,12 +58,12 @@ class AutoManager:
57
58
  _instance = None
58
59
  _decoder = json.Decoder(type=_ConfigFormat, strict=True)
59
60
 
60
- def __new__(cls, config_name: str = "managers.json") -> Self:
61
+ def __new__(cls) -> Self:
61
62
  if cls._instance is None:
62
63
  cls._instance = super().__new__(cls)
63
64
  return cls._instance
64
65
 
65
- def __init__(self, config_name: str = "managers.json"):
66
+ def __init__(self, config_name: str = "managers.json") -> None:
66
67
  if not hasattr(self, "_initialized"):
67
68
  self.config_name = config_name
68
69
  self._ConfigFormat = _ConfigFormat
@@ -87,7 +88,11 @@ class AutoManager:
87
88
  pkg = self.get_pkg_manager()
88
89
  if pkg not in managers:
89
90
  raise ValueError(f"Package manager '{pkg}' not found in configuration.")
90
- run([pkg, managers[pkg].install] + libs)
91
+ try:
92
+ run([pkg, managers[pkg].install] + libs, check=True)
93
+ except CalledProcessError as e:
94
+ print(f"Failed to install packages: {e}")
95
+
91
96
 
92
97
  if __name__ == "__main__":
93
98
  # Example usage of AutoManager singleton
@@ -2,28 +2,27 @@
2
2
  "managers": {
3
3
  "pip": {
4
4
  "install": "install",
5
- "uninstall": "uninstall",
6
- "list": "freeze"
5
+ "uninstall": "uninstall"
6
+ },
7
+ "pipx": {
8
+ "install": "install",
9
+ "uninstall": "uninstall"
10
+ },
11
+ "pyenv": {
12
+ "install": "install",
13
+ "uninstall": "uninstall"
7
14
  },
8
15
  "conda": {
9
16
  "install": "install",
10
- "uninstall": "uninstall",
11
- "list": "list"
17
+ "uninstall": "uninstall"
12
18
  },
13
19
  "uv": {
14
20
  "install": "add",
15
- "uninstall": "remove",
16
- "list": "pip list"
17
- },
18
- "pyenv": {
19
- "install": "install",
20
- "uninstall": "uninstall",
21
- "list": "versions"
21
+ "uninstall": "remove"
22
22
  },
23
23
  "poetry": {
24
24
  "install": "add",
25
- "uninstall": "remove",
26
- "list": "show"
25
+ "uninstall": "remove"
27
26
  }
28
27
  }
29
28
  }
@@ -1,6 +1,6 @@
1
1
  from ..template import Template
2
- import os
3
- import pathlib
2
+ from os import path
3
+ from pathlib import Path
4
4
  from subprocess import run
5
5
 
6
6
 
@@ -11,8 +11,8 @@ class DjangoManager(Template):
11
11
  example = True
12
12
 
13
13
  def create_example(self, example_id) -> None:
14
- package_dir = pathlib.Path(__file__).resolve().parent
14
+ package_dir = Path(__file__).resolve().parent
15
15
  example_folder_path = package_dir / "examples" / f"{self.framework_name}_{example_id}"
16
16
 
17
- if os.path.isdir(example_folder_path):
17
+ if path.isdir(example_folder_path):
18
18
  run(["django-admin", "startproject", f"--template={example_folder_path}", self.name])
@@ -3,11 +3,10 @@ from ..template import Template
3
3
  class FastapiManager(Template):
4
4
  extra_libs = ["sqlalchemy", "python-multipart", "databases", "python-multipart", "aiofiles", "uvicorn", "jinja2", "bcrypt"]
5
5
  extra_dirs = ["db"]
6
- example = False
6
+ example = True
7
7
 
8
8
  class StarletteManager(FastapiManager):
9
9
  extra_libs = ["aiomysql"]
10
10
 
11
11
  class LitestarManager(StarletteManager):
12
12
  extra_libs = ["msgspec", "starlette", "httpx"]
13
- example = True
@@ -1,31 +1,26 @@
1
1
  import argparse
2
2
  from pathlib import Path
3
3
  from . import Template
4
- #
5
- import gc
6
4
 
7
- def all_subclasses(cls):
5
+ def all_subclasses(cls) -> list[type]:
8
6
  subclasses = cls.__subclasses__()
9
7
  for subclass in subclasses:
10
8
  subclasses += all_subclasses(subclass)
11
9
  return subclasses
12
10
 
13
- def find_manager_class(base_name: str):
14
- base_name_lower = base_name.lower()
15
- target_suffix = "manager"
16
-
17
- for obj in gc.get_objects():
18
- if isinstance(obj, type):
19
- cls_name = obj.__name__
20
- if cls_name.lower() == base_name_lower + target_suffix:
21
- return obj
11
+ def find_manager_class(base_name: str) -> type:
12
+ base_name_lower = base_name.lower() + "manager"
13
+ for cls in all_subclasses(Template):
14
+ if cls.__name__.lower() == base_name_lower:
15
+ return cls
22
16
  raise Exception(f"Manager class for '{base_name}' not found. Ensure it is defined and imported correctly.")
23
17
 
18
+
24
19
  FRAMEWORKS_PATH = Path(__file__).parent / "frameworks"
25
20
 
26
21
 
27
22
  class Main:
28
- def __init__(self):
23
+ def __init__(self) -> None:
29
24
  #
30
25
  self.available_frameworks = self._discover_frameworks()
31
26
  #
@@ -45,18 +40,18 @@ class Main:
45
40
  #
46
41
  self.framework_manager: type = find_manager_class(self.args.framework)
47
42
 
48
- def _discover_frameworks(self):
43
+ def _discover_frameworks(self) -> list[str]:
49
44
  return sorted(set([cls.__name__.removesuffix("Manager").lower() for cls in all_subclasses(Template)]))
50
45
 
51
- def run(self):
46
+ def run(self) -> None:
52
47
  framework = self.framework_manager(self.args.name)
53
48
  #
54
49
  if hasattr(self.framework_manager, "install_framework"):
55
- framework.install_framework(version=self.args.version)
50
+ framework.install_framework(_version=self.args.version)
56
51
  if hasattr(self.framework_manager, "create_example"):
57
- framework.create_example(1 if self.args.example is None else self.args.example)
52
+ framework.create_example(self.args.example or 1)
58
53
 
59
- def main_entry_point():
54
+ def main_entry_point() -> None:
60
55
  Main().run()
61
56
 
62
57
 
@@ -0,0 +1,80 @@
1
+ from pathlib import Path
2
+ from .config import AutoManager
3
+ from .config import Config
4
+ from typing import Optional, List
5
+ from copy import deepcopy
6
+
7
+
8
+ cfg = Config()
9
+
10
+ class Template:
11
+ extra_libs: List[str]
12
+ extra_dirs: List[str]
13
+ extra_files: List[str]
14
+ example: bool = True
15
+
16
+ def __init_subclass__(cls, **kwargs) -> None:
17
+ super().__init_subclass__(**kwargs)
18
+ cls.framework_name = cls.__name__.lower().removesuffix("manager")
19
+
20
+ bases = [base for base in cls.__mro__[1:] if issubclass(base, Template)]
21
+
22
+ fields = ["extra_libs", "extra_dirs", "extra_files"]
23
+
24
+ seen = set()
25
+ for attr in fields:
26
+ values = [
27
+ item
28
+ for base in reversed(bases)
29
+ if base not in seen and not seen.add(base)
30
+ for item in getattr(base, attr, [])
31
+ ]
32
+ values += getattr(cls, attr, [])
33
+ setattr(cls, attr, values)
34
+
35
+ cls.example = getattr(cls, "example", True)
36
+
37
+
38
+ def __init__(
39
+ self,
40
+ name: str,
41
+ framework_name: Optional[str] = None,
42
+ source_dir: Optional[str] = None,
43
+ project_name: Optional[str] = None
44
+ ):
45
+ self.name = name
46
+ self.source_dir = source_dir or cfg.source_dir
47
+ self.project_name = project_name or cfg.project_name
48
+ self.framework_name = framework_name or self.__class__.framework_name
49
+ self.AutoManager = AutoManager()
50
+ #
51
+ self.extra_libs = deepcopy(self.__class__.extra_libs)
52
+ self.extra_dirs = deepcopy(self.__class__.extra_dirs)
53
+ self.extra_files = deepcopy(self.__class__.extra_files)
54
+ self.example = self.__class__.example
55
+
56
+ def install_framework(self, _version: Optional[str] = None) -> None:
57
+ self.AutoManager.install_libs(
58
+ [f"{self.framework_name}=={_version}"] if _version else [self.framework_name]
59
+ + self.extra_libs)
60
+ self._setup_framework()
61
+
62
+ def _setup_framework(self) -> None:
63
+ if self.extra_dirs:
64
+ cfg.create_dirs(self.extra_dirs)
65
+ if self.extra_files:
66
+ cfg.create_files(self.extra_files)
67
+
68
+ def create_example(self, example_id) -> None:
69
+ if self.example:
70
+ from pkgutil import get_data
71
+
72
+ example_code = get_data("rapidframework", f"frameworks/examples/{self.framework_name}_{example_id}.py")
73
+
74
+ if example_code is None:
75
+ raise FileNotFoundError(f"Example {example_id} not found for {self.framework_name} framework.")
76
+
77
+ with open(Path(self.source_dir) / f"{self.name}.py", "w", encoding="utf-8") as f:
78
+ f.write(example_code.decode("utf-8"))
79
+ else:
80
+ raise NotImplementedError(f"Example creation is not implemented for {self.framework_name} framework.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rapidframework-lib
3
- Version: 1.0.9
3
+ Version: 1.1.1
4
4
  Description-Content-Type: text/markdown
5
5
  License-File: LICENSE
6
6
  Requires-Dist: msgspec
@@ -13,7 +13,7 @@ Dynamic: requires-dist
13
13
 
14
14
  > **RapidFramework** is a Python library for quickly creating and setting up projects from templates.
15
15
 
16
- ## https://pypi.org/project/rapidframework-lib/1.0.9/
16
+ ## https://pypi.org/project/rapidframework-lib/1.1.1/
17
17
 
18
18
  ## Installation
19
19
 
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name="rapidframework-lib",
6
- version="1.0.9",
6
+ version="1.1.1",
7
7
  packages=find_packages(),
8
8
  install_requires=[
9
9
  "msgspec"
@@ -1,88 +0,0 @@
1
- from os import path
2
- from .config import AutoManager
3
- from .config import Config
4
- from typing import Optional, List
5
-
6
- cfg = Config()
7
-
8
- class Template:
9
- extra_libs: List[str] = []
10
- extra_dirs: List[str] = []
11
- extra_files: List[str] = []
12
- example: bool = True
13
-
14
- def __init_subclass__(cls, **kwargs):
15
- super().__init_subclass__(**kwargs)
16
- cls.framework_name = cls.__name__.lower().replace("manager", "")
17
-
18
- bases = [base for base in cls.__mro__[1:] if issubclass(base, Template)]
19
-
20
- seen = set()
21
- for attr in ["extra_libs", "extra_dirs", "extra_files"]:
22
- values = []
23
- for base in reversed(bases):
24
- if base not in seen:
25
- seen.add(base)
26
- values += getattr(base, attr, [])
27
- values += getattr(cls, attr, [])
28
- setattr(cls, attr, values)
29
-
30
- cls.example = getattr(cls, "example", True)
31
-
32
-
33
- def __init__(
34
- self,
35
- name: str,
36
- framework_name: Optional[str] = None,
37
- source_dir = cfg.source_dir,
38
- project_name = cfg.project_name
39
- ):
40
- self.name = name
41
- self.framework_name = framework_name or self.__class__.framework_name
42
- self.source_dir = source_dir
43
- self.project_name = project_name
44
- self.AutoManager = AutoManager()
45
- self.extra_libs = self.__class__.extra_libs
46
- self.extra_dirs = self.__class__.extra_dirs
47
- self.extra_files = self.__class__.extra_files
48
- self.example = self.__class__.example
49
-
50
- def install_framework(self, **kwargs):
51
- version = f"=={kwargs.get('version')}" if kwargs.get('version') else ""
52
- libs_to_install: list = kwargs.get("libs") or []
53
- #
54
- libs_to_install.extend([f"{self.framework_name}{version}"])
55
- libs_to_install.extend(self.extra_libs)
56
- #
57
- self.AutoManager.install_libs(libs_to_install)
58
- #
59
- self.setup_framework()
60
-
61
- def setup_framework(self, _source_dir: Optional[str] = None, extra_dirs: Optional[list] = None, extra_files: Optional[list] = None):
62
- source_dir: str = _source_dir or self.source_dir
63
- #
64
- dirs = (extra_dirs or []) + self.extra_dirs
65
- files = (extra_files or []) + self.extra_files
66
- #
67
- if dirs:
68
- cfg.create_dirs(source_dir, dirs)
69
- if files:
70
- cfg.create_files(files)
71
-
72
- def create_example(self, example_id) -> None:
73
- if self.example:
74
- from pkgutil import get_data
75
-
76
- example_code = get_data(
77
- "rapidframework",
78
- f"frameworks/examples/{self.framework_name}_{example_id}.py",
79
- )
80
- if not example_code:
81
- raise Exception(f"Example {example_id} not found for {self.framework_name} framework.")
82
-
83
- with open(
84
- path.join(self.source_dir, self.name + ".py"), "w", encoding="utf-8"
85
- ) as example_file:
86
- example_file.write(example_code.decode("utf-8"))
87
- else:
88
- raise Exception("Example method is'n allowed for this framework !")