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

Skip empty pages directory when deploying streamlit #1499

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

sfc-gh-astus
Copy link
Contributor

@sfc-gh-astus sfc-gh-astus commented Aug 27, 2024

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

Added check in Streamlit to skip put on stage when directory is empty.

@sfc-gh-astus sfc-gh-astus force-pushed the skip-empty-pages-directory branch 2 times, most recently from 1befdef to 56ad4fc Compare August 27, 2024 13:39
Comment on lines 61 to 62
if not bool(os.listdir(file)):
cli_console.warning(f"Skipping empty directory: {file}")
continue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I should add it in StageManager.put? WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO it belongs here- it's streamlit logic, not stage put logic- it's the Streamlit manager that should decide what files and dirs to put, and Stage manager should know how to handle them to put'em on stage.

@sfc-gh-astus sfc-gh-astus marked this pull request as ready for review August 28, 2024 08:03
@sfc-gh-astus sfc-gh-astus requested review from a team as code owners August 28, 2024 08:03
@@ -57,6 +58,10 @@ def _put_streamlit_files(
stage_manager = StageManager()
for file in artifacts:
if file.is_dir():
if not bool(os.listdir(file)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not bool(os.listdir(file)):
if not any(file.iterdir()):

To avoid additional os import

mock_get_account.return_value = "my_account"

with project_directory("streamlit_empty_pages") as directory:
os.makedirs(directory / "pages", exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
os.makedirs(directory / "pages", exist_ok=True)
(directory / "pages").mkdir(parents=True, exist_ok=True)

Comment on lines 61 to 62
if not bool(os.listdir(file)):
cli_console.warning(f"Skipping empty directory: {file}")
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO it belongs here- it's streamlit logic, not stage put logic- it's the Streamlit manager that should decide what files and dirs to put, and Stage manager should know how to handle them to put'em on stage.

@@ -57,6 +58,10 @@ def _put_streamlit_files(
stage_manager = StageManager()
for file in artifacts:
if file.is_dir():
if not bool(os.listdir(file)):
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need bool() here. Empty list evaluates as false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to any(file.iterdir()).

@sfc-gh-astus sfc-gh-astus force-pushed the skip-empty-pages-directory branch from 56ad4fc to 46ff5f5 Compare August 28, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants