Skip to content

Commit

Permalink
Format all Python code with black
Browse files Browse the repository at this point in the history
Fixes: #2650
  • Loading branch information
TeddyAndrieux committed Feb 8, 2021
1 parent 25480da commit d66ec12
Show file tree
Hide file tree
Showing 136 changed files with 7,799 additions and 7,767 deletions.
2 changes: 1 addition & 1 deletion buildchain/buildchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@


# Root of the repository.
ROOT: Path = (Path(__file__)/'../../../').resolve()
ROOT: Path = (Path(__file__) / "../../../").resolve()
127 changes: 71 additions & 56 deletions buildchain/buildchain/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def task__build_builder() -> Iterator[types.TaskDict]:
yield builder.task


def _builder_image(
name: str, dockerfile: Path, **kwargs: Any
) -> LocalImage:
def _builder_image(name: str, dockerfile: Path, **kwargs: Any) -> LocalImage:
"""Create a builder image.
Arguments:
Expand All @@ -32,96 +30,113 @@ def _builder_image(
Keyword Arguments:
They are passed to `LocalImage` init method.
"""
img_name = '{}-{}-builder'.format(config.PROJECT_NAME.lower(), name)
kwargs.setdefault('task_dep', []).append('_build_root')
img_name = "{}-{}-builder".format(config.PROJECT_NAME.lower(), name)
kwargs.setdefault("task_dep", []).append("_build_root")

return LocalImage(
name=img_name,
version='latest',
version="latest",
dockerfile=dockerfile,
destination=config.BUILD_ROOT,
save_on_disk=False,
**kwargs
)


