Skip to content

Commit

Permalink
Fix bug with default settings_file & source error with /bin/sh (#2
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kaxil authored Aug 14, 2023
1 parent f22cb51 commit 0f301b0
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and test
on:
push:
branches: [ 'main' ]

pull_request:
branches: [ 'main' ]

# This allows a subsequently queued workflow run to interrupt and cancel previous runs
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
Run-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: [ '3.8', '3.9', '3.10', '3.11' ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '${{ matrix.python }}'
architecture: 'x64'
- run: pip install -U pip wheel poetry
- run: poetry install --with dev
- run: poetry run pytest tests
10 changes: 6 additions & 4 deletions airflowctl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def init(
def build(
project_path: Path = typer.Argument(Path.cwd(), help="Absolute path to the Airflow project directory."),
settings_file: Path = typer.Option(
Path.cwd() / SETTINGS_FILENAME,
help="Path to the settings file.",
None, help="Path to the settings file. Defaults to PROJECT_DIR/settings.yaml.", show_default=False
),
venv_path: Path = typer.Option(
Path.cwd() / ".venv",
Expand All @@ -93,9 +92,12 @@ def build(

airflowctl_project_check(project_path)
project_path = Path(project_path).absolute()

if not settings_file:
settings_file = project_path / SETTINGS_FILENAME
settings_file = Path(settings_file).absolute()

if not Path(project_path / SETTINGS_FILENAME).exists():
if not settings_file.exists():
typer.echo(f"Settings file '{settings_file}' not found.")
raise typer.Exit(1)

Expand Down Expand Up @@ -412,7 +414,7 @@ def print_next_steps(venv_path: str | Path, version: str):

next_steps = "Next Steps:"

activate_command = f"$ source {venv_path}/bin/activate"
activate_command = activate_virtualenv_cmd(venv_path)

assert Path(venv_path).exists()

Expand Down
2 changes: 1 addition & 1 deletion airflowctl/utils/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def verify_or_create_venv(venv_path: str | Path, recreate: bool, python_version:
def activate_virtualenv_cmd(venv_path: str | Path) -> str:
if os.name == "posix":
bin_path = os.path.join(venv_path, "bin", "activate")
activate_cmd = f"source {bin_path}"
activate_cmd = f". {bin_path}"
elif os.name == "nt":
bin_path = os.path.join(venv_path, "Scripts", "activate")
activate_cmd = f"call {bin_path}"
Expand Down
76 changes: 75 additions & 1 deletion poetry.lock

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

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ psutil = "^5.9.5"
[tool.poetry.scripts]
airflowctl = "airflowctl.cli:app"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
Empty file added tests/__init__.py
Empty file.
58 changes: 58 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import tempfile

import pytest
from typer.testing import CliRunner

from airflowctl.cli import app

runner = CliRunner()


@pytest.fixture(scope="function")
def temp_project_dir():
with tempfile.TemporaryDirectory() as temp_dir:
yield temp_dir


def test_init_command(temp_project_dir):
result = runner.invoke(
app,
[
"init",
temp_project_dir,
"--project-name",
"my_project",
"--airflow-version",
"2.6.3",
"--build-start",
"--background",
],
)

assert result.exit_code == 0, result.output
assert "Airflow project built successfully." in result.output


def test_build_command(temp_project_dir):
result = runner.invoke(
app,
[
"init",
temp_project_dir,
"--project-name",
"my_project",
],
)

assert result.exit_code == 0, result.output
result_1 = runner.invoke(
app,
[
"build",
temp_project_dir,
# "--recreate-venv"
],
)

assert result_1.exit_code == 0, result_1.output
assert "Airflow project built successfully." in result_1.output

0 comments on commit 0f301b0

Please sign in to comment.