Skip to content

feat: add support for Python virtual environment in testsuite setup #956

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

Merged
merged 6 commits into from
Jul 24, 2025

Conversation

Khitoshi
Copy link
Contributor

@Khitoshi Khitoshi commented Jul 22, 2025

close #917

Description

This PR resolves the issue with Python package management in the dev.sh script by adding support for Python virtual environments when running the integration testsuite.

Changes Made

Added Virtual Environment Support

  • Added --use-venv command line flag to enable Python virtual environment usage
  • Implemented setup_venv() function to create and activate virtual environments
  • Implemented cleanup_venv() function to properly deactivate virtual environments
  • Virtual environment is created at testsuite/venv when enabled

Enhanced Testsuite Execution

  • When --use-venv flag is used:
    • Creates a Python virtual environment in testsuite/venv
    • Installs Python packages within the isolated environment
    • Automatically cleans up the environment after execution
  • When flag is not used:
    • Maintains backward compatibility with global installation
    • Shows warning message recommending virtual environment usage

Updated Documentation

  • Added --use-venv option to help message
  • Updated usage instructions to include the new flag

Usage Examples

# Run test suites using virtual environments (recommended and default)
./dev.sh --testsuite

# Use global environment (conventional operation)
./dev.sh --testsuite --use-global-env

# Use detailed output and virtual environment
./dev.sh --testsuite --verbose

Summary by CodeRabbit

  • New Features
    • Added optional support for running Python integration tests in a dedicated virtual environment, enabled via a command-line option.
  • Chores
    • Updated .gitignore to exclude common Python virtual environment directories from version control.
  • Documentation
    • Added a clarifying comment regarding compatibility with older versions of a dependency in the integration tests.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

The changes add optional support in dev.sh to run the Python integration testsuite using either a virtual environment or the global Python environment, controlled by a new --use-global-env flag. Functions for virtual environment setup and cleanup are introduced. .gitignore is updated to exclude common virtual environment directories. A version check for libtmux is added in the testsuite code.

Changes

File(s) Change Summary
dev.sh Adds --use-global-env option; adds setup_venv() and cleanup_venv() functions; manages venv creation, activation, pip upgrade, and cleanup; installs requirements either globally or in venv.
.gitignore Adds ignore rules for venv/, .venv/, testsuite/venv/, and testsuite/.venv/.
testsuite/core/tmux_manager.py Adds runtime libtmux version check in constructor; adds comment about active_pane attribute absence in older versions.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant dev.sh
    participant Python
    participant venv

    Developer->>dev.sh: Run with or without --use-global-env
    alt Use global environment
        dev.sh->>Python: pip install -r requirements.txt (global)
        dev.sh->>Python: Run integration testsuite (global)
    else Use virtual environment
        dev.sh->>venv: setup_venv(./venv)
        venv-->>dev.sh: venv created & activated
        dev.sh->>Python: pip install -r requirements.txt (inside venv)
        dev.sh->>Python: Run integration testsuite (inside venv)
        dev.sh->>venv: cleanup_venv() on exit/interruption
    end
Loading

Estimated code review effort

2 (~20 minutes)

Poem

🐇 Hop, hop, hooray! A choice today,
Global or venv, you get to play!
Pip installs tidy, no mess in sight,
Virtual or global, your code runs right.
Ignore those venvs, keep Git pristine,
A rabbit’s cheer for the dev routine! 🎉🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7e2a55 and 4175ccc.

📒 Files selected for processing (2)
  • dev.sh (5 hunks)
  • testsuite/core/tmux_manager.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • testsuite/core/tmux_manager.py
  • dev.sh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build and Test (windows-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
dev.sh (1)

119-122: Offer a short flag for ergonomics

Consider adding -e as a shorthand for --use-venv, mirroring the existing pattern (-t/-s/-v). Small DX win, zero cost.

-        --use-venv)
+        -e|--use-venv)
             USE_VENV=true
             shift
             ;;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29dc4d0 and 17d18af.

📒 Files selected for processing (1)
  • dev.sh (7 hunks)

@Khitoshi
Copy link
Contributor Author

Khitoshi commented Jul 22, 2025

Cases of failure (e.g., libtmux version is out of date)

