Skip to content

Commit 6cbd91e

Browse files
authored
🐛 Include hidden files in app archive (#115)
1 parent e3150eb commit 6cbd91e

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ def _get_app_name(path: Path) -> str:
3434

3535

3636
def _should_exclude_entry(path: Path) -> bool:
37-
parts_to_exclude = [".venv", "__pycache__", ".mypy_cache", ".pytest_cache"]
37+
parts_to_exclude = [
38+
".venv",
39+
"__pycache__",
40+
".mypy_cache",
41+
".pytest_cache",
42+
".gitignore",
43+
".fastapicloudignore",
44+
]
3845

3946
if any(part in path.parts for part in parts_to_exclude):
4047
return True
@@ -51,6 +58,7 @@ def archive(path: Path, tar_path: Path) -> Path:
5158
path,
5259
should_exclude_entry=_should_exclude_entry,
5360
additional_ignore_paths=[".fastapicloudignore"],
61+
ignore_hidden=False,
5462
)
5563

5664
logger.debug("Archive will be created at: %s", tar_path)

tests/test_archive.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,16 @@ def test_archive_preserves_relative_paths(src_path: Path, tar_path: Path) -> Non
7272

7373
def test_archive_respects_fastapicloudignore(src_path: Path, tar_path: Path) -> None:
7474
"""Should exclude files specified in .fastapicloudignore."""
75-
# Create test files
7675
(src_path / "main.py").write_text("print('hello')")
7776
(src_path / "config.py").write_text("CONFIG = 'value'")
7877
(src_path / "secrets.env").write_text("SECRET_KEY=xyz")
7978
(src_path / "data").mkdir()
8079
(src_path / "data" / "file.txt").write_text("data")
8180

82-
# Create .fastapicloudignore file
8381
(src_path / ".fastapicloudignore").write_text("secrets.env\ndata/\n")
8482

85-
# Create archive
8683
archive(src_path, tar_path)
8784

88-
# Verify ignored files are excluded
8985
with tarfile.open(tar_path, "r") as tar:
9086
names = tar.getnames()
9187
assert set(names) == {
@@ -98,21 +94,39 @@ def test_archive_respects_fastapicloudignore_unignore(
9894
src_path: Path, tar_path: Path
9995
) -> None:
10096
"""Test we can use .fastapicloudignore to unignore files inside .gitignore"""
101-
# Create test files
10297
(src_path / "main.py").write_text("print('hello')")
98+
99+
(src_path / "ignore_me.txt").write_text("You should ignore me")
100+
103101
(src_path / "static/build").mkdir(exist_ok=True, parents=True)
104102
(src_path / "static/build/style.css").write_text("body { background: #bada55 }")
103+
105104
# Rignore needs a .git folder to make .gitignore work
106105
(src_path / ".git").mkdir(exist_ok=True, parents=True)
107-
(src_path / ".gitignore").write_text("build/")
106+
(src_path / ".gitignore").write_text("ignore_me.txt\nbuild/")
108107

109-
# Create .fastapicloudignore file
110108
(src_path / ".fastapicloudignore").write_text("!static/build")
111109

112-
# Create archive
113110
archive(src_path, tar_path)
114111

115-
# Verify ignored files are excluded
116112
with tarfile.open(tar_path, "r") as tar:
117113
names = tar.getnames()
118114
assert set(names) == {"main.py", "static/build/style.css"}
115+
116+
117+
def test_archive_includes_hidden_files(src_path: Path, tar_path: Path) -> None:
118+
"""Should include hidden files in the archive by default."""
119+
(src_path / "main.py").write_text("print('hello')")
120+
(src_path / ".env").write_text("SECRET_KEY=xyz")
121+
(src_path / ".config").mkdir()
122+
(src_path / ".config" / "settings.json").write_text('{"setting": "value"}')
123+
124+
archive(src_path, tar_path)
125+
126+
with tarfile.open(tar_path, "r") as tar:
127+
names = tar.getnames()
128+
assert set(names) == {
129+
"main.py",
130+
".env",
131+
".config/settings.json",
132+
}

0 commit comments

Comments
 (0)