Skip to content

Commit c6d2b90

Browse files
authored
Gaiaplat 1838 : Applying Black formatter to Docker_Dev (#1367)
* GAIAPLAT-1838 - Applying Black formatter to docker_dev project. https://gaiaplatform.atlassian.net/browse/GAIAPLAT-1838
1 parent 533a8df commit c6d2b90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1235
-812
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ repos:
171171
rev: 21.7b0
172172
hooks:
173173
- id: black
174-
exclude: ^(dev_tools/gdev/|dev_tools/docker_dev/|production/tools/tests/gaiat/lit.cfg.py)
174+
exclude: ^(dev_tools/gdev/|production/tools/tests/gaiat/lit.cfg.py)
175175

176176
- repo: https://github.com/PyCQA/flake8
177177
rev: 4.0.1
178178
hooks:
179179
- id: flake8
180-
exclude: ^(dev_tools/gdev/|dev_tools/docker_dev/|production/tools/tests/gaiat/lit.cfg.py)
180+
exclude: ^(dev_tools/gdev/|production/tools/tests/gaiat/lit.cfg.py)
181181
args:
182182
- --ignore=E203,E501,W503
183183

dev_tools/docker_dev/gdev/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import sys
1515
from gdev.main import DockerDev
1616

17+
1718
def main() -> int:
1819
"""
1920
Module main entry point into the application.
2021
"""
2122
DockerDev().main()
2223
return 0
2324

24-
if __name__ == '__main__':
25+
26+
if __name__ == "__main__":
2527
sys.exit(main())

dev_tools/docker_dev/gdev/cmd/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"""
99
Module to provide for the `cfg` subcommand entry point.
1010
"""
11+
1112
from gdev.dependency import Dependency
1213
from gdev.third_party.atools import memoize
13-
from .gen.run.build import GenRunBuild
14+
from gdev.cmd.gen.run.build import GenRunBuild
1415

1516

1617
class Build(Dependency):

dev_tools/docker_dev/gdev/cmd/cfg.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"""
99
Module to provide for the `cfg` subcommand entry point.
1010
"""
11+
1112
from gdev.third_party.atools import memoize
12-
from .gen.run.cfg import GenRunCfg
13+
from gdev.cmd.gen.run.cfg import GenRunCfg
1314

1415

1516
class Cfg(GenRunCfg):
@@ -23,10 +24,7 @@ def cli_entrypoint(self) -> None:
2324
Execution entrypoint for this module.
2425
"""
2526
print(
26-
'\n'.join(
27-
self.get_lines(
28-
cfg_enables=self.options.cfg_enables,
29-
path=self.path
30-
)
27+
"\n".join(
28+
self.get_lines(cfg_enables=self.options.cfg_enables, path=self.path)
3129
)
3230
)

dev_tools/docker_dev/gdev/cmd/dockerfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"""
99
Module to provide for the `dockerfile` subcommand entry point.
1010
"""
11+
1112
from gdev.dependency import Dependency
1213
from gdev.third_party.atools import memoize
13-
from .gen.run.dockerfile import GenRunDockerfile
14+
from gdev.cmd.gen.run.dockerfile import GenRunDockerfile
1415

1516

1617
class Dockerfile(Dependency):

dev_tools/docker_dev/gdev/cmd/gen/_abc/build.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
# We require buildkit support for inline caching of multi-stage dockerfiles. It's also way faster
2626
# and the terminal output is relatively sane.
27-
os.environ['DOCKER_BUILDKIT'] = '1'
28-
os.environ['DOCKER_CLI_EXPERIMENTAL'] = 'enabled'
27+
os.environ["DOCKER_BUILDKIT"] = "1"
28+
os.environ["DOCKER_CLI_EXPERIMENTAL"] = "enabled"
2929

3030

3131
class GenAbcBuild(Dependency, ABC):
@@ -53,12 +53,14 @@ def _get_actual_label_value(self, name: str) -> str:
5353
"""
5454
Request that docker provide information about the label value for the current image.
5555
"""
56-
if (line := Host.execute_and_get_line_sync(
57-
f'docker image inspect'
56+
if (
57+
line := Host.execute_and_get_line_sync(
58+
f"docker image inspect"
5859
f' --format="{{{{.Config.Labels.{name}}}}}"'
59-
f' {self.get_tag()}'
60-
)) == '"<no value>"':
61-
value = ''
60+
f" {self.get_tag()}"
61+
)
62+
) == '"<no value>"':
63+
value = ""
6264
else:
6365
value = line.strip('"')
6466

@@ -70,7 +72,7 @@ def _get_actual_label_value_by_name(self) -> Mapping[str, str]:
7072
Get the hash of an image with the actual label values that are called
7173
for by the configuration.
7274
"""
73-
return {'GitHash': self._get_actual_label_value(name='GitHash')}
75+
return {"GitHash": self._get_actual_label_value(name="GitHash")}
7476

7577
@memoize
7678
def get_actual_label_value_by_name(self) -> Mapping[str, str]:
@@ -80,13 +82,14 @@ def get_actual_label_value_by_name(self) -> Mapping[str, str]:
8082
"""
8183

8284
actual_label_value_by_name = self._get_actual_label_value_by_name()
83-
self.log.debug('actual_label_value_by_name = %s', actual_label_value_by_name)
85+
self.log.debug("actual_label_value_by_name = %s", actual_label_value_by_name)
8486
return actual_label_value_by_name
8587

8688
@memoize
8789
def __get_base_build_names(self) -> Iterable[str]:
8890

8991
seen_dockerfiles = set()
92+
9093
def inner(dockerfile: GenAbcDockerfile) -> Iterable[str]:
9194
build_names = []
9295
if dockerfile not in seen_dockerfiles:
@@ -99,7 +102,7 @@ def inner(dockerfile: GenAbcDockerfile) -> Iterable[str]:
99102

100103
base_build_names = tuple(inner(self.dockerfile))
101104

102-
self.log.debug('base_build_names = %s', base_build_names)
105+
self.log.debug("base_build_names = %s", base_build_names)
103106

104107
return base_build_names
105108

@@ -110,13 +113,13 @@ def get_sha(self) -> str:
110113
"""
111114

112115
if lines := Host.execute_and_get_lines_sync(
113-
f'docker image ls -q --no-trunc {self.get_tag()}'
116+
f"docker image ls -q --no-trunc {self.get_tag()}"
114117
):
115118
sha = next(iter(lines))
116119
else:
117-
sha = ''
120+
sha = ""
118121

119-
self.log.debug('sha = %s', sha)
122+
self.log.debug("sha = %s", sha)
120123

121124
return sha
122125

@@ -126,9 +129,9 @@ def get_tag(self) -> str:
126129
Construct a tag from the name of the dockerfile.
127130
"""
128131

129-
tag = f'{self.dockerfile.get_name()}:latest'
132+
tag = f"{self.dockerfile.get_name()}:latest"
130133

131-
self.log.debug('tag = %s', tag)
134+
self.log.debug("tag = %s", tag)
132135

133136
return tag
134137

@@ -137,17 +140,17 @@ def __get_wanted_git_hash(self) -> str:
137140
"""
138141
Request that GIT provides information about the SHA of the HEAD node.
139142
"""
140-
wanted_git_hash = Host.execute_and_get_line_sync('git rev-parse HEAD')
143+
wanted_git_hash = Host.execute_and_get_line_sync("git rev-parse HEAD")
141144

142-
self.log.debug('wanted_git_hash = %s', wanted_git_hash)
145+
self.log.debug("wanted_git_hash = %s", wanted_git_hash)
143146

144147
return wanted_git_hash
145148

146149
def _get_wanted_label_value_by_name(self) -> Mapping[str, str]:
147150
"""
148151
Get the hash of the image with the label values that are called for by the configuration.
149152
"""
150-
return {'GitHash': self.__get_wanted_git_hash()}
153+
return {"GitHash": self.__get_wanted_git_hash()}
151154

152155
@memoize
153156
def get_wanted_label_value_by_name(self) -> Mapping[str, str]:
@@ -156,7 +159,7 @@ def get_wanted_label_value_by_name(self) -> Mapping[str, str]:
156159
"""
157160
wanted_label_value_by_name = self._get_wanted_label_value_by_name()
158161

159-
self.log.debug('wanted_label_value_by_name = %s', wanted_label_value_by_name)
162+
self.log.debug("wanted_label_value_by_name = %s", wanted_label_value_by_name)
160163

161164
return wanted_label_value_by_name
162165

@@ -169,39 +172,35 @@ def main(self) -> None:
169172

170173
cached_images = ""
171174
if self.options.registry:
172-
cached_images = ','.join(
173-
[f'{self.options.registry}/{base_build_name}:latest'
174-
for base_build_name in self.__get_base_build_names()])
175+
cached_images = ",".join(
176+
[
177+
f"{self.options.registry}/{base_build_name}:latest"
178+
for base_build_name in self.__get_base_build_names()
179+
]
180+
)
175181
cached_images = f"--cache-from {cached_images}"
176182

177183
self.log.info('Creating image "%s"', self.get_tag())
178184
Host.execute_sync(
179-
f'docker buildx build'
180-
f' -f {self.dockerfile.path}'
181-
f' -t {self.get_tag()}'
182-
183-
f'''{''.join([
185+
f"docker buildx build"
186+
f" -f {self.dockerfile.path}"
187+
f" -t {self.get_tag()}"
188+
f"""{''.join([
184189
f' --label {name}="{value}"'
185190
for name, value
186191
in (self.get_wanted_label_value_by_name()).items()
187-
])}'''
188-
192+
])}"""
189193
# Keep metadata about layers so that they can be used as a cache source.
190-
f' --build-arg BUILDKIT_INLINE_CACHE=1'
191-
192-
f' --platform linux/{self.options.platform}'
193-
194+
f" --build-arg BUILDKIT_INLINE_CACHE=1"
195+
f" --platform linux/{self.options.platform}"
194196
# Required to run production.
195-
f' --shm-size 1gb'
196-
197+
f" --shm-size 1gb"
197198
# Allow cloning repos with ssh.
198-
f' --ssh default'
199-
200-
f' {cached_images}'
201-
202-
f' {GaiaPath.repo()}'
199+
f" --ssh default"
200+
f" {cached_images}"
201+
f" {GaiaPath.repo()}"
203202
)
204-
Host.execute_sync('docker image prune -f')
203+
Host.execute_sync("docker image prune -f")
205204

206205
# pylint: disable=import-outside-toplevel
207206
#
@@ -216,7 +215,9 @@ def cli_entrypoint(self) -> None:
216215
build = self
217216
else:
218217
from gdev.cmd.gen._custom.build import GenCustomBuild
218+
219219
build = GenCustomBuild(options=self.options, base_build=self)
220220

221221
build.run()
222+
222223
# pylint: enable=import-outside-toplevel

0 commit comments

Comments
 (0)