Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/src-info-duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrothea authored Apr 1, 2021
2 parents d19a2e7 + a4d0fdd commit e5c24d7
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 58 deletions.
15 changes: 7 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
psutil==5.8.0
pytest==6.2.2
PyYAML==5.4.1
rich==9.13.0
sh==1.14.1
4 changes: 2 additions & 2 deletions src/ipbb/cli/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
9 changes: 7 additions & 2 deletions src/ipbb/cli/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Modules
import click
from ._utils import completeProject
from ..depparser import dep_command_types


# ------------------------------------------------------------------------------
Expand All @@ -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
Expand Down
69 changes: 46 additions & 23 deletions src/ipbb/cmds/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,8 +60,6 @@ def report(ictx, filters):
lFieldNotFound = []
lFilters = []

# print ( filters )

for f in filters:
m = lFilterFormat.match(f)
if not m:
Expand Down Expand Up @@ -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),
Expand All @@ -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()
Expand Down Expand Up @@ -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():
Expand All @@ -204,10 +218,7 @@ def components(ictx, output):

# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------


@contextlib.contextmanager
def set_env(**environ):
"""
Expand All @@ -234,7 +245,7 @@ def set_env(**environ):

# ------------------------------------------------------------------------------
# ----------------------------
def hashAndUpdate0g(
def hash_and_update0g(
aFilePath, aChunkSize=0x10000, aUpdateHashes=None, aAlgo=hashlib.sha1
):

Expand All @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)



# ------------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions src/ipbb/cmds/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions src/ipbb/cmds/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
5 changes: 3 additions & 2 deletions src/ipbb/depparser/__init__.py
Original file line number Diff line number Diff line change
@@ -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 *
from ._formatters import *
from ._definitions import dep_command_types
4 changes: 3 additions & 1 deletion src/ipbb/depparser/_definitions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
depfiletypes = {
dep_file_types = {
'.dep': {'fwd': False},
'.d3': {'fwd': True},
}

dep_command_types = ('setup', 'util', 'src', 'hlssrc', 'addrtab', 'iprepo')
7 changes: 4 additions & 3 deletions src/ipbb/depparser/_fileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
15 changes: 4 additions & 11 deletions src/ipbb/depparser/_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
isfile,
isdir,
)
from ._definitions import dep_command_types


class DepFormatter(object):
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/ipbb/scripts/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e5c24d7

Please sign in to comment.