Skip to content

Commit

Permalink
commands: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Mar 8, 2024
1 parent c4f504f commit 9e1fb8e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
8 changes: 5 additions & 3 deletions apio/commands/build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""DOC: TODO"""
"""Main implementation of APIO BUILD command"""

# -*- coding: utf-8 -*-
# -- This file is part of the Apio project
# -- (C) 2016-2019 FPGAwars
# -- Author Jesús Arroyo
# -- Licence GPLv2

from pathlib import Path

import click

from apio.managers.scons import SCons
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 14 additions & 6 deletions apio/commands/clean.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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(
Expand All @@ -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)
8 changes: 5 additions & 3 deletions apio/commands/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# -- Licence GPLv2
"""TODO"""

from pathlib import Path

import click

from apio.managers.examples import Examples
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 10 additions & 3 deletions apio/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -35,7 +37,7 @@
@click.option(
"-p",
"--project-dir",
type=str,
type=Path,
metavar="project_dir",
help="Set the target directory for the project.",
)
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions apio/managers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions apio/managers/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions apio/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e1fb8e

Please sign in to comment.