chore: apply pre-commit hooks

This commit is contained in:
Xyphuz 2022-06-03 17:19:43 +08:00
parent 747dd06be1
commit eca68a8190
8 changed files with 26 additions and 49 deletions

View file

@ -16,8 +16,8 @@ class Service:
depends_on: List[str] = [], depends_on: List[str] = [],
links: List[str] = [], links: List[str] = [],
extends: Optional[Extends] = None, extends: Optional[Extends] = None,
cgroup_parent: str = None, cgroup_parent: Optional[str] = None,
container_name: str = None, container_name: Optional[str] = None,
devices: List[str] = [], devices: List[str] = [],
env_file: List[str] = [], env_file: List[str] = [],
expose: List[str] = [], expose: List[str] = [],

View file

@ -176,7 +176,6 @@ class Parser:
if service_data.links is not None: if service_data.links is not None:
service_links = service_data.links service_links = service_data.links
cgroup_parent: Optional[str] = None cgroup_parent: Optional[str] = None
if service_data.cgroup_parent is not None: if service_data.cgroup_parent is not None:
cgroup_parent = service_data.cgroup_parent cgroup_parent = service_data.cgroup_parent
@ -185,26 +184,24 @@ class Parser:
if service_data.container_name is not None: if service_data.container_name is not None:
container_name = service_data.container_name container_name = service_data.container_name
env_file: List[str] = [] env_file: List[str] = []
if service_data.env_file is not None: if service_data.env_file is not None:
if type(service_data.env_file) is spec.StringOrList: if type(service_data.env_file) is spec.StringOrList:
if(type(service_data.env_file.__root__) is spec.ListOfStrings): if type(service_data.env_file.__root__) is spec.ListOfStrings:
env_file = service_data.env_file.__root__.__root__ env_file = service_data.env_file.__root__.__root__
elif(type(service_data.env_file.__root__) is str): elif type(service_data.env_file.__root__) is str:
env_file.append(service_data.env_file.__root__) env_file.append(service_data.env_file.__root__)
expose: List[str] = [] expose: List[str] = []
if service_data.expose is not None: if service_data.expose is not None:
expose = service_data.expose for port in service_data.expose:
expose.append(str(port))
profiles: List[str] = [] profiles: List[str] = []
if service_data.profiles is not None: if service_data.profiles is not None:
if type(service_data.profiles) is spec.ListOfStrings: if type(service_data.profiles) is spec.ListOfStrings:
profiles = service_data.profiles.__root__ profiles = service_data.profiles.__root__
services.append( services.append(
Service( Service(
name=service_name, name=service_name,

View file

@ -272,24 +272,17 @@ from compose_viz.parser import Parser
Service( Service(
name="frontend", name="frontend",
image="awesome/frontend", image="awesome/frontend",
env_file=[ env_file=["a.env"],
"a.env"
],
), ),
Service( Service(
name="backend", name="backend",
image="awesome/backend", image="awesome/backend",
env_file=[ env_file=["b.env"],
"b.env"
],
), ),
Service( Service(
name="db", name="db",
image="awesome/db", image="awesome/db",
env_file=[ env_file=["c.env", "d.env"],
"c.env",
"d.env"
],
), ),
], ],
), ),
@ -301,17 +294,12 @@ from compose_viz.parser import Parser
Service( Service(
name="frontend", name="frontend",
image="awesome/frontend", image="awesome/frontend",
expose=[ expose=["27118"],
"27118"
],
), ),
Service( Service(
name="backend", name="backend",
image="awesome/backend", image="awesome/backend",
expose=[ expose=["27017", "27018"],
"27017",
"27018"
],
), ),
], ],
), ),
@ -323,24 +311,17 @@ from compose_viz.parser import Parser
Service( Service(
name="frontend", name="frontend",
image="awesome/frontend", image="awesome/frontend",
profiles=[ profiles=["frontend"],
"frontend"
],
), ),
Service( Service(
name="phpmyadmin", name="phpmyadmin",
image="phpmyadmin", image="phpmyadmin",
profiles=[ profiles=["debug"],
"debug"
],
), ),
Service( Service(
name="db", name="db",
image="awesome/db", image="awesome/db",
profiles=[ profiles=["db", "sql"],
"db",
"sql"
],
), ),
], ],
), ),
@ -380,7 +361,6 @@ def test_parse_file(test_file_path: str, expected: Compose) -> None:
assert actual_service.extends.service_name == expected_service.extends.service_name assert actual_service.extends.service_name == expected_service.extends.service_name
assert actual_service.extends.from_file == expected_service.extends.from_file assert actual_service.extends.from_file == expected_service.extends.from_file
assert actual_service.cgroup_parent == expected_service.cgroup_parent assert actual_service.cgroup_parent == expected_service.cgroup_parent
assert actual_service.container_name == expected_service.container_name assert actual_service.container_name == expected_service.container_name