Skip to content

Commit

Permalink
FABulous: Add auto set for FAB_ROOT env var and add main()
Browse files Browse the repository at this point in the history
Automatically sets the fabulousRoot path if no FAB_ROOT env var is specified.

Add Python interpreter path in file header.

Add main() function.

Signed-off-by: Jonas K. <[email protected]>
  • Loading branch information
EverythingElseWasAlreadyTaken committed May 7, 2024
1 parent 6c386e2 commit 1539ec3
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions FABulous/FABulous.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright 2021 University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -45,17 +47,29 @@

MAX_BITBYTES = 16384

fabulousRoot = os.getenv("FAB_ROOT")
if fabulousRoot is None:
print("FAB_ROOT environment variable not set!")
print("Use 'export FAB_ROOT=<path to FABulous root>'")
sys.exit(-1)

logger = logging.getLogger(__name__)
logging.basicConfig(
format="[%(levelname)s]-%(asctime)s - %(message)s", level=logging.INFO
)

metaDataDir = ".FABulous"

fabulousRoot = os.getenv('FAB_ROOT')
if fabulousRoot is None:
fabulousRoot = os.path.dirname(os.path.realpath(__file__))
logger.warning("FAB_ROOT environment variable not set!")
logger.warning(f"Using {fabulousRoot} as FAB_ROOT")
else:
if not os.path.exists(fabulousRoot):
logger.error(
f"FAB_ROOT environment variable set to {fabulousRoot} but the directory does not exist")
sys.exit()
else:
if os.path.exists(f"{fabulousRoot}/FABulous"):
fabulousRoot = f"{fabulousRoot}/FABulous"

logger.info(f"FAB_ROOT set to {fabulousRoot}")


# Create a FABulous Verilog project that contains all the required files
def create_project(project_dir, type: Literal["verilog", "vhdl"] = "verilog"):
Expand Down Expand Up @@ -161,8 +175,8 @@ class FABulousShell(cmd.Cmd):
Type help or ? to list commands
To see documentation for a command type:
help <command>
or
help <command>
or
?<command>
To execute a shell command type:
Expand Down Expand Up @@ -230,8 +244,7 @@ def inter(*args, **varargs):
if fun.startswith("do_"):
name = fun.strip("do_")
tcl.createcommand(
name, wrap_with_except_handling(getattr(self, fun))
)
name, wrap_with_except_handling(getattr(self, fun)))

# os.chdir(args.project_dir)
tcl.eval(script)
Expand Down Expand Up @@ -1179,7 +1192,7 @@ def complete_tcl(self, text, *ignored):
return self._complete_path(text)


if __name__ == "__main__":
def main():
if sys.version_info < (3, 9, 0):
print("Need Python 3.9 or above to run FABulous")
exit(-1)
Expand Down Expand Up @@ -1232,7 +1245,6 @@ def complete_tcl(self, text, *ignored):
args = parser.parse_args()

args.top = args.project_dir.split("/")[-1]
metaDataDir = ".FABulous"

if args.createProject:
create_project(args.project_dir, args.writer)
Expand Down Expand Up @@ -1267,3 +1279,7 @@ def complete_tcl(self, text, *ignored):
fabShell.cmdloop()
else:
fabShell.cmdloop()


if __name__ == "__main__":
main()

0 comments on commit 1539ec3

Please sign in to comment.