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

MYPY Types added #97

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cloudinary_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from cloudinary_cli.version import __version__

import cloudinary
Expand Down
10 changes: 10 additions & 0 deletions cloudinary_cli/cli_group.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Optional
import click
from click import Context

def cli(
config: Optional[str] = None,
config_saved: Optional[str] = None,
ctx: Optional[Context] = None
) -> bool:
...
36 changes: 36 additions & 0 deletions cloudinary_cli/core/admin.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import List, Tuple, Any
from click import command, argument, option

@command("admin",
short_help="Run any methods that can be called through the admin API.",
help="""\b
Run any methods that can be called through the admin API.
Format: cld <cli options> admin <command options> <method> <method parameters>
\te.g. cld admin resources max_results=10 tags=sample
\t OR
\t cld admin resources -o max_results 10 -o tags sample
\t OR
\t cld admin resources max_results=10 -o tags sample
""")
@argument("params", nargs=-1)
@option("-o", "--optional_parameter", multiple=True, nargs=2, help="Pass optional parameters as raw strings.")
@option("-O", "--optional_parameter_parsed", multiple=True, nargs=2,
help="Pass optional parameters as interpreted strings.")
@option("-A", "--auto_paginate", is_flag=True, help="Will auto paginate Admin API calls.", default=False)
@option("-ff", "--filter_fields", multiple=True, help="Filter fields to return when using auto pagination.")
@option("-F", "--force", is_flag=True, help="Skip confirmation when running --auto-paginate.")
@option("-ls", "--ls", is_flag=True, help="List all available methods in the Admin API.")
@option("--save", nargs=1, help="Save output to a file.")
@option("-d", "--doc", is_flag=True, help="Open the Admin API reference in a browser.")
def admin(
params: Tuple[str, ...],
optional_parameter: List[Tuple[str, str]],
optional_parameter_parsed: List[Tuple[str, str]],
auto_paginate: bool,
force: bool,
filter_fields: List[str],
ls: bool,
save: str,
doc: bool
) -> Any:
...
21 changes: 21 additions & 0 deletions cloudinary_cli/core/config.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Optional, Any, Tuple
from click import command, option

@command("config", help="Display the current configuration, and manage additional configurations.")
@option("-n", "--new", help="""\b Create and name a configuration from a Cloudinary account environment variable.
e.g. cld config -n <NAME> <CLOUDINARY_URL>""", nargs=2)
@option("-ls", "--ls", help="List all saved configurations.", is_flag=True)
@option("-s", "--show", help="Show details of a specified configuration.", nargs=1)
@option("-rm", "--rm", help="Delete a specified configuration.", nargs=1)
@option("-url", "--from_url",
help="Create a configuration from a Cloudinary account environment variable. "
"The configuration name is the cloud name.",
nargs=1)
def config(
new: Optional[Tuple[str, str]],
ls: bool,
show: Optional[str],
rm: Optional[str],
from_url: Optional[str]
) -> Optional[Any]:
...
16 changes: 16 additions & 0 deletions cloudinary_cli/core/overrides.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# cloudinary_cli/stubs/overrides.pyi

from typing import Any, Tuple, Optional
from click import Context, Command

# Define a type for the `resolve_command` method
def resolve_command(self: Any, ctx: Context, args: list[str]) -> Tuple[str, Optional[Command], list[str]]:
...

# Define a type for the `upload` function
def upload(file: Any, **options: Any) -> Any:
...

# Define a type for the `cloudinary_url` function
def cloudinary_url(source: Any, **options: Any) -> Any:
...
26 changes: 26 additions & 0 deletions cloudinary_cli/core/provisioning.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import List, Tuple, Any, Optional
from click import command, argument, option

@command("provisioning",
short_help="Run any methods that can be called through the provisioning API.",
help="""\b
Run any methods that can be called through the provisioning API.
Format: cld <cli options> provisioning <command options> <method> <method parameters>
\te.g. cld provisioning sub_accounts
""")
@argument("params", nargs=-1)
@option("-o", "--optional_parameter", multiple=True, nargs=2, help="Pass optional parameters as raw strings.")
@option("-O", "--optional_parameter_parsed", multiple=True, nargs=2,
help="Pass optional parameters as interpreted strings.")
@option("-ls", "--ls", is_flag=True, help="List all available methods in the Provisioning API.")
@option("--save", nargs=1, help="Save output to a file.")
@option("-d", "--doc", is_flag=True, help="Open the Provisioning API reference in a browser.")
def provisioning(
params: Tuple[str, ...],
optional_parameter: List[Tuple[str, str]],
optional_parameter_parsed: List[Tuple[str, str]],
ls: bool,
save: Optional[str],
doc: bool
) -> Any:
...
57 changes: 57 additions & 0 deletions cloudinary_cli/core/search.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import List, Optional, Tuple, Any
from click import command, argument, option, launch

