Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds precommit #5

Merged
merged 13 commits into from
Feb 4, 2025
50 changes: 50 additions & 0 deletions .github/workflows/static_analisys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Static analysis

# on PR and push to main
on:
push:
branches:
- main
pull_request:

permissions:
contents: read

# Limit concurrency by workflow/branch combination.
#
# For pull request builds, pushing additional changes to the
# branch will cancel prior in-progress and pending builds.
#
# For builds triggered on a branch push, additional changes
# will wait for prior builds to complete before starting.
#
# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
pre-commit-checks:
name: Pre-commit checks
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.26"
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python
run: uv python install

- name: Install Project
run: uv sync --all-extras --dev

- name: Run pre-commit
run: uv run pre-commit run --show-diff-on-failure --color=always --all-files
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.9.4"
hooks:
- id: ruff
language_version: python3
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.26
hooks:
- id: uv-lock
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
exclude: package-lock.json|_vendor/.*|docs/styles/.*
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies:
- pydantic>=1.10.0,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0
- types-cachetools==5.3.0.5
- types-pyyaml==6.0.12.9
files: |
(?x)^(
src/prefect_cloud/.*
)$
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies = [
"typing-extensions>=4.12.2",
]


[project.scripts]
prefect-cloud = "prefect_cloud:cli.app"

Expand All @@ -25,6 +26,7 @@ build-backend = "hatchling.build"

[dependency-groups]
dev = [
"pre-commit>=4.1.0",
"pytest-asyncio>=0.25.3",
"pytest>=8.3.4",
]
Expand Down
54 changes: 22 additions & 32 deletions src/prefect_cloud/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from pathlib import Path

import typer
from rich.progress import Progress, SpinnerColumn, TextColumn
from typing_extensions import Annotated

from prefect.cli._utilities import exit_with_error
from prefect.cli.root import PrefectTyper
from prefect.client.base import ServerType, determine_server_type
from prefect.utilities.urls import url_for

from prefect_cloud.bundle import package_files
from prefect_cloud.dependencies import get_dependencies
from prefect_cloud.github import GitHubFileRef, get_github_raw_content
from prefect_cloud.client import (
Expand Down Expand Up @@ -42,33 +38,25 @@ def process_key_value_pairs(env: list[str]) -> dict[str, str]:
@app.command()
async def deploy(
function: str,
file: Annotated[
str,
typer.Option(
"--from",
"-f",
help=".py file containing the function to deploy.",
),
],
dependencies: Annotated[
list[str],
typer.Option(
"--with",
"-d",
help="Dependencies to include. Can be a single package `--with prefect`, "
"multiple packages `--with prefect --with pandas`, "
"the path to a requirements or pyproject.toml file "
"`--with requirements.txt / pyproject.toml`."
),
] = None,
env: Annotated[
list[str],
typer.Option(
"--env",
"-e",
help="Environment variables to set in the format KEY=VALUE. Can be specified multiple times.",
),
] = None,
file: str = typer.Option(
None,
"--from",
"-f",
help=".py file containing the function to deploy.",
),
dependencies: list[str] = typer.Option(
"--with",
"-d",
help="Dependencies to include. Can be a single package `--with prefect`, "
"multiple packages `--with prefect --with pandas`, "
"the path to a requirements or pyproject.toml file "
"`--with requirements.txt / pyproject.toml`.",
),
env: list[str] = typer.Option(
"--env",
"-e",
help="Environment variables to set in the format KEY=VALUE. Can be specified multiple times.",
),
):
ensure_prefect_cloud()

Expand Down Expand Up @@ -133,10 +121,12 @@ async def deploy(
style="blue",
)


@app.command()
async def schedule():
raise NotImplementedError


@app.command()
async def init():
raise NotImplementedError
raise NotImplementedError
7 changes: 4 additions & 3 deletions src/prefect_cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

PREFECT_MANAGED = "prefect:managed"

#TODO: temporary remove

# TODO: temporary remove
def get_cloud_api_url():
url = PREFECT_API_URL.value()
if url.startswith("https://api.prefect.dev/api"):
Expand Down Expand Up @@ -92,14 +93,14 @@ async def create_managed_deployment(

async def create_code_storage(self) -> UUID:
response = await self._client.post(
f"/mex/storage/",
"/mex/storage/",
json={"hash": str(uuid4()), "labels": {}},
)
return UUID(response.json()["id"])

async def upload_code_to_storage(self, storage_id, contents: str):
await self._client.post(
f"/mex/storage/upload",
"/mex/storage/upload",
data={"mex_storage_id": str(storage_id)},
files={"file": ("code", contents)},
)
Expand Down
4 changes: 2 additions & 2 deletions src/prefect_cloud/github.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Literal
from typing import Any, Literal, cast
from urllib.parse import urlparse

from httpx import AsyncClient
Expand Down Expand Up @@ -45,7 +45,7 @@ def from_url(cls, url: str) -> "GitHubFileRef":
)

owner, repo = parts[:2]
ref_type = parts[2]
ref_type = cast(Literal["blob", "tree"], parts[2])

if ref_type not in ("blob", "tree"):
raise ValueError(
Expand Down
1 change: 1 addition & 0 deletions src/prefect_cloud/utilities/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
parameter_docstrings,
)


def get_parameter_schema_from_content(
content: str, function_name: str
) -> ParameterSchema:
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from pytest_asyncio import is_async_test


def pytest_collection_modifyitems(items: list[pytest.Item]):
# Ensure that all async tests are run with the session loop scope
pytest_asyncio_tests = [item for item in items if is_async_test(item)]
Expand Down
Loading