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 #2 (a?): (Revision Control) Frontend #147

Merged
merged 6 commits into from
Dec 10, 2021
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/regression_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Install Poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: 1.1.7
poetry-version: 1.1.9

- name: Setup Python Env - Metal
working-directory: python/origen_metal
Expand Down
10 changes: 10 additions & 0 deletions python/origen/origen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@
next

import _origen
from _origen import _origen_metal

# Replace origen_metal's native _origen_metal built library
# with the one built from origen.
sys.modules["origen_metal._origen_metal"] = _origen_metal
_origen.initialize(init_verbosity, vks, cli_path, cli_ver)

# Initialize origen_metal's frontend
import origen_metal
origen_metal.frontend.initialize()

from pathlib import Path
import importlib
from contextlib import contextmanager
Expand Down
8 changes: 5 additions & 3 deletions python/origen/origen/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from origen.errors import *
from origen.callbacks import _callbacks
from types import ModuleType
import origen_metal


class Base(_origen.application.PyApplication):
Expand Down Expand Up @@ -89,7 +90,7 @@ def user_session(self):

@property
def rc(self):
return self._rc
return origen_metal.frontend.frontend().revision_control

@property
def linter(self):
Expand Down Expand Up @@ -118,7 +119,8 @@ def __init__(self, *args, **options):
self._plugin = False
self._root = origen.root
self._name = _origen.app_config()["name"]
self._rc = _origen.utility.revision_control.app_rc()
origen_metal.frontend.frontend(
).rc = _origen.utility.revision_control.app_rc()
self._unit_tester = _origen.utility.unit_testers.app_unit_tester()
#self._linter = _origen.utility.linter.app_linter()
self._publisher = _origen.utility.publisher.app_publisher()
Expand All @@ -128,7 +130,7 @@ def __init__(self, *args, **options):
self._plugin = True
self._root = options["root"]
self._name = options["name"]
self._rc = None
origen_metal.frontend.frontend().rc = None
self._unit_tester = None
self._linter = None
self._publisher = None
Expand Down
7 changes: 0 additions & 7 deletions python/origen/origen/utility/revision_control/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions python/origen/origen/utility/revision_control/git.py

This file was deleted.

51 changes: 16 additions & 35 deletions python/origen/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions python/origen/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ generate-setup-file = false
o2 = 'origen.__bin__:run_origen'

[tool.poetry.dependencies]
python = ">=3.6,<3.11"
origen_metal = "= 0.3.0"
python = ">=3.7,<3.10"
origen_metal = "= 0.4.0"
termcolor = ">= 1.1.0"
colorama = "^0.4"
bs4 = "0.0.1"
Expand Down
11 changes: 10 additions & 1 deletion python/origen_metal/origen_metal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# This needs to be commented out to run pdoc, but is required for functionality
from ._origen_metal import *

import sys

if "origen_metal._origen_metal" in sys.modules:
# If "origen_metal._origen_metal" is already defined,
# use this library instead of the native one
from origen_metal._origen_metal import *
_origen_metal = sys.modules["origen_metal._origen_metal"]
else:
from ._origen_metal import *
6 changes: 5 additions & 1 deletion python/origen_metal/origen_metal/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@

They are generic enough to allow you to use them to create a similar feature in your own
application framework, but they are not quite as generic as the APIs found in the origen_metal.utils module.
"""
"""

from origen_metal import _origen_metal

Outcome = _origen_metal.framework.outcomes.Outcome
7 changes: 6 additions & 1 deletion python/origen_metal/origen_metal/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""
This module contains low-level APIs that are very generic and could be used in many
different applications.
"""
"""

from . import revision_control
from .revision_control import RevisionControlAPI

rc = revision_control
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import origen_metal
from abc import ABC, abstractclassmethod

Base = origen_metal._origen_metal.utils.revision_control.Base


class RevisionControlAPI(ABC):
@abstractclassmethod
def system(self):
...

@abstractclassmethod
def populate(self, version):
...

@abstractclassmethod
def revert(self, path):
...

@abstractclassmethod
def checkout(self, force, path, version):
...

@abstractclassmethod
def status(self, path):
...

@abstractclassmethod
def tag(self, force, path, version):
...

@abstractclassmethod
def is_initialized(self, tagname, force, message):
...

@abstractclassmethod
def init(self):
...
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .git import Git
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from origen_metal import _origen_metal
from origen_metal.utils.revision_control import RevisionControlAPI

_Git = _origen_metal.utils.revision_control.supported.Git


class Git(_Git, RevisionControlAPI):
def __init__(self, config):
_Git.__init__(self, config)
75 changes: 75 additions & 0 deletions python/origen_metal/tests/test_frontend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import pytest
from origen_metal._origen_metal import __test__
from origen_metal.utils import revision_control
from origen_metal.framework import Outcome
from origen_metal._origen_metal import frontend


def init_frontend():
frontend.reset()
assert fe() is None
assert frontend.initialize() is True
assert isinstance(fe(), frontend.PyFrontend)


def fe():
return frontend.frontend()


@pytest.fixture
def frontend_init():
init_frontend()


def test_frontend_is_accessible():
assert fe() is None
init_frontend()


def test_multiple_frontend_initializes_are_benign(frontend_init):
assert frontend.initialize() is False


class TestRevisionControlFrontend:
class DummyRC(revision_control.RevisionControlAPI):
def init(self):
return Outcome(succeeded=True, message="From Dummy RC")

def is_initialized(self):
return True

def checkout(self):
raise NotImplemented("checkout not available for DummyRC")

def populate(self):
raise NotImplemented("populate not available for DummyRC")

def revert(self):
raise NotImplemented("revert not available for DummyRC")

def status(self):
raise NotImplemented("status not available for DummyRC")

def system(self):
self.__class__.name

def tag(self):
raise NotImplemented("tag not available for DummyRC")

@pytest.fixture
def dummy_rc(self):
fe().rc = TestRevisionControlFrontend.DummyRC()

def test_frontend_rc_driver(frontend_init):
assert fe().rc is None
assert fe().revision_control is None

def test_frontend_rc_driver_can_be_set(frontend_init, dummy_rc):
assert isinstance(fe().rc, TestRevisionControlFrontend.DummyRC)
assert isinstance(fe().revision_control,
TestRevisionControlFrontend.DummyRC)

def test_frontend_rc_can_be_called_by_the_backend(frontend_init, dummy_rc):
outcome = __test__.rc_init_from_metal()
assert outcome.succeeded is True
assert outcome.message == "From Dummy RC"
Loading