Skip to content

Comments

feat(python): add support for creating python .venv and installing dependencies#346

Open
mwbrooks wants to merge 12 commits intomainfrom
mwbrooks-python-venv
Open

feat(python): add support for creating python .venv and installing dependencies#346
mwbrooks wants to merge 12 commits intomainfrom
mwbrooks-python-venv

Conversation

@mwbrooks
Copy link
Member

@mwbrooks mwbrooks commented Feb 20, 2026

Changelog

Updated the slack create and slack init commands to support creating a Python virtual environment (.venv) when it doesn't exist and installing the project's dependencies from requirements.txt and pyproject.toml.

Summary

This pull request adds support for creating a Python virtual environment when it doesn't already exist and installs the dependencies defined in requirements.txt and pyproject.toml.

Out-of-scope:

  • Activating the virtual environment on each Slack CLI commands. We can follow-up in another PR with that feature.

Known issues:

  • When a pyproject.toml doesn't include a [project] section or dependencies array, the Slack CLI will display an error. It gracefully fails by continuing with the installation process for requirements.txt. However, I think we have an opportunity to update the Slack CLI to display a "Skipped updating pyproject.toml: no dependencies array" message instead of an error. That can be handled in a follow-up PR.

Related PRs:

Preview

Example of an app with a valid pyproject.toml:

image

Example of an app with an incomplete pyproject.toml:

image

Reviewers

Example of an app with a valid pyproject.toml:

$ lack create my-test-app/
# → Select "AI Agent App"
# → Select "Bolt for Python"

# Validate output:
# → Confirm: "Created virtual environment at .venv"
# → Confirm: "Installed dependencies from pyproject.toml"
# → Confirm: "Installed dependencies from requirements.txt"
# → Confirm: No errors

# Validate .env
$ ls -al my-test-app/.venv
# → Confirm: Exists

# Test app dependencies installed
$ cd my-test-app/
$ source .venv/bin/activate
$ lack run
# → Confirm: App starts

# Clean up
$ cd ../
$ rm -rf my-test-app/

Example of an app with an incomplete pyproject.toml:

$ lack create my-test-app/
# → Select "Starter App"
# → Select "Bolt for Python"

# Validate output:
# → Confirm: "Created virtual environment at .venv"
# → Confirm: "Error updating pyproject.toml: pyproject.toml missing project section"
# → Confirm: "Installed dependencies from pyproject.toml"
# → Confirm: "Installed dependencies from requirements.txt"

# Validate .env
$ ls -al my-test-app/.venv
# → Confirm: Exists

# Test app dependencies installed
$ cd my-test-app/
$ source .venv/bin/activate
$ lack run
# → Confirm: App starts

# Clean up
$ cd ../
$ rm -rf my-test-app/

Requirements

@mwbrooks mwbrooks self-assigned this Feb 20, 2026
@mwbrooks mwbrooks added enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment area:bolt-python Related to github.com/slackapi/bolt-python changelog Use on updates to be included in the release notes labels Feb 20, 2026
@mwbrooks mwbrooks added this to the Next Release milestone Feb 20, 2026
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 71.60494% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.77%. Comparing base (113aa42) to head (180d499).

Files with missing lines Patch % Lines
internal/runtime/python/python.go 71.25% 14 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #346      +/-   ##
==========================================
+ Coverage   64.73%   64.77%   +0.04%     
==========================================
  Files         212      212              
  Lines       17809    17860      +51     
==========================================
+ Hits        11528    11569      +41     
- Misses       5207     5212       +5     
- Partials     1074     1079       +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Clarify error messages in installPyProjectToml to include "updating
pyproject.toml" context, and remove early return on file update errors
so pip install is attempted regardless.
@mwbrooks mwbrooks changed the title feat(python): add support for creating and activating venv feat(python): add support for creating a python .venv Feb 20, 2026
@mwbrooks mwbrooks changed the title feat(python): add support for creating a python .venv feat(python): update 'create' and 'init' commands to support creating a python .venv Feb 20, 2026
@mwbrooks mwbrooks changed the title feat(python): update 'create' and 'init' commands to support creating a python .venv feat(python): update 'create' and 'init' to support creating a python .venv Feb 20, 2026
@mwbrooks mwbrooks changed the title feat(python): update 'create' and 'init' to support creating a python .venv feat(python): update 'create' and 'init' to support creating and installing python .venv Feb 20, 2026
@mwbrooks mwbrooks changed the title feat(python): update 'create' and 'init' to support creating and installing python .venv feat(python): add support for creating python .venv and installing dependencies Feb 20, 2026
Copy link
Member Author

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

Comments for the kind folks 👓

if !exists {
err := fmt.Errorf("pyproject.toml missing project section")
return fmt.Sprintf("Error: %s", err), err
return fmt.Sprintf("Error updating pyproject.toml: %s", err), err
Copy link
Member Author

Choose a reason for hiding this comment

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

note: Improving error messages when there is an error adding slack-cli-hooks to pyproject.toml.

Route createVirtualEnvironment and runPipInstall through HookExecutor
instead of os/exec, matching the npm runtime pattern. This makes the
functions testable with the mock filesystem. Also add missing
AddDefaultMocks call, remove stale test cases, and fix assertion strings.
Comment on lines +98 to +108
hookScript := hooks.HookScript{
Name: "CreateVirtualEnvironment",
Command: fmt.Sprintf("%s -m venv .venv", getPythonExecutable()),
}
stdout := bytes.Buffer{}
hookExecOpts := hooks.HookExecOpts{
Hook: hookScript,
Stdout: &stdout,
Directory: projectDirPath,
}
_, err := hookExecutor.Execute(ctx, hookExecOpts)
Copy link
Member Author

Choose a reason for hiding this comment

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

note: While it's verbose, we use the hookExecutor so that we can mock the exec calls during tests. This is how we also handle npm install.

@mwbrooks mwbrooks marked this pull request as ready for review February 21, 2026 00:33
@mwbrooks mwbrooks requested a review from a team as a code owner February 21, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:bolt-python Related to github.com/slackapi/bolt-python changelog Use on updates to be included in the release notes enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant