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

Metal Integration Waypoint #1 #145

Merged
merged 21 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 20 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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]

runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish_metal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
maturin-version: v0.11.3-beta.6
command: build
args: --release --no-sdist --manifest-path rust/pyapi_metal/Cargo.toml --interpreter python3.6 python3.7 python3.8
args: --release --no-sdist --manifest-path rust/pyapi_metal/Cargo.toml --interpreter python3.6 python3.7 python3.8 python3.9
manylinux: 2010
container: quay.io/pypa/manylinux2010_x86_64:2021-08-16-2fbce44
rust-toolchain: 1.54.0
Expand All @@ -28,7 +28,7 @@ jobs:
with:
maturin-version: v0.11.3-beta.6
command: build
args: --release --no-sdist --manifest-path rust/pyapi_metal/Cargo.toml --interpreter C:\hostedtoolcache\windows\Python\3.6.8\x64\python.exe C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe C:\hostedtoolcache\windows\Python\3.8.10\x64\python.exe
args: --release --no-sdist --manifest-path rust/pyapi_metal/Cargo.toml --interpreter C:\hostedtoolcache\windows\Python\3.6.8\x64\python.exe C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe C:\hostedtoolcache\windows\Python\3.8.10\x64\python.exe C:\hostedtoolcache\windows\Python\3.9.6\x64\python.exe
target: x86_64-pc-windows-msvc
rust-toolchain: 1.54.0

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/regression_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]

runs-on: ${{ matrix.os }}
env:
Expand Down Expand Up @@ -55,11 +55,11 @@ jobs:

- name: Build PyAPI
run: origen build

- name: Setup App Env
working-directory: test_apps/python_app
run: origen env setup

- name: Display Origen App Version
working-directory: test_apps/python_app
run: origen -v
Expand Down
31 changes: 28 additions & 3 deletions python/origen/origen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,23 @@
dict: Application and/or workspace attributes as key-value pairs.
'''

# root = Path(status["root"])
if status["is_app_present"]:
root = Path(status["root"])
root = None
''' If applicable, returns the application's root.

Returns:
pathlib.Path: Application's root as an OS-specific path object.
None: If not in an application's workspace.
'''

__console_history_file__ = None
''' History file when ``origen i`` is run. Only valid when an app is present.
'''

if status["is_app_present"]:
root = Path(status["root"])
__console_history_file__ = root.joinpath(".origen").joinpath(
"console_history")

__in_origen_core_app = status["in_origen_core_app"]
''' Indicates if the current application is the Origen core package

Expand Down Expand Up @@ -300,6 +307,24 @@ def current_user():
return _origen.users.current_user()


def __interactive_context__():
''' Returns the local context passed to an interactive section ``origen i`` is run.
'''
from origen_metal._helpers import interactive
from origen.registers.actions import write, verify, write_transaction, verify_transaction
context = {
"origen": origen,
"dut": dut,
"tester": tester,
"write": write,
"verify": verify,
"write_transaction": write_transaction,
"verify_transaction": verify_transaction
}
context.update(interactive.metal_context())
return context


