Skip to content

fix: detect virtualenvs on Windows #472

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 4 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed
- Python virtualenvs are now detected in Windows environments, and are automatically
excluded from the uploaded bundle.

### Added

- Add `--disable-env-management`, `--disable-env-management-py` and `--disable-env-management-r` flags for all content types
Expand Down
11 changes: 8 additions & 3 deletions rsconnect/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,13 @@ def create_glob_set(directory, excludes):


def is_environment_dir(directory):
"""Detect whether `directory` is a virtualenv"""

# A virtualenv will have Python at ./bin/python
python_path = join(directory, "bin", "python")
return exists(python_path)
# But on Windows, it's at Scripts\Python.exe
win_path = join(directory, "Scripts", "Python.exe")
return exists(python_path) or exists(win_path)


def list_environment_dirs(directory):
Expand Down Expand Up @@ -859,7 +864,7 @@ def make_api_manifest(
:return: the manifest and a list of the files involved.
"""
if is_environment_dir(directory):
excludes = list(excludes or []) + ["bin/", "lib/"]
excludes = list(excludes or []) + ["bin/", "lib/", "Lib/", "Scripts/", "Include/"]

extra_files = extra_files or []
skip = [environment.filename, "manifest.json"]
Expand Down Expand Up @@ -1483,7 +1488,7 @@ def _warn_if_environment_directory(directory):
if is_environment_dir(directory):
click.secho(
" Warning: The deployment directory appears to be a python virtual environment.\n"
" Excluding the 'bin' and 'lib' directories.",
" Python libraries and binaries will be excluded from the deployment.",
fg="yellow",
)

Expand Down
2 changes: 1 addition & 1 deletion rsconnect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def _warn_if_environment_directory(directory):
if is_environment_dir(directory):
click.secho(
" Warning: The deployment directory appears to be a python virtual environment.\n"
" Excluding the 'bin' and 'lib' directories.",
" Python libraries and binaries will be excluded from the deployment.",
fg="yellow",
)

Expand Down