Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make use of python entry_points #19

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clean:
rm -rf dist *.egg-info

format:
find ./riocore/ ./tests/ ./bin/ -type f | grep ".py$$\|bin/" | xargs -r -l ruff format -q
find ./riocore/ ./tests/ -type f | grep ".py$$" | xargs -r -l ruff format -q

check:
find ./riocore/ ./bin/ -type f | grep ".py$$\|bin/" | xargs -r -l ruff check
Expand All @@ -16,7 +16,7 @@ verilator:
find ./riocore/ -type f | grep ".v$$" | xargs -r -l verilator --lint-only

readmes:
PYTHONPATH=. bin/rio-plugininfo -g
PYTHONPATH=. python3 -m rio-plugininfo -g
PYTHONPATH=. riocore/files/update_boards_and_toolchains_readme.py

dist:
Expand All @@ -30,7 +30,14 @@ pypi: clean dist

pyvenv: clean dist
python3 -m venv pyvenv
pyvenv/bin/python -m pip install -r requirements.txt
pyvenv/bin/python -m pip install dist/riocore*
pyvenv/bin/python bin/rio-generator Altera10M08Eval/config-test.json
. pyvenv/bin/activate; \
pip install -r requirements.txt; \
pip install dist/riocore*;\
rio-generator Altera10M08Eval/config.json

devvenv: clean dist
python3 -m venv pyvenv
. pyvenv/bin/activate; \
pip install -r requirements.txt; \
pip install -e .; \
rio-generator Altera10M08Eval/config.json
65 changes: 0 additions & 65 deletions bin/rio-generator

This file was deleted.

97 changes: 0 additions & 97 deletions bin/rio-plugininfo

This file was deleted.

Empty file modified riocore/__init__.py
100755 → 100644
Empty file.
Empty file added riocore/apps/__init__.py
Empty file.
70 changes: 70 additions & 0 deletions riocore/apps/rio_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
#
#

import argparse
import os

import riocore

riocore_path = os.path.dirname(riocore.__file__)

def main():
parser = argparse.ArgumentParser()
parser.add_argument("config", help="json config file", nargs="?", type=str, default=None)
parser.add_argument("output", help="output directory", nargs="?", type=str, default=None)
parser.add_argument("--preview", "-p", help="generate preview / no pll config", default=False, action="store_true")
parser.add_argument("--build", "-b", help="build gateware", default=False, action="store_true")
parser.add_argument("--flash", "-f", help="flash gateware", default=False, action="store_true")
args = parser.parse_args()

if args.config:
if args.config.endswith(".json"):
if os.path.isfile(args.config):
config_file = args.config
elif os.path.isfile(f"{riocore_path}/configs/{args.config}"):
config_file = f"{riocore_path}/configs/{args.config}"
else:
print(f"can not load: {args.config}")
exit(1)
print(f"loading: {config_file}")
project = riocore.Project(config_file, args.output)
project.generator(preview=args.preview)

config_name = project.config.get("name")

if args.build:
cmd = f"(cd Output/{config_name}/Gateware/ ; make clean all)"
print("")
print("running:")
print(f" {cmd}")
print("")
os.system(cmd)
if args.flash:
cmd = f"(cd Output/{config_name}/Gateware/ ; make load)"
print("")
print("running:")
print(f" {cmd}")
print("")
os.system(cmd)

elif args.config.startswith("testbench:"):
plugin = args.config.split(":")[-1]
plugins = riocore.Plugins()
plugin_instance = plugins.load_plugin(plugin, {"type": plugin}, {"speed": 1000000, "jdata": {"clock": {"speed": 1000000}}})
plugins.testbench_builder(plugin, plugin_instance)

elif args.config.startswith("plugininfo:"):
plugin = args.config.split(":")[-1]
plugins = riocore.Plugins()
print(plugins.info(plugin))

elif args.config.startswith("pluginlist"):
plugin = args.config.split(":")[-1]
plugins = riocore.Plugins()
for line in plugins.list():
print(line)


if __name__ == '__main__':
main()
103 changes: 103 additions & 0 deletions riocore/apps/rio_plugininfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env python3
#
#

import argparse
import os

import riocore

riocore_path = os.path.dirname(riocore.__file__)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--list", "-l", help="list all plugins", default=False, action="store_true")
parser.add_argument("--generate", "-g", help="generate readme files for all plugins", default=False, action="store_true")
parser.add_argument("plugin", help="plugin", nargs="?", type=str, default=None)
args = parser.parse_args()

if args.list:
plugins = riocore.Plugins()
for plugin in plugins.list():
plugins.load_plugins({"plugins": [{"type": plugin["name"]}]})

print("Interfaces:")
print("")
for plugin_instance in plugins.plugin_instances:
if plugin_instance.TYPE == "interface":
print(f" {plugin_instance.NAME:20s} {plugin_instance.INFO}")
print("")

print("Expansions:")
print("")
for plugin_instance in plugins.plugin_instances:
if plugin_instance.TYPE == "expansion":
print(f" {plugin_instance.NAME:20s} {plugin_instance.INFO}")
print("")

print("Joints:")
print("")
for plugin_instance in plugins.plugin_instances:
if plugin_instance.TYPE == "joint":
print(f" {plugin_instance.NAME:20s} {plugin_instance.INFO}")
print("")

print("IO:")
print("")
for plugin_instance in plugins.plugin_instances:
if plugin_instance.TYPE == "io":
print(f" {plugin_instance.NAME:20s} {plugin_instance.INFO}")
print("")

elif args.generate:
plugins = riocore.Plugins()
for plugin in plugins.list():
filename = f"riocore/plugins/{plugin['name']}/README.md"
print(filename)
text = plugins.info(plugin["name"])
open(filename, "w").write(text)

filename = "PLUGINS.md"
print(filename)
text = []

text.append("# PLUGINS")
text.append("")
text.append("| Type | Name | Info | Image |")
text.append("| --- | :---: | --- | :---: |")

for title, ptype in {
"Interfaces": "interface",
"Joints": "joint",
"IO": "io",
"FrameIO": "frameio",
"Expansions": "expansion",
}.items():
# text.append(f"## {title}:")
# text.append("")

for plugin_instance in plugins.plugin_instances:
if plugin_instance.TYPE == ptype:
image = ""
plugin_path = f"{riocore_path}/plugins/{plugin_instance.NAME}"
image_path = f"{plugin_path}/image.png"
if os.path.isfile(image_path):
image = f'<img src="riocore/plugins/{plugin_instance.NAME}/image.png" height="48">'

text.append(f"| {title} | [{plugin_instance.NAME}](riocore/plugins/{plugin_instance.NAME}/README.md) | {plugin_instance.INFO} | {image} |")

title = ""

text.append("")

open(filename, "w").write("\n".join(text))


elif args.plugin:
plugins = riocore.Plugins()
print(plugins.info(args.plugin))


if __name__ == "__main__":
main()
Loading