Skip to content

Commit d544fc1

Browse files
authored
Warning about --python and --override-python-version deprecation (#655)
1 parent 98923cb commit d544fc1

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- `rsconnect` now detects Python interpreter version requirements from
1212
`.python-version`, `pyproject.toml` and `setup.cfg`
13+
- `--python` and `--override-python-version` options are now deprecated
14+
in favor of using `.python-version` requirement file.
1315

1416
## [1.25.2] - 2025-02-26
1517

rsconnect/environment.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,20 @@ def create_python_environment(
128128
python_version_requirement = pyproject.detect_python_version_requirement(directory)
129129
_warn_on_missing_python_version(python_version_requirement)
130130

131+
if python is not None:
132+
# TODO: Remove the option in a future release
133+
logger.warning(
134+
"On modern Posit Connect versions, the --python option won't influence "
135+
"the Python version used to deploy the application anymore. "
136+
"Please use a .python-version file to force a specific interpreter version."
137+
)
138+
131139
if override_python_version:
132-
# TODO: --override-python-version should be deprecated in the future
133-
# and instead we should suggest the user sets it in .python-version
134-
# or pyproject.toml
140+
# TODO: Remove the option in a future release
141+
logger.warning(
142+
"The --override-python-version option is deprecated, "
143+
"please use a .python-version file to force a specific interpreter version."
144+
)
135145
python_version_requirement = f"=={override_python_version}"
136146

137147
# with cli_feedback("Inspecting Python environment"):

tests/test_environment.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tempfile
55
import subprocess
66
from unittest import TestCase
7+
from unittest import mock
78

89
import rsconnect.environment
910
from rsconnect.exception import RSConnectException
@@ -270,3 +271,37 @@ def fake_inspect_environment(
270271

271272
assert environment.python_interpreter == expected_python
272273
assert environment == expected_environment
274+
275+
class TestEnvironmentDeprecations:
276+
def test_override_python_version(self):
277+
with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning:
278+
result = Environment.create_python_environment(get_dir("pip1"), override_python_version=None)
279+
assert mock_warning.call_count == 0
280+
assert result.python_version_requirement is None
281+
282+
with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning:
283+
result = Environment.create_python_environment(get_dir("pip1"), override_python_version="3.8")
284+
assert mock_warning.call_count == 1
285+
mock_warning.assert_called_once_with(
286+
"The --override-python-version option is deprecated, "
287+
"please use a .python-version file to force a specific interpreter version."
288+
)
289+
assert result.python_version_requirement == "==3.8"
290+
291+
def test_python_interpreter(self):
292+
current_python_version = ".".join((str(v) for v in sys.version_info[:3]))
293+
294+
with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning:
295+
result = Environment.create_python_environment(get_dir("pip1"))
296+
assert mock_warning.call_count == 0
297+
assert result.python == current_python_version
298+
299+
with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning:
300+
result = Environment.create_python_environment(get_dir("pip1"), python=sys.executable)
301+
assert mock_warning.call_count == 1
302+
mock_warning.assert_called_once_with(
303+
"On modern Posit Connect versions, the --python option won't influence "
304+
"the Python version used to deploy the application anymore. "
305+
"Please use a .python-version file to force a specific interpreter version."
306+
)
307+
assert result.python == current_python_version

0 commit comments

Comments
 (0)