Skip to content

Commit

Permalink
refactor: more stuff to sudoblockio
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Dec 6, 2022
1 parent 33b3a6d commit 77615b1
Show file tree
Hide file tree
Showing 38 changed files with 266 additions and 59 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<img align="right" width="280" height="280" src="https://raw.githubusercontent.com/robcxyz/tackle/main/docs/assets/logo-box.png">
<img align="right" width="280" height="280" src="https://raw.githubusercontent.com/sudoblockio/tackle/main/docs/assets/logo-box.png">

[//]: # (TODO: update codecov url)

# tackle

[![pypi](https://img.shields.io/pypi/v/tackle.svg)](https://pypi.python.org/pypi/tackle)
[![python](https://img.shields.io/pypi/pyversions/tackle.svg)](https://pypi.python.org/pypi/tackle)
[![codecov](https://codecov.io/gh/robcxyz/tackle/branch/main/graphs/badge.svg?branch=main)](https://codecov.io/github/robcxyz/tackle?branch=main)
[![codeql](https://github.com/robcxyz/tackle/actions/workflows/codeql.yml/badge.svg)](https://github.com/robcxyz/tackle/actions/workflows/codeql.yml)
[![codecov](https://codecov.io/gh/robcxyz/tackle/branch/main/graphs/badge.svg?branch=main)](https://codecov.io/github/sudoblockio/tackle?branch=main)
[![codeql](https://github.com/sudoblockio/tackle/actions/workflows/codeql.yml/badge.svg)](https://github.com/sudoblockio/tackle/actions/workflows/codeql.yml)
[![Foresight Docs](https://api-public.service.runforesight.com/api/v1/badge/success?repoId=4abde40b-565a-4557-afc0-983461857bb4)](https://docs.runforesight.com/)
[![Foresight Docs](https://api-public.service.runforesight.com/api/v1/badge/test?repoId=4abde40b-565a-4557-afc0-983461857bb4)](https://docs.runforesight.com/)
[![Foresight Docs](https://api-public.service.runforesight.com/api/v1/badge/utilization?repoId=4abde40b-565a-4557-afc0-983461857bb4)](https://docs.runforesight.com/)

[//]: # ([![main-tests]&#40;https://github.com/robcxyz/tackle/actions/workflows/main.yml/badge.svg&#41;]&#40;https://github.com/robcxyz/tackle/actions&#41;)
[//]: # ([![main-tests]&#40;https://github.com/sudoblockio/tackle/actions/workflows/main.yml/badge.svg&#41;]&#40;https://github.com/sudoblockio/tackle/actions&#41;)

* [Documentation](https://sudoblockio.github.io/tackle)
* [Discord](https://discord.gg/7uVUfUVD7K)
Expand Down Expand Up @@ -56,7 +58,7 @@ python -m venv env && source env/bin/activate
pip install tackle
```

**Quick Demo:** `tackle robcxyz/tackle-hello-world`
**Quick Demo:** `tackle sudoblockio/tackle-hello-world`

### Hello world

Expand All @@ -68,7 +70,7 @@ Check out the [docs](https://sudoblockio.github.io/tackle/hello-worlds/) for >10
hw->: print Hello world!
```

To run, call `tackle hello.yaml`. Can also be [version controlled](https://sudoblockio.github.io/tackle/creating-providers/) -> [`tackle robcxyz/tackle-hello-world`](https://github.com/robcxyz/tackle-hello-world).
To run, call `tackle hello.yaml`. Can also be [version controlled](https://sudoblockio.github.io/tackle/creating-providers/) -> [`tackle sudoblockio/tackle-hello-world`](https://github.com/sudoblockio/tackle-hello-world).

Can also use [loops, conditionals, and other base methods](https://sudoblockio.github.io/tackle/hook-methods/).

Expand Down Expand Up @@ -136,7 +138,7 @@ With the declarative hooks being callable from the command line:
```shell
tackle hello.yaml greeter --target world!
# Or from a github repo
tackle robcxyz/tackle-hello-world --checkout v0.1.0
tackle sudoblockio/tackle-hello-world --checkout v0.1.0
```

Documentation can be embedded into the hooks.
Expand Down
6 changes: 3 additions & 3 deletions mkdocs.tackle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
site_name: tackle
site_description: Declarative DSL for building modular workflows and code generators.
site_url: https://robcxyz.github.io/tackle
site_url: https://sudoblockio.github.io/tackle
theme:
name: material
palette:
Expand All @@ -27,8 +27,8 @@ theme:
# logo: img/icon-white.svg
# favicon: img/favicon.png
language: en
repo_name: robcxyz/tackle
repo_url: https://github.com/robcxyz/tackle
repo_name: sudoblockio/tackle
repo_url: https://github.com/sudoblockio/tackle
edit_uri: ''
nav:
# - Usage Docs:
Expand Down
4 changes: 1 addition & 3 deletions tackle/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ def main(raw_args=None):
help="A string to a file to use as overrides when parsing a tackle file or "
"some dict to use with keys to additionally use when parsing a file.",
)
parser.add_argument(
'--version', action='version', version=f'tackle {__version__}'
)
parser.add_argument('--version', action='version', version=f'tackle {__version__}')

args, unknown_args = parser.parse_known_args(raw_args)

Expand Down
2 changes: 1 addition & 1 deletion tackle/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, extra_message=None):
self.message = (
f"Unimplemented / needs to be built "
f"- PLEASE HELP -> "
f"https://github.com/robcxyz/tackle/blob/main/{self.file_location()}"
f"https://github.com/sudoblockio/tackle/blob/main/{self.file_location()}"
f"\n{self.extra_message}"
)
super().__init__(self.message)
Expand Down
4 changes: 2 additions & 2 deletions tackle/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import TYPE_CHECKING

# TODO: RM after dealing with namespace issue for validators
# https://github.com/robcxyz/tackle/issues/43
# https://github.com/sudoblockio/tackle/issues/43
# import random
# import string

Expand Down Expand Up @@ -181,7 +181,7 @@ def import_hook_from_path(

# TODO: RM after dealing with namespace issue for validators
# Use a unique RUN_ID to prevent duplicate validator errors
# https://github.com/robcxyz/tackle/issues/43
# https://github.com/sudoblockio/tackle/issues/43
# _run_id = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(4))
# module_name = mod_name + '.hooks.' + file_base[0] + _run_id
# TODO: Correct version
Expand Down
10 changes: 7 additions & 3 deletions tackle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Config:
smart_union = True

# TODO: RM after dealing with namespace issue for validators
# https://github.com/robcxyz/tackle/issues/43
# https://github.com/sudoblockio/tackle/issues/43
run_id: str = None

def __init__(self, **data: Any):
Expand All @@ -86,7 +86,10 @@ class Context(BaseContext):
None, description="A str for a file or dict to override inputs with."
)

context_functions: list = None
function_fields: list = None
function_dict: dict = None

# return_: bool = False

hook_dirs: list = Field(
None, description="A list of additional directories to import hooks."
Expand Down Expand Up @@ -253,7 +256,7 @@ class JinjaHook(BaseModel):

class Config:
# TODO: Had to add this to get `make test` to run.
# https://github.com/robcxyz/tackle/issues/90
# https://github.com/sudoblockio/tackle/issues/90
arbitrary_types_allowed = True

def wrapped_exec(self, *args, **kwargs):
Expand Down Expand Up @@ -283,6 +286,7 @@ def wrapped_exec(self, *args, **kwargs):
public_hooks=self.context.public_hooks,
key_path=self.context.key_path,
verbose=self.context.verbose,
env_=self.context.env_,
).exec()
return output

Expand Down
16 changes: 10 additions & 6 deletions tackle/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_hook(hook_type, context: 'Context') -> Type[BaseHook]:
for method in hook_parts:
new_hook = None

# TODO: Fix this -> https://github.com/robcxyz/tackle/issues/113
# TODO: Fix this -> https://github.com/sudoblockio/tackle/issues/113
# When hooks are in `hooks` dir we apparently need to instantiate the base
if isinstance(h, LazyBaseFunction):
h = create_function_model(
Expand All @@ -123,6 +123,10 @@ def get_hook(hook_type, context: 'Context') -> Type[BaseHook]:
if i not in new_hook.function_dict:
# Base method should not override child.
new_hook.function_dict[i] = h.__fields__['function_dict'].default[i]
if new_hook.function_fields is None:
new_hook.function_fields = []

new_hook.function_fields.append(i)

# Methods that are of type LazyBaseFunction which need to have the base
# instantiated before getting the hook. Allows nested methods for functions.
Expand Down Expand Up @@ -236,7 +240,7 @@ def merge_block_output(
keys from the key path and move them up one level.
"""
if append_hook_value:
# TODO: https://github.com/robcxyz/tackle/issues/66
# TODO: https://github.com/sudoblockio/tackle/issues/66
# Allow merging into lists
if isinstance(context.key_path_block[-1], bytes):
# An exception maybe needed here or this error is snubbed.
Expand Down Expand Up @@ -357,7 +361,7 @@ def render_hook_vars(hook_dict: dict, Hook: ModelMetaclass, context: 'Context'):
# TODO: When we build our own custom Field function then this will change
# TODO: This causes errors when the field is aliased as the lookup doesn't
# work and needs a deeper introspection.
# https://github.com/robcxyz/tackle/issues/80
# https://github.com/sudoblockio/tackle/issues/80
# Fixing with custom Field def should fix this.
elif 'render_by_default' in Hook.__fields__[key].field_info.extra:
hook_dict[key] = render_variable(context, wrap_jinja_braces(value))
Expand Down Expand Up @@ -443,7 +447,7 @@ def parse_hook(
# Render the remaining hook variables
render_hook_vars(hook_dict, Hook, context)

# TODO: WIP - https://github.com/robcxyz/tackle/issues/104
# TODO: WIP - https://github.com/sudoblockio/tackle/issues/104
tmp_no_input = (
None if 'no_input' not in hook_dict else hook_dict.pop('no_input')
)
Expand All @@ -469,7 +473,7 @@ def parse_hook(
# TODO: Improve -> This is an error when we have multiple of the same
# base attribute. Should not conflict in the future when we do
# composition on the context but for now, catching common error.
# TODO: WIP - https://github.com/robcxyz/tackle/issues/104
# TODO: WIP - https://github.com/sudoblockio/tackle/issues/104
raise exceptions.UnknownInputArgumentException(
str(e) + " - Can't assign duplicate base fields.", context=context
) from None
Expand Down Expand Up @@ -1341,7 +1345,7 @@ def create_function_model(
**new_func,
**function_input.dict(include={'args', 'render_exclude'}),
**{'function_dict': (dict, function_dict)}, # Preserve for `extends` key
# https://github.com/robcxyz/tackle/issues/99
# https://github.com/sudoblockio/tackle/issues/99
public_hooks=context.public_hooks,
private_hooks=context.private_hooks,
calling_directory=context.calling_directory,
Expand Down
4 changes: 2 additions & 2 deletions tackle/providers/command/hooks/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _set_size(self, fd):

def exec(self) -> Any:
# TODO: Fix multi-line calls
# https://github.com/robcxyz/tackle/issues/14
# https://github.com/sudoblockio/tackle/issues/14
if self.multiline:
commands = [self.command.replace('\n', ' ').split()]
else:
Expand Down Expand Up @@ -86,7 +86,7 @@ def exec(self) -> Any:
while readable:
# TODO: Session is not interactive and fails below when interactive
# prompts are displayed
# https://github.com/robcxyz/tackle/issues/13
# https://github.com/sudoblockio/tackle/issues/13
# x = select(readable, [], [])[0]
for fd in select(readable, [], [])[0]:
try:
Expand Down
4 changes: 2 additions & 2 deletions tackle/providers/command/tests/interactive.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#https://github.com/robcxyz/tackle/issues/13
#https://github.com/robcxyz/tackle/issues/14
#https://github.com/sudoblockio/tackle/issues/13
#https://github.com/sudoblockio/tackle/issues/14

run->: command "echo 'here' && echo -n 'this'"
2 changes: 1 addition & 1 deletion tackle/providers/command/tests/multi-line-cmd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#https://github.com/robcxyz/tackle/issues/14
#https://github.com/sudoblockio/tackle/issues/14
multiline:
->: command
multiline: true
Expand Down
8 changes: 4 additions & 4 deletions tackle/providers/command/tests/test_provider_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
# assert context['cmd'] == context['cmd_arg']


# TODO: https://github.com/robcxyz/tackle/issues/14
# TODO: https://github.com/robcxyz/tackle/issues/71
# TODO: https://github.com/sudoblockio/tackle/issues/14
# TODO: https://github.com/sudoblockio/tackle/issues/71
@pytest.mark.skipif(
sys.platform == 'darwin', reason="https://github.com/robcxyz/tackle/issues/71"
sys.platform == 'darwin', reason="https://github.com/sudoblockio/tackle/issues/71"
)
def test_provider_system_hook_command_multi_line(change_dir):
output = tackle('multi-line-cmd.yaml')
assert output['multiline'].startswith('stuff and thing')
assert output['singleline'].startswith('stuff and thing')


# TODO: https://github.com/robcxyz/tackle/issues/13
# TODO: https://github.com/sudoblockio/tackle/issues/13
# def test_provider_system_hook_interactive_shell(chdir):
# o = tackle('interactive.yaml')
# assert o
Expand Down
2 changes: 1 addition & 1 deletion tackle/providers/console/hooks/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MarkdownPrintHook(BaseHook):
args: list = ['text']

# TODO: Map this https://rich.readthedocs.io/en/stable/reference/markdown.html?highlight=markdown%20#rich.markdown.Markdown
# https://github.com/robcxyz/tackle/issues/57
# https://github.com/sudoblockio/tackle/issues/57
def exec(self):
console = Console()
console.print(Markdown(self.text, justify='left', inline_code_lexer='python'))
Expand Down
2 changes: 1 addition & 1 deletion tackle/providers/console/hooks/prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def exec(self) -> None:
if 'rich' in sys.modules:
# TODO: Line up these docs
# https://rich.readthedocs.io/en/stable/reference/pretty.html?highlight=pprint#rich.pretty.pprint
# https://github.com/robcxyz/tackle/issues/57
# https://github.com/sudoblockio/tackle/issues/57
pprint(
self.objects,
max_length=self.width,
Expand Down
1 change: 1 addition & 0 deletions tackle/providers/context/hooks/pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def exec(self) -> Union[dict, list, None]:
target_context, set_key_path = get_target_and_key(
self, key_path=encode_key_path(self.src, self.sep)
)
print(target_context)

self.src = nested_get(
element=target_context,
Expand Down
2 changes: 1 addition & 1 deletion tackle/providers/logic/hooks/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def block_macro(self, key, val) -> dict:
if self.verbose:
print(
"You are likely going to hit a bug."
"https://github.com/robcxyz/tackle/issues/67"
"https://github.com/sudoblockio/tackle/issues/67"
)
return {key[:-2]: output}
# return output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def test_hook_match_loop(change_dir):
assert output


# TODO: https://github.com/robcxyz/tackle/issues/66
# TODO: https://github.com/sudoblockio/tackle/issues/66
# Add merge to loop functions
# def test_hook_match_block_loop(change_dir):
# """Check that we can merge from a looped block into a looped match."""
# output = tackle('block-loop.yaml')
# # Assertions in fixture
# assert output

# TODO: https://github.com/robcxyz/tackle/issues/66
# TODO: https://github.com/sudoblockio/tackle/issues/66
# Fix basic block macro functionality
# def test_hook_match_block_if(change_dir):
# """Check that any kind of first level block makes sense."""
Expand Down
4 changes: 3 additions & 1 deletion tackle/providers/paths/tests/glob.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
g->: glob *
star->: glob *

file->: glob child.yaml
2 changes: 1 addition & 1 deletion tackle/providers/paths/tests/test_provider_system_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def test_provider_paths_base_dir_name(change_dir):
def test_provider_paths_glob(change_dir):
output = tackle('glob.yaml')

assert 'dirs' in output['g']
assert 'dirs' in output['star']
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_provider_prompt_checkbox_list_no_input(change_dir):
assert output['selection'] == ['stuff', 'things']


# # TODO: https://github.com/robcxyz/tackle/issues/46
# # TODO: https://github.com/sudoblockio/tackle/issues/46
# def test_provider_prompt_checkbox_list(change_dir, mocker):
# mocker.patch(
# 'tackle.providers.prompts.hooks.checkbox.prompt',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# from tackle.main import tackle
#
# TODO: https://github.com/robcxyz/tackle/issues/46
# TODO: https://github.com/sudoblockio/tackle/issues/46
# def test_provider_pyinquirer_confirm_hook(change_dir, mocker):
# mocker.patch(
# 'tackle.providers.prompts.hooks.confirm.prompt', return_value={"tmp": True}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# from tackle.main import tackle
#
# # TODO: https://github.com/robcxyz/tackle/issues/46
# # TODO: https://github.com/sudoblockio/tackle/issues/46
#
# def test_provider_pyinquirer_input_hook(change_dir, mocker):
# # mocker.patch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# from tackle.main import tackle
#
# # TODO: https://github.com/robcxyz/tackle/issues/46
# # TODO: https://github.com/sudoblockio/tackle/issues/46
#
# def test_provider_prompts_password_hook(change_dir, mocker):
# mocker.patch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# from tackle import tackle
#
# # TODO: https://github.com/robcxyz/tackle/issues/46
# # TODO: https://github.com/sudoblockio/tackle/issues/46
#
#
# def test_provider_select_list_this(change_dir, mocker):
Expand Down
Loading

0 comments on commit 77615b1

Please sign in to comment.