Skip to content

Commit

Permalink
chore: don't forget ruff-format (#255)
Browse files Browse the repository at this point in the history
* chore: don't forget ruff-format

* fix formatting
  • Loading branch information
efiop authored Jul 3, 2024
1 parent 09d9032 commit 5677f46
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 64 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.3.4'
hooks:
- id: ruff-format
files: |
(?x)(
^projects/fal/src/|
^projects/fal/tests/|
^projects/fal_client/
)
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
files: |
Expand Down
7 changes: 3 additions & 4 deletions projects/fal/src/fal/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def create_rlock(count: int, owner: int) -> RLockType:

def pickle_rlock(obj: RLockType) -> tuple[Callable, tuple]:
r = obj.__repr__()
count = int(r.split('count=')[1].split()[0].rstrip('>'))
owner = int(r.split('owner=')[1].split()[0])
count = int(r.split("count=")[1].split()[0].rstrip(">"))
owner = int(r.split("owner=")[1].split()[0])

return create_rlock, (count, owner)

Expand All @@ -209,7 +209,7 @@ def pickle_locals(obj: ConsoleThreadLocals) -> tuple[Callable, tuple]:
"buffer": obj.buffer,
"buffer_index": obj.buffer_index,
}
return create_locals, (kwargs, )
return create_locals, (kwargs,)

_register(ConsoleThreadLocals, pickle_locals)

Expand All @@ -231,4 +231,3 @@ def patch_pickle() -> None:
_patch_exceptions()

_register_pickle_by_value("fal")

3 changes: 1 addition & 2 deletions projects/fal/src/fal/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def _backwards_compatible_app_id(app_id: str) -> str:


@dataclass
class _Status:
...
class _Status: ...


@dataclass
Expand Down
1 change: 0 additions & 1 deletion projects/fal/src/fal/cli/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def _runners(args):

from fal.sdk import FalServerlessClient


client = FalServerlessClient(args.host)
with client.connect() as connection:
runners = connection.list_alias_runners(alias=args.app_name)
Expand Down
6 changes: 1 addition & 5 deletions projects/fal/src/fal/cli/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ def debugtools(args):
def get_debug_parser():
parser = FalParser(add_help=False)
group = parser.add_argument_group(title="Debug")
group.add_argument(
"--debug",
action="store_true",
help="Show verbose errors."
)
group.add_argument("--debug", action="store_true", help="Show verbose errors.")
group.add_argument(
"--pdb",
action="store_true",
Expand Down
15 changes: 8 additions & 7 deletions projects/fal/src/fal/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def _deploy(args):
# Try to find a python file in the current directory
options = list(Path(".").glob("*.py"))
if len(options) == 0:
raise FalServerlessError(
"No python files found in the current directory"
)
raise FalServerlessError("No python files found in the current directory")
elif len(options) > 1:
raise FalServerlessError(
"Multiple python files found in the current directory. "
Expand Down Expand Up @@ -107,8 +105,12 @@ def _deploy(args):
"Registered a new revision for function "
f"'{app_name}' (revision='{app_id}')."
)
args.console.print(f"Playground: https://fal.ai/models/{user.username}/{app_name}")
args.console.print(f"Endpoint: https://{gateway_host}/{user.username}/{app_name}")
args.console.print(
f"Playground: https://fal.ai/models/{user.username}/{app_name}"
)
args.console.print(
f"Endpoint: https://{gateway_host}/{user.username}/{app_name}"
)


def add_parser(main_subparsers, parents):
Expand Down Expand Up @@ -139,8 +141,7 @@ def valid_auth_option(option):
nargs="?",
action=RefAction,
help=(
"Application reference. "
"For example: `myfile.py::MyApp`, `myfile.py`."
"Application reference. " "For example: `myfile.py::MyApp`, `myfile.py`."
),
)
parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion projects/fal/src/fal/cli/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def _list(args):
keys = connection.list_user_keys()
for key in keys:
table.add_row(
key.key_id, str(key.created_at), str(key.scope.value), key.alias,
key.key_id,
str(key.created_at),
str(key.scope.value),
key.alias,
)

args.console.print(table)
Expand Down
5 changes: 1 addition & 4 deletions projects/fal/src/fal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def _run(args):

def add_parser(main_subparsers, parents):
run_help = "Run fal function."
epilog = (
"Examples:\n"
" fal run path/to/myfile.py::myfunc"
)
epilog = "Examples:\n" " fal run path/to/myfile.py::myfunc"
parser = main_subparsers.add_parser(
"run",
description=run_help,
Expand Down
8 changes: 3 additions & 5 deletions projects/fal/src/fal/cli/secrets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

from .parser import DictAction, FalClientParser


def _set(args):
from fal.sdk import FalServerlessClient

client = FalServerlessClient(args.host)
with client.connect() as connection:
for name, value in args.secrets.items():
Expand All @@ -12,10 +12,7 @@ def _set(args):

def _add_set_parser(subparsers, parents):
set_help = "Set a secret."
epilog = (
"Examples:\n"
" fal secrets set HF_TOKEN=hf_***"
)
epilog = "Examples:\n" " fal secrets set HF_TOKEN=hf_***"

parser = subparsers.add_parser(
"set",
Expand Down Expand Up @@ -64,6 +61,7 @@ def _add_list_parser(subparsers, parents):

def _unset(args):
from fal.sdk import FalServerlessClient

client = FalServerlessClient(args.host)
with client.connect() as connection:
connection.delete_secret(args.secret)
Expand Down
1 change: 1 addition & 0 deletions projects/fal/src/fal/exceptions/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

class FalServerlessException(Exception):
"""Base exception type for fal Serverless related flows and APIs."""

pass
1 change: 0 additions & 1 deletion projects/fal/src/fal/logging/isolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class IsolateLogPrinter:

debug: bool

def __init__(self, debug: bool = False) -> None:
Expand Down
2 changes: 1 addition & 1 deletion projects/fal/src/fal/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def from_proto(

@from_grpc.register(isolate_proto.ApplicationInfo)
def _from_grpc_application_info(
message: isolate_proto.ApplicationInfo
message: isolate_proto.ApplicationInfo,
) -> ApplicationInfo:
return ApplicationInfo(
application_id=message.application_id,
Expand Down
1 change: 1 addition & 0 deletions projects/fal/src/fal/toolkit/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
else:
from pydantic import GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema

IS_PYDANTIC_V2 = True

from pydantic import BaseModel, Field
Expand Down
4 changes: 3 additions & 1 deletion projects/fal/src/fal/toolkit/file/providers/fal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def _save(self, file: FileData, storage_type: str) -> str:

grpc_host = os.environ.get("FAL_HOST", "api.alpha.fal.ai")
rest_host = grpc_host.replace("api", "rest", 1)
storage_url = f"https://{rest_host}/storage/upload/initiate?storage_type={storage_type}"
storage_url = (
f"https://{rest_host}/storage/upload/initiate?storage_type={storage_type}"
)

try:
req = Request(
Expand Down
13 changes: 6 additions & 7 deletions projects/fal/src/fal/toolkit/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ImageSize(BaseModel):

ImageSizeInput = Union[ImageSize, ImageSizePreset]


def get_image_size(source: ImageSizeInput) -> ImageSize:
if isinstance(source, ImageSize):
return source
Expand All @@ -62,7 +63,8 @@ class Image(File):
"""

width: Optional[int] = Field(
None, description="The width of the image in pixels.",
None,
description="The width of the image in pixels.",
examples=[1024],
)
height: Optional[int] = Field(
Expand All @@ -84,8 +86,8 @@ def from_bytes( # type: ignore[override]
file_name=file_name,
repository=repository,
)
obj.width=size.width if size else None
obj.height=size.height if size else None
obj.width = size.width if size else None
obj.height = size.height if size else None
return obj

@classmethod
Expand Down Expand Up @@ -120,9 +122,7 @@ def to_pil(self, mode: str = "RGB") -> PILImage.Image:
from PIL import Image as PILImage
from PIL import ImageOps
except ImportError:
raise ImportError(
"The PIL package is required to use Image.to_pil()."
)
raise ImportError("The PIL package is required to use Image.to_pil().")

# Stream the image data from url to a temp file and convert it to a PIL image
with NamedTemporaryFile() as temp_file:
Expand All @@ -134,4 +134,3 @@ def to_pil(self, mode: str = "RGB") -> PILImage.Image:
img = ImageOps.exif_transpose(img)

return img

1 change: 0 additions & 1 deletion projects/fal/src/fal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ def load_function_from(
f"Function '{function_name}' is not a fal.function or a fal.App"
)
return target, app_name

17 changes: 11 additions & 6 deletions projects/fal/tests/cli/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ def test_set_rev():
def test_scale():
args = parse_args(
[
"apps", "scale", "myapp",
"--keep-alive", "123",
"--max-multiplexing", "321",
"--min-concurrency", "7",
"--max-concurrency", "10",
"apps",
"scale",
"myapp",
"--keep-alive",
"123",
"--max-multiplexing",
"321",
"--min-concurrency",
"7",
"--max-concurrency",
"10",
]
)
assert args.func == _scale
Expand All @@ -61,4 +67,3 @@ def test_delete_rev():
args = parse_args(["apps", "delete-rev", "myrev"])
assert args.func == _delete_rev
assert args.app_rev == "myrev"

2 changes: 1 addition & 1 deletion projects/fal/tests/cli/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def test_login():
args = parse_args(["auth", "login"])
assert args.func == _login


def test_logout():
args = parse_args(["auth", "logout"])
assert args.func == _logout
Expand All @@ -14,4 +15,3 @@ def test_logout():
def test_whoami():
args = parse_args(["auth", "whoami"])
assert args.func == _whoami

6 changes: 4 additions & 2 deletions projects/fal/tests/cli/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ def test_create():
[
"keys",
"create",
"--scope", "API",
"--desc", "My test key",
"--scope",
"API",
"--desc",
"My test key",
]
)
assert args.func == _create
Expand Down
1 change: 0 additions & 1 deletion projects/fal/tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ def init_compressed_file_on_fal(input: TestInput) -> int:


def test_fal_cdn(isolated_client):

@isolated_client(requirements=[f"pydantic=={pydantic_version}"])
def upload_to_fal_cdn() -> FalImage:
return FalImage.from_bytes(b"0", "jpeg", repository="cdn")
Expand Down
23 changes: 16 additions & 7 deletions projects/fal/tests/test_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def mult(a, b):

assert mult(5, 2) == 10

@pytest.mark.xfail(reason="The support needs to be deployed. See https://github.com/fal-ai/isolate-cloud/pull/1809")

@pytest.mark.xfail(
reason="The support needs to be deployed. See https://github.com/fal-ai/isolate-cloud/pull/1809"
)
def test_regular_function_in_a_container(isolated_client):
@isolated_client("container")
def regular_function():
Expand All @@ -70,7 +73,10 @@ def mult(a, b):

assert mult(5, 2) == 10

@pytest.mark.xfail(reason="The support needs to be deployed. See https://github.com/fal-ai/isolate-cloud/pull/1809")

@pytest.mark.xfail(
reason="The support needs to be deployed. See https://github.com/fal-ai/isolate-cloud/pull/1809"
)
def test_regular_function_in_a_container_with_custom_image(isolated_client):
@isolated_client(
"container",
Expand Down Expand Up @@ -557,11 +563,14 @@ def get_env_var(name: str) -> str | None:


@pytest.mark.parametrize(
"repo_type, url_prefix",
[
("fal", "https://storage.googleapis.com/isolate-dev-smiling-shark_toolkit_bucket/"),
("fal_v2", "https://v2.fal.media/files"),
]
"repo_type, url_prefix",
[
(
"fal",
"https://storage.googleapis.com/isolate-dev-smiling-shark_toolkit_bucket/",
),
("fal_v2", "https://v2.fal.media/files"),
],
)
def test_fal_storage(isolated_client, repo_type, url_prefix):
file = File.from_bytes(b"Hello fal storage from local", repository=repo_type)
Expand Down
4 changes: 2 additions & 2 deletions projects/fal/tests/toolkit/file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def test_uniqueness_of_file_name(repo: RepositoryId | FileRepository):

host_and_path = file.url.split("?")[0]
last_path = host_and_path.split("/")[-1]
assert (
last_path.endswith(".py")
assert last_path.endswith(
".py"
), f"The file name {last_path} should end with the same extension"
assert (
len(last_path) > 10
Expand Down
2 changes: 1 addition & 1 deletion projects/fal_client/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def test_fal_client(client: fal_client.AsyncClient):
arguments={
"prompt": "a cat",
},
hint="lora:a"
hint="lora:a",
)
assert len(output["images"]) == 1

Expand Down
Loading

0 comments on commit 5677f46

Please sign in to comment.