~/superfile$ ./dev.sh --testsuite --use-global-env
🚀 Starting superfile development workflow

==> Tidying Go modules...
✓ Go modules tidied
==> Formatting Go code...
✓ Code formatted
==> Running golangci-lint...
✓ Linting passed
==> Running unit tests...
?       github.com/yorukot/superfile    [no test files]
?       github.com/yorukot/superfile/src/cmd    [no test files]
?       github.com/yorukot/superfile/src/config [no test files]
?       github.com/yorukot/superfile/src/config/icon    [no test files]
ok      github.com/yorukot/superfile/src/internal       (cached)
ok      github.com/yorukot/superfile/src/internal/common        (cached)
?       github.com/yorukot/superfile/src/internal/ui    [no test files]
ok      github.com/yorukot/superfile/src/internal/ui/prompt     (cached)
ok      github.com/yorukot/superfile/src/internal/ui/rendering  (cached)
ok      github.com/yorukot/superfile/src/internal/ui/sidebar    (cached)
ok      github.com/yorukot/superfile/src/internal/utils (cached)
?       github.com/yorukot/superfile/src/pkg/file_preview       [no test files]
?       github.com/yorukot/superfile/src/pkg/string_function    [no test files]
✓ Unit tests passed
==> Running integration testsuite...
==> Installing testsuite requirements globally...
⚠ Using global Python environment - consider removing --use-global-env flag to use virtual environment
⚠ Failed to install testsuite requirements - continuing anyway
Traceback (most recent call last):
  File "/home/khitoshi/superfile/testsuite/main.py", line 64, in <module>
    main()
  File "/home/khitoshi/superfile/testsuite/main.py", line 58, in main
    success = run_tests(spf_path, only_run_tests=args.tests)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/khitoshi/superfile/testsuite/core/runner.py", line 57, in run_tests
    spf_manager = TmuxSPFManager(str(spf_path))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/khitoshi/superfile/testsuite/core/tmux_manager.py", line 33, in __init__
    raise RuntimeError(
RuntimeError: libtmux version 0.31.0 or higher is required. Current version: 0.30.2. Please upgrade with: pip install 'libtmux>=0.31.0'
✗ Integration testsuite failed

Successful Cases

~/superfile$ ./dev.sh --testsuite --use-global-env
🚀 Starting superfile development workflow

==> Tidying Go modules...
✓ Go modules tidied
==> Formatting Go code...
✓ Code formatted
==> Running golangci-lint...
✓ Linting passed
==> Running unit tests...
?       github.com/yorukot/superfile    [no test files]
?       github.com/yorukot/superfile/src/cmd    [no test files]
?       github.com/yorukot/superfile/src/config [no test files]
?       github.com/yorukot/superfile/src/config/icon    [no test files]
ok      github.com/yorukot/superfile/src/internal       (cached)
ok      github.com/yorukot/superfile/src/internal/common        (cached)
?       github.com/yorukot/superfile/src/internal/ui    [no test files]
ok      github.com/yorukot/superfile/src/internal/ui/prompt     (cached)
ok      github.com/yorukot/superfile/src/internal/ui/rendering  (cached)
ok      github.com/yorukot/superfile/src/internal/ui/sidebar    (cached)
ok      github.com/yorukot/superfile/src/internal/utils (cached)
?       github.com/yorukot/superfile/src/pkg/file_preview       [no test files]
?       github.com/yorukot/superfile/src/pkg/string_function    [no test files]
✓ Unit tests passed
==> Running integration testsuite...
==> Installing testsuite requirements globally...
⚠ Using global Python environment - consider removing --use-global-env flag to use virtual environment
⚠ Failed to install testsuite requirements - continuing anyway
[2025-07-23 12:38:44 -    INFO] Testcases : [ChooserFileTest, CopyWTest, DeleteDirTest, EmptyPanelTest, CompressExtractTest, CommandTest, CopyDirTest, RenameTest, CutTest, CopyTest, DeleteTest]
[2025-07-23 12:38:44 -    INFO] Running test ChooserFileTest
[2025-07-23 12:38:48 -    INFO] Passed test ChooserFileTest
[2025-07-23 12:38:48 -    INFO] Running test CopyWTest
[2025-07-23 12:38:50 -    INFO] Passed test CopyWTest
[2025-07-23 12:38:50 -    INFO] Running test DeleteDirTest
[2025-07-23 12:38:51 -    INFO] Passed test DeleteDirTest
[2025-07-23 12:38:51 -    INFO] Running test EmptyPanelTest
[2025-07-23 12:38:53 -    INFO] Passed test EmptyPanelTest
[2025-07-23 12:38:53 -    INFO] Running test CompressExtractTest
[2025-07-23 12:38:55 -    INFO] Passed test CompressExtractTest
[2025-07-23 12:38:55 -    INFO] Running test CommandTest
[2025-07-23 12:38:57 -    INFO] Passed test CommandTest
[2025-07-23 12:38:57 -    INFO] Running test CopyDirTest
[2025-07-23 12:38:58 -    INFO] Passed test CopyDirTest
[2025-07-23 12:38:58 -    INFO] Running test RenameTest
[2025-07-23 12:39:00 -    INFO] Passed test RenameTest
[2025-07-23 12:39:00 -    INFO] Running test CutTest
[2025-07-23 12:39:02 -    INFO] Passed test CutTest
[2025-07-23 12:39:02 -    INFO] Running test CopyTest
[2025-07-23 12:39:04 -    INFO] Passed test CopyTest
[2025-07-23 12:39:04 -    INFO] Running test DeleteTest
[2025-07-23 12:39:06 -    INFO] Passed test DeleteTest
[2025-07-23 12:39:06 -    INFO] Finished running 11 test. 11 passed
✓ Integration testsuite passed
==> Building spf binary...
✓ Build completed successfully

🎉 All steps completed successfully!
Binary location: ./bin/spf
Binary size: 23M

@Khitoshi
Copy link
Contributor Author

Khitoshi commented Jul 22, 2025

~/superfile$ ./dev.sh --testsuite
🚀 Starting superfile development workflow

==> Tidying Go modules...
✓ Go modules tidied
==> Formatting Go code...
✓ Code formatted
==> Running golangci-lint...
✓ Linting passed
==> Running unit tests...
?       github.com/yorukot/superfile    [no test files]
?       github.com/yorukot/superfile/src/cmd    [no test files]
?       github.com/yorukot/superfile/src/config [no test files]
?       github.com/yorukot/superfile/src/config/icon    [no test files]
ok      github.com/yorukot/superfile/src/internal       (cached)
ok      github.com/yorukot/superfile/src/internal/common        (cached)
?       github.com/yorukot/superfile/src/internal/ui    [no test files]
ok      github.com/yorukot/superfile/src/internal/ui/prompt     (cached)
ok      github.com/yorukot/superfile/src/internal/ui/rendering  (cached)
ok      github.com/yorukot/superfile/src/internal/ui/sidebar    (cached)
ok      github.com/yorukot/superfile/src/internal/utils (cached)
?       github.com/yorukot/superfile/src/pkg/file_preview       [no test files]
?       github.com/yorukot/superfile/src/pkg/string_function    [no test files]
✓ Unit tests passed
==> Running integration testsuite...
==> Using existing virtual environment at ./venv
==> Upgrading pip in virtual environment...
✓ Pip upgraded successfully
==> Installing testsuite requirements in virtual environment...
✓ Testsuite requirements installed in virtual environment
[2025-07-23 12:46:00 -    INFO] Testcases : [ChooserFileTest, CopyWTest, DeleteDirTest, EmptyPanelTest, CompressExtractTest, CommandTest, CopyDirTest, RenameTest, CutTest, CopyTest, DeleteTest]
[2025-07-23 12:46:00 -    INFO] Running test ChooserFileTest
[2025-07-23 12:46:04 -    INFO] Passed test ChooserFileTest
[2025-07-23 12:46:04 -    INFO] Running test CopyWTest
[2025-07-23 12:46:06 -    INFO] Passed test CopyWTest
[2025-07-23 12:46:06 -    INFO] Running test DeleteDirTest
[2025-07-23 12:46:07 -    INFO] Passed test DeleteDirTest
[2025-07-23 12:46:07 -    INFO] Running test EmptyPanelTest
[2025-07-23 12:46:09 -    INFO] Passed test EmptyPanelTest
[2025-07-23 12:46:09 -    INFO] Running test CompressExtractTest
[2025-07-23 12:46:11 -    INFO] Passed test CompressExtractTest
[2025-07-23 12:46:11 -    INFO] Running test CommandTest
[2025-07-23 12:46:13 -    INFO] Passed test CommandTest
[2025-07-23 12:46:13 -    INFO] Running test CopyDirTest
[2025-07-23 12:46:15 -    INFO] Passed test CopyDirTest
[2025-07-23 12:46:15 -    INFO] Running test RenameTest
[2025-07-23 12:46:16 -    INFO] Passed test RenameTest
[2025-07-23 12:46:16 -    INFO] Running test CutTest
[2025-07-23 12:46:18 -    INFO] Passed test CutTest
[2025-07-23 12:46:18 -    INFO] Running test CopyTest
[2025-07-23 12:46:22 -    INFO] Passed test CopyTest
[2025-07-23 12:46:22 -    INFO] Running test DeleteTest
[2025-07-23 12:46:24 -    INFO] Passed test DeleteTest
[2025-07-23 12:46:24 -    INFO] Finished running 11 test. 11 passed
✓ Integration testsuite passed
==> Building spf binary...
✓ Build completed successfully

🎉 All steps completed successfully!
Binary location: ./bin/spf
Binary size: 23M

@Khitoshi Khitoshi changed the title feat: add support for Python virtual environment in testsuite setup [WIP]feat: add support for Python virtual environment in testsuite setup Jul 22, 2025
@Khitoshi
Copy link
Contributor Author

Khitoshi commented Jul 22, 2025

~/superfile$ ./dev.sh --testsuite --use-global-env --verbose

....

[2025-07-23 01:54:28 -   DEBUG] spf_manager info : [], Current file structure : 
D-dir1
D-dir2
F-dir1/file1(1).txt
F-dir1/file1.txt

[2025-07-23 01:54:28 -    INFO] Passed test CopyTest
[2025-07-23 01:54:28 -    INFO] Running test DeleteTest
[2025-07-23 01:54:28 -   DEBUG] Current file structure : 
F-file_to_delete.txt

[2025-07-23 01:54:28 -   DEBUG] windows_command : /home/khitoshi/superfile/bin/spf -c /home/khitoshi/superfile/src/superfile_config/config.toml --hf /home/khitoshi/superfile/src/superfile_config/hotkeys.toml
[2025-07-23 01:54:28 -   DEBUG] spf_session initialised : Session($0 spf_session)
[2025-07-23 01:54:29 -   DEBUG] sendind key : 'a'
[2025-07-23 01:54:29 -   DEBUG] sendind key : '\x04'
[2025-07-23 01:54:29 -   DEBUG] sendind key : '\r'
[2025-07-23 01:54:29 -   DEBUG] sendind key : '\x1b'
[2025-07-23 01:54:30 -   DEBUG] Finished Execution
[2025-07-23 01:54:30 -   DEBUG] spf_manager info : [], Current file structure : 

[2025-07-23 01:54:30 -    INFO] Passed test DeleteTest
[2025-07-23 01:54:30 -    INFO] Finished running 11 test. 11 passed
✓ Integration testsuite passed
==> Building spf binary...
✓ Build completed successfully

@Khitoshi Khitoshi changed the title [WIP]feat: add support for Python virtual environment in testsuite setup feat: add support for Python virtual environment in testsuite setup Jul 22, 2025
dev.sh Outdated
if pip3 install -r requirements.txt > /dev/null 2>&1; then
print_success "Testsuite requirements installed"
# Setup virtual environment if requested
if [ "$USE_VENV" = true ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @Khitoshi Thanks for this. I would prefer if its other way around.

--use-global-env or a better name -> Uses global
default -> Uses venv

Default using global sounds bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that makes more sense. I’ll switch the default to venv and add a --use-global-env flag.

Copy link
Collaborator

@lazysegtree lazysegtree left a comment

Choose a reason for hiding this comment

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

LGTM. Tested. I would have @yorukot also take a look as he wrote this script.

@lazysegtree lazysegtree requested a review from yorukot July 23, 2025 04:28
@lazysegtree lazysegtree merged commit 8ac4107 into yorukot:main Jul 24, 2025
8 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.

Add virtual environment support to dev.sh script for Python testsuite
3 participants