Skip to content

Commit

Permalink
Merge pull request #7 from airflow-laminar/tkp/start
Browse files Browse the repository at this point in the history
Cloning and library list utilities
  • Loading branch information
timkpaine authored Jan 10, 2025
2 parents bc9e1b1 + a41345b commit 687cc43
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions airflow_common_operators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .common import *
from .git import *

__version__ = "0.1.0"
43 changes: 43 additions & 0 deletions airflow_common_operators/git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import List

from pydantic import BaseModel, Field

__all__ = ("clone_repo", "GitRepo", "PipLibrary", "LibraryList")


def clone_repo(name, repo, branch="main", install=True):
ret = f"""
[[ -d {name} ]] || git clone {repo}
pushd {name}
git stash
git clean -fdx
git fetch --all --force
git checkout {branch}
git reset origin/{branch} --hard
"""
if install:
ret += """
pip install -e .
"""
return ret


class GitRepo(BaseModel):
name: str
repo: str
branch: str = "main"

def clone(self, install: bool = True):
return clone_repo(name=self.name, repo=self.repo, branch=self.branch, install=install)


class PipLibrary(BaseModel):
name: str


class LibraryList(BaseModel):
pip: List[PipLibrary] = Field(default_factory=list)
git: List[GitRepo] = Field(default_factory=list)

# def install(self):
# return "pip install " + " ".join(lib.name for lib in self.libraries)
4 changes: 4 additions & 0 deletions airflow_common_operators/tests/git/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @package _global_
_target_: airflow_config.Configuration
defaults:
- extensions/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @package extensions.libraries

defaults: []

_target_: airflow_common_operators.LibraryList
pip:
- name: lib1
- name: lib2
- name: lib3
git:
- name: git1
repo: test
- name: git2
repo: test
branch: develop
- name: git3
repo: test

10 changes: 10 additions & 0 deletions airflow_common_operators/tests/git/test_git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from airflow_config import load_config


class TestConfig:
def test_load_config_hydra(self):
config = load_config(config_name="config")
assert config
assert "libraries" in config.extensions
assert len(config.extensions["libraries"].pip) == 3
assert len(config.extensions["libraries"].git) == 3
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ classifiers = [

dependencies = [
"apache-airflow>=2,<3",
"pydantic",
]

[project.optional-dependencies]
Expand Down

0 comments on commit 687cc43

Please sign in to comment.