Skip to content

Commit

Permalink
Merge pull request enzienaudio#8 from dromer/feature/flake8
Browse files Browse the repository at this point in the history
Feature/flake8
  • Loading branch information
dromer authored Apr 1, 2021
2 parents 460bac3 + aca046b commit a0f4f0f
Show file tree
Hide file tree
Showing 180 changed files with 5,862 additions and 735 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: HVCC

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tox
run: |
tox
10 changes: 10 additions & 0 deletions bin/hvcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python3

# -*- coding: utf-8 -*-
import sys

from hvcc import main

if __name__ == '__main__':
sys.exit(main())

46 changes: 26 additions & 20 deletions hvcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Colours:
underline = "\033[4m"
end = "\033[0m"


def add_error(results, error):
if "hvcc" in results:
results["hvcc"]["notifs"]["errors"].append({"message": error})
Expand All @@ -61,6 +62,7 @@ def add_error(results, error):
}
return results


def check_extern_name_conflicts(extern_type, extern_list, results):
""" In most of the generator code extern names become capitalised when used
as enums. This method makes sure that there are no cases where two unique
Expand All @@ -69,12 +71,12 @@ def check_extern_name_conflicts(extern_type, extern_list, results):
have a list of all extern names.
"""
for i, v in enumerate(extern_list):
for j, u in enumerate(extern_list[i+1:]):
for j, u in enumerate(extern_list[i + 1:]):
if v[0].upper() == u[0].upper():
add_error(results,
"Conflicting {0} names '{1}' and '{2}', make sure that "
"capital letters are not the only difference.".format(
extern_type, v[0], u[0]))
"Conflicting {0} names '{1}' and '{2}', make sure that "
"capital letters are not the only difference.".format(extern_type, v[0], u[0]))


def generate_extern_info(hvir, results):
""" Simplifies the receiver/send and table lists by only containing values
Expand Down Expand Up @@ -105,7 +107,7 @@ def generate_extern_info(hvir, results):
check_extern_name_conflicts("output event", out_event_list, results)

# Exposed tables
table_list = [(k, v) for k, v in hvir["tables"].items() if v.get("extern", None) == True]
table_list = [(k, v) for k, v in hvir["tables"].items() if v.get("extern", None)]
table_list.sort(key=lambda x: x[0])
check_extern_name_conflicts("table", table_list, results)

Expand All @@ -121,17 +123,18 @@ def generate_extern_info(hvir, results):
"tables": table_list,
# generate patch heuristics to ensure enough memory allocated for the patch
"memoryPoolSizesKb": {
"internal": 10, # TODO(joe): should this increase if there are a lot of internal connections?
"internal": 10, # TODO(joe): should this increase if there are a lot of internal connections?
"inputQueue": max(2, int(len(in_parameter_list) + len(in_event_list) / 4)),
"outputQueue": max(2, int(len(out_parameter_list) + len(out_event_list) / 4)),
}
}


def compile_dataflow(in_path, out_dir, patch_name=None,
search_paths=None, generators=None, verbose=False,
copyright=None, hvir=None):
search_paths=None, generators=None, verbose=False,
copyright=None, hvir=None):

results = OrderedDict() # default value, empty dictionary
results = OrderedDict() # default value, empty dictionary

# basic error checking on input
if os.path.isfile(in_path):
Expand Down Expand Up @@ -169,7 +172,7 @@ def compile_dataflow(in_path, out_dir, patch_name=None,
results["hv2ir"] = hv2ir.hv2ir.compile(
hv_file=os.path.join(list(results.values())[0]["out_dir"], list(results.values())[0]["out_file"]),
# ensure that the ir filename has no funky characters in it
ir_file=os.path.join(out_dir, "ir", re.sub("\W", "_", patch_name)+".heavy.ir.json"),
ir_file=os.path.join(out_dir, "ir", re.sub("\W", "_", patch_name) + ".heavy.ir.json"),
patch_name=patch_name,
verbose=verbose)

Expand Down Expand Up @@ -287,7 +290,7 @@ def compile_dataflow(in_path, out_dir, patch_name=None,
c_src_dir=c_src_dir,
out_dir=os.path.join(out_dir, "pdext"),
patch_name=patch_name,
ext_name=patch_name+"~",
ext_name=patch_name + "~",
num_input_channels=num_input_channels,
num_output_channels=num_output_channels,
externs=externs,
Expand Down Expand Up @@ -321,11 +324,13 @@ def compile_dataflow(in_path, out_dir, patch_name=None,

return results


def main():
tick = time.time()

parser = argparse.ArgumentParser(
description="This is the Enzien Audio Heavy compiler. It compiles supported dataflow languages into C, and other supported frameworks.")
description="This is the Enzien Audio Heavy compiler. It compiles supported dataflow languages into C,"
" and other supported frameworks.")
parser.add_argument(
"in_path",
help="The input dataflow file.")
Expand All @@ -351,7 +356,8 @@ def main():
help="List of generator outputs: c, unity, wwise, js, vst2, dpf, fabric")
parser.add_argument(
"--results_path",
help="Write results dictionary to the given path as a JSON-formatted string. Target directory will be created if it does not exist.")
help="Write results dictionary to the given path as a JSON-formatted string."
" Target directory will be created if it does not exist.")
parser.add_argument(
"-v",
"--verbose",
Expand All @@ -375,23 +381,22 @@ def main():
for r in list(results.values()):
# print any errors
if r["notifs"].get("has_error", False):
for i,error in enumerate(r["notifs"].get("errors", [])):
for i, error in enumerate(r["notifs"].get("errors", [])):
print("{4:3d}) {2}Error{3} {0}: {1}".format(
r["stage"], error["message"], Colours.red, Colours.end, i+1))
r["stage"], error["message"], Colours.red, Colours.end, i + 1))

# only print exception if no errors are indicated
if len(r["notifs"].get("errors", [])) == 0 and \
r["notifs"].get("exception",None) is not None:
if len(r["notifs"].get("errors", [])) == 0 and r["notifs"].get("exception", None) is not None:
print("{2}Error{3} {0} exception: {1}".format(
r["stage"], r["notifs"]["exception"], Colours.red, Colours.end))

# clear any exceptions such that results can be JSONified if necessary
r["notifs"]["exception"] = []

# print any warnings
for i,warning in enumerate(r["notifs"].get("warnings", [])):
for i, warning in enumerate(r["notifs"].get("warnings", [])):
print("{4:3d}) {2}Warning{3} {0}: {1}".format(
r["stage"], warning["message"], Colours.yellow, Colours.end, i+1))
r["stage"], warning["message"], Colours.yellow, Colours.end, i + 1))

if args.results_path:
results_path = os.path.realpath(os.path.abspath(args.results_path))
Expand All @@ -404,7 +409,8 @@ def main():
json.dump(results, f)

if args.verbose:
print("Total compile time: {0:.2f}ms".format(1000*(time.time()-tick)))
print("Total compile time: {0:.2f}ms".format(1000 * (time.time() - tick)))


if __name__ == "__main__":
main()
12 changes: 6 additions & 6 deletions hvcc/core/hv2ir/BufferPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from .HeavyException import HeavyException


class BufferPool:

def __init__(self):
Expand All @@ -28,7 +29,6 @@ def __init__(self):
"~i>": defaultdict(list)
}


def num_buffers(self, connection_type=None):
""" Returns the number of buffers with the given retain count. By default returns
the size of the entire pool. Number of buffers per connection type can also be retrieved.
Expand All @@ -54,7 +54,7 @@ def get_buffer(self, connection_type, count=1, excludeSet=None):
pool[0].remove(b)
else:
# if we get here, then no available buffer was found. Create a new one.
b = (connection_type, self.num_buffers(connection_type)) # new buffer index for the given type
b = (connection_type, self.num_buffers(connection_type)) # new buffer index for the given type
pool[count].append(b)
return b