RPM_BUILDER : Dict[str, LocalImage] = {
'7': _builder_image(
name='redhat-7-rpm',
dockerfile=constants.ROOT/'packages/redhat/7/Dockerfile',
build_context=constants.ROOT/'packages/redhat',
RPM_BUILDER: Dict[str, LocalImage] = {
"7": _builder_image(
name="redhat-7-rpm",
dockerfile=constants.ROOT / "packages/redhat/7/Dockerfile",
build_context=constants.ROOT / "packages/redhat",
file_dep=[
constants.ROOT/'packages'/'redhat'/'common'/
'yum_repositories'/'kubernetes.repo',
constants.ROOT/'packages'/'redhat'/'common'/
'yum_repositories'/'saltstack.repo',
constants.ROOT
/ "packages"
/ "redhat"
/ "common"
/ "yum_repositories"
/ "kubernetes.repo",
constants.ROOT
/ "packages"
/ "redhat"
/ "common"
/ "yum_repositories"
/ "saltstack.repo",
],
build_args={
# Used to template the SaltStack repository definition
'SALT_VERSION': versions.SALT_VERSION,
"SALT_VERSION": versions.SALT_VERSION,
},
),
'8': _builder_image(
name='redhat-8-rpm',
dockerfile=constants.ROOT/'packages/redhat/8/Dockerfile',
build_context=constants.ROOT/'packages/redhat',
"8": _builder_image(
name="redhat-8-rpm",
dockerfile=constants.ROOT / "packages/redhat/8/Dockerfile",
build_context=constants.ROOT / "packages/redhat",
file_dep=[
constants.ROOT/'packages'/'redhat'/'common'/
'yum_repositories'/'kubernetes.repo',
constants.ROOT/'packages'/'redhat'/'common'/
'yum_repositories'/'saltstack.repo',
constants.ROOT
/ "packages"
/ "redhat"
/ "common"
/ "yum_repositories"
/ "kubernetes.repo",
constants.ROOT
/ "packages"
/ "redhat"
/ "common"
/ "yum_repositories"
/ "saltstack.repo",
],
build_args={
# Used to template the SaltStack repository definition
'SALT_VERSION': versions.SALT_VERSION,
"SALT_VERSION": versions.SALT_VERSION,
},
),
}

DEB_BUILDER : Dict[str, LocalImage] = {
'18.04': _builder_image(
name='ubuntu-18.04-deb',
dockerfile=constants.ROOT/'packages/debian/18.04/Dockerfile',
build_context=constants.ROOT/'packages/debian',
DEB_BUILDER: Dict[str, LocalImage] = {
"18.04": _builder_image(
name="ubuntu-18.04-deb",
dockerfile=constants.ROOT / "packages/debian/18.04/Dockerfile",
build_context=constants.ROOT / "packages/debian",
),
}

DOC_BUILDER : LocalImage = _builder_image(
name='doc',
dockerfile=constants.ROOT/'docs/Dockerfile',
DOC_BUILDER: LocalImage = _builder_image(
name="doc",
dockerfile=constants.ROOT / "docs/Dockerfile",
build_context=constants.ROOT,
file_dep=[
constants.ROOT/'tox.ini', constants.ROOT/'docs/requirements.txt'
]
file_dep=[constants.ROOT / "tox.ini", constants.ROOT / "docs/requirements.txt"],
)

GO_BUILDER : LocalImage = _builder_image(
name='go',
dockerfile=constants.STORAGE_OPERATOR_ROOT/'Dockerfile',
GO_BUILDER: LocalImage = _builder_image(
name="go",
dockerfile=constants.STORAGE_OPERATOR_ROOT / "Dockerfile",
file_dep=[
constants.STORAGE_OPERATOR_ROOT/'go.mod',
constants.STORAGE_OPERATOR_ROOT/'go.sum',
]
constants.STORAGE_OPERATOR_ROOT / "go.mod",
constants.STORAGE_OPERATOR_ROOT / "go.sum",
],
)

UI_BUILDER : LocalImage = _builder_image(
name='ui',
dockerfile=constants.ROOT/'ui'/'Dockerfile',
build_args={'NODE_IMAGE_VERSION': versions.NODEJS_IMAGE_VERSION},
UI_BUILDER: LocalImage = _builder_image(
name="ui",
dockerfile=constants.ROOT / "ui" / "Dockerfile",
build_args={"NODE_IMAGE_VERSION": versions.NODEJS_IMAGE_VERSION},
file_dep=[
constants.ROOT/'ui'/'package.json',
constants.ROOT/'ui'/'package-lock.json',
constants.ROOT/'ui'/'entrypoint.sh',
]
constants.ROOT / "ui" / "package.json",
constants.ROOT / "ui" / "package-lock.json",
constants.ROOT / "ui" / "entrypoint.sh",
],
)


_BUILDERS : Tuple[LocalImage, ...] = (
DOC_BUILDER,
GO_BUILDER,
UI_BUILDER,
) + tuple(RPM_BUILDER.values()) \
+ tuple(DEB_BUILDER.values())
_BUILDERS: Tuple[LocalImage, ...] = (
(
DOC_BUILDER,
GO_BUILDER,
UI_BUILDER,
)
+ tuple(RPM_BUILDER.values())
+ tuple(DEB_BUILDER.values())
)


__all__ = utils.export_only_tasks(__name__)
27 changes: 13 additions & 14 deletions buildchain/buildchain/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from buildchain import types
from buildchain import utils


def task_codegen() -> Iterator[types.TaskDict]:
"""Run the code generation tools."""
for create_codegen_task in CODEGEN:
Expand All @@ -22,28 +23,26 @@ def task_codegen() -> Iterator[types.TaskDict]:

def codegen_go() -> types.TaskDict:
"""Generate Go code using operator-sdk."""
cwd = constants.STORAGE_OPERATOR_ROOT
cwd = constants.STORAGE_OPERATOR_ROOT
actions = []
for target in ('k8s', 'crds'):
cmd = ' '.join(map(shlex.quote, [
config.ExtCommand.OPERATOR_SDK.value, 'generate', target
]))
for target in ("k8s", "crds"):
cmd = " ".join(
map(shlex.quote, [config.ExtCommand.OPERATOR_SDK.value, "generate", target])
)
actions.append(doit.action.CmdAction(cmd, cwd=cwd))

return {
'name': 'go',
'title': utils.title_with_subtask_name('CODEGEN'),
'doc': codegen_go.__doc__,
'actions': actions,
'task_dep': ['check_for:operator-sdk'],
'file_dep': list(constants.STORAGE_OPERATOR_SOURCES),
"name": "go",
"title": utils.title_with_subtask_name("CODEGEN"),
"doc": codegen_go.__doc__,
"actions": actions,
"task_dep": ["check_for:operator-sdk"],
"file_dep": list(constants.STORAGE_OPERATOR_SOURCES),
}


# List of available code generation tasks.
CODEGEN : Tuple[Callable[[], types.TaskDict], ...] = (
codegen_go,
)
CODEGEN: Tuple[Callable[[], types.TaskDict], ...] = (codegen_go,)


__all__ = utils.export_only_tasks(__name__)
54 changes: 29 additions & 25 deletions buildchain/buildchain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,31 @@


# Project name.
PROJECT_NAME : str = os.getenv('PROJECT_NAME', 'MetalK8s')
PROJECT_NAME: str = os.getenv("PROJECT_NAME", "MetalK8s")

# Path to the root of the build directory.
BUILD_ROOT : Path = Path(os.getenv('BUILD_ROOT', '_build'))
BUILD_ROOT: Path = Path(os.getenv("BUILD_ROOT", "_build"))
if not BUILD_ROOT.is_absolute():
BUILD_ROOT = ROOT/BUILD_ROOT
BUILD_ROOT = ROOT / BUILD_ROOT
BUILD_ROOT = BUILD_ROOT.resolve()

# Vagrant configuration.
VAGRANT_PROVIDER : str = os.getenv('VAGRANT_PROVIDER', 'virtualbox')
_DEFAULT_VAGRANT_UP_ARGS : str = ' '.join((
'--provision',
'--no-destroy-on-error',
'--parallel',
'--provider', VAGRANT_PROVIDER
))

VAGRANT_SNAPSHOT_NAME: str = 'bootstrap.autosnapshot'

VAGRANT_UP_ARGS : Tuple[str, ...] = tuple(shlex.split(
os.getenv('VAGRANT_UP_ARGS', _DEFAULT_VAGRANT_UP_ARGS)
))
VAGRANT_PROVIDER: str = os.getenv("VAGRANT_PROVIDER", "virtualbox")
_DEFAULT_VAGRANT_UP_ARGS: str = " ".join(
(
"--provision",
"--no-destroy-on-error",
"--parallel",
"--provider",
VAGRANT_PROVIDER,
)
)

VAGRANT_SNAPSHOT_NAME: str = "bootstrap.autosnapshot"

VAGRANT_UP_ARGS: Tuple[str, ...] = tuple(
shlex.split(os.getenv("VAGRANT_UP_ARGS", _DEFAULT_VAGRANT_UP_ARGS))
)

# External commands {{{

Expand All @@ -52,22 +55,23 @@
class ExtCommand(enum.Enum):
"""External commands used by the build chain."""

GIT = os.getenv('GIT_BIN', 'git')
HARDLINK = os.getenv('HARDLINK_BIN', 'hardlink')
IMPLANTISOMD5 = os.getenv('IMPLANTISOMD5_BIN', 'implantisomd5')
MKISOFS = os.getenv('MKISOFS_BIN', 'mkisofs')
SKOPEO = os.getenv('SKOPEO_BIN', 'skopeo')
VAGRANT = os.getenv('VAGRANT_BIN', 'vagrant')
OPERATOR_SDK = os.getenv('OPERATOR_SDK_BIN', 'operator-sdk')
GOFMT = os.getenv('GOFMT_BIN', 'gofmt')
GIT = os.getenv("GIT_BIN", "git")
HARDLINK = os.getenv("HARDLINK_BIN", "hardlink")
IMPLANTISOMD5 = os.getenv("IMPLANTISOMD5_BIN", "implantisomd5")
MKISOFS = os.getenv("MKISOFS_BIN", "mkisofs")
SKOPEO = os.getenv("SKOPEO_BIN", "skopeo")
VAGRANT = os.getenv("VAGRANT_BIN", "vagrant")
OPERATOR_SDK = os.getenv("OPERATOR_SDK_BIN", "operator-sdk")
GOFMT = os.getenv("GOFMT_BIN", "gofmt")

@property
def command_name(self) -> str:
"""Return the name of the command."""
if self is self.OPERATOR_SDK:
return 'operator-sdk'
return "operator-sdk"
# See https://github.com/PyCQA/pylint/issues/2062
# pylint: disable=no-member
return self.name.lower()


# }}}
Loading

0 comments on commit d66ec12

Please sign in to comment.