From cc57eb43b54961fc78c6b307e6842b1907d31256 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Tue, 8 Apr 2025 15:04:13 +0200 Subject: [PATCH 1/5] Deprecate --override-python --- rsconnect/environment.py | 7 ++++--- tests/test_environment.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/rsconnect/environment.py b/rsconnect/environment.py index ec0052bd..eefcbca5 100644 --- a/rsconnect/environment.py +++ b/rsconnect/environment.py @@ -129,9 +129,10 @@ def create_python_environment( _warn_on_missing_python_version(python_version_requirement) if override_python_version: - # TODO: --override-python-version should be deprecated in the future - # and instead we should suggest the user sets it in .python-version - # or pyproject.toml + logger.warning( + "The --override-python-version option is deprecated, " + "please use a .python-version file to force a specific interpreter version." + ) python_version_requirement = f"=={override_python_version}" # with cli_feedback("Inspecting Python environment"): diff --git a/tests/test_environment.py b/tests/test_environment.py index 52df3c35..16105ecf 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -4,6 +4,7 @@ import tempfile import subprocess from unittest import TestCase +from unittest import mock import rsconnect.environment from rsconnect.exception import RSConnectException @@ -270,3 +271,19 @@ def fake_inspect_environment( assert environment.python_interpreter == expected_python assert environment == expected_environment + +class TestEnvironmentDeprecations: + def test_override_python_version(self): + with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning: + result = Environment.create_python_environment(get_dir("pip1"), override_python_version=None) + assert mock_warning.call_count == 0 + assert result.python_version_requirement is None + + with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning: + result = Environment.create_python_environment(get_dir("pip1"), override_python_version="3.8") + assert mock_warning.call_count == 1 + mock_warning.assert_called_once_with( + "The --override-python-version option is deprecated, " + "please use a .python-version file to force a specific interpreter version." + ) + assert result.python_version_requirement == "==3.8" From 4757dde67f619540fd95a042e44b9e4b7b1c2745 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Tue, 8 Apr 2025 15:14:35 +0200 Subject: [PATCH 2/5] deprecate --python --- rsconnect/environment.py | 9 +++++++++ tests/test_environment.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/rsconnect/environment.py b/rsconnect/environment.py index eefcbca5..951d11d6 100644 --- a/rsconnect/environment.py +++ b/rsconnect/environment.py @@ -128,7 +128,16 @@ def create_python_environment( python_version_requirement = pyproject.detect_python_version_requirement(directory) _warn_on_missing_python_version(python_version_requirement) + if python is not None: + # TODO: Remove the option in a future release + logger.warning( + "On modern connect versions, the --python option won't influence " + "the Python version used to deploy the application anymore. " + "Please use a .python-version file to force a specific interpreter version." + ) + if override_python_version: + # TODO: Remove the option in a future release logger.warning( "The --override-python-version option is deprecated, " "please use a .python-version file to force a specific interpreter version." diff --git a/tests/test_environment.py b/tests/test_environment.py index 16105ecf..8a8731fa 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -287,3 +287,21 @@ def test_override_python_version(self): "please use a .python-version file to force a specific interpreter version." ) assert result.python_version_requirement == "==3.8" + + def test_python_interpreter(self): + current_python_version = ".".join((str(v) for v in sys.version_info[:3])) + + with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning: + result = Environment.create_python_environment(get_dir("pip1")) + assert mock_warning.call_count == 0 + assert result.python == current_python_version + + with mock.patch.object(rsconnect.environment.logger, "warning") as mock_warning: + result = Environment.create_python_environment(get_dir("pip1"), python=sys.executable) + assert mock_warning.call_count == 1 + mock_warning.assert_called_once_with( + "On modern connect versions, the --python option won't influence " + "the Python version used to deploy the application anymore. " + "Please use a .python-version file to force a specific interpreter version." + ) + assert result.python == current_python_version From b29fa8eea798bc297a60f68773ab662df431b356 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Tue, 8 Apr 2025 15:24:44 +0200 Subject: [PATCH 3/5] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4830b427..0185cae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `rsconnect` now detects Python interpreter version requirements from `.python-version`, `pyproject.toml` and `setup.cfg` +- `--python` and `--override-python-version` options are now deprecated + in favor of using `.python-version` requirement file. ## [1.25.2] - 2025-02-26 From 2ecc563e1c050fb256e8dc1d7b1328960f1b169c Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Thu, 10 Apr 2025 10:32:38 +0200 Subject: [PATCH 4/5] Update rsconnect/environment.py Co-authored-by: Brian Smith --- rsconnect/environment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsconnect/environment.py b/rsconnect/environment.py index 951d11d6..35280fef 100644 --- a/rsconnect/environment.py +++ b/rsconnect/environment.py @@ -131,7 +131,7 @@ def create_python_environment( if python is not None: # TODO: Remove the option in a future release logger.warning( - "On modern connect versions, the --python option won't influence " + "On modern Posit Connect versions, the --python option won't influence " "the Python version used to deploy the application anymore. " "Please use a .python-version file to force a specific interpreter version." ) From 78bb2e516298a406bd35f64ab3cafd66cf552ef5 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Thu, 10 Apr 2025 10:58:54 +0200 Subject: [PATCH 5/5] Update test --- tests/test_environment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_environment.py b/tests/test_environment.py index 8a8731fa..d62befc1 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -300,7 +300,7 @@ def test_python_interpreter(self): result = Environment.create_python_environment(get_dir("pip1"), python=sys.executable) assert mock_warning.call_count == 1 mock_warning.assert_called_once_with( - "On modern connect versions, the --python option won't influence " + "On modern Posit Connect versions, the --python option won't influence " "the Python version used to deploy the application anymore. " "Please use a .python-version file to force a specific interpreter version." )