Skip to content

Commit 98d2ba6

Browse files
committed
warn if the base directory is a virtualenv
1 parent a71bd16 commit 98d2ba6

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

rsconnect/bundle.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,19 @@ def create_glob_set(directory, excludes):
402402
return GlobSet(work)
403403

404404

405+
def is_environment_dir(directory):
406+
python_path = join(directory, "bin", "python")
407+
return exists(python_path)
408+
409+
405410
def list_environment_dirs(directory):
406411
# type: (...) -> typing.List[str]
407412
"""Returns a list of subdirectories in `directory` that appear to contain virtual environments."""
408413
envs = []
409414

410415
for name in os.listdir(directory):
411-
python_path = join(directory, name, "bin", "python")
412-
if exists(python_path):
416+
path = join(directory, name)
417+
if is_environment_dir(path):
413418
envs.append(name)
414419
return envs
415420

@@ -484,6 +489,9 @@ def make_api_manifest(
484489
:param excludes: a sequence of glob patterns that will exclude matched files.
485490
:return: the manifest and a list of the files involved.
486491
"""
492+
if is_environment_dir(directory):
493+
excludes = list(excludes or []) + ["bin/", "lib/"]
494+
487495
relevant_files = _create_api_file_list(directory, environment.filename, extra_files, excludes)
488496
manifest = make_source_manifest(entry_point, environment, app_mode)
489497

rsconnect/main.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040

4141
from . import api
42-
from .bundle import make_manifest_bundle
42+
from .bundle import is_environment_dir, make_manifest_bundle
4343
from .metadata import ServerStore, AppStore
4444
from .models import AppModes
4545

@@ -403,6 +403,20 @@ def _warn_if_no_requirements_file(directory):
403403
)
404404

405405

406+
def _warn_if_environment_directory(directory):
407+
"""
408+
Issue a warning if the deployment directory is itself a virtualenv (yikes!).
409+
410+
:param directory: the directory to check in.
411+
"""
412+
if is_environment_dir(directory):
413+
click.secho(
414+
" Warning: The deployment directory appears to be a python virtual environment.\n"
415+
" Excluding the 'bin' and 'lib' directories..",
416+
fg="yellow",
417+
)
418+
419+
406420
def _warn_on_ignored_conda_env(environment):
407421
"""
408422
Checks for a discovered Conda environment and produces a warning that it will be ignored when
@@ -575,8 +589,10 @@ def deploy_notebook(
575589

576590
click.secho(' Deploying %s to server "%s"' % (file, connect_server.url))
577591

578-
_warn_on_ignored_manifest(dirname(file))
579-
_warn_if_no_requirements_file(dirname(file))
592+
base_dir = dirname(file)
593+
_warn_on_ignored_manifest(base_dir)
594+
_warn_if_no_requirements_file(base_dir)
595+
_warn_if_environment_directory(base_dir)
580596

581597
with cli_feedback("Inspecting Python environment"):
582598
python, environment = get_python_env_info(file, python, conda, force_generate)
@@ -588,7 +604,7 @@ def deploy_notebook(
588604
_warn_on_ignored_conda_env(environment)
589605

590606
if force_generate:
591-
_warn_on_ignored_requirements(dirname(file), environment.filename)
607+
_warn_on_ignored_requirements(base_dir, environment.filename)
592608

593609
with cli_feedback("Creating deployment bundle"):
594610
bundle = create_notebook_deployment_bundle(
@@ -881,6 +897,7 @@ def _deploy_by_framework(
881897

882898
_warn_on_ignored_manifest(directory)
883899
_warn_if_no_requirements_file(directory)
900+
_warn_if_environment_directory(directory)
884901

885902
with cli_feedback("Inspecting Python environment"):
886903
_, environment = get_python_env_info(module_file, python, conda, force_generate)

0 commit comments

Comments
 (0)