From 2ccbbbe4e4f3cd53bec6c4f085dccfea5401fa57 Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Thu, 18 Aug 2022 21:39:25 +0200 Subject: [PATCH] f4pga: style Signed-off-by: Unai Martinez-Corral --- f4pga/__init__.py | 48 ++++++++++++------------ f4pga/flows/common.py | 2 +- f4pga/flows/common_modules/synth.py | 19 +++++----- f4pga/flows/flow.py | 5 ++- f4pga/flows/flow_config.py | 13 +++---- f4pga/flows/stage.py | 57 ++++++++++++----------------- 6 files changed, 66 insertions(+), 78 deletions(-) diff --git a/f4pga/__init__.py b/f4pga/__init__.py index 89349c4..8b75bd9 100644 --- a/f4pga/__init__.py +++ b/f4pga/__init__.py @@ -1,24 +1,24 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (C) 2022 F4PGA Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 - -from f4pga.flows import main - - -if __name__ == "__main__": - main() +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2022 F4PGA Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +from f4pga.flows import main + + +if __name__ == "__main__": + main() diff --git a/f4pga/flows/common.py b/f4pga/flows/common.py index f6d4d92..f2efe8f 100644 --- a/f4pga/flows/common.py +++ b/f4pga/flows/common.py @@ -198,7 +198,7 @@ def vpr(mode: str, vprargs: VprArgs, cwd=None): + modeargs + vprargs.optional ), - cwd=str(cwd), + cwd=cwd, ) diff --git a/f4pga/flows/common_modules/synth.py b/f4pga/flows/common_modules/synth.py index 2ec5936..41eab06 100755 --- a/f4pga/flows/common_modules/synth.py +++ b/f4pga/flows/common_modules/synth.py @@ -60,15 +60,14 @@ class SynthModule(Module): extra_products: "list[str]" def map_io(self, ctx: ModuleContext): - mapping = {} + top = Path(ctx.takes.build_dir) / ctx.values.top if ctx.takes.build_dir else Path(ctx.values.top) - top = ctx.values.top - if ctx.takes.build_dir: - top = str(Path(ctx.takes.build_dir) / top) - mapping["eblif"] = top + ".eblif" - mapping["fasm_extra"] = top + "_fasm_extra.fasm" - mapping["json"] = top + ".json" - mapping["synth_json"] = top + "_io.json" + mapping = { + "eblif": f"{top!s}.eblif", + "fasm_extra": f"{top!s}_fasm_extra.fasm", + "json": f"{top!s}.json", + "synth_json": f"{top!s}_io.json", + } for extra in self.extra_products: name, spec = decompose_depname(extra) @@ -77,8 +76,8 @@ class SynthModule(Module): f"Yosys synth extra products can't use 'maybe\ " f"(?) specifier. Product causing this error: `{extra}`." ) - elif spec == 'req': - mapping[name] = str(Path(top).parent / f'{ctx.values.device}_{name}.{name}') + elif spec == "req": + mapping[name] = str(top.parent / f"{ctx.values.device}_{name}.{name}") return mapping diff --git a/f4pga/flows/flow.py b/f4pga/flows/flow.py index 95c3d79..811fd10 100644 --- a/f4pga/flows/flow.py +++ b/f4pga/flows/flow.py @@ -239,12 +239,13 @@ class Flow: def _build_dep(self, dep): paths = self.dep_paths.get(dep) - provider = self.os_map.get(dep) - run = (provider.name in self.run_stages) if provider else False if not paths: sfprint(2, f"Dependency {dep} is unresolved.") return False + provider = self.os_map.get(dep) + run = (provider.name in self.run_stages) if provider else False + if p_req_exists(paths) and not run: return True else: diff --git a/f4pga/flows/flow_config.py b/f4pga/flows/flow_config.py index 949e527..29ffaf7 100644 --- a/f4pga/flows/flow_config.py +++ b/f4pga/flows/flow_config.py @@ -73,9 +73,7 @@ class FlowDefinition: if global_vals is not None: self.r_env.add_values(global_vals) - stages_d = flow_def["stages"] - - for stage_name, stage_def in stages_d.items(): + for stage_name, stage_def in flow_def["stages"].items(): self.stages[stage_name] = Stage(stage_name, stage_def) def stage_names(self): @@ -142,14 +140,13 @@ class FlowConfig: def __init__(self, project_config: ProjectFlowConfig, platform_def: FlowDefinition, part: str): self.r_env = platform_def.r_env - platform_vals = project_config.get_values_raw(part) - self.r_env.add_values(platform_vals) + self.r_env.add_values(project_config.get_values_raw(part)) self.stages = platform_def.stages self.part = part - raw_project_deps = project_config.get_dependencies_raw(part) - - self.dependencies_explicit = deep(lambda p: str(Path(p).resolve()))(self.r_env.resolve(raw_project_deps)) + self.dependencies_explicit = deep(lambda p: str(Path(p).resolve()))( + self.r_env.resolve(project_config.get_dependencies_raw(part)) + ) for stage_name, stage in platform_def.stages.items(): project_val_ovds = project_config.get_stage_value_overrides(part, stage_name) diff --git a/f4pga/flows/stage.py b/f4pga/flows/stage.py index 7582195..a5cf402 100644 --- a/f4pga/flows/stage.py +++ b/f4pga/flows/stage.py @@ -25,8 +25,7 @@ from f4pga.flows.runner import get_module, module_io class StageIO: """ Stage dependency input/output. - TODO: Solve the inconsistecy between usage of that and usage of - `decompose_depname` with an unprocessed string. + TODO: Solve the inconsistecy between usage of that and usage of `decompose_depname` with an unprocessed string. """ name: str # A symbolic name given to the dependency @@ -47,49 +46,41 @@ class StageIO: class Stage: """ - Represents a single stage in a flow. I.e an instance of a module with a - local set of values. + Represents a single stage in a flow. + I.e an instance of a module with a local set of values. """ - name: str # Name of the stage (module's name) - takes: "list[StageIO]" # List of symbolic names of dependencies used by - # the stage - produces: "list[StageIO]" # List of symbolic names of dependencies - # produced by the stage - value_overrides: "dict[str, ]" # Stage-specific values module: Module - meta: "dict[str, str]" # Stage's metadata extracted from module's - # output. + + # Name of the stage (module's name) + name: str + + # List of symbolic names of dependencies used by the stage + takes: "list[StageIO]" + + # List of symbolic names of dependencies produced by the stage + produces: "list[StageIO]" + + # Stage-specific values + value_overrides: "dict[str, ]" + + # Stage's metadata extracted from module's output. + meta: "dict[str, str]" def __init__(self, name: str, stage_def: "dict[str, ]"): + self.name = name + if stage_def is None: stage_def = {} - modstr = stage_def["module"] - - module_path = resolve_modstr(modstr) - ModuleClass = get_module(module_path) - self.module = ModuleClass(stage_def.get("params")) + self.module = get_module(resolve_modstr(stage_def["module"]))(stage_def.get("params")) values = stage_def.get("values") - if values is not None: - self.value_overrides = values - else: - self.value_overrides = {} + self.value_overrides = values if values is not None else {} mod_io = module_io(self.module) - self.name = name - - self.takes = [] - for input in mod_io["takes"]: - io = StageIO(input) - self.takes.append(io) - - self.produces = [] - for input in mod_io["produces"]: - io = StageIO(input) - self.produces.append(io) - + self.takes = [StageIO(input) for input in mod_io["takes"]] + self.produces = [StageIO(input) for input in mod_io["produces"]] self.meta = mod_io["meta"] def __repr__(self) -> str: