Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Z committed May 7, 2020
1 parent 6c2a406 commit 89d8721
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
twine==3.1.1
pbr==5.4.5
jinja2>=2.11
pyyaml>=5.3.1
28 changes: 26 additions & 2 deletions src/rkd/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .argparsing import CommandlineParsingHelper
from .inputoutput import SystemIO, LEVEL_INFO as LOG_LEVEL_INFO
from .exception import TaskNotFoundException
from .yaml_context import YamlContextFactory


CURRENT_SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -115,11 +116,34 @@ class ContextFactory:
Takes responsibility of loading all tasks defined in USER PROJECT, USER HOME and GLOBALLY
"""

@staticmethod
def _load_context_from_directory(path: str) -> Context:
def _load_context_from_directory(self, path: str) -> Context:
if not os.path.isdir(path):
raise Exception('Path "%s" font found' % path)

ctx = Context([], [])
contexts = []

if os.path.isfile(path + '/makefile.py'):
contexts.append(self._load_from_py(path))

if os.path.isfile(path + '/makefile.yaml'):
contexts.append(self._load_from_yaml(path))

if not contexts:
raise Exception('The directory "%s" should contain at least makefile.py or makfile.yaml' % path)

for subctx in contexts:
ctx = Context.merge(ctx, subctx)

return ctx

def _load_from_yaml(self, path: str) -> Context:
makefile_path = path + '/makefile.yaml'

with open(makefile_path, 'rb') as handle:
return YamlContextFactory().parse(handle.read().decode('utf-8'))

def _load_from_py(self, path: str):
makefile_path = path + '/makefile.py'

if not os.path.isfile(makefile_path):
Expand Down
3 changes: 3 additions & 0 deletions src/rkd/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ class UserInputException(Exception):
class NotSupportedEnvVariableError(UserInputException):
pass


class YamlParsingException(ContextException):
pass
33 changes: 33 additions & 0 deletions src/rkd/yaml_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

import yaml
from typing import List
from .exception import YamlParsingException
from .inputoutput import SystemIO
from .context import Context
from .syntax import TaskDeclaration


class YamlContextFactory:
io: SystemIO

def __init__(self, io: SystemIO):
self.io = io

def parse(self, content: str):
parsed = yaml.parse(content)

if "imports" in parsed:
imports = self._parse_imports(parsed['imports'])

if "tasks" not in parsed:
raise YamlParsingException('"tasks" section not found in YAML file')

def _parse_imports(self, classes: List[str]) -> List[TaskDeclaration]:
parsed = []

for importstr in classes:
parts = importstr.split('.')
classname = parts[-1]
import_path = parts[:-1]


0 comments on commit 89d8721

Please sign in to comment.