rapidframework-lib 1.0.8.2__py3-none-any.whl → 1.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.
Files changed (23) hide show
  1. rapidframework/config.py +64 -45
  2. rapidframework/frameworks/django.py +16 -31
  3. rapidframework/frameworks/examples/django_1/manage.py-tpl +25 -0
  4. rapidframework/frameworks/examples/django_1/project_name/__init__.py-tpl +0 -0
  5. rapidframework/frameworks/examples/django_1/project_name/asgi.py-tpl +21 -0
  6. rapidframework/frameworks/examples/django_1/project_name/settings.py-tpl +162 -0
  7. rapidframework/frameworks/examples/django_1/project_name/urls.py-tpl +13 -0
  8. rapidframework/frameworks/examples/django_1/project_name/users/__init__.py-tpl +0 -0
  9. rapidframework/frameworks/examples/django_1/project_name/users/admin.py-tpl +5 -0
  10. rapidframework/frameworks/examples/django_1/project_name/users/migrations/0001_initial.py-tpl +46 -0
  11. rapidframework/frameworks/examples/django_1/project_name/users/migrations/__init__.py-tpl +0 -0
  12. rapidframework/frameworks/examples/django_1/project_name/users/models.py-tpl +5 -0
  13. rapidframework/frameworks/examples/django_1/project_name/wsgi.py-tpl +18 -0
  14. rapidframework/frameworks/fastapi.py +2 -0
  15. rapidframework/main.py +3 -5
  16. rapidframework/template.py +20 -11
  17. {rapidframework_lib-1.0.8.2.dist-info → rapidframework_lib-1.0.9.dist-info}/METADATA +2 -2
  18. rapidframework_lib-1.0.9.dist-info/RECORD +40 -0
  19. rapidframework_lib-1.0.8.2.dist-info/RECORD +0 -29
  20. {rapidframework_lib-1.0.8.2.dist-info → rapidframework_lib-1.0.9.dist-info}/WHEEL +0 -0
  21. {rapidframework_lib-1.0.8.2.dist-info → rapidframework_lib-1.0.9.dist-info}/entry_points.txt +0 -0
  22. {rapidframework_lib-1.0.8.2.dist-info → rapidframework_lib-1.0.9.dist-info}/licenses/LICENSE +0 -0
  23. {rapidframework_lib-1.0.8.2.dist-info → rapidframework_lib-1.0.9.dist-info}/top_level.txt +0 -0
rapidframework/config.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from os import getcwd, listdir, path, makedirs
2
2
  from typing import Self, Dict
3
3
  import pkgutil
4
- from msgspec import json, Struct, field
4
+ from msgspec import json, Struct, field, DecodeError
5
5
  from subprocess import run
6
6
  from importlib.metadata import distribution
7
7
  from re import sub
@@ -12,10 +12,15 @@ class Config:
12
12
 
13
13
  def __new__(cls) -> Self:
14
14
  if cls._instance is None:
