Skip to content

Commit

Permalink
Merge pull request #8 from capitec/release/v0.3.0
Browse files Browse the repository at this point in the history
Release/v0.3.0
  • Loading branch information
sjnarmstrong authored Sep 23, 2024
2 parents 59eca10 + 374b28a commit a4ffda5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 27 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ jobs:
if-no-files-found: error

release:
needs: ["build-docs", "build-package"]
needs: ["build-docs", "build-package", "get-version"]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/spockflow
permissions:
id-token: write
pages: write
contents: write
pull-requests: write
repository-projects: write
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -151,7 +154,7 @@ jobs:
PACKAGE_VERSION: ${{needs.get-version.outputs.PACKAGE_VERSION}}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Sholto Armstrong"
git config --global user.name "Github Bot"
git tag -a v${PACKAGE_VERSION} -m "Release v${PACKAGE_VERSION}"
- name: Set up Python
Expand Down Expand Up @@ -187,7 +190,7 @@ jobs:
name: python-package
path: dist

- name: Upload Docker image
- name: Build Docker image
uses: docker/build-push-action@v3
with:
context: .
Expand All @@ -213,6 +216,12 @@ jobs:
if: github.ref == 'refs/heads/main'
uses: actions/deploy-pages@v4

- name: Push Tag
env:
PACKAGE_VERSION: ${{needs.get-version.outputs.PACKAGE_VERSION}}
run: |
git push origin tag v${PACKAGE_VERSION}
- name: Create Release
if: github.ref == 'refs/heads/main'
id: release-snapshot
Expand Down
28 changes: 27 additions & 1 deletion spockflow/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from hamilton import graph


def omitted_function():
"""This function is omitted as it forms part of SpockFlow"""
pass


class Driver(driver.Driver):
def raw_execute(
self,
Expand Down Expand Up @@ -118,6 +123,27 @@ def _get_outputs(cls, g: "graph.FunctionGraph") -> List[str]:
g._spock_cached_default_out = default_out
return g._spock_cached_default_out

@staticmethod
def _filter_originating_functions(nodes: List[node.Node]) -> List[node.Node]:
out = []
for node_ in nodes:
current_originating_functions = node_.originating_functions
if current_originating_functions is None:
out.append(node_)
continue
if not any(
isinstance(f, VariableNode) for f in current_originating_functions
):
out.append(node_)
continue

new_originating_functions = tuple(
omitted_function if isinstance(f, VariableNode) else f
for f in current_originating_functions
)
out.append(node_.copy_with(originating_functions=new_originating_functions))
return out

def generate_nodes(
self, fn: "Callable", configuration: "Dict[str, Any]"
) -> "Collection[node.Node]":
Expand All @@ -135,7 +161,7 @@ def generate_nodes(
# nodes += [self.add_final_node(fn, final_node_name, namespace)]
if not self.ignore_output:
nodes.append(self.set_spock_output_flag(node.Node.from_fn(fn), force=True))
return nodes
return self._filter_originating_functions(nodes)


class set_function_as_output(tag):
Expand Down
53 changes: 30 additions & 23 deletions spockflow/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,40 +132,47 @@ def required_config(self) -> typing.Optional[typing.List[str]]:
return None


assert (
base.NodeCreator.get_lifecycle_name() == "generate"
), "The version of Hamilton you are using is incompatible with this generation"


class VariableNode(BaseModel):
"""This is a base class for all variable nodes to use"""

_name: typing.Optional[str] = None
_module: typing.Optional[str] = None
# NOTE: this assumes that base.NodeCreator.get_lifecycle_name() returns generate
generate: typing.ClassVar[typing.List[base.NodeCreator]] = [VariableNodeCreator()]

# generate: typing.ClassVar[typing.List[base.NodeCreator]] = [VariableNodeCreator()]
_allowed_lifecycle_keys: typing.ClassVar[typing.List[str]] = [
base.NodeCreator.get_lifecycle_name(),
base.NodeDecorator.get_lifecycle_name(),
]
# def model_post_init(self, __context):
# setattr(self, base.NodeCreator.get_lifecycle_name(), [VariableNodeCreator()])
#

# TODO evaluate if this is worthwile
# _lifecycle_hooks: dict = PrivateAttr(default_factory=lambda:{
# "generate": [VariableNodeCreator()]
# })
# def __getattr__(self, name: str) -> typing.Any:
# try:
# return super().__getattr__(name)
# except AttributeError as e:
# if name in self._lifecycle_hooks:
# return self._lifecycle_hooks[name]
# raise e from e

# def __hasattr__(self, name: str) -> bool:
# has_attr = super().__hasattr__(name)
# if has_attr or name in self._lifecycle_hooks:
# return True
# return False
_lifecycle_hooks: dict = PrivateAttr(
default_factory=lambda: {
base.NodeCreator.get_lifecycle_name(): [VariableNodeCreator()]
}
)

def __getattr__(self, name: str) -> typing.Any:
try:
return super().__getattr__(name)
except AttributeError as e:
if name in self._lifecycle_hooks:
return self._lifecycle_hooks[name]
raise e from e

def __setattr__(self, name: str, value: typing.Any):
if name in self._allowed_lifecycle_keys:
self._lifecycle_hooks[name] = value
return
super().__setattr__(name, value)

def __hasattr__(self, name: str) -> bool:
has_attr = super().__hasattr__(name)
if has_attr or name in self._lifecycle_hooks:
return True
return False

# def add_lifecycle(self, lifecycle: base.NodeTransformLifecycle, skip_validation=False) -> "Self":
# if skip_validation:
Expand Down

0 comments on commit a4ffda5

Please sign in to comment.