diff --git a/apio/commands/build.py b/apio/commands/build.py index d0a482ff..6a2d36bb 100644 --- a/apio/commands/build.py +++ b/apio/commands/build.py @@ -1,4 +1,4 @@ -"""DOC: TODO""" +"""Main implementation of APIO BUILD command""" # -*- coding: utf-8 -*- # -- This file is part of the Apio project @@ -6,6 +6,8 @@ # -- Author Jesús Arroyo # -- Licence GPLv2 +from pathlib import Path + import click from apio.managers.scons import SCons @@ -34,8 +36,8 @@ @click.option( "-p", "--project-dir", - type=str, - metavar="path", + type=Path, + metavar="project_dir", help="Set the target directory for the project.", ) @click.option( diff --git a/apio/commands/clean.py b/apio/commands/clean.py index b001d5cd..5ef3e578 100644 --- a/apio/commands/clean.py +++ b/apio/commands/clean.py @@ -1,9 +1,12 @@ +"""Main implementation of APIO CLEAN command""" + # -*- coding: utf-8 -*- # -- This file is part of the Apio project # -- (C) 2016-2019 FPGAwars # -- Author Jesús Arroyo # -- Licence GPLv2 -"""TODO""" + +from pathlib import Path import click @@ -16,8 +19,8 @@ @click.option( "-p", "--project-dir", - type=str, - metavar="path", + type=Path, + metavar="project_dir", help="Set the target directory for the project.", ) @click.option( @@ -31,7 +34,12 @@ ) def cli(ctx, board, project_dir, verbose): """Clean the previous generated files.""" - exit_code = SCons(project_dir).clean( - {"board": board, "verbose": {"all": verbose}} - ) + + # -- Create the scons object + scons = SCons(project_dir) + + # -- Build the project with the given parameters + exit_code = scons.clean({"board": board, "verbose": {"all": verbose}}) + + # -- Done! ctx.exit(exit_code) diff --git a/apio/commands/examples.py b/apio/commands/examples.py index 7b53151f..7fdc2a61 100644 --- a/apio/commands/examples.py +++ b/apio/commands/examples.py @@ -5,6 +5,8 @@ # -- Licence GPLv2 """TODO""" +from pathlib import Path + import click from apio.managers.examples import Examples @@ -36,9 +38,9 @@ @click.option( "-p", "--project-dir", - type=str, - metavar="path", - help="Set the target directory for the examples.", + type=Path, + metavar="project_dir", + help="Set the target directory for the project.", ) @click.option( "-n", diff --git a/apio/commands/init.py b/apio/commands/init.py index dbaf3777..7c79e32d 100644 --- a/apio/commands/init.py +++ b/apio/commands/init.py @@ -3,7 +3,9 @@ # -- (C) 2016-2019 FPGAwars # -- Author Jesús Arroyo # -- Licence GPLv2 -"""TODO""" +"""Main implementation of APIO INIT command""" + +from pathlib import Path import click @@ -35,7 +37,7 @@ @click.option( "-p", "--project-dir", - type=str, + type=Path, metavar="project_dir", help="Set the target directory for the project.", ) @@ -48,8 +50,13 @@ def cli(ctx, board, top_module, scons, project_dir, sayyes): """Manage apio projects.""" + # -- Create a project + project = Project() + + # -- scons option: Create default SConstruct file if scons: - Project().create_sconstruct(project_dir, "ice40", sayyes) + project.create_sconstruct(project_dir, "ice40", sayyes) + elif board: # -- Set the default top_module when creating the ini file if not top_module: diff --git a/apio/managers/project.py b/apio/managers/project.py index 9cf34e71..83d21a70 100644 --- a/apio/managers/project.py +++ b/apio/managers/project.py @@ -8,7 +8,7 @@ import sys from os.path import isfile -# from pathlib import Path +from pathlib import Path # -- Config Parser: Use INI config files with easy # https://docs.python.org/3/library/configparser.html @@ -32,7 +32,7 @@ def __init__(self): # -- Top module by default: main self.top_module = "main" - def create_sconstruct(self, project_dir="", arch=None, sayyes=False): + def create_sconstruct(self, project_dir: Path, arch=None, sayyes=False): """Creates a default SConstruct file""" project_dir = util.check_dir(project_dir) diff --git a/apio/managers/scons.py b/apio/managers/scons.py index c32d0d20..41385643 100644 --- a/apio/managers/scons.py +++ b/apio/managers/scons.py @@ -42,7 +42,7 @@ class SCons: """Class for managing the scons tools""" - def __init__(self, project_dir=""): + def __init__(self, project_dir: Path): """Initialization: * project_dir: path where the sources are located If not given, the curent working dir is used @@ -55,7 +55,7 @@ def __init__(self, project_dir=""): self.resources = Resources() # -- Project path is given - if project_dir is not None: + if not project_dir: # Check if it is a correct folder # (or create a new one) project_dir = util.check_dir(project_dir) diff --git a/apio/util.py b/apio/util.py index b53b6459..3493bb5d 100644 --- a/apio/util.py +++ b/apio/util.py @@ -668,9 +668,7 @@ def check_dir(_dir: Path) -> Path: """ # -- If no path is given, get the current working directory - if _dir: - _dir = Path(_dir) - else: + if not _dir: _dir = Path.cwd() # -- Check if the path is a file or a folder