@command("search",
short_help="Run the admin API search method.",
help="""\b
Run the admin API search method.
Format: cld <cli options> search <command options> <Lucene query syntax string>
e.g. cld search cat AND tags:kitten -s public_id desc -f context -f tags -n 10
""")
@argument("query", nargs=-1)
@option("-f", "--with_field", multiple=True, help="Specify which non-default asset attributes to include "
"in the result as a comma separated list. ")
@option("-fi", "--fields", multiple=True, help="Specify which asset attributes to include in the result "
"(together with a subset of the default attributes) as a comma separated"
" list. This overrides any value specified for with_field.")
@option("-s", "--sort_by", nargs=2, help="Sort search results by (field, <asc|desc>).")
@option("-a", "--aggregate", nargs=1,
help="Specify the attribute for which an aggregation count should be calculated and returned.")
@option("-n", "--max_results", nargs=1, default=10,
help="The maximum number of results to return. Default: 10, maximum: 500.")
@option("-c", "--next_cursor", nargs=1, help="Continue a search using an existing cursor.")
@option("-A", "--auto_paginate", is_flag=True, help="Return all results. Will call Admin API multiple times.")
@option("-F", "--force", is_flag=True, help="Skip confirmation when running --auto-paginate.")
@option("-ff", "--filter_fields", multiple=True, help="Specify which attributes to show in the response. "
"None of the others will be shown.")
@option("-t", "--ttl", nargs=1, default=300, help="Set the Search URL TTL in seconds. Default: 300.")
@option("-u", "--url", is_flag=True, help="Build a signed search URL.")
@option("-sq", "--search-query", is_flag=True, help="Show the search request query.", hidden=True)
@option("--json", nargs=1, help="Save JSON output to a file. Usage: --json <filename>")
@option("--csv", nargs=1, help="Save CSV output to a file. Usage: --csv <filename>")
@option("-d", "--doc", is_flag=True, help="Open Search API documentation page.")
def search(
query: Tuple[str, ...],
with_field: List[str],
fields: List[str],
sort_by: Optional[Tuple[str, str]],
aggregate: Optional[str],
max_results: str,
next_cursor: Optional[str],
auto_paginate: bool,
force: bool,
filter_fields: List[str],
ttl: str,
url: bool,
search_query: bool,
json: Optional[str],
csv: Optional[str],
doc: bool
) -> None:
...

def execute_single_request(expression: Any, fields_to_keep: Tuple[str, ...]) -> Any:
...

def handle_auto_pagination(res: Any, expression: Any, force: bool, fields_to_keep: Tuple[str, ...]) -> Any:
...
13 changes: 13 additions & 0 deletions cloudinary_cli/core/uploader.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# cloudinary_cli/stubs/uploader.pyi

from typing import Tuple, List, Any
from click import Command

def uploader(
params: Tuple[str, ...],
optional_parameter: List[Tuple[str, str]],
optional_parameter_parsed: List[Tuple[str, str]],
ls: bool,
save: str | None,
doc: bool
) -> Any: ...
39 changes: 39 additions & 0 deletions cloudinary_cli/core/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import List, Tuple, Any
from click import command, argument, option, Choice, echo, launch

@command("utils", help="Call Cloudinary utility methods.")
@argument("params", nargs=-1)
@option("-o", "--optional_parameter", multiple=True, nargs=2, help="Pass optional parameters as raw strings.")
@option("-O", "--optional_parameter_parsed", multiple=True, nargs=2,
help="Pass optional parameters as interpreted strings.")
@option("-ls", "--ls", is_flag=True, help="List all available utility methods.")
def utils(
params: Tuple[str, ...],
optional_parameter: List[Tuple[str, str]],
optional_parameter_parsed: List[Tuple[str, str]],
ls: bool
) -> bool:
...

@command("url", help="Generate a Cloudinary URL, which you can optionally open in your browser.")
@argument("public_id", required=True)
@argument("transformation", default="")
@option("-rt", "--resource_type", default="image", type=Choice(['image', 'video', 'raw']), help="The asset type")
@option("-t", "--type", "delivery_type", default="upload",
type=Choice([
'upload', 'private', 'public', 'authenticated', 'fetch', 'list', 'url2png',
'sprite', 'text', 'multi', 'facebook', 'twitter', 'twitter_name', 'gravatar',
'youtube', 'hulu', 'vimeo', 'animoto', 'worldstarhiphop', 'dailymotion'
]),
help="The delivery type.")
@option("-o", "--open", 'open_in_browser', is_flag=True, help="Generate the derived asset and open it in your browser.")
@option("-s", "--sign", is_flag=True, help="Generate a signed URL.", default=False)
def url(
public_id: str,
transformation: str,
resource_type: str,
delivery_type: str,
open_in_browser: bool,
sign: bool
) -> None:
...
1 change: 1 addition & 0 deletions cloudinary_cli/defaults.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import logging
import os
from os.path import join as path_join, expanduser, abspath, dirname
Expand Down
13 changes: 13 additions & 0 deletions cloudinary_cli/modules/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import List, Callable

# Assuming each imported command function has the same signature
# You may need to adjust the Callable type based on actual function signatures
CommandFunction = Callable[..., None]

upload_dir: CommandFunction
make: CommandFunction
migrate: CommandFunction
sync: CommandFunction
regen_derived: CommandFunction

