Skip to content

Commit 9fbc8f3

Browse files
authored
Merge branch 'master' into mm-verify-deployments
2 parents 2030b95 + f11851c commit 9fbc8f3

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Common environment directories (`env, venv, .env, .venv`) are no longer
1717
excluded by name. Environments are detected by the presence of a python
1818
executable in `bin` or `Scripts` and excluded.
19+
- Lines output from `pip freeze` which start with [notice] are filtered out from the generated `requirements.txt`.
1920

2021
### Added
2122
- Added support for the `no_proxy` or `NO_PROXY` environment variables to specify

rsconnect/environment.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ def output_file(dirname, filename, package_manager):
145145

146146

147147
def pip_freeze():
148-
"""Inspect the environment using `pip freeze`.
148+
"""Inspect the environment using `pip freeze --disable-pip-version-check version`.
149149
150150
Returns a dictionary containing the filename
151151
(always 'requirements.txt') and contents if successful,
152152
or a dictionary containing 'error' on failure.
153153
"""
154154
try:
155155
proc = subprocess.Popen(
156-
[sys.executable, "-m", "pip", "freeze"],
156+
[sys.executable, "-m", "pip", "freeze", "--disable-pip-version-check"],
157157
stdout=subprocess.PIPE,
158158
stderr=subprocess.PIPE,
159159
universal_newlines=True,
@@ -168,7 +168,7 @@ def pip_freeze():
168168
msg = pip_stderr or ("exited with code %d" % pip_status)
169169
raise EnvironmentException("Error during pip freeze: %s" % msg)
170170

171-
pip_stdout = "\n".join([line for line in pip_stdout.split("\n") if "rsconnect" not in line])
171+
pip_stdout = filter_pip_freeze_output(pip_stdout)
172172

173173
pip_stdout = (
174174
"# requirements.txt generated by rsconnect-python on " + str(datetime.datetime.utcnow()) + "\n" + pip_stdout
@@ -182,6 +182,13 @@ def pip_freeze():
182182
}
183183

184184

185+
def filter_pip_freeze_output(pip_stdout):
186+
# Filter out dependency on `rsconnect` and ignore output lines from pip which start with `[notice]`
187+
return "\n".join(
188+
[line for line in pip_stdout.split("\n") if (("rsconnect" not in line) and (line.find("[notice]") != 0))]
189+
)
190+
191+
185192
def strip_ref(line):
186193
# remove erroneous conda build paths that will break pip install
187194
return line.split(" @ file:", 1)[0].strip()

rsconnect/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def _warn_if_no_requirements_file(directory):
749749
"""
750750
if not exists(join(directory, "requirements.txt")):
751751
click.secho(
752-
" Warning: Capturing the environment using 'pip freeze'.\n"
752+
" Warning: Capturing the environment using 'pip freeze --disable-pip-version-check'.\n"
753753
" Consider creating a requirements.txt file instead.",
754754
fg="yellow",
755755
)

tests/test_environment.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
detect_environment,
99
get_default_locale,
1010
get_python_version,
11+
filter_pip_freeze_output,
1112
)
1213
from .utils import get_dir
1314

@@ -72,3 +73,24 @@ def test_pip_freeze(self):
7273
source="pip_freeze",
7374
)
7475
self.assertEqual(expected, result)
76+
77+
def test_filter_pip_freeze_output(self):
78+
raw_stdout = "numpy\npandas\n[notice] A new release of pip is available: 23.1.2 -> 23.3\n\
79+
[notice] To update, run: pip install --upgrade pip"
80+
filtered = filter_pip_freeze_output(raw_stdout)
81+
expected = "numpy\npandas"
82+
83+
self.assertEqual(filtered, expected)
84+
85+
raw_stdout = "numpy\npandas"
86+
filtered = filter_pip_freeze_output(raw_stdout)
87+
expected = "numpy\npandas"
88+
89+
self.assertEqual(filtered, expected)
90+
91+
raw_stdout = "numpy\npandas\nnot at beginning [notice]\n\
92+
[notice] To update, run: pip install --upgrade pip"
93+
filtered = filter_pip_freeze_output(raw_stdout)
94+
expected = "numpy\npandas\nnot at beginning [notice]"
95+
96+
self.assertEqual(filtered, expected)

0 commit comments

Comments
 (0)