Skip to content

Commit 42aa11a

Browse files
committed
fixed mypy issues
1 parent 68f84cd commit 42aa11a

38 files changed

+88
-81
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
<p align="center"> Ellar CLI Tool for Scaffolding Ellar Projects and Modules and also running Ellar Commands</p>
66

7-
![Test](https://github.com/eadwinCode/ellar/actions/workflows/test_full.yml/badge.svg)
8-
![Coverage](https://img.shields.io/codecov/c/github/eadwinCode/ellar)
9-
[![PyPI version](https://badge.fury.io/py/ellar.svg)](https://badge.fury.io/py/ellar)
10-
[![PyPI version](https://img.shields.io/pypi/v/ellar.svg)](https://pypi.python.org/pypi/ellar)
11-
[![PyPI version](https://img.shields.io/pypi/pyversions/ellar.svg)](https://pypi.python.org/pypi/ellar)
12-
13-
7+
![Test](https://github.com/eadwinCode/ellar-cli/actions/workflows/test_full.yml/badge.svg)
8+
![Coverage](https://img.shields.io/codecov/c/github/eadwinCode/ellar-cli)
9+
[![PyPI version](https://badge.fury.io/py/ellar.svg)](https://badge.fury.io/py/ellar-cli)
10+
[![PyPI version](https://img.shields.io/pypi/v/ellar.svg)](https://pypi.python.org/pypi/ellar-cli)
11+
[![PyPI version](https://img.shields.io/pypi/pyversions/ellar.svg)](https://pypi.python.org/pypi/ellar-cli)

ellar_cli/file_scaffolding.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
class ProjectScaffoldContext(dict):
15-
def __init__(self, environment: Environment, **kwargs):
15+
def __init__(self, environment: Environment, **kwargs: t.Any) -> None:
1616
super().__init__(kwargs)
1717
self.environment = environment
1818
self.environment.globals.update(kwargs)
@@ -27,7 +27,7 @@ def __init__(
2727
working_directory: str,
2828
scaffold_ellar_template_root_path: str,
2929
ellar_cli_service: EllarCLIService,
30-
):
30+
) -> None:
3131
self._schema = schema
3232
self._working_project_name = working_project_name
3333
self._ctx = ProjectScaffoldContext(
@@ -78,7 +78,10 @@ def on_scaffold_started(self) -> None:
7878
assert self._ctx[context], f"{context} template context is missing."
7979

8080
def create_directory(
81-
self, file: EllarScaffoldList, scaffold_ellar_template_path, working_directory
81+
self,
82+
file: EllarScaffoldList,
83+
scaffold_ellar_template_path: str,
84+
working_directory: str,
8285
) -> None:
8386
name = file.name
8487
if name in self._ctx:

ellar_cli/main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import typing as t
44

55
import typer
6-
from typer import Typer
7-
from typer.models import CommandInfo
8-
96
from ellar.commands import EllarTyper
107
from ellar.constants import CALLABLE_COMMAND_INFO, ELLAR_META, MODULE_METADATA
118
from ellar.core.factory import AppFactory
129
from ellar.services import Reflector
10+
from typer import Typer
11+
from typer.models import CommandInfo
1312

1413
from .manage_commands import create_module, create_project, runserver
1514
from .service import EllarCLIService
@@ -35,7 +34,7 @@ def typer_callback(
3534
help="Run Specific Command on a specific project",
3635
),
3736
) -> None:
38-
meta_: EllarCLIService = EllarCLIService.import_project_meta(project)
37+
meta_: t.Optional[EllarCLIService] = EllarCLIService.import_project_meta(project)
3938
ctx.meta[ELLAR_META] = meta_
4039

4140

@@ -54,7 +53,7 @@ def build_typers() -> None:
5453
except Exception:
5554
raise typer.Abort()
5655

57-
meta_: EllarCLIService = EllarCLIService.import_project_meta(app_name)
56+
meta_: t.Optional[EllarCLIService] = EllarCLIService.import_project_meta(app_name)
5857

5958
if meta_ and meta_.has_meta:
6059
modules = AppFactory.get_all_modules(meta_.import_root_module())

ellar_cli/manage_commands/create_module.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from importlib import import_module
55

66
import typer
7-
87
from ellar.constants import ELLAR_META
8+
from ellar.helper.module_loading import module_dir
9+
910
from ellar_cli import scaffolding
1011
from ellar_cli.schema import EllarScaffoldSchema
11-
from ellar.helper.module_loading import module_dir
1212

13-
from ..service import EllarCLIException, EllarCLIService
1413
from ..file_scaffolding import FileTemplateScaffold
14+
from ..service import EllarCLIException, EllarCLIService
1515

1616
__all__ = ["create_module"]
1717

ellar_cli/manage_commands/create_project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from importlib import import_module
55

66
import typer
7-
87
from ellar.constants import ELLAR_META
8+
from ellar.helper.module_loading import module_dir
9+
910
from ellar_cli import scaffolding
1011
from ellar_cli.schema import EllarScaffoldSchema
11-
from ellar.helper.module_loading import module_dir
1212

13-
from ..service import EllarCLIException, EllarCLIService
1413
from ..file_scaffolding import FileTemplateScaffold
14+
from ..service import EllarCLIException, EllarCLIService
1515

1616
__all__ = ["create_project"]
1717

ellar_cli/manage_commands/runserver.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from pathlib import Path
66

77
import typer
8+
from ellar.constants import ELLAR_CONFIG_MODULE, ELLAR_META, LOG_LEVELS
9+
from ellar.core import Config
10+
from ellar.helper.enums import create_enums_from_list
811
from h11._connection import DEFAULT_MAX_INCOMPLETE_EVENT_SIZE
912
from uvicorn.config import (
1013
HTTP_PROTOCOLS,
@@ -17,10 +20,6 @@
1720
)
1821
from uvicorn.main import run as uvicorn_run
1922

20-
from ellar.constants import ELLAR_CONFIG_MODULE, ELLAR_META, LOG_LEVELS
21-
from ellar.core import Config
22-
from ellar.helper.enums import create_enums_from_list
23-
2423
from ..service import EllarCLIException, EllarCLIService
2524

2625
__all__ = ["runserver"]

ellar_cli/schema.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import typing as t
22

3-
from pydantic import Field
4-
53
from ellar.serializer import Serializer
4+
from pydantic import Field
65

76

87
class EllarPyProjectSerializer(Serializer):
@@ -43,4 +42,4 @@ def schema_example(cls) -> "EllarScaffoldSchema":
4342
],
4443
),
4544
],
46-
)
45+
)

ellar_cli/service.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import typing as t
33

44
from click import ClickException
5+
from ellar.constants import ELLAR_PY_PROJECT
6+
from ellar.core import App, Config, ModuleBase
7+
from ellar.helper.importer import import_from_string, module_import
8+
from ellar.helper.module_loading import module_dir
59
from tomlkit import dumps as tomlkit_dumps, parse as tomlkit_parse, table
610
from tomlkit.items import Table
711

8-
from ellar.constants import ELLAR_PY_PROJECT
9-
from ellar.core import App, Config, ModuleBase, schema
1012
from ellar_cli.schema import EllarPyProjectSerializer
11-
from ellar.helper.importer import import_from_string, module_import
12-
from ellar.helper.module_loading import module_dir
1313

1414
PY_PROJECT_TOML = "pyproject.toml"
1515
ELLAR_DEFAULT_KEY = "default"
@@ -23,7 +23,9 @@ class EllarCLIException(ClickException):
2323
class EllarPyProject:
2424
def __init__(self, ellar: Table = None) -> None:
2525
self._ellar = ellar if ellar is not None else table()
26-
self._projects = self._ellar.setdefault(ELLAR_PROJECTS_KEY, table())
26+
self._projects = t.cast(
27+
Table, self._ellar.setdefault(ELLAR_PROJECTS_KEY, table())
28+
)
2729
self._default_project = self._ellar.get(ELLAR_DEFAULT_KEY, None)
2830

2931
@classmethod
@@ -49,11 +51,11 @@ def get_projects(self) -> Table:
4951
return self._projects
5052

5153
def get_project(self, project_name: str) -> Table:
52-
return self._projects.get(project_name)
54+
return t.cast(Table, self._projects.get(project_name))
5355

5456
def get_or_create_project(self, project_name: str) -> Table:
5557
project = self._projects.setdefault(project_name.lower(), table())
56-
return project
58+
return t.cast(Table, project)
5759

5860
def has_project(self, project_name: t.Optional[str]) -> bool:
5961
if not project_name:
@@ -65,7 +67,7 @@ def get_root_node(self) -> Table:
6567

6668

6769
class EllarCLIService:
68-
schema_cls: t.Type[schema.Serializer] = EllarPyProjectSerializer
70+
schema_cls: t.Type[EllarPyProjectSerializer] = EllarPyProjectSerializer
6971

7072
def __init__(
7173
self,
@@ -101,7 +103,7 @@ def import_project_meta(
101103
cls, project: t.Optional[str] = None
102104
) -> t.Optional["EllarCLIService"]:
103105
cwd = os.getcwd()
104-
project_to_load: t.Optional[str] = None
106+
project_to_load: str = "ellar"
105107
ellar_py_projects = None
106108

107109
py_project_file_path = os.path.join(cwd, PY_PROJECT_TOML)
@@ -118,16 +120,13 @@ def import_project_meta(
118120
project
119121
) or ellar_py_projects.has_project(ellar_py_projects.default_project):
120122
project_to_load = (
121-
project
123+
project # type: ignore
122124
if ellar_py_projects.has_project(project)
123125
else ellar_py_projects.default_project
124126
)
125127

126-
_ellar_pyproject_serializer = t.cast(
127-
EllarPyProjectSerializer,
128-
cls.schema_cls.parse_obj(
129-
ellar_py_projects.get_project(project_to_load)
130-
),
128+
_ellar_pyproject_serializer = cls.schema_cls.parse_obj(
129+
ellar_py_projects.get_project(project_to_load)
131130
)
132131

133132
return cls(
@@ -137,6 +136,7 @@ def import_project_meta(
137136
app_name=project_to_load,
138137
ellar_py_projects=ellar_py_projects,
139138
)
139+
return None
140140

141141
def create_ellar_project_meta(self, project_name: str) -> None:
142142
pyproject_table = EllarCLIService.read_py_project(self.py_project_path)
@@ -173,32 +173,40 @@ def read_py_project(path: str) -> t.Optional[Table]:
173173
with open(path, mode="r") as fp:
174174
table_content = tomlkit_parse(fp.read())
175175
return table_content
176+
return None
176177

177178
@staticmethod
178179
def write_py_project(path: str, content: Table) -> None:
179180
with open(path, mode="w") as fw:
180181
fw.writelines(tomlkit_dumps(content))
181182

182183
def import_application(self) -> "App":
183-
application_module = import_from_string(self._meta.application)
184+
assert self._meta
185+
application_module = t.cast("App", import_from_string(self._meta.application))
184186
return application_module
185187

186188
def import_configuration(self) -> t.Type["Config"]:
187-
config = import_from_string(self._meta.config)
189+
assert self._meta
190+
config = t.cast(t.Type["Config"], import_from_string(self._meta.config))
188191
return config
189192

190193
def get_application_config(self) -> "Config":
194+
assert self._meta
191195
config = Config(self._meta.config)
192196
return config
193197

194198
def import_root_module(self) -> t.Type["ModuleBase"]:
195-
root_module = import_from_string(self._meta.root_module)
199+
assert self._meta
200+
root_module = t.cast(
201+
t.Type["ModuleBase"], import_from_string(self._meta.root_module)
202+
)
196203
return root_module
197204

198205
def import_apps_module(self) -> t.Any:
206+
assert self._meta
199207
apps_module = module_import(self._meta.apps_module)
200208
return apps_module
201209

202210
def get_apps_module_path(self) -> str:
203211
apps_module = self.import_apps_module()
204-
return module_dir(apps_module)
212+
return module_dir(apps_module) # type: ignore

mypy.ini

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ disallow_untyped_defs = True
1818
check_untyped_defs = True
1919
implicit_reexport = False
2020

21-
[mypy-ellar.compatible.*]
21+
[mypy-ellar_cli.compatible.*]
2222
ignore_errors = True
2323

24-
[mypy-ellar.cli.*]
24+
[mypy-ellar_cli.cli.*]
2525
ignore_errors = True
2626

27-
[mypy-ellar.core.schema.*]
27+
[mypy-ellar_cli.schema.*]
2828
ignore_errors = True
2929

30-
[mypy-ellar.__main__.*]
30+
[mypy-ellar_cli.__main__.*]
3131
ignore_errors = True
3232

33-
[mypy-ellar.samples.*]
33+
[mypy-ellar_cli.manage_commands.*]
34+
ignore_errors = True
35+
36+
[mypy-ellar_cli.testing.*]
3437
ignore_errors = True

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ dependencies = [
5050
ellar = "ellar_cli.cli:main"
5151

5252
[project.urls]
53-
Documentation = "https://github.com/eadwinCode/ellar"
54-
Source = "https://github.com/eadwinCode/ellar"
55-
Homepage = "https://eadwincode.github.io/ellar/"
53+
Documentation = "https://github.com/eadwinCode/ellar-cli"
54+
Source = "https://github.com/eadwinCode/ellar-cli"
55+
Homepage = "https://eadwincode.github.io/ellar-cli/"
5656

5757
[project.optional-dependencies]
5858
test = [

0 commit comments

Comments
 (0)