15
- cls._instance = super(Config, cls).__new__(cls)
16
- cls._instance.source_dir = getcwd()
17
- cls._instance.source_files = listdir()
18
- cls._instance.dirs_to_create = [
15
+ cls._instance = super().__new__(cls)
16
+ return cls._instance
17
+
18
+ def __init__(self) -> None:
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()
23
+ self.dirs_to_create = [
19
24
  "tests",
20
25
  "templates",
21
26
  "static",
@@ -23,61 +28,75 @@ class Config:
23
28
  "static/js",
24
29
  "static/images",
25
30
  ]
31
+ self.install = AutoManager().get_config_managers()
32
+ self.pkg_manager = AutoManager().get_pkg_manager()
33
+ self._initialized = True
26
34
 
27
- # cls._instance.pyproject_deps: list
28
- cls._instance.project_name = path.basename(cls._instance.source_dir)
29
- cls.install = AutoManager().get_config_managers()
30
- cls.pkg_manager = AutoManager().get_pkg_manager()
31
-
32
- return cls._instance
33
35
 
34
- def create_dirs(cls, app_path, extra_dirs=[]) -> None:
35
- dirs_to_create: list = cls._instance.dirs_to_create.copy()
36
+ def create_dirs(self, app_path, extra_dirs=[]) -> None:
37
+ dirs_to_create: list = self.dirs_to_create.copy()
36
38
  dirs_to_create.extend(extra_dirs)
37
39
  #
38
40
  for _dir in dirs_to_create:
39
41
  makedirs(path.join(app_path, _dir), exist_ok=True)
40
-
41
- def create_files(cls, file_paths) -> None:
42
+
43
+ def create_files(self, file_paths) -> None:
42
44
  for file_path in file_paths:
43
- with open(path.join(cls._instance.source_dir, file_path), "w"): ...
45
+ with open(path.join(self.source_dir, file_path), "w"): ...
44
46
 
47
+
48
+ class _ConfigCommands(Struct):
49
+ install: str
50
+ uninstall: str
51
+ list_: str = field(name="list")
45
52
 
46
- class AutoManager:
47
- _instance = None
53
+ class _ConfigFormat(Struct):
54
+ managers: Dict[str, _ConfigCommands]
48
55
 
49
-
56
+ class AutoManager:
57
+ _instance = None
58
+ _decoder = json.Decoder(type=_ConfigFormat, strict=True)
59
+
50
60
  def __new__(cls, config_name: str = "managers.json") -> Self:
51
61
  if cls._instance is None:
52
- cls._instance = super(AutoManager, cls).__new__(cls)
53
-
54
- class _ConfigCommands(Struct):
55
- install: str
56
- uninstall: str
57
- list_: str = field(name="list")
58
-
59
- class _ConfigFormat(Struct):
60
- managers: Dict[str, _ConfigCommands]
61
-
62
- cls._instance.config_name = config_name
63
- cls._instance._ConfigFormat = _ConfigFormat
64
- cls._instance.decoder = json.Decoder()
65
-
62
+ cls._instance = super().__new__(cls)
66
63
  return cls._instance
67
-
68
-
69
- def get_config_managers(cls) -> dict:
70
- config = pkgutil.get_data("rapidframework", f"configs/{cls._instance.config_name}")
71
- return json.decode(config.decode("utf-8"), type=cls._instance._ConfigFormat)
72
64
 
65
+ def __init__(self, config_name: str = "managers.json"):
66
+ if not hasattr(self, "_initialized"):
67
+ self.config_name = config_name
68
+ self._ConfigFormat = _ConfigFormat
69
+ self._initialized = True
70
+
71
+ def get_config_managers(self) -> _ConfigFormat:
72
+ config = pkgutil.get_data("rapidframework", f"configs/{self.config_name}")
73
+ #
74
+ if config is None:
75
+ raise FileNotFoundError(f"Configuration file '{self.config_name}' not found.")
76
+ #
77
+ return self._decoder.decode(config.decode("utf-8"))
73
78
 
74
- def get_pkg_manager(cls) -> str:
79
+ def get_pkg_manager(self) -> str:
75
80
  try:
76
- return sub(r'\s+', '', distribution("rapidframework-lib").read_text("INSTALLER"))
77
- except:
81
+ return sub(r'\s+', '', distribution("rapidframework-lib").read_text("INSTALLER")) # type: ignore
82
+ except (DecodeError, FileNotFoundError, ValueError):
78
83
  return "pip"
79
84
 
80
-
81
- def install_libs(cls, libs: list) -> None:
82
- print(libs)
83
- run([cls.get_pkg_manager(), cls.get_config_managers().managers.get(cls.get_pkg_manager()).install] + libs)
85
+ def install_libs(self, libs: list) -> None:
86
+ managers = self.get_config_managers().managers
87
+ pkg = self.get_pkg_manager()
88
+ if pkg not in managers:
89
+ raise ValueError(f"Package manager '{pkg}' not found in configuration.")
90
+ run([pkg, managers[pkg].install] + libs)
91
+
92
+ if __name__ == "__main__":
93
+ # Example usage of AutoManager singleton
94
+ a = AutoManager()
95
+ b = AutoManager()
96
+ print(f"{a is b=}") # Should print True, confirming singleton behavior
97
+ assert a is b
98
+ # # Example usage of Config singleton
99
+ c = Config()
100
+ d = Config()
101
+ print(f"{c is d=}") # Should print True, confirming singleton behavior
102
+ assert c is d
@@ -1,33 +1,18 @@
1
- # from ..template import Template
2
- # from subprocess import run
3
- # from os import chdir
1
+ from ..template import Template
2
+ import os
3
+ import pathlib
4
+ from subprocess import run
4
5
 
5
6
 
6
- # class DjangoManager(Template):
7
- # extra_libs = ["Pillow"]
8
- # example = False
9
-
10
- # def run_manage(self, commands: list):
11
- # manage_py = f"{self.source_dir}/{self.project_name}/manage.py"
12
- # for command in commands:
13
- # full_command = ["python", manage_py] + command.strip().split(" ")
14
- # run(full_command, check=True)
15
-
16
- # def setup_framework(self):
17
- # run([
18
- # "python", "-m", "django", "startproject",
19
- # self.project_name, self.source_dir
20
- # ], check=True)
21
-
22
- # chdir(f"{self.source_dir}/{self.project_name}")
23
- # self.run_manage([f"startapp {self.name}", "makemigrations", "migrate"])
24
-
25
- # self.extra_files.append(f"{self.project_name}/{self.name}/urls.py")
26
-
27
- # return super().setup_framework(
28
- # source_dir=f"{self.source_dir}/{self.project_name}/{self.name}",
29
- # extra_files=self.extra_files
30
- # )
31
- """
32
- The class is being redeveloped for better performance and capabilities
33
- """
7
+ class DjangoManager(Template):
8
+ extra_libs = ["Pillow", "djangorestframework", "django-cors-headers", \
9
+ "celery", "django-redis", "redis", "django-allauth", "django-crispy-forms", "django-environ", \
10
+ "django-extensions", "gunicorn", "whitenoise", "django-configurations", "django-debug-toolbar"]
11
+ example = True
12
+
13
+ def create_example(self, example_id) -> None:
14
+ package_dir = pathlib.Path(__file__).resolve().parent
15
+ example_folder_path = package_dir / "examples" / f"{self.framework_name}_{example_id}"
16
+
17
+ if os.path.isdir(example_folder_path):
18
+ run(["django-admin", "startproject", f"--template={example_folder_path}", self.name])
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env python
2
+ """Django's command-line utility for administrative tasks."""
3
+ import os
4
+ import sys
5
+
6
+
7
+ def main():
8
+ """Run administrative tasks."""
9
+ configuration = os.getenv('ENVIRONMENT', 'development').title()
10
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
11
+ os.environ.setdefault('DJANGO_CONFIGURATION', configuration)
12
+
13
+ try:
14
+ from configurations.management import execute_from_command_line
15
+ except ImportError as exc:
16
+ raise ImportError(
17
+ "Couldn't import Django. Are you sure it's installed and "
18
+ "available on your PYTHONPATH environment variable? Did you "
19
+ "forget to activate a virtual environment?"
20
+ ) from exc
21
+ execute_from_command_line(sys.argv)
22
+
23
+
24
+ if __name__ == '__main__':
25
+ main()
@@ -0,0 +1,21 @@
1
+ """
2
+ ASGI config for {{ project_name }} project.
3
+
4
+ It exposes the ASGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/asgi/
8
+ """
9
+
10
+ import os
11
+
12
+
13
+ configuration = os.getenv('ENVIRONMENT', 'development').title()
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
15
+ os.environ.setdefault('DJANGO_CONFIGURATION', configuration)
16
+
17
+ from configurations import importer # noqa
18
+ importer.install()
19
+
20
+ from django.core.asgi import get_asgi_application # noqa
21
+ application = get_asgi_application()
@@ -0,0 +1,162 @@
1
+ """
2
+ Django settings for {{ project_name }} project.
3
+
4
+ For more information on this file, see
5
+ https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/
6
+
7
+ For the full list of settings and their values, see
8
+ https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
9
+ """
10
+ import os
11
+ from pathlib import Path
12
+
13
+ from configurations import Configuration, values
14
+
15
+
16
+ class Common(Configuration):
17
+ # Build paths inside the project like this: BASE_DIR / 'subdir'.
18
+ BASE_DIR = Path(__file__).resolve().parent.parent
19
+
20
+ # SECURITY WARNING: keep the secret key used in production secret!
21
+ SECRET_KEY = values.SecretValue()
22
+
23
+ # SECURITY WARNING: don't run with debug turned on in production!
24
+ DEBUG = values.BooleanValue(False)
25
+
26
+ ALLOWED_HOSTS = values.ListValue([])
27
+
28
+ # Application definition
29
+ INSTALLED_APPS = [
30
+ 'django.contrib.admin',
31
+ 'django.contrib.auth',
32
+ 'django.contrib.contenttypes',
33
+ 'django.contrib.sessions',
34
+ 'django.contrib.messages',
35
+ 'whitenoise.runserver_nostatic',
36
+ 'django.contrib.staticfiles',
37
+
38
+ 'django_extensions',
39
+ 'debug_toolbar',
40
+
41
+ '{{ project_name }}.users',
42
+ ]
43
+
44
+ MIDDLEWARE = [
45
+ 'django.middleware.security.SecurityMiddleware',
46
+ 'whitenoise.middleware.WhiteNoiseMiddleware',
47
+ 'django.contrib.sessions.middleware.SessionMiddleware',
48
+ 'django.middleware.common.CommonMiddleware',
49
+ 'django.middleware.csrf.CsrfViewMiddleware',
50
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
51
+ 'django.contrib.messages.middleware.MessageMiddleware',
52
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
53
+ ]
54
+
55
+ ROOT_URLCONF = '{{ project_name }}.urls'
56
+
57
+ TEMPLATES = [
58
+ {
59
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
60
+ 'DIRS': [],
61
+ 'APP_DIRS': True,
62
+ 'OPTIONS': {
63
+ 'context_processors': [
64
+ 'django.template.context_processors.debug',
65
+ 'django.template.context_processors.request',
66
+ 'django.contrib.auth.context_processors.auth',
67
+ 'django.contrib.messages.context_processors.messages',
68
+ ],
69
+ },
70
+ },
71
+ ]
72
+
73
+ WSGI_APPLICATION = '{{ project_name }}.wsgi.application'
74
+
75
+ # Database
76
+ # https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases
77
+ DATABASES = values.DatabaseURLValue(
78
+ 'sqlite:///{}'.format(os.path.join(BASE_DIR, 'db.sqlite3'))
79
+ )
80
+
81
+ # Password validation
82
+ # https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#auth-password-validators
83
+ AUTH_PASSWORD_VALIDATORS = [
84
+ {
85
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
86
+ },
87
+ {
88
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
89
+ },
90
+ {
91
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
92
+ },
93
+ {
94
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
95
+ },
96
+ ]
97
+
98
+ # Internationalization
99
+ # https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/
100
+ LANGUAGE_CODE = 'en-us'
101
+
102
+ TIME_ZONE = 'UTC'
103
+
104
+ USE_I18N = True
105
+
106
+ USE_L10N = True
107
+
108
+ USE_TZ = True
109
+
110
+ # Static files (CSS, JavaScript, Images)
111
+ # https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
112
+ STATIC_URL = '/static/'
113
+ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
114
+ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
115
+
116
+ # Default primary key field type
117
+ # https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#default-auto-field
118
+ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
119
+
120
+ AUTH_USER_MODEL = 'users.User'
121
+
122
+
123
+ class Development(Common):
124
+ """
125
+ The in-development settings and the default configuration.
126
+ """
127
+ DEBUG = True
128
+
129
+ ALLOWED_HOSTS = []
130
+
131
+ INTERNAL_IPS = [
132
+ '127.0.0.1'
133
+ ]
134
+
135
+ MIDDLEWARE = Common.MIDDLEWARE + [
136
+ 'debug_toolbar.middleware.DebugToolbarMiddleware'
137
+ ]
138
+
139
+
140
+ class Staging(Common):
141
+ """
142
+ The in-staging settings.
143
+ """
144
+ # Security
145
+ SESSION_COOKIE_SECURE = values.BooleanValue(True)
146
+ SECURE_BROWSER_XSS_FILTER = values.BooleanValue(True)
147
+ SECURE_CONTENT_TYPE_NOSNIFF = values.BooleanValue(True)
148
+ SECURE_HSTS_INCLUDE_SUBDOMAINS = values.BooleanValue(True)
149
+ SECURE_HSTS_SECONDS = values.IntegerValue(31536000)
150
+ SECURE_REDIRECT_EXEMPT = values.ListValue([])
151
+ SECURE_SSL_HOST = values.Value(None)
152
+ SECURE_SSL_REDIRECT = values.BooleanValue(True)
153
+ SECURE_PROXY_SSL_HEADER = values.TupleValue(
154
+ ('HTTP_X_FORWARDED_PROTO', 'https')
155
+ )
156
+
157
+
158
+ class Production(Staging):
159
+ """
160
+ The in-production settings.
161
+ """
162
+ pass
@@ -0,0 +1,13 @@
1
+ from django.conf import settings
2
+ from django.contrib import admin
3
+ from django.urls import include, path
4
+
5
+ urlpatterns = [
6
+ path('admin/', admin.site.urls),
7
+ ]
8
+
9
+ if settings.DEBUG:
10
+ import debug_toolbar
11
+ urlpatterns = [
12
+ path('__debug__/', include(debug_toolbar.urls)),
13
+ ] + urlpatterns
@@ -0,0 +1,5 @@
1
+ from django.contrib import admin
2
+ from django.contrib.auth.admin import UserAdmin
3
+ from .models import User
4
+
5
+ admin.site.register(User, UserAdmin)
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by Django 1.11.2 on 2017-06-20 13:29
3
+ from __future__ import unicode_literals
4
+
5
+ import django.contrib.auth.models
6
+ import django.contrib.auth.validators
7
+ from django.db import migrations, models
8
+ import django.utils.timezone
9
+
10
+
11
+ class Migration(migrations.Migration):
12
+
13
+ initial = True
14
+
15
+ dependencies = [
16
+ ('auth', '0008_alter_user_username_max_length'),
17
+ ]
18
+
19
+ operations = [
20
+ migrations.CreateModel(
21
+ name='User',
22
+ fields=[
23
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
24
+ ('password', models.CharField(max_length=128, verbose_name='password')),
25
+ ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
26
+ ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
27
+ ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
28
+ ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
29
+ ('last_name', models.CharField(blank=True, max_length=30, verbose_name='last name')),
30
+ ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
31
+ ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
32
+ ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
33
+ ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
34
+ ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
35
+ ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
36
+ ],
37
+ options={
38
+ 'verbose_name_plural': 'users',
39
+ 'verbose_name': 'user',
40
+ 'abstract': False,
41
+ },
42
+ managers=[
43
+ ('objects', django.contrib.auth.models.UserManager()),
44
+ ],
45
+ ),
46
+ ]
@@ -0,0 +1,5 @@
1
+ from django.contrib.auth.models import AbstractUser
2
+
3
+
4
+ class User(AbstractUser):
5
+ pass
@@ -0,0 +1,18 @@
1
+ """
2
+ WSGI config for {{ project_name }} project.
3
+
4
+ It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/wsgi/
8
+ """
9
+
10
+ import os
11
+
12
+ configuration = os.getenv('ENVIRONMENT', 'development').title()
13
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
14
+ os.environ.setdefault('DJANGO_CONFIGURATION', configuration)
15
+
16
+ from configurations.wsgi import get_wsgi_application
17
+
18
+ application = get_wsgi_application()
@@ -3,9 +3,11 @@ 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
7
 
7
8
  class StarletteManager(FastapiManager):
8
9
  extra_libs = ["aiomysql"]
9
10
 
10
11
  class LitestarManager(StarletteManager):
11
12
  extra_libs = ["msgspec", "starlette", "httpx"]
13
+ example = True
rapidframework/main.py CHANGED
@@ -19,7 +19,7 @@ def find_manager_class(base_name: str):
19
19
  cls_name = obj.__name__
20
20
  if cls_name.lower() == base_name_lower + target_suffix:
21
21
  return obj
22
- return None
22
+ raise Exception(f"Manager class for '{base_name}' not found. Ensure it is defined and imported correctly.")
23
23
 
24
24
  FRAMEWORKS_PATH = Path(__file__).parent / "frameworks"
25
25
 
@@ -43,20 +43,18 @@ class Main:
43
43
  #
44
44
  self.args = self.parser.parse_args()
45
45
  #
46
- self.framework_manager = find_manager_class(self.args.framework)
46
+ self.framework_manager: type = find_manager_class(self.args.framework)
47
47
 
48
48
  def _discover_frameworks(self):
49
49
  return sorted(set([cls.__name__.removesuffix("Manager").lower() for cls in all_subclasses(Template)]))
50
50
 
51
51
  def run(self):
52
- example_id = 1 if self.args.example is None else self.args.example
53
- #
54
52
  framework = self.framework_manager(self.args.name)
55
53
  #
56
54
  if hasattr(self.framework_manager, "install_framework"):
57
55
  framework.install_framework(version=self.args.version)
58
56
  if hasattr(self.framework_manager, "create_example"):
59
- framework.create_example(example_id)
57
+ framework.create_example(1 if self.args.example is None else self.args.example)
60
58
 
61
59
  def main_entry_point():
62
60
  Main().run()
@@ -17,11 +17,18 @@ class Template:
17
17
 
18
18
  bases = [base for base in cls.__mro__[1:] if issubclass(base, Template)]
19
19
 
20
- cls.extra_libs = sum([getattr(base, "extra_libs", []) for base in reversed(bases)], []) + cls.extra_libs
21
- cls.extra_dirs = sum([getattr(base, "extra_dirs", []) for base in reversed(bases)], []) + cls.extra_dirs
22
- cls.extra_files = sum([getattr(base, "extra_files", []) for base in reversed(bases)], []) + cls.extra_files
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)
23
29
 
