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

fix: Implement Automatic Activation of Virtual Environment in the dev nox session #3408

Conversation

akhilender-bongirwar
Copy link
Contributor

Description

  • Implement automatic activation of the virtual environment in the 'dev' Nox session
  • Enhance the 'dev' Nox session defined in noxfile.py
  • Simplify the development setup process for contributors and developers

This commit enhances the 'dev' Nox session to automatically activate the virtual environment when running 'nox -s dev'.

Fixes #3388

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

…v' Nox Session

- Implement automatic activation of the virtual environment in the 'dev' Nox session
- Enhance the 'dev' Nox session defined in `noxfile.py`
- Simplify the development setup process for contributors and developers

This commit enhances the 'dev' Nox session to automatically activate the virtual environment when running 'nox -s dev'.

Signed-off-by: Akhilender <[email protected]>
@agriyakhetarpal agriyakhetarpal self-requested a review October 4, 2023 22:04
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Thanks, @akhilender-bongirwar, looks off to a good start! I tested this locally and it doesn't look like there is a method to activate the virtual environment from inside a nox session (we should ask users to do so like they currently do). We can target some other relevant improvements, some comments below

noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
- Imported `Path` directly from `pathlib` for better readability.
- Moved the definition of `venv_dir` closer to `PYBAMM_ENV` and marked it as a constant.
- Installed development dependencies using `-e .[dev]` to set up the developer environment and silenced the warning with `external=True`.
- Added the installation of `[jax,odes]` extras for macOS and Linux platforms.

Signed-off-by: Akhilender <[email protected]>
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

I think this is almost ready. Could you update the documentation for the source installation in this file, highlighting the change and updating the new location of the virtual environment directory (plus how to activate it)? I left some more comments below

noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
- Installed `virtualenv` and `cmake` before other dependencies.
- Installed all and dev dependencies together using a single `pip` command to avoid redundant wheel building.
- Corrected sys.platform to maintain consistency in the code

Signed-off-by: Akhilender <[email protected]>
noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

You also need to update the documentation for the source installation page as highlighted above

@agriyakhetarpal
Copy link
Member

You need to update this section. We need to 1. update the location of the virtual environment—should now be venv/ instead of .nox/dev/ wherever it is referenced, and 2. update the command used to activate the virtual environment—this should be source venv/bin/activate instead of .nox/dev/bin/activate, and so on

@akhilender-bongirwar
Copy link
Contributor Author

Thank you @agriyakhetarpal : ).

@akhilender-bongirwar
Copy link
Contributor Author

@agriyakhetarpal, please review the changes : ).

@agriyakhetarpal
Copy link
Member

agriyakhetarpal commented Oct 7, 2023

The Files interface currently shows that that the entirety of the lines in the two files were modified. Did you change the Git settings about your line endings on your platform recently, or otherwise push the last commit from another platform that might have a different line ending scheme compared to the commits before that? We would have to normalise it to properly display the modified lines. Could you drop your most recent commit and force push? This answer might help: https://stackoverflow.com/a/30757723

@akhilender-bongirwar akhilender-bongirwar force-pushed the enhancement/activate-venv-dev-nox branch from a5392dc to 713da15 Compare October 8, 2023 08:25
@akhilender-bongirwar
Copy link
Contributor Author

@agriyakhetarpal , I actually pushed the commit from WSL instead of using Bash. I reverted the last the last commit.

- Corrected the space between virtualenv and cmake
- Changed macos to darwin
- Updated the docs regarding the virtual environment
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for working on this, @akhilender-bongirwar! Tested this locally and it works without issues. I will request a review from @Saransh-cpp in case there are any additional changes to be made and also to get a workflow run triggered here

noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
- Added external = True instead of silent = False as it is not required for session.run()
@akhilender-bongirwar
Copy link
Contributor Author

Looks good to me, thanks for working on this, @akhilender-bongirwar! Tested this locally and it works without issues. I will request a review from @Saransh-cpp in case there are any additional changes to be made and also to get a workflow run triggered here

Thank you, @agriyakhetarpal, for allowing me to work under your guidance for this issue. Although I made a few mistakes in the beginning, it has been great working together.

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, @akhilender-bongirwar! I think we'll still need to set the env variables before installing scikits.odes (the dev session fails for me locally) - @arjxn-py @agriyakhetarpal.

Also, we should use an if-else block to save time by installing pybamm only once -

noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
@agriyakhetarpal
Copy link
Member

Okay, that's strange because it works well on my end (I checked and purged the cached wheels so that it builds a wheel for scikits.odes again). The dev session is meant to be run after pybamm-requires so that the SUNDIALS installation can be found (the set_environment_variables function is taking care of the SUNDIALS_INST environment variable)

@agriyakhetarpal
Copy link
Member

Note: the earlier export command was incorrect anyway because it didn't change anything in the activation script, so if we want to keep that we should modify it to use a command similar to what pybamm_install_odes does

It might also be a discrepancy in the Python version. This newer dev session will create a virtualenv with the version of Python with which it was installed

@Saransh-cpp
Copy link
Member

Weird. I'll suggest that we install scikits.odes only on Linux in this PR, given that we install scikits.odes only on Linux in the other nox sessions (except for the coverage session, don't really know why). #3417 can then modify the noxfile appropriately to support MacOS.

@codecov
Copy link

codecov bot commented Oct 8, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (d02a78b) 99.58% compared to head (7629414) 99.58%.
Report is 53 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3408   +/-   ##
========================================
  Coverage    99.58%   99.58%           
========================================
  Files          256      256           
  Lines        19998    19998           
========================================
  Hits         19915    19915           
  Misses          83       83           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@agriyakhetarpal
Copy link
Member

Weird. I'll suggest that we install scikits.odes only on Linux in this PR

No worries, happy to help debug your installation offline 😄

except for the coverage session, don't really know why

This is because we don't compile the IDAKLU component for macOS in CI, because we are running pybamm-requires only on Linux. I have fixed that in #3301, but as discussed in the developer meeting we'll be merging that one after 23.9 non-RC is out, and that could take some time (the wheels have to be fixed too). @arjxn-py, please feel free to copy the relevant changes from there if you want to or create a new PR because that one is slightly big (but contains some needed changes).

@akhilender-bongirwar
Copy link
Contributor Author

@agriyakhetarpal, should I still make any new changes or is the code working fine ?

@agriyakhetarpal
Copy link
Member

For now, you may install [odes] only on Linux and also resolve Saransh's comments. Happy to approve then

akhilender-bongirwar and others added 3 commits October 11, 2023 15:54
- Removed redundant code

Co-authored-by: Saransh Chopra <[email protected]>
- Added all the installation in a single line

Co-authored-by: Saransh Chopra <[email protected]>
- Added else block for efficient running of the code

Co-authored-by: Saransh Chopra <[email protected]>
noxfile.py Outdated Show resolved Hide resolved
- Altered and removed the darwin platform
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Everything looks good to me now. Thanks for working on this, @akhilender-bongirwar!

noxfile.py Outdated Show resolved Hide resolved
akhilender-bongirwar and others added 2 commits October 13, 2023 12:00
- Made a single line of 89 characters into few smaller lines
@Saransh-cpp Saransh-cpp merged commit ff8c998 into pybamm-team:develop Oct 18, 2023
25 of 33 checks passed
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.

Make it possible to activate the venv in the dev nox session
4 participants