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

[change] Move python dependencies to requirements.txt file #60

Merged

Conversation

shwetd19
Copy link
Contributor

Checklist


Reference to Existing Issue

Closes #52.


Description of Changes

This pull request moves Python dependencies from pip.yml to a requirements.txt file for easier management. Here’s what was done:

  1. Created a requirements.txt file:

    • Added all dependencies, such as Flask, Werkzeug, and uwsgi, into this file to keep things organized.
  2. Updated pip.yml:

    • Adjusted the Ansible tasks to install dependencies from requirements.txt instead of listing them directly in the file.
    • Added steps to:
      • Update pip and related tools like setuptools and wheel.
      • Install dependencies in a virtual environment using the requirements.txt file.
  3. Dependabot Integration:

    • Made sure tools like Dependabot can track and update dependencies in requirements.txt automatically.
  4. Tested the Changes:

    • Ran the updated playbook to confirm everything works as expected.

These changes make it easier to manage and update dependencies while keeping the setup clean and consistent.

Added all dependencies, such as Flask, Werkzeug, and uwsgi, into this file to keep things organized.
Adjusted the Ansible tasks to install dependencies from requirements.txt instead of listing them directly in the file & updated pip and related tools like setuptools and wheel.
tasks/pip.yml Outdated
Comment on lines 23 to 19
- name: Install Flask, Werkzeug and uWSGI
- name: Read local requirements.txt
local_action: command cat requirements.txt
register: requirements
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this is correct? Did you try running the tests locally?
https://github.com/openwisp/ansible-wireguard-openwisp?tab=readme-ov-file#how-to-run-tests

Using `{{ role_path }}` instead of absolute paths, this variable points to the root directory of our Ansible role, where requirements.txt is located.
@shwetd19
Copy link
Contributor Author

@pandafy , I've fixed the path for requirements.txt file, now it's working.. can you please check nd lmk, Thanks!

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

See my comment below, please also take a look at the message returned by the QA checks failure regarding the lack of capital letter after the square bracket, eg:

[prefix] done something should be [prefix] Done something.

tasks/pip.yml Outdated
- wheel
- attrs
- importlib-metadata
- packaging
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't move these because we're always upgrade to the latest version available.

The aim is to move only the python packages that we are pinning to as pecific version range, so that dependabot can help us update those more with less intervention from our end.

( `setuptools`, `wheel`, `attrs`, `importlib-metadata`, `packaging`) are removed from req file
  - I've ensured `setuptools`, `wheel`, `attrs`, `importlib-metadata`, and `packaging` are installed directly via pip task
  - Replaced reading `requirements.txt` via `local_action` with explicit file copy to virtualenv
  - Changed package installation to use the copied `requirements.txt` file
  - Added condition to install packages only if `requirements.txt` changes
@shwetd19
Copy link
Contributor Author

shwetd19 commented Jan 24, 2025

Hey @pandafy @nemesifier I've modified the changes can you please review this once. Thanks!

  • Removed unnecessary dependencies (setuptools, wheel, attrs, importlib-metadata, packaging) from requirements.txt

  • Updated pip.yml:

    • Ensured setuptools, wheel, attrs, importlib-metadata, and packaging are installed directly via pip task
    • Replaced reading requirements.txt via local_action with explicit file copy to virtualenv
    • Changed package installation to use the copied requirements.txt file
    • Added condition to install packages only if requirements.txt changes
  • I've also tested it locally this time, it worked!

Blue and Yellow Playful Doodle Digital Brainstorm Presentation (1)

@nemesifier nemesifier changed the title 52 python dependencies to requirements [change] Move python dependencies to requirements.txt file Jan 24, 2025
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Great progress @shwetd19!

See my comments below.
Again I want to bring to your attention to please also take a look at the message returned by the QA checks failure regarding the lack of capital letter after the square bracket, eg:

[prefix] done something should be [prefix] Done something.

@shwetd19
Copy link
Contributor Author

@nemesifier I've made the suggested changes, please let me know if any changes are required, also pls forgive me if I'm making silly mistakes here, it's just I'm testing everything I can locally..

@shwetd19
Copy link
Contributor Author

Hey @pandafy @nemesifier can you please test this with QA checks.. nd let me know if any changes are required also can you pls tell me where I can contribute more ?

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Small adjustments for consistency

@shwetd19
Copy link
Contributor Author

@nemesifier Thanks you very much for this! I'll try to learn as much as I can for never miss an oversight like this

@shwetd19 shwetd19 requested a review from nemesifier January 27, 2025 14:21
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

LGTM!

@shwetd19 shwetd19 requested a review from pandafy January 27, 2025 14:59
Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

I took a closer look and found the following area for improvements.

requirements.txt Outdated
Copy link
Member

Choose a reason for hiding this comment

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

This file should be inside the files/ directory.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved requirements.txt from the root directory to files/requirements.txt

tasks/pip.yml Outdated
@@ -36,3 +38,4 @@
delay: 10
register: result
until: result is success
when: requirements_copy is changed
Copy link
Member

Choose a reason for hiding this comment

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

This should be run always.

Suggested change
when: requirements_copy is changed

@shwetd19
Copy link
Contributor Author

Hey @nemesifier @pandafy I've made the suggested changes

  1. Moved requirements.txt from the root directory to files/requirements.txt
  2. Updated the copy task to use the correct source path (requirements.txt will automatically look in the files/ directory)
  3. Changed the destination path to {{ openwisp2_wireguard_path }}/requirements.txt instead of putting it in the virtualenv
  4. Removed the when: requirements_copy is changed condition so pip install runs always
  5. Updated the pip install task to use the requirements file from the new location

I've tested the code locally too at my end, pls let me know if any change is required, Thanks!

image

@shwetd19 shwetd19 requested a review from pandafy January 27, 2025 17:14
@shwetd19 shwetd19 requested a review from nemesifier January 28, 2025 10:07
@shwetd19
Copy link
Contributor Author

Hey @nemesifier @pandafy both suggested fixes are done! pls can you check once

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for contributing @shwetd19 🚀

@nemesifier nemesifier merged commit 182ebde into openwisp:main Jan 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

[change] Move Python dependencies to requirements.txt
3 participants