diff --git a/requirements.txt b/requirements.txt index a51d6cd5..e9a3da44 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,14 @@ Cerberus==1.3.2 click==7.1.2 click-didyoumean==0.0.3 -configparser==5.0.0 +configparser==5.0.2 future==0.18.2 ipaddress==1.0.23 -ipdb==0.13.4 +ipdb==0.13.7 ipython==7.16.1 pexpect==4.8.0 -psutil==5.7.2 -pytest==6.1.1 -PyYAML==5.4 -rich==6.1.2 -sh==1.14.0 -texttable==1.6.3 \ No newline at end of file +psutil==5.8.0 +pytest==6.2.2 +PyYAML==5.4.1 +rich==9.13.0 +sh==1.14.1 \ No newline at end of file diff --git a/src/ipbb/cli/_utils.py b/src/ipbb/cli/_utils.py index 76f2261e..0a69066c 100644 --- a/src/ipbb/cli/_utils.py +++ b/src/ipbb/cli/_utils.py @@ -26,14 +26,14 @@ def completeDepFileImpl(ctx, args, incomplete): if not exists(basepath): return [] - from ..depparser import depfiletypes + from ..depparser import dep_file_types # print() # print(basepath) lDepFiles = [] for root, dirs, files in walk(basepath): - lDepFiles += [normpath(f) for f in files if any([f.endswith(ext) for ext in depfiletypes])] + lDepFiles += [normpath(f) for f in files if any([f.endswith(ext) for ext in dep_file_types])] return [ f for f in lDepFiles if f.startswith(incomplete)] diff --git a/src/ipbb/cli/dep.py b/src/ipbb/cli/dep.py index cfd91fd3..2b8d8f0b 100644 --- a/src/ipbb/cli/dep.py +++ b/src/ipbb/cli/dep.py @@ -3,6 +3,7 @@ # Modules import click from ._utils import completeProject +from ..depparser import dep_command_types # ------------------------------------------------------------------------------ @@ -28,16 +29,20 @@ def report(env, filters): # ------------------------------------------------------------------------------ @dep.command('ls', short_help="List project files by group") -@click.argument('group', type=click.Choice(['setup', 'src', 'addrtab', 'cgpfile'])) +@click.argument('group', type=click.Choice(dep_command_types)) @click.option('-o', '--output', default=None, help="Destination of the command output. Default: stdout") @click.pass_obj def ls(env, group, output): '''List project files by group + \b - setup: Project setup scripts - src: Code files + - hlssrc: HLS source files - addrtab: Address tables - - cgpfile: ? + - utils: Utility files + - iprepo: IP repository + ''' from ..cmds.dep import ls diff --git a/src/ipbb/cmds/dep.py b/src/ipbb/cmds/dep.py index 51af9146..923277e8 100644 --- a/src/ipbb/cmds/dep.py +++ b/src/ipbb/cmds/dep.py @@ -23,7 +23,7 @@ ) from ..console import cprint from ..tools.common import which, SmartOpen -from ..depparser import DepFormatter +from ..depparser import DepFormatter, dep_command_types from ..utils import DirSentry, printDictTable, printAlienTable from rich.table import Table, Column from rich.padding import Padding @@ -60,8 +60,6 @@ def report(ictx, filters): lFieldNotFound = [] lFilters = [] - # print ( filters ) - for f in filters: m = lFilterFormat.match(f) if not m: @@ -113,8 +111,6 @@ def report(ictx, filters): continue lCmdTable = Table(*lCmdHeaders) - # lCmdTable.set_deco(Texttable.HEADER | Texttable.BORDER) - # lCmdTable.set_chars(['-', '|', '+', '-']) for lCmd in lParser.commands[k]: lRow = [ relpath(lCmd.filepath, ictx.srcdir), @@ -137,9 +133,6 @@ def report(ictx, filters): lString = '' - # lString += '+----------------------------------+\n' - # lString += '| Resolved packages & components |\n' - # lString += '+----------------------------------+\n' lString += 'packages: ' + lDepFmt.drawPackages() + '\n' lString += 'components:\n' lString += lDepFmt.drawComponents() @@ -177,22 +170,43 @@ def report(ictx, filters): # ------------------------------------------------------------------------------ -def ls(ictx, group, output): - '''List project files by group +def ls(ictx, group: str, output: str): + ''' + List project files by group + - setup: Project setup scripts - src: Code files - - addrtab: Address tables - - cgpfile: ? + - addrtab: Address tables + + :param ictx: The ictx + :type ictx: { type_description } + :param group: The group + :type group: str + :param output: The output + :type output: str + + + + :rtype: None ''' with SmartOpen(output) as lWriter: - for addrtab in ictx.depParser.commands[group]: - lWriter(addrtab.filepath) + for f in ictx.depParser.commands[group]: + lWriter(f.filepath) # ------------------------------------------------------------------------------ -def components(ictx, output): + +def components(ictx, output: str): + """ + { function_description } + + :param ictx: The ictx + :type ictx: { type_description } + :param output: The output + :type output: str + """ with SmartOpen(output) as lWriter: for lPkt, lCmps in ictx.depParser.packages.items(): @@ -204,10 +218,7 @@ def components(ictx, output): # ------------------------------------------------------------------------------ - # ------------------------------------------------------------------------------ - - @contextlib.contextmanager def set_env(**environ): """ @@ -234,7 +245,7 @@ def set_env(**environ): # ------------------------------------------------------------------------------ # ---------------------------- -def hashAndUpdate0g( +def hash_and_update0g( aFilePath, aChunkSize=0x10000, aUpdateHashes=None, aAlgo=hashlib.sha1 ): @@ -257,7 +268,7 @@ def hashAndUpdate0g( # ---------------------------- -def hashAndUpdate(aPath, aChunkSize=0x10000, aUpdateHashes=None, aAlgo=hashlib.sha1): +def hash_and_update(aPath, aChunkSize=0x10000, aUpdateHashes=None, aAlgo=hashlib.sha1): # New instance of the selected algorithm lHash = aAlgo() @@ -274,7 +285,7 @@ def hashAndUpdate(aPath, aChunkSize=0x10000, aUpdateHashes=None, aAlgo=hashlib.s elif isdir(aPath): for root, dirs, files in os.walk(aPath): for f in files: - hashAndUpdate(f, aChunkSize, aUpdateHashes=aUpdateHashes, aAlgo=aAlgo) + hash_and_update(f, aChunkSize, aUpdateHashes=aUpdateHashes, aAlgo=aAlgo) return lHash @@ -312,7 +323,7 @@ def hash(ictx, output, verbose): lWriter("# " + lGrp) lWriter("#" + "-" * 79) for lCmd in lCmds: - lCmdHash = hashAndUpdate( + lCmdHash = hash_and_update( lCmd.filepath, aUpdateHashes=[lProjHash, lGrpHash], aAlgo=lAlgo ).hexdigest() if verbose: @@ -344,7 +355,19 @@ def hash(ictx, output, verbose): # ------------------------------------------------------------------------------ def archive(ictx): - print('archive') + + import tarfile + def tarinfo_relpath(tarinfo): + # Note: the source dir leading '/' [1:] is removed because tarindo names don't have it + tarinfo.name = relpath(tarinfo.name, ictx.srcdir[1:]) + return tarinfo + + with tarfile.open(f"{ictx.currentproj.name}_src.tar.gz", "w:gz") as tar: + for c in dep_command_types: + for f in ictx.depParser.commands[c]: + print(f.filepath) + tar.add(f.filepath, filter=tarinfo_relpath) + # ------------------------------------------------------------------------------ diff --git a/src/ipbb/cmds/proj.py b/src/ipbb/cmds/proj.py index 78a97b1e..fdedebeb 100644 --- a/src/ipbb/cmds/proj.py +++ b/src/ipbb/cmds/proj.py @@ -12,7 +12,7 @@ from ..defaults import kProjAreaFile, kProjDir from ..context import ProjectInfo from ..utils import DirSentry, raiseError, validateComponent, findFirstParentDir -from ..depparser import depfiletypes, Pathmaker +from ..depparser import dep_file_types, Pathmaker from rich.table import Table from os.path import join, split, exists, splitext, relpath, isdir, basename @@ -118,7 +118,7 @@ def create(ictx, toolset, projname, component, topdep): lTopDepDir = lPathmaker.getPath(lTopPackage, lTopComponent, 'include') - for ft in depfiletypes: + for ft in dep_file_types: lTopDepCandidates = [ "'{}'".format(relpath(p, lTopDepDir)) for p in glob.glob(join(lTopDepDir, '*' + ft)) diff --git a/src/ipbb/cmds/repo.py b/src/ipbb/cmds/repo.py index 89cbb49e..70db68de 100644 --- a/src/ipbb/cmds/repo.py +++ b/src/ipbb/cmds/repo.py @@ -12,10 +12,9 @@ from ..console import cprint from ..defaults import kSourceDir, kProjDir, kWorkAreaFile, kRepoSetupFile -from ..depparser import Pathmaker +from ..depparser import Pathmaker, DepFormatter, dep_command_types from ..tools.common import mkdir from ..utils import DirSentry, findFileInParents, raiseError, formatDictTable -from ..depparser import DepFormatter from .proj import info as proj_info from urllib.parse import urlparse from distutils.dir_util import mkpath @@ -608,7 +607,7 @@ def srcs_create_component(ictx, component): cprint("ERROR: Component '{}' already exists".format(lCmpPath), style='red') raise click.ClickException("Command aborted") - for sd in ['src', 'include', 'iprepo', 'addrtab']: + for sd in lPathMaker.fpaths: lPath = lPathMaker.getPath(*component, command=sd) mkdir(lPath) cprint("Folder {} created.".format(lPath), style='cyan') diff --git a/src/ipbb/depparser/__init__.py b/src/ipbb/depparser/__init__.py index 3132ae5b..76c1b0bd 100644 --- a/src/ipbb/depparser/__init__.py +++ b/src/ipbb/depparser/__init__.py @@ -1,5 +1,6 @@ -from ._fileparser import DepFileParser, DepFormatter, depfiletypes +from ._fileparser import DepFileParser, DepFormatter, dep_file_types from ._pathmaker import Pathmaker from ._definitions import * -from ._formatters import * \ No newline at end of file +from ._formatters import * +from ._definitions import dep_command_types \ No newline at end of file diff --git a/src/ipbb/depparser/_definitions.py b/src/ipbb/depparser/_definitions.py index 15fb2d80..f4dbb8c1 100644 --- a/src/ipbb/depparser/_definitions.py +++ b/src/ipbb/depparser/_definitions.py @@ -1,4 +1,6 @@ -depfiletypes = { +dep_file_types = { '.dep': {'fwd': False}, '.d3': {'fwd': True}, } + +dep_command_types = ('setup', 'util', 'src', 'hlssrc', 'addrtab', 'iprepo') \ No newline at end of file diff --git a/src/ipbb/depparser/_fileparser.py b/src/ipbb/depparser/_fileparser.py index 9e3d496e..e4c4a3d9 100644 --- a/src/ipbb/depparser/_fileparser.py +++ b/src/ipbb/depparser/_fileparser.py @@ -5,10 +5,11 @@ import copy import string -from ._definitions import depfiletypes +from ._definitions import dep_file_types, dep_command_types from ._pathmaker import Pathmaker from ._cmdparser import ComponentAction, DepCmdParser, DepCmdParserError from ._cmdtypes import SrcCommand, IncludeCommand + from ..tools.alien import AlienTree, AlienTemplate from collections import OrderedDict @@ -99,7 +100,7 @@ class DepFileParser(object): @staticmethod def forwardparsing(aDepFileName): - ftype = depfiletypes.get(splitext(aDepFileName)[1], None) + ftype = dep_file_types.get(splitext(aDepFileName)[1], None) if ftype is not None: return ftype['fwd'] return True @@ -126,7 +127,7 @@ def __init__(self, aToolSet, aPathmaker, aVariables={}, aVerbosity=0): self.libs = set() self.packages = OrderedDict() - self.commands = {c: [] for c in ['setup', 'util', 'src', 'hlssrc', 'addrtab', 'iprepo']} + self.commands = {c: [] for c in dep_command_types} self.unresolved = list() self.errors = list() diff --git a/src/ipbb/depparser/_formatters.py b/src/ipbb/depparser/_formatters.py index f7f258bb..59cc4c75 100644 --- a/src/ipbb/depparser/_formatters.py +++ b/src/ipbb/depparser/_formatters.py @@ -10,6 +10,7 @@ isfile, isdir, ) +from ._definitions import dep_command_types class DepFormatter(object): @@ -67,17 +68,9 @@ def drawDeptreeCommandsSummary(self): Draws a deptree commands summary table. """ - # lCommandKinds = ['setup', 'src', 'hlssrc', 'util', 'addrtab', 'iprepo'] - # lDepTable = Texttable() - # lDepTable.set_cols_align(['c'] * len(lCommandKinds)) - # lDepTable.add_row(lCommandKinds) - # lDepTable.add_row([len(self.parser.commands[k]) for k in lCommandKinds]) - # return lDepTable.draw() - - lCommandKinds = ('setup', 'src', 'hlssrc', 'util', 'addrtab', 'iprepo') - # lDepTable = Table( *(Column(c, justify='center') for c in lCommandKinds) ) - lDepTable = Table( *lCommandKinds) - lDepTable.add_row( *(str(len(self.parser.commands[k])) for k in lCommandKinds) ) + + lDepTable = Table( *dep_command_types) + lDepTable.add_row( *(str(len(self.parser.commands[k])) for k in dep_command_types) ) return lDepTable diff --git a/src/ipbb/scripts/builder.py b/src/ipbb/scripts/builder.py index ae01a0cd..99bf35d7 100755 --- a/src/ipbb/scripts/builder.py +++ b/src/ipbb/scripts/builder.py @@ -148,7 +148,7 @@ def main(): obj = Context() try: - climain(obj=obj) + climain(obj=obj, show_default=True) except Exception as e: from sys import version_info exc_type, exc_obj, exc_tb = sys.exc_info()