__all__ = [
*internal_members(sys.modules[__name__]), 'config', 'status', 'root',
'version', 'logger', 'log', 'running_on_windows', 'running_on_linux',
Expand Down
165 changes: 42 additions & 123 deletions python/origen/origen/boot.py
Original file line number Diff line number Diff line change
@@ -1,99 +1,9 @@
# These must come before all other imports.
from __future__ import print_function, unicode_literals, absolute_import

import sys
import pathlib
import importlib

if sys.platform == "win32":
# The below is needed only for pyreadline, which is needed only for Windows support.
# This setup was taken from the pyreadline documentation:
# https://pythonhosted.org/pyreadline/introduction.html
# The below was copied directly from the above source.
#
#this file is needed in site-packages to emulate readline
#necessary for rlcompleter since it relies on the existance
#of a readline module
from pyreadline.rlmain import Readline
__all__ = [
'parse_and_bind',
'get_line_buffer',
'insert_text',
'clear_history',
'read_init_file',
'read_history_file',
'write_history_file',
'get_current_history_length',
'get_history_length',
'get_history_item',
'set_history_length',
'set_startup_hook',
'set_pre_input_hook',
'set_completer',
'get_completer',
'get_begidx',
'get_endidx',
'set_completer_delims',
'get_completer_delims',
'add_history',
'callback_handler_install',
'callback_handler_remove',
'callback_read_char',
] #Some other objects are added below

# create a Readline object to contain the state
rl = Readline()

if rl.disable_readline:

def dummy(completer=""):
pass

for funk in __all__:
globals()[funk] = dummy
else:

def GetOutputFile():
'''Return the console object used by readline so that it can be used for printing in color.'''
return rl.console

__all__.append("GetOutputFile")

import pyreadline.console as console

# make these available so this looks like the python readline module
read_init_file = rl.read_init_file
parse_and_bind = rl.parse_and_bind
clear_history = rl.clear_history
add_history = rl.add_history
insert_text = rl.insert_text

write_history_file = rl.write_history_file
read_history_file = rl.read_history_file

get_completer_delims = rl.get_completer_delims
get_current_history_length = rl.get_current_history_length
get_history_length = rl.get_history_length
get_history_item = rl.get_history_item
get_line_buffer = rl.get_line_buffer
set_completer = rl.set_completer
get_completer = rl.get_completer
get_begidx = rl.get_begidx
get_endidx = rl.get_endidx

set_completer_delims = rl.set_completer_delims
set_history_length = rl.set_history_length
set_pre_input_hook = rl.set_pre_input_hook
set_startup_hook = rl.set_startup_hook

callback_handler_install = rl.callback_handler_install
callback_handler_remove = rl.callback_handler_remove
callback_read_char = rl.callback_read_char

console.install_readline(rl.readline)

__all__ += ["rl", "run_cmd"]


def run_cmd(command,
targets=None,
Expand All @@ -117,6 +27,7 @@ def run_cmd(command,

import origen
import _origen
import origen_metal

import origen.application
import origen.target
Expand Down Expand Up @@ -162,32 +73,13 @@ def run_cmd(command,
_origen.set_operation("interactive")
origen.logger.trace("Starting interactive session (on Python side)")
origen.target.load()
import atexit, os, sys, colorama, termcolor, readline, rlcompleter

# Colorama init only required on windows, but place it here to keep consistent with all platforms, or in case options
# need to be added
# Also, its a known issue that powershell doesn't display yellow text correctly. The standard command prompt will
# though.
colorama.init()
historyPath = origen.root.joinpath(".origen").joinpath(
"console_history")

def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)

if os.path.exists(historyPath):
readline.read_history_file(historyPath)

atexit.register(save_history)
del os, atexit, readline, rlcompleter, sys, colorama, termcolor, save_history, historyPath

import code
from origen_metal._helpers import interactive
from origen import dut, tester
from origen.registers.actions import write, verify, write_transaction, verify_transaction
code.interact(banner=f"Origen {origen.version}",
local=locals(),
exitmsg="")
interactive.prep_shell(origen.__console_history_file__)
interactive.interact(banner=f"Origen {origen.version}",
context=origen.__interactive_context__())

elif command == "web:build":
_origen.set_operation("web")
Expand Down Expand Up @@ -256,6 +148,7 @@ def save_history(historyPath=historyPath):

# Internal command to give the Origen version loaded by the application to the CLI
elif command == "_version_":
import importlib_metadata

def tabify(message):
return "\n".join([f"\t{l}" for l in message.split("\n")])
Expand All @@ -271,18 +164,10 @@ def tabify(message):
if origen.__in_origen_core_app:
origen.logger.info("Running in Origen core application")
else:
import subprocess, sys
cmd = f"{sys.executable} -m poetry show origen"
origen.logger.trace(f"Retrieving Origen version from {cmd}")
print("Origen")
try:
res = subprocess.run(cmd,
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True,
check=True)
v = str(res.stdout).split("\n")[1].split(":")[1].strip()
print(f"Success\n{tabify(v)}")
print(
f"Success\n{tabify(importlib_metadata.version('origen'))}")
except Exception as e:
print("Error")
print(tabify(repr(e)))
Expand Down Expand Up @@ -319,6 +204,40 @@ def tabify(message):
print("Error")
print(tabify(repr(e)))

print("_ OrigenMetal (Rust Backend - Origen)")
try:
print(
f"Success\n{tabify(origen.status['origen_metal_backend_version'])}"
)
except Exception as e:
print("Error")
print(tabify(repr(e)))

print("_ origen_metal")
try:
print(
f"Success\n{tabify(importlib_metadata.version('origen_metal'))}"
)
except Exception as e:
print("Error")
print(tabify(repr(e)))

print("_ _origen_metal (PyAPI Metal)")
try:
print(f"Success\n{tabify(origen_metal._origen_metal.__version__)}")
except Exception as e:
print("Error")
print(tabify(repr(e)))

print("_ OrigenMetal (Rust Backend - PyAPI Metal)")
try:
print(
f"Success\n{tabify(origen_metal._origen_metal.__origen_metal_backend_version__)}"
)
except Exception as e:
print("Error")
print(tabify(repr(e)))

# Internal command to dispatch an app/plugin command
elif command == "_dispatch_":
path = f'{origen.app.name}.commands'
Expand Down
Loading