24
30
  cls.example = getattr(cls, "example", True)
31
+
25
32
 
26
33
  def __init__(
27
34
  self,
@@ -51,8 +58,8 @@ class Template:
51
58
  #
52
59
  self.setup_framework()
53
60
 
54
- def setup_framework(self, source_dir: list = None, extra_dirs: list = None, extra_files: list = None):
55
- source_dir = source_dir or self.source_dir
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
56
63
  #
57
64
  dirs = (extra_dirs or []) + self.extra_dirs
58
65
  files = (extra_files or []) + self.extra_files
@@ -62,18 +69,20 @@ class Template:
62
69
  if files:
63
70
  cfg.create_files(files)
64
71
 
65
- def create_example(self, example_id):
66
- if self.__class__.example:
72
+ def create_example(self, example_id) -> None:
73
+ if self.example:
67
74
  from pkgutil import get_data
68
-
75
+
69
76
  example_code = get_data(
70
77
  "rapidframework",
71
78
  f"frameworks/examples/{self.framework_name}_{example_id}.py",
72
- ).decode("utf-8")
73
-
79
+ )
80
+ if not example_code:
81
+ raise Exception(f"Example {example_id} not found for {self.framework_name} framework.")
82
+
74
83
  with open(
75
84
  path.join(self.source_dir, self.name + ".py"), "w", encoding="utf-8"
76
85
  ) as example_file:
77
- example_file.write(example_code)
86
+ example_file.write(example_code.decode("utf-8"))
78
87
  else:
79
88
  raise Exception("Example method is'n allowed for this framework !")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rapidframework-lib
3
- Version: 1.0.8.2
3
+ Version: 1.0.9
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.8.2/
16
+ ## https://pypi.org/project/rapidframework-lib/1.0.9/
17
17
 
18
18
  ## Installation
19
19
 
@@ -0,0 +1,40 @@
1
+ rapidframework/__init__.py,sha256=0f6S18Vy0QQs3VW9m4A6sNDfHoYGvf9Dzk32xlZ5RNs,151
2
+ rapidframework/config.py,sha256=xfsmdtMfmOSe6LXLMkDWbTiPdRHPSRhLkICvvk2I0Ug,3470
3
+ rapidframework/main.py,sha256=9c-iaW4QAnVFLgHVBz6oYqhx8-QnlPOI6XBt9yrNoqU,2129
4
+ rapidframework/template.py,sha256=Km9hI435jh_GjZmjWjqRA-DdE0QxBBF20IuFcQTUC4c,3148
5
+ rapidframework/__pycache__/main.cpython-313.pyc,sha256=J3Y41E5fOwmGEQtwgTq-NBUl0s0VxCvDC5KUnCGvIdU,3891
6
+ rapidframework/configs/managers.json,sha256=EEBDjTVQuNXGIF_oIXuNVpXK4kTk2HsRb2aPrbmUjo4,664
7
+ rapidframework/frameworks/__init__.py,sha256=CJETvRzO000nPloWwKFd-AnLmR5PM9SSZUyB-C4M8a4,464
8
+ rapidframework/frameworks/django.py,sha256=eG69Sdn4ALn0fAXeY1TknJgTvcut8TArDybluPjF_Jo,792
9
+ rapidframework/frameworks/fastapi.py,sha256=vZ06QrsTJqzasnt1q7Bph59F3CcoKz_xuAv8CEcUFU8,428
10
+ rapidframework/frameworks/simple_frameworks.py,sha256=9PEu-ZvA17pT7QLQTnfQ_2PGjCDbi8ECaaSO1MPp2Lg,1023
11
+ rapidframework/frameworks/examples/__init__.py,sha256=ovguP4wzQEDNguczwiZnhMm4dRRVcvnzmHrfQtlRCNQ,15
12
+ rapidframework/frameworks/examples/bottle_1.py,sha256=AhEqgse_IinZ0jx211y0ybyxB0dknGI-x6zhIOQ4Qos,118
13
+ rapidframework/frameworks/examples/cherrypy_1.py,sha256=BKNIPXOgWFTpnwyFK46NMDmPtFnhAARAPAkwgQ-0CYQ,146
14
+ rapidframework/frameworks/examples/fastapi_1.py,sha256=Rhmcr1BrBHR1_xhqk4UmZiF5MDqixRbucR03T6yvBvg,261
15
+ rapidframework/frameworks/examples/flask_1.py,sha256=DuVlouunkJtGygqrU2B_ysKUtKTP-MWCmgpHmTGqeJM,428
16
+ rapidframework/frameworks/examples/grok_1.py,sha256=Lz9xIGiYf1q4IJIMQVy1uzGeBLw2opXOdwqnSdv0j3A,146
17
+ rapidframework/frameworks/examples/litestar_1.py,sha256=kcAsS3LE5g6ZYmkNtRsrLHTNSmtCUXtsgJmoOtiubnk,220
18
+ rapidframework/frameworks/examples/pyramid_1.py,sha256=k1pinobySIBnWQI4KxpvnFTjgFPFzLzYRijhvY4p7U8,456
19
+ rapidframework/frameworks/examples/socketify_1.py,sha256=xV54kgvvXRhqhvGLet9qGE13ZdMVI3EvZ_AV1csCWx0,184
20
+ rapidframework/frameworks/examples/starlette_1.py,sha256=6T9tUyXJ329qHl3ZYgNOCy5eXOX8luT2HP_FWfQ6E4Y,268
21
+ rapidframework/frameworks/examples/tornado_1.py,sha256=vnOqnzcFyCFSMl_5x4pyfbYi6PL9EMQBn9Mv_6yXpZM,368
22
+ rapidframework/frameworks/examples/turbogears2_1.py,sha256=IytFwU7N-qSi3CDQDrN2wNHDAfV60swOw44_D-UDr-I,435
23
+ rapidframework/frameworks/examples/web2py_1.py,sha256=fscmfjeH9HUb96aDGZBLS88e9Fx_nbU1usLDb0GWbRs,41
24
+ rapidframework/frameworks/examples/django_1/manage.py-tpl,sha256=kmDMGGVdz-D_EWebfbnza_uczyqWZ9TLFHe9ZZZC6qs,811
25
+ rapidframework/frameworks/examples/django_1/project_name/__init__.py-tpl,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
+ rapidframework/frameworks/examples/django_1/project_name/asgi.py-tpl,sha256=vsenIiDoaHY6VDf8X9N_h0oT8DFBS6OipYg8dPOPwD0,626
27
+ rapidframework/frameworks/examples/django_1/project_name/settings.py-tpl,sha256=J_fjSigDjBdVQvA4cyP0Ge79mvj62h1jN8uZEksZmMk,4898
28
+ rapidframework/frameworks/examples/django_1/project_name/urls.py-tpl,sha256=FF6eNEcArBxSBpYkPP4tE_Q-x_12HjiBNJfsPvAUXsw,302
29
+ rapidframework/frameworks/examples/django_1/project_name/wsgi.py-tpl,sha256=gdu2tnPhAeqYvTfSpEOdA8-5uC5h_RsoYSrGnnI2lKI,556
30
+ rapidframework/frameworks/examples/django_1/project_name/users/__init__.py-tpl,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
+ rapidframework/frameworks/examples/django_1/project_name/users/admin.py-tpl,sha256=2WGwHDAbzSlNWKj_pjBT4hmhPdNUmob8cI-rpjNVexw,144
32
+ rapidframework/frameworks/examples/django_1/project_name/users/models.py-tpl,sha256=BDqPNCqoqDWPRTQJZjyRQSk9zwPVV14HLKtjS-qtKz8,89
33
+ rapidframework/frameworks/examples/django_1/project_name/users/migrations/0001_initial.py-tpl,sha256=V-yCkAE_F0oWEAG4xcSLPOjxnbD3sPble_On_Ny49kA,2931
34
+ rapidframework/frameworks/examples/django_1/project_name/users/migrations/__init__.py-tpl,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ rapidframework_lib-1.0.9.dist-info/licenses/LICENSE,sha256=lXsPzvyEfL6vjzMMCRYi7gpsIjpSUYUsDF-MvMHyhc0,1070
36
+ rapidframework_lib-1.0.9.dist-info/METADATA,sha256=tsriVBHgFt36eExvJ8rloKzHLAlB-qq44W_-B5TBtzA,1242
37
+ rapidframework_lib-1.0.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
38
+ rapidframework_lib-1.0.9.dist-info/entry_points.txt,sha256=UaOaGJ-BDCxtmNoPp-u_TnXXLbnXtrB13PYr5BgqmHA,72
39
+ rapidframework_lib-1.0.9.dist-info/top_level.txt,sha256=7PXDkFZsYowz4aB2xVaSso4qD45jd2kHn6x3xxhMMNs,15
40
+ rapidframework_lib-1.0.9.dist-info/RECORD,,
@@ -1,29 +0,0 @@
1
- rapidframework/__init__.py,sha256=0f6S18Vy0QQs3VW9m4A6sNDfHoYGvf9Dzk32xlZ5RNs,151
2
- rapidframework/config.py,sha256=lNptfXPi50MELfL2BnaQFa9-ea6lv7R9abqipFwqwYE,2767
3
- rapidframework/main.py,sha256=P5MT1oCo-ntw9RT0V364wiRH_5-I5TiKvzqCik8doxo,2069
4
- rapidframework/template.py,sha256=pRMEFgVY5YfxxCqMgqlil11AlJpx46H9A6rswkOS3iY,2925
5
- rapidframework/__pycache__/main.cpython-313.pyc,sha256=J3Y41E5fOwmGEQtwgTq-NBUl0s0VxCvDC5KUnCGvIdU,3891
6
- rapidframework/configs/managers.json,sha256=EEBDjTVQuNXGIF_oIXuNVpXK4kTk2HsRb2aPrbmUjo4,664
7
- rapidframework/frameworks/__init__.py,sha256=CJETvRzO000nPloWwKFd-AnLmR5PM9SSZUyB-C4M8a4,464
8
- rapidframework/frameworks/django.py,sha256=8uY20KU608Ku5tTQPlCrxI8ye7Pz7XS4jhZ9vVJmYOM,1110
9
- rapidframework/frameworks/fastapi.py,sha256=uAbUCzJxIgYnfmsq2SSxc_tvKsKQpBY9F3ahr1Vxhrg,389
10
- rapidframework/frameworks/simple_frameworks.py,sha256=9PEu-ZvA17pT7QLQTnfQ_2PGjCDbi8ECaaSO1MPp2Lg,1023
11
- rapidframework/frameworks/examples/__init__.py,sha256=ovguP4wzQEDNguczwiZnhMm4dRRVcvnzmHrfQtlRCNQ,15
12
- rapidframework/frameworks/examples/bottle_1.py,sha256=AhEqgse_IinZ0jx211y0ybyxB0dknGI-x6zhIOQ4Qos,118
13
- rapidframework/frameworks/examples/cherrypy_1.py,sha256=BKNIPXOgWFTpnwyFK46NMDmPtFnhAARAPAkwgQ-0CYQ,146
14
- rapidframework/frameworks/examples/fastapi_1.py,sha256=Rhmcr1BrBHR1_xhqk4UmZiF5MDqixRbucR03T6yvBvg,261
15
- rapidframework/frameworks/examples/flask_1.py,sha256=DuVlouunkJtGygqrU2B_ysKUtKTP-MWCmgpHmTGqeJM,428
16
- rapidframework/frameworks/examples/grok_1.py,sha256=Lz9xIGiYf1q4IJIMQVy1uzGeBLw2opXOdwqnSdv0j3A,146
17
- rapidframework/frameworks/examples/litestar_1.py,sha256=kcAsS3LE5g6ZYmkNtRsrLHTNSmtCUXtsgJmoOtiubnk,220
18
- rapidframework/frameworks/examples/pyramid_1.py,sha256=k1pinobySIBnWQI4KxpvnFTjgFPFzLzYRijhvY4p7U8,456
19
- rapidframework/frameworks/examples/socketify_1.py,sha256=xV54kgvvXRhqhvGLet9qGE13ZdMVI3EvZ_AV1csCWx0,184
20
- rapidframework/frameworks/examples/starlette_1.py,sha256=6T9tUyXJ329qHl3ZYgNOCy5eXOX8luT2HP_FWfQ6E4Y,268
21
- rapidframework/frameworks/examples/tornado_1.py,sha256=vnOqnzcFyCFSMl_5x4pyfbYi6PL9EMQBn9Mv_6yXpZM,368
22
- rapidframework/frameworks/examples/turbogears2_1.py,sha256=IytFwU7N-qSi3CDQDrN2wNHDAfV60swOw44_D-UDr-I,435
23
- rapidframework/frameworks/examples/web2py_1.py,sha256=fscmfjeH9HUb96aDGZBLS88e9Fx_nbU1usLDb0GWbRs,41
24
- rapidframework_lib-1.0.8.2.dist-info/licenses/LICENSE,sha256=lXsPzvyEfL6vjzMMCRYi7gpsIjpSUYUsDF-MvMHyhc0,1070
25
- rapidframework_lib-1.0.8.2.dist-info/METADATA,sha256=Zgf5i3IZUmq8nprCwJa8D1fVKe8M2S0t7WtD47Tub5k,1246
26
- rapidframework_lib-1.0.8.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- rapidframework_lib-1.0.8.2.dist-info/entry_points.txt,sha256=UaOaGJ-BDCxtmNoPp-u_TnXXLbnXtrB13PYr5BgqmHA,72
28
- rapidframework_lib-1.0.8.2.dist-info/top_level.txt,sha256=7PXDkFZsYowz4aB2xVaSso4qD45jd2kHn6x3xxhMMNs,15
29
- rapidframework_lib-1.0.8.2.dist-info/RECORD,,