Skip to content

[feature] Run collectstatic only when python dependencies change #246#473

Merged
nemesifier merged 9 commits into
openwisp:masterfrom
stktyagi:master
Jun 18, 2025
Merged

[feature] Run collectstatic only when python dependencies change #246#473
nemesifier merged 9 commits into
openwisp:masterfrom
stktyagi:master

Conversation

@stktyagi

@stktyagi stktyagi commented Jun 7, 2025

Copy link
Copy Markdown
Member

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #246

Description of Changes

Added a collectsatic_control.py file that computes a hash of the current installed Python packages (pip freeze output) and connects to Redis to retrieve a previously stored hash. If the hash is missing or changed, it runs Django’s collectstatic command to gather static files and updates the stored hash in Redis and if the hash is unchanged, it skips running collectstatic.

Implementation of smart collectstatic logic to compare freeze hash before calling collectstatic, saving time and avoiding redundant calls.

Fixes openwisp#246

@pandafy pandafy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good start @stktyagi, let's refine the implementation a bit more before merging.

Comment thread images/common/collectstatic_control.py Outdated
Comment thread images/common/collectstatic_control.py Outdated
Comment thread images/common/init_command.sh Outdated
@pandafy pandafy moved this from To do (general) to In progress in OpenWISP Contributor's Board Jun 7, 2025
Added error handling in the collectstatic logic and usage of relative path instead of absolute in init_command.sh.

Fixes openwisp#246
@stktyagi
stktyagi requested a review from pandafy June 7, 2025 14:30

@nemesifier nemesifier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@stktyagi great progress here!

Can you please add an env var called COLLECTSTATIC_WHEN_DEPS_CHANGE, defaulting to True, which allows us to disable this feature?
This can be useful during development or on systems where we are using the
development version and the version identifier of the openwisp modules does not change but we still need to call collectstatic anyway.

We'll need to add this var to the docs as well.

Comment thread images/common/init_command.sh Outdated
Comment thread images/common/collectstatic_control.py Outdated
stktyagi added 3 commits June 14, 2025 18:50
…penwisp#246

Added COLLECTSTATIC_WHEN_DEPS_CHANGE env var to control collectstatic. Updated script and docs to support disabling it.

Fixes openwisp#246
…penwisp#246

Added COLLECTSTATIC_WHEN_DEPS_CHANGE env var to control collectstatic. Updated script and docs to support disabling it.

Fixes openwisp#246
…penwisp#246

Added COLLECTSTATIC_WHEN_DEPS_CHANGE env var to control collectstatic. Updated script and docs to support disabling it.

Fixes openwisp#246
@stktyagi

Copy link
Copy Markdown
Member Author

There was some conflict between formatter and the qa tester while adding the docstring in collecstatic, hence the redundant commits. Will make sure in the future.

@stktyagi
stktyagi requested a review from nemesifier June 14, 2025 13:37
Comment thread images/common/collectstatic.py Outdated

def main():
if os.environ.get("COLLECTSTATIC_WHEN_DEPS_CHANGE", "true").lower() == "false":
print("COLLECTSTATIC_WHEN_DEPS_CHANGE is false; skipping collectstatic.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not what I meant.
If the env var is False we shall always execute collectstatic. Not executing it is not an option.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, sorry for the misunderstanding. In fact I was wondering the previous change.

For updation :-
if unset -> default to true -> run if "pip freeze" changed
if false -> always execute collectstatic

@nemesifier nemesifier added the enhancement New feature or request label Jun 16, 2025
Post commit, if the env var is true we run collectstatic if pip freeze changes else we run collectstatic each time.

Fix openwisp#473
@stktyagi
stktyagi requested a review from nemesifier June 18, 2025 05:50

@nemesifier nemesifier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I did some minor improvements, feel free to review. LGTM ✔️

@stktyagi

Copy link
Copy Markdown
Member Author

I did some minor improvements, feel free to review. LGTM ✔️

looks like I forgot to update the docs, my bad. Thank you for doing that.

@nemesifier nemesifier changed the title [feature] Feature implementation for collectstatic #246 [feature] Execute collect static only when python dependencies change #246 Jun 18, 2025
@nemesifier nemesifier changed the title [feature] Execute collect static only when python dependencies change #246 [feature] Run collectstatic only when python dependencies change #246 Jun 18, 2025
@nemesifier
nemesifier merged commit 7603dc2 into openwisp:master Jun 18, 2025
1 check passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in OpenWISP Contributor's Board Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[feature] Execute collect static only when versions change

3 participants