Skip to content

Commit 6dba192

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent d21ed00 commit 6dba192

File tree

12 files changed

+126
-93
lines changed

12 files changed

+126
-93
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ updates:
99
directory: "/" # Location of package manifests
1010
schedule:
1111
interval: "weekly"
12-

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ jobs:
4848
# If you wish to specify custom queries, you can do so here or in a config file.
4949
# By default, queries listed here will override any specified in a config file.
5050
# Prefix the list here with "+" to use these queries and those in the config file.
51-
51+
5252
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
5353
# queries: security-extended,security-and-quality
5454

55-
55+
5656
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5757
# If this step fails, then you should remove it and run the build manually (see below)
5858
- name: Autobuild
@@ -61,7 +61,7 @@ jobs:
6161
# ℹ️ Command-line programs to run using the OS shell.
6262
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
6363

64-
# If the Autobuild fails above, remove it and uncomment the following three lines.
64+
# If the Autobuild fails above, remove it and uncomment the following three lines.
6565
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
6666

6767
# - run: |

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/rest-start.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

djstartlib/main.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
help="Custom Environment Name",
1717
type=lambda p: pathlib.Path(p).absolute(),
1818
)
19-
@click.option("-v", "--virtualenv", is_flag=True, help="Install Environment Is Deprecated")
20-
@click.option('-u', '--url-path', help='Set Custom URL Path for your App')
19+
@click.option(
20+
"-v",
21+
"--virtualenv",
22+
is_flag=True,
23+
help="Install Environment Is Deprecated",
24+
)
25+
@click.option("-u", "--url-path", help="Set Custom URL Path for your App")
2126
def main(**kwargs):
2227
"""
2328
Prepare a new Django project quickly and automatically and,
@@ -29,17 +34,16 @@ def main(**kwargs):
2934
fg="white",
3035
bg="red",
3136
)
32-
click.secho("Creating a virtual environment is a best practice!",
33-
fg="green")
37+
click.secho(
38+
"Creating a virtual environment is a best practice!", fg="green"
39+
)
3440

3541
app = DjangoStart(
36-
kwargs['name'],
37-
app=kwargs['app_name'],
38-
project=kwargs['project_name']
42+
kwargs["name"], app=kwargs["app_name"], project=kwargs["project_name"]
3943
)
4044

4145
app.setup_project()
42-
app.setup_app(app_url=kwargs['url_path'] or '')
46+
app.setup_app(app_url=kwargs["url_path"] or "")
4347

4448

4549
if __name__ == "__main__":

djstartlib/models/app_manager.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
import click
44

55
from models.utils import Environment
6-
from models.utils.helper import (build_view_func, build_views_urls,
7-
executable_python_command, generate_html,
8-
warn_stdout)
6+
from models.utils.helper import (
7+
build_view_func,
8+
build_views_urls,
9+
executable_python_command,
10+
generate_html,
11+
warn_stdout,
12+
)
913

1014

1115
class AppManager(Environment):
1216
def __init__(self, *args, **kwargs):
1317
super().__init__(**kwargs)
14-
self.__app_name = kwargs.get('app', None)
18+
self.__app_name = kwargs.get("app", None)
1519
self.__workdir = os.path.join(
16-
self.get_workdir(),
17-
f'{self.get_app_name()}'
20+
self.get_workdir(), f"{self.get_app_name()}"
1821
)
19-
self.__views = os.path.join(self.workdir, 'views.py')
20-
self.__urls = os.path.join(self.workdir, 'urls.py')
21-
self.__templates = os.path.join(self.workdir, 'templates')
22+
self.__views = os.path.join(self.workdir, "views.py")
23+
self.__urls = os.path.join(self.workdir, "urls.py")
24+
self.__templates = os.path.join(self.workdir, "templates")
2225

2326
@property
2427
def app_name(self) -> str:
@@ -43,55 +46,47 @@ def urls(self) -> str:
4346
def create_app(self) -> None:
4447
if self.app_name not in os.listdir(self.get_workdir()):
4548
click.secho(
46-
f"\U00002728 Create '{self.app_name}' App...",
47-
fg="blue"
49+
f"\U00002728 Create '{self.app_name}' App...", fg="blue"
4850
)
4951
executable_python_command(f"manage.py startapp {self.app_name}")
5052
else:
5153
warn_stdout(f'"{self.app_name}" already exist!')
5254

5355
def update_view(self) -> None:
54-
click.secho(
55-
f"\U0001F304 Create '{self.app_name}' Views...",
56-
fg="blue"
57-
)
56+
click.secho(f"\U0001f304 Create '{self.app_name}' Views...", fg="blue")
5857

5958
self.read_file(self.views)
6059
if "# Create your views here.\n" in self.line_list:
6160
code_of_block = build_view_func().substitute(
62-
app_name=self.app_name,
63-
html_file="index.html"
61+
app_name=self.app_name, html_file="index.html"
6462
)
6563
self.replace_line(
66-
self.index("# Create your views here.\n"),
67-
code_of_block
64+
self.index("# Create your views here.\n"), code_of_block
6865
)
6966
self.write(self.views)
7067

7168
else:
7269
warn_stdout('"home" View is Exists!')
7370

7471
def create_urls(self) -> None:
75-
click.secho(
76-
f"\U0001F517 Create {self.app_name} URLs...",
77-
fg="blue"
78-
)
72+
click.secho(f"\U0001f517 Create {self.app_name} URLs...", fg="blue")
7973

8074
block_of_code = build_views_urls().substitute(view_name="home")
8175
self.write(self.urls, value=block_of_code)
8276

8377
def create_templates(self) -> None:
8478
click.secho(
85-
f"\U0001F389 Generate '{self.app_name}' Index Page...",
86-
fg="blue"
79+
f"\U0001f389 Generate '{self.app_name}' Index Page...", fg="blue"
8780
)
8881

89-
index_path = f'{self.templates}{os.sep}{self.app_name}'
82+
index_path = f"{self.templates}{os.sep}{self.app_name}"
9083
if not os.path.exists(self.templates):
9184
os.mkdir(self.templates)
9285

9386
if not os.path.exists(index_path):
9487
os.mkdir(index_path)
95-
self.write(f'{index_path}{os.sep}index.html', value=generate_html())
88+
self.write(
89+
f"{index_path}{os.sep}index.html", value=generate_html()
90+
)
9691
else:
97-
warn_stdout('Index.html is Already exists.')
92+
warn_stdout("Index.html is Already exists.")

djstartlib/models/djstart_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def setup_project(self):
1414
self.project_cls.create_project()
1515
self.project_cls.requirements_extract()
1616

17-
def setup_app(self, app_url: str = ''):
17+
def setup_app(self, app_url: str = ""):
1818
self.app_cls.create_app()
1919
self.project_cls.update_settings()
2020
self.project_cls.update_urls(path=app_url)

djstartlib/models/project_manager.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,54 @@
33
import click
44

55
from models.utils import Environment
6-
from models.utils.helper import (executable_django_command, install_dep,
7-
requirements_extract, upgrade_pip,
8-
warn_stdout)
6+
from models.utils.helper import (
7+
executable_django_command,
8+
install_dep,
9+
requirements_extract,
10+
upgrade_pip,
11+
warn_stdout,
12+
)
913

1014

1115
class ProjectManager(Environment):
1216
def __init__(self, *args, **kwargs):
1317
super().__init__(**kwargs)
1418
self.__urls = os.path.join(
15-
self.get_workdir(), f'{self.get_project_name()}/urls.py'
19+
self.get_workdir(), f"{self.get_project_name()}/urls.py"
1620
)
1721
self.__settings = os.path.join(
18-
self.get_workdir(), f'{self.get_project_name()}/settings.py'
22+
self.get_workdir(), f"{self.get_project_name()}/settings.py"
1923
)
2024

2125
@property
22-
def urls_path(self) -> str: return self.__urls
26+
def urls_path(self) -> str:
27+
return self.__urls
2328

2429
@property
25-
def settings_path(self) -> str: return self.__settings
30+
def settings_path(self) -> str:
31+
return self.__settings
2632

2733
def update_settings(self) -> None:
2834
self.read_file(self.settings_path)
2935
if f"\t'{self.get_app_name()}',\n" not in self.line_list:
30-
click.secho("\U0001F527 Update Project Settings...", fg="blue")
36+
click.secho("\U0001f527 Update Project Settings...", fg="blue")
3137
self.insert_line("]\n", f"\t'{self.get_app_name()}',\n")
3238
self.write(self.settings_path)
3339
else:
3440
warn_stdout(f'"{self.get_app_name()}" is installed!')
3541

3642
def update_import_statment(self):
37-
import_statment = 'from django.urls import include\n'
38-
if 'from django.urls import path, include\n' in self.line_list:
43+
import_statment = "from django.urls import include\n"
44+
if "from django.urls import path, include\n" in self.line_list:
3945
return 0
4046
elif import_statment not in self.line_list:
41-
self.insert_line('from django.urls import path\n', import_statment)
47+
self.insert_line("from django.urls import path\n", import_statment)
4248

4349
def update_urls(self, path: str) -> None:
4450
self.read_file(self.urls_path)
45-
view_path = f"\tpath('{path}', include('{self.get_app_name()}.urls')),\n"
51+
view_path = (
52+
f"\tpath('{path}', include('{self.get_app_name()}.urls')),\n"
53+
)
4654
self.update_import_statment()
4755

4856
if view_path not in self.line_list:
@@ -53,22 +61,27 @@ def update_urls(self, path: str) -> None:
5361

5462
@staticmethod
5563
def upgrade_pip() -> None:
56-
click.secho("\U0001F4E6 Upgrade Pip...", fg="blue")
64+
click.secho("\U0001f4e6 Upgrade Pip...", fg="blue")
5765
upgrade_pip()
5866

5967
@staticmethod
6068
def install_dep() -> None:
61-
click.secho("\U000023F3 Install Dependencies...", fg="blue")
69+
click.secho("\U000023f3 Install Dependencies...", fg="blue")
6270
install_dep()
6371

6472
@staticmethod
6573
def requirements_extract() -> None:
66-
click.secho("\U0001F4C3 Generate Requirements.txt...", fg="blue")
74+
click.secho("\U0001f4c3 Generate Requirements.txt...", fg="blue")
6775
requirements_extract()
6876

6977
def create_project(self) -> None:
7078
if self.get_project_name() not in os.listdir(self.get_workdir()):
71-
click.secho(f"\U00002728 Create '{self.get_project_name()}' Project", fg="blue")
72-
executable_django_command(f"startproject {self.get_project_name()} .")
79+
click.secho(
80+
f"\U00002728 Create '{self.get_project_name()}' Project",
81+
fg="blue",
82+
)
83+
executable_django_command(
84+
f"startproject {self.get_project_name()} ."
85+
)
7386
else:
7487
warn_stdout(f'"{self.get_project_name()}" Already exist!')

djstartlib/models/utils/environment.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33

44
class Environment:
55
def __init__(self, **kwargs):
6-
self.__app_name = kwargs.get('app')
7-
self.__project_name = kwargs.get('project')
6+
self.__app_name = kwargs.get("app")
7+
self.__project_name = kwargs.get("project")
88
self.__workdir = os.getcwd()
9-
self.__exec = os.getenv('PYTHONEXEC')
10-
self.__django_admin = os.getenv('DJANGOADMIN')
9+
self.__exec = os.getenv("PYTHONEXEC")
10+
self.__django_admin = os.getenv("DJANGOADMIN")
1111
self.__line_list = []
1212

1313
@property
14-
def line_list(self) -> list: return self.__line_list
14+
def line_list(self) -> list:
15+
return self.__line_list
1516

16-
def index(self, value: str) -> int: return self.line_list.index(value)
17+
def index(self, value: str) -> int:
18+
return self.line_list.index(value)
1719

1820
def insert_line(self, flag: str, value: str) -> None:
1921
self.line_list.insert(self.index(flag), value)
@@ -31,25 +33,30 @@ def read_file(self, file: str) -> list:
3133
f.close()
3234
return self.line_list
3335

34-
def write(self, file_path: str, value = None) -> None:
35-
with open(file_path, 'w') as f:
36-
f.write(''.join(value or self.line_list))
36+
def write(self, file_path: str, value=None) -> None:
37+
with open(file_path, "w") as f:
38+
f.write("".join(value or self.line_list))
3739
f.close()
3840

39-
def get_app_name(self) -> str: return self.__app_name
41+
def get_app_name(self) -> str:
42+
return self.__app_name
4043

41-
def get_project_name(self) -> str: return self.__project_name
44+
def get_project_name(self) -> str:
45+
return self.__project_name
4246

43-
def get_workdir(self) -> str: return self.__workdir
47+
def get_workdir(self) -> str:
48+
return self.__workdir
4449

45-
def get_exec(self) -> str: return self.__exec
50+
def get_exec(self) -> str:
51+
return self.__exec
4652

47-
def get_django_admin(self) -> str: return self.__django_admin
53+
def get_django_admin(self) -> str:
54+
return self.__django_admin
4855

4956
def test(self):
50-
print(f'Call {self.__class__.__name__}')
51-
print(f'App Name: {self.get_app_name()}')
52-
print(f'Project Name: {self.get_project_name()}')
53-
print(f'Workdir: {self.get_workdir()}')
54-
print(f'Python Path: {self.get_exec()}')
55-
print(f'Django Admin: {self.get_django_admin()}')
57+
print(f"Call {self.__class__.__name__}")
58+
print(f"App Name: {self.get_app_name()}")
59+
print(f"Project Name: {self.get_project_name()}")
60+
print(f"Workdir: {self.get_workdir()}")
61+
print(f"Python Path: {self.get_exec()}")
62+
print(f"Django Admin: {self.get_django_admin()}")

0 commit comments

Comments
 (0)