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

[reflex export] backend.zip excludes dirs that look like venv dirs #2009

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all 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
24 changes: 22 additions & 2 deletions reflex/utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def _zip(
component_name: constants.ComponentName,
target: str,
root_dir: str,
exclude_venv_dirs: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add default values for these args?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Default values are usually for convenience:

  • We cannot (or don't want to) update existing call sites.
  • We think it's too burdensome to ask new call sites to be explicit.
    But the drawback is we lose (IMO) a lot of readability.

In this case the trade-off seems quite skewed toward not doing defaults. It's a private function that has two existing call sites.

exclude_sqlite_db_files: bool,
dirs_to_exclude: set[str] | None = None,
files_to_exclude: set[str] | None = None,
) -> None:
Expand All @@ -68,6 +70,8 @@ def _zip(
component_name: The name of the component: backend or frontend.
target: The target zip file.
root_dir: The root directory to zip.
exclude_venv_dirs: Whether to exclude venv directories.
exclude_sqlite_db_files: Whether to exclude sqlite db files.
dirs_to_exclude: The directories to exclude.
files_to_exclude: The files to exclude.

Expand All @@ -85,9 +89,17 @@ def _zip(
if (basename := os.path.basename(os.path.normpath(d)))
not in dirs_to_exclude
and not basename.startswith(".")
and (
not exclude_venv_dirs or not _looks_like_venv_dir(os.path.join(root, d))
)
]
# Modify the files in-place so the hidden files and db files are excluded.
files[:] = [
f
for f in files
if not f.startswith(".")
and (not exclude_sqlite_db_files or not f.endswith(".db"))
]
# Modify the files in-place so the hidden files are excluded.
files[:] = [f for f in files if not f.startswith(".")]
files_to_zip += [
os.path.join(root, file) for file in files if file not in files_to_exclude
]
Expand Down Expand Up @@ -170,6 +182,8 @@ def export(
),
root_dir=".web/_static",
files_to_exclude=files_to_exclude,
exclude_venv_dirs=False,
exclude_sqlite_db_files=False,
)
if backend:
_zip(
Expand All @@ -180,6 +194,8 @@ def export(
root_dir=".",
dirs_to_exclude={"assets", "__pycache__"},
files_to_exclude=files_to_exclude,
exclude_venv_dirs=True,
exclude_sqlite_db_files=True,
)


Expand Down Expand Up @@ -230,3 +246,7 @@ def setup_frontend_prod(
"""
setup_frontend(root, disable_telemetry)
export(deploy_url=get_config().deploy_url)


def _looks_like_venv_dir(dir_to_check: str) -> bool:
return os.path.exists(os.path.join(dir_to_check, "pyvenv.cfg"))
Loading