Skip to content

Commit 44c0550

Browse files
committed
fixed pyproject.toml issues with vscode #78
1 parent 57aa8d2 commit 44c0550

File tree

8 files changed

+30
-26
lines changed

8 files changed

+30
-26
lines changed

ellar_cli/service/cli.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ellar.utils.importer import import_from_string, module_import
1212
from tomlkit import dumps as tomlkit_dumps
1313
from tomlkit import parse as tomlkit_parse
14+
from tomlkit import table
1415
from tomlkit.items import Table
1516

1617
from ellar_cli.constants import ELLAR_PY_PROJECT
@@ -83,13 +84,14 @@ def import_project_meta(
8384

8485
py_project_file_path = os.path.join(cwd, PY_PROJECT_TOML)
8586
if os.path.exists(py_project_file_path):
86-
pyproject_table = EllarCLIService.read_py_project(py_project_file_path)
87+
pyproject_table = (
88+
EllarCLIService.read_py_project(py_project_file_path) or table()
89+
)
8790
_ellar_pyproject_serializer: t.Optional[EllarPyProjectSerializer] = None
91+
tools = pyproject_table.get("tool", {})
8892

89-
if pyproject_table and ELLAR_PY_PROJECT in pyproject_table:
90-
ellar_py_projects = EllarPyProject(
91-
pyproject_table.get(ELLAR_PY_PROJECT)
92-
)
93+
if ELLAR_PY_PROJECT in tools:
94+
ellar_py_projects = EllarPyProject(tools.get(ELLAR_PY_PROJECT))
9395
if ellar_py_projects.has_project(
9496
project
9597
) or ellar_py_projects.has_project(ellar_py_projects.default_project):

ellar_cli/service/pyproject.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def __init__(self, ellar: t.Optional[Table] = None) -> None:
2222
def get_or_create_ellar_py_project(
2323
cls, py_project_table: Table
2424
) -> "EllarPyProject":
25-
ellar_py_project_table = py_project_table.setdefault(ELLAR_PY_PROJECT, table())
25+
ellar_py_project_table = py_project_table.setdefault(
26+
"tool", table()
27+
).setdefault(ELLAR_PY_PROJECT, table())
2628
return cls(ellar_py_project_table)
2729

2830
@property

tests/sample_app/example_project/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class BaseConfig(ConfigDefaultTypesMixin):
5757
] = {}
5858

5959
# Object Serializer custom encoders
60-
SERIALIZER_CUSTOM_ENCODER: t.Dict[
61-
t.Any, t.Callable[[t.Any], t.Any]
62-
] = encoders_by_type
60+
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = (
61+
encoders_by_type
62+
)
6363

6464

6565
class DevelopmentConfig(BaseConfig):

tests/sample_app/example_project_2/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class BaseConfig(ConfigDefaultTypesMixin):
5757
] = {}
5858

5959
# Object Serializer custom encoders
60-
SERIALIZER_CUSTOM_ENCODER: t.Dict[
61-
t.Any, t.Callable[[t.Any], t.Any]
62-
] = encoders_by_type
60+
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = (
61+
encoders_by_type
62+
)
6363

6464

6565
class DevelopmentConfig(BaseConfig):

tests/sample_app/example_project_3/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class BaseConfig(ConfigDefaultTypesMixin):
5757
] = {}
5858

5959
# Object Serializer custom encoders
60-
SERIALIZER_CUSTOM_ENCODER: t.Dict[
61-
t.Any, t.Callable[[t.Any], t.Any]
62-
] = encoders_by_type
60+
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = (
61+
encoders_by_type
62+
)
6363

6464

6565
class DevelopmentConfig(BaseConfig):

tests/sample_app/plain_project/plain_project/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class BaseConfig(ConfigDefaultTypesMixin):
6161
EXCEPTION_HANDLERS: t.List[IExceptionHandler] = []
6262

6363
# Object Serializer custom encoders
64-
SERIALIZER_CUSTOM_ENCODER: t.Dict[
65-
t.Any, t.Callable[[t.Any], t.Any]
66-
] = encoders_by_type
64+
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = (
65+
encoders_by_type
66+
)
6767

6868

6969
class DevelopmentConfig(BaseConfig):

tests/sample_app/pyproject.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
[ellar]
1+
[tool.ellar]
22
default = "example_project"
3-
[ellar.projects]
4-
[ellar.projects.example_project]
3+
[tool.ellar.projects.example_project]
54
project-name = "example_project"
65
application = "example_project.server:application"
76
config = "example_project.config:DevelopmentConfig"
87
root-module = "example_project.root_module:ApplicationModule"
98

10-
[ellar.projects.example_project_2]
9+
[tool.ellar.projects.example_project_2]
1110
project-name = "example_project_2"
1211
application = "example_project_2.server:bootstrap"
1312
config = "example_project_2.config:DevelopmentConfig"
1413
root-module = "example_project_2.root_module:ApplicationModule"
15-
[ellar.projects.example_project_3]
14+
[tool.ellar.projects.example_project_3]
1615
project-name = "example_project_3"
1716
application = "example_project_3.server:bootstrap"
1817
config = "example_project_3.config:DevelopmentConfig"

tests/test_ellar_py_project.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
def test_get_or_create_ellar_py_project(mock_py_project_table):
99
assert ELLAR_PY_PROJECT not in mock_py_project_table
1010
EllarPyProject.get_or_create_ellar_py_project(mock_py_project_table)
11-
assert ELLAR_PY_PROJECT in mock_py_project_table
11+
assert ELLAR_PY_PROJECT in mock_py_project_table["tool"]
1212

1313
new_py_project_table = table()
14+
tool = new_py_project_table.setdefault("tool", table())
1415
ellar = table()
1516
ellar.update({"not_a_new_instance": True})
16-
new_py_project_table.add(ELLAR_PY_PROJECT, ellar)
17+
tool.add(ELLAR_PY_PROJECT, ellar)
1718

1819
ellar_py_project = EllarPyProject.get_or_create_ellar_py_project(
1920
new_py_project_table
@@ -59,6 +60,6 @@ def test_get_root_node(mock_py_project_table):
5960
ellar_py_project = EllarPyProject.get_or_create_ellar_py_project(
6061
mock_py_project_table
6162
)
62-
assert ellar_py_project.get_root_node() is mock_py_project_table.get(
63+
assert ellar_py_project.get_root_node() is mock_py_project_table["tool"].get(
6364
ELLAR_PY_PROJECT
6465
)

0 commit comments

Comments
 (0)