Skip to content

Commit 7a39272

Browse files
committed
Show list of files larger than threshold
1 parent 8477df2 commit 7a39272

1 file changed

Lines changed: 46 additions & 4 deletions

File tree

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,19 @@ def _should_exclude_entry(path: Path) -> bool:
108108
return False
109109

110110

111-
def archive(path: Path, tar_path: Path) -> Path:
112-
logger.debug("Starting archive creation for path: %s", path)
113-
files = rignore.walk(
111+
def _rignore_walk(path: Path) -> rignore.Walker:
112+
return rignore.walk(
114113
path,
115114
should_exclude_entry=_should_exclude_entry,
116115
additional_ignore_paths=[".fastapicloudignore"],
117116
ignore_hidden=False,
118117
)
119118

119+
120+
def archive(path: Path, tar_path: Path) -> Path:
121+
logger.debug("Starting archive creation for path: %s", path)
122+
files = _rignore_walk(path)
123+
120124
logger.debug("Archive will be created at: %s", tar_path)
121125

122126
file_count = 0
@@ -134,6 +138,19 @@ def archive(path: Path, tar_path: Path) -> Path:
134138
return tar_path
135139

136140

141+
def _get_large_files(path: Path, threshold: int) -> list[tuple[Path, int]]:
142+
large_files = []
143+
files = _rignore_walk(path)
144+
for filename in files:
145+
if filename.is_dir():
146+
continue
147+
file_size = filename.stat().st_size
148+
if file_size >= threshold:
149+
large_files.append((filename.relative_to(path), file_size))
150+
151+
return large_files
152+
153+
137154
class Team(BaseModel):
138155
id: str
139156
slug: str
@@ -804,10 +821,35 @@ def deploy(
804821
)
805822
raise typer.Exit(1)
806823

824+
large_file_threshold = 10 * 1024 * 1024 # 10 MB
825+
app_path = path or Path.cwd()
826+
827+
large_files = _get_large_files(app_path, threshold=large_file_threshold)
828+
if large_files:
829+
threshold_mb = large_file_threshold // (1024 * 1024)
830+
toolkit.print(
831+
f"⚠️ Some uploaded files are larger than {threshold_mb} MB ⚖️ :",
832+
tag="warning",
833+
)
834+
top_3 = sorted(large_files, key=lambda x: x[1], reverse=True)[:3]
835+
for fname, fsize in top_3:
836+
fsize_mb = fsize // (1024 * 1024)
837+
toolkit.print(f" • {fname} [yellow]({fsize_mb} MB)[/yellow]")
838+
is_more = len(large_files) > 3
839+
if is_more:
840+
toolkit.print(f" [dim]...and {len(large_files) - 3} more[/dim]")
841+
842+
large_files_docs_url = "https://fastapicloud.com/docs/deployment#control-what-is-uploaded"
843+
toolkit.print(
844+
f"Read more: [link={large_files_docs_url}]{large_files_docs_url}[/link]",
845+
tag="tip",
846+
)
847+
toolkit.print_line()
848+
807849
with tempfile.TemporaryDirectory() as temp_dir:
808850
logger.debug("Creating archive for deployment")
809851
archive_path = Path(temp_dir) / "archive.tar"
810-
archive(path or Path.cwd(), archive_path)
852+
archive(app_path, archive_path)
811853

812854
with (
813855
toolkit.progress(

0 commit comments

Comments
 (0)