commands: List[CommandFunction]
22 changes: 22 additions & 0 deletions cloudinary_cli/modules/make.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Tuple, List
from click import argument, option
from cloudinary_cli.cli_group import cli

@cli.command("make", short_help="Return template code for implementing the specified Cloudinary widget.",
help="""\b
Return template code for implementing the specified Cloudinary widget.
e.g. cld make media library widget
cld make python find all empty folders
""")
@argument("template", nargs=-1)
@option("-ll", "--list-languages", is_flag=True, help="List available languages.")
@option("-lt", "--list-templates", is_flag=True, help="List available templates.")
def make(
template: Tuple[str, ...],
list_languages: bool,
list_templates: bool
) -> bool:
...

def _handle_language_and_template(language_and_template: Tuple[str, ...]) -> Tuple[str, List[str]]:
...
20 changes: 20 additions & 0 deletions cloudinary_cli/modules/migrate.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
from typing import List
from click import command, argument, option

@command("migrate",
short_help="Migrate files using an existing auto-upload mapping and a file of URLs.",
help="Migrate a list of external media files to Cloudinary. "
"The URLs of the files to migrate are listed in a separate file and must all have the same prefix.")
@argument("upload_mapping", type=str)
@argument("file", type=str)
@option("-d", "--delimiter", default="\n", help="The separator used between the URLs. Default: New line")
@option("-v", "--verbose", is_flag=True)
def migrate(
upload_mapping: str,
file: str,
delimiter: str,
verbose: bool
) -> bool:
...

69 changes: 69 additions & 0 deletions cloudinary_cli/modules/sync.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from typing import Dict, Any, List, Tuple, Optional

class SyncDir:
def __init__(self, local_dir: str, remote_dir: str, include_hidden: bool,
concurrent_workers: int, force: bool, keep_deleted: bool,
deletion_batch_size: int, folder_mode: Optional[str],
optional_parameter: Optional[List[Tuple[str, str]]],
optional_parameter_parsed: Optional[List[Tuple[str, str]]]) -> None:
self.local_dir: str
self.remote_dir: str
self.user_friendly_remote_dir: str
self.include_hidden: bool
self.concurrent_workers: int
self.force: bool
self.keep_unique: bool
self.deletion_batch_size: int
self.folder_mode: Optional[str]
self.optional_parameter: Optional[List[Tuple[str, str]]]
self.optional_parameter_parsed: Optional[List[Tuple[str, str]]]
self.sync_meta_file: str
self.verbose: bool
self.local_files: Dict[str, Dict[str, Any]]
self.local_folder_exists: bool
self.remote_files: Dict[str, Dict[str, Any]]
self.remote_duplicate_names: Dict[str, List[str]]
self.diverse_file_names: Dict[str, str]
self.recovered_remote_files: Dict[str, Dict[str, Any]]
self.unique_remote_file_names: set
self.unique_local_file_names: set
self.out_of_sync_local_file_names: set
self.out_of_sync_remote_file_names: set
self.synced_files_count: int

def push(self) -> bool:
...

def pull(self) -> bool:
...

def _normalize_remote_file_names(self, remote_files: Dict[str, Any],
local_files: Dict[str, Any]) -> Dict[str, Any]:
...

def _local_candidates(self, candidate_path: str) -> Dict[str, str]:
...

def _print_duplicate_file_names(self) -> None:
...

def _print_sync_status(self, success: Dict[str, Any], errors: Dict[str, Any]) -> None:
...

def _save_sync_meta_file(self, upload_results: Dict[str, Any]) -> None:
...

def _handle_unique_remote_files(self) -> bool:
...

def _get_out_of_sync_file_names(self, common_file_names: set) -> set:
...

def _handle_unique_local_files(self) -> bool:
...

def _handle_files_deletion(self, num_files: int, location: str) -> Optional[bool]:
...

def _handle_files_deletion_decision(self, num_files: int, location: str) -> Optional[bool]:
...
19 changes: 19 additions & 0 deletions cloudinary_cli/modules/upload_dir.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import List, Tuple, Dict, Union
from click import Context

def upload_dir(
directory: str,
glob_pattern: str = "**/*",
include_hidden: bool = False,
optional_parameter: List[Tuple[str, str]] = None,
optional_parameter_parsed: List[Tuple[str, str]] = None,
transformation: Union[str, None] = None,
folder: str = "",
folder_mode: Union[str, None] = None,
preset: Union[str, None] = None,
concurrent_workers: int = 30,
exclude_dir_name: bool = False,
doc: bool = False,
ctx: Context = None
) -> bool:
...
9 changes: 9 additions & 0 deletions cloudinary_cli/samples/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Optional
from click import Command

def sample(transformation: Optional[str] = "") -> None: ...
def couple(transformation: Optional[str] = "") -> None: ...
def dog(transformation: Optional[str] = "") -> None: ...
def _handle_sample_command(source: str, transformation: Optional[str] = None, open_in_browser: bool = False, resource_type: str = "image") -> None: ...

commands: list[Command]
Loading
Loading