Expand All @@ -69,8 +69,8 @@ def retain_buffer(self, b, count=1):
for k, v in pool.items():
if b in v:
v.remove(b)
pool[k+count].append(b)
return k+count # return the new retain count
pool[k + count].append(b)
return k + count # return the new retain count
raise HeavyException("{0} not found in BufferPool!".format(b))

def release_buffer(self, b, count=1):
Expand All @@ -86,8 +86,8 @@ def release_buffer(self, b, count=1):
for k, v in pool.items():
if b in v:
v.remove(b)
pool[k-count].append(b)
return k-count # return the new retain count
pool[k - count].append(b)
return k - count # return the new retain count
raise HeavyException("{0} not found in BufferPool!".format(b))

def __repr__(self):
Expand Down
12 changes: 5 additions & 7 deletions hvcc/core/hv2ir/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ def __init__(self, from_object, outlet_index, to_object, inlet_index, conn_type)
def copy(self, from_object=None, outlet_index=None, to_object=None, inlet_index=None, type=None):
""" Create a new connection based on the existing one, changing the given values.
"""
return Connection(
from_object = self.from_object if from_object is None else from_object,
outlet_index = self.outlet_index if outlet_index is None else outlet_index,
to_object = self.to_object if to_object is None else to_object,
inlet_index = self.inlet_index if inlet_index is None else inlet_index,
conn_type = self.type if type is None else type
)
return Connection(from_object=self.from_object if from_object is None else from_object,
outlet_index=self.outlet_index if outlet_index is None else outlet_index,
to_object=self.to_object if to_object is None else to_object,
inlet_index=self.inlet_index if inlet_index is None else inlet_index,
conn_type=self.type if type is None else type)

@property
def is_signal(self):
Expand Down
1 change: 1 addition & 0 deletions hvcc/core/hv2ir/HIrConvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .HeavyIrObject import HeavyIrObject


class HIrConvolution(HeavyIrObject):
""" __conv~f
"""
Expand Down
3 changes: 2 additions & 1 deletion hvcc/core/hv2ir/HIrInlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .HeavyException import HeavyException
from .HeavyIrObject import HeavyIrObject


class HIrInlet(HeavyIrObject):
""" A specific implementation of the inlet object.
"""
Expand All @@ -28,7 +29,7 @@ def _resolved_outlet_type(self, outlet_index=0):
connection_type_set = {c.type for c in connections}
if len(connection_type_set) == 0:
# object has no incident connections.
return "-->" # outlet type defaults to control (-->)
return "-->" # outlet type defaults to control (-->)
elif len(connection_type_set) == 1:
return list(connection_type_set)[0]
else:
Expand Down
1 change: 1 addition & 0 deletions hvcc/core/hv2ir/HIrLorenz.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .HeavyIrObject import HeavyIrObject


class HIrLorenz(HeavyIrObject):
""" __lorenz~f
"""
Expand Down
1 change: 1 addition & 0 deletions hvcc/core/hv2ir/HIrOutlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .HeavyIrObject import HeavyIrObject


class HIrOutlet(HeavyIrObject):
""" A specific implementation of the outlet object.
"""
Expand Down
7 changes: 4 additions & 3 deletions hvcc/core/hv2ir/HIrPack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

from .HeavyIrObject import HeavyIrObject


class HIrPack(HeavyIrObject):

def __init__(self, obj_type, args=None, graph=None, annotations=None):
HeavyIrObject.__init__(self, "__pack", args=args, graph=graph,
num_inlets=len(args["values"]),
num_outlets=1,
annotations=annotations)
num_inlets=len(args["values"]),
num_outlets=1,
annotations=annotations)
4 changes: 3 additions & 1 deletion hvcc/core/hv2ir/HIrReceive.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import re
from .HeavyIrObject import HeavyIrObject


class HIrReceive(HeavyIrObject):
""" A specific implementation of the __receive object.
"""
Expand All @@ -26,4 +27,5 @@ def __init__(self, obj_type, args=None, graph=None, annotations=None):
# externed receivers must contain only alphanumeric characters or underscores,
# so that the names can be easily and transparently turned into code
if re.search("\W", args["name"]):
self.add_error("Parameter and Event names may only contain alphanumeric characters or underscore: '{0}'".format(args["name"]))
self.add_error("Parameter and Event names may only contain"
f"alphanumeric characters or underscore: '{args['name']}'")
6 changes: 4 additions & 2 deletions hvcc/core/hv2ir/HIrSend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import re
from .HeavyIrObject import HeavyIrObject


class HIrSend(HeavyIrObject):
""" A specific implementation of the __send object.
"""
Expand All @@ -26,7 +27,8 @@ def __init__(self, obj_type, args=None, graph=None, annotations=None):
# output parameters must contain only alphanumeric characters or underscores,
# so that the names can be easily and transparently turned into code
if re.search("\W", args["name"]):
self.add_error("Parameter and Event names may only contain alphanumeric characters or underscore: '{0}'".format(args["name"]))
self.add_error(f"Parameter and Event names may only contain \
alphanumeric characters or underscore: '{args['name']}'")

def get_ir_control_list(self):
receive_objs = self.graph.resolve_objects_for_name(self.name, "__receive")
Expand All @@ -37,5 +39,5 @@ def get_ir_control_list(self):
"extern": self.args["extern"],
"hash": self.args["hash"],
"display": self.args["name"],
"name": (("_"+self.args["name"]) if re.match("\d", self.args["name"]) else self.args["name"])
"name": (("_" + self.args["name"]) if re.match("\d", self.args["name"]) else self.args["name"])
}]
11 changes: 6 additions & 5 deletions hvcc/core/hv2ir/HIrSwitchcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

from .HeavyIrObject import HeavyIrObject


class HIrSwitchcase(HeavyIrObject):
""" A specific implementation of the __switchcase object.
"""

def __init__(self, obj_type, args=None, graph=None, annotations=None):
HeavyIrObject.__init__(self, "__switchcase",
args=args,
graph=graph,
num_inlets=1,
num_outlets=len(args["cases"])+1,
annotations=annotations)
args=args,
graph=graph,
num_inlets=1,
num_outlets=len(args["cases"]) + 1,
annotations=annotations)
1 change: 1 addition & 0 deletions hvcc/core/hv2ir/HIrTabhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .HeavyIrObject import HeavyIrObject


class HIrTabhead(HeavyIrObject):
""" __tabhead~f and __tabhead
"""
Expand Down
2 changes: 1 addition & 1 deletion hvcc/core/hv2ir/HIrTabread.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .HeavyException import HeavyException
from .HeavyIrObject import HeavyIrObject


class HIrTabread(HeavyIrObject):
""" __tabread~if
"""
Expand Down
1 change: 1 addition & 0 deletions hvcc/core/hv2ir/HIrTabwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .HeavyIrObject import HeavyIrObject


class HIrTabwrite(HeavyIrObject):
""" __tabwrite~f
"""
Expand Down
Loading

0 comments on commit a0f4f0f

Please sign in to comment.