Skip to content

Bump python version to 3.12#68843

Open
dwoz wants to merge 26 commits intosaltstack:masterfrom
dwoz:pyversion
Open

Bump python version to 3.12#68843
dwoz wants to merge 26 commits intosaltstack:masterfrom
dwoz:pyversion

Conversation

@dwoz
Copy link
Copy Markdown
Contributor

@dwoz dwoz commented Mar 25, 2026

What does this PR do?

What issues does this PR fix or reference?

Fixes

Previous Behavior

Remove this section if not relevant

New Behavior

Remove this section if not relevant

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes/No

@dwoz dwoz requested a review from a team as a code owner March 25, 2026 21:06
twangboy
twangboy previously approved these changes Mar 30, 2026
dwoz and others added 26 commits April 6, 2026 15:05
The setuptools-scm 10.0.2 sdist contains a pyproject.toml with a
backend-path entry (../vcs-versioning/src) that points outside its own
source tree — a developer's local monorepo path that was accidentally
shipped in the release. pip 25.2 now validates that backend-path entries
stay inside the source tree and rejects it. The wheel is fine since it
bypasses pyproject.toml processing entirely.
`lxml` → requirements/base.txt: added lxml>=5.0.0; sys_platform != 'win32' (no cp312 wheels before 5.0.0)
`ncclient` → requirements/static/ci/common.in: added ncclient>=0.6.16; sys_platform != 'win32' (SafeConfigParser removed in Python 3.12)
`pygit2` → requirements/static/ci/{linux,darwin,windows}.in: bumped >=1.10.1 → >=1.14.0 (no cp312 wheels before 1.14.0)
…Subset, distutils, and utcnow

Agent-Logs-Url: https://github.com/saltstack/salt/sessions/8d432548-1f18-44b2-9fea-496226ca1f79

Co-authored-by: dwoz <1527763+dwoz@users.noreply.github.com>
…ypp_plugins.py, test_pip.py)

Co-authored-by: dwoz <1527763+dwoz@users.noreply.github.com>
- tests/unit/test_zypp_plugins.py: replace `import imp` (removed in
  Python 3.12) with `importlib.util`, and replace `imp.load_source()`
  with `spec_from_file_location` + `module_from_spec` + `exec_module`

- salt/modules/virtualenv_mod.py: fix `get_distribution_path` to use
  `importlib.metadata` instead of `pkg_resources`; old setuptools
  references `pkgutil.ImpImporter` which was removed in Python 3.12

- salt/utils/versions.py: replace `datetime.utcnow()` (deprecated in
  Python 3.12) with `datetime.now(datetime.timezone.utc)` to eliminate
  the DeprecationWarning that breaks test_deprecation_warnings[env0-False]

Agent-Logs-Url: https://github.com/saltstack/salt/sessions/80a13379-dae2-4c51-bff3-d9e06c170f4b

Co-authored-by: dwoz <1527763+dwoz@users.noreply.github.com>
Replace deprecated datetime.utcnow() calls with a compatibility
function that uses datetime.now(timezone.utc) for Python 3.12+
and falls back to datetime.utcnow() for older versions.

Also fix zeromq test that failed due to accessing uninitialized
socket object by calling _init_socket() before socket access.

Changes:
- Add salt.utils.timeutil.utcnow() compatibility function
- Replace all datetime.utcnow() calls across salt modules
- Fix test_request_client_send_recv_loop_closed socket initialization
Use named argument format to avoid duplicate 'distribution' parameter
in string formatting.
Replace datetime.datetime.utcnow() calls in transport_ssl.py test
fixtures with salt.utils.timeutil.utcnow() to avoid deprecation
warnings in Python 3.12+.
Replace remaining datetime.utcnow() calls in test files with
salt.utils.timeutil.utcnow() to avoid deprecation errors when
RAISE_DEPRECATIONS_RUNTIME_ERRORS=1 in Python 3.12+.

Fixed files:
- tests/pytests/functional/modules/test_system.py (8 occurrences)
- tests/pytests/unit/test_fileserver.py (1 occurrence)
- tests/pytests/unit/utils/test_aws.py (7 occurrences)
- tests/unit/modules/test_x509.py (3 occurrences)
In Python 3.12, importlib.util.spec_from_file_location() returns None
for files without .py extension when it cannot infer the loader.
The zyppnotify file lacks a .py extension, causing the spec to be None
and resulting in AttributeError when trying to access spec.loader.

Fix by explicitly using importlib.machinery.SourceFileLoader to create
the spec, which works regardless of file extension.
1. Fix datetime.utcnow() to return naive datetime
   - pytz.localize() requires naive datetime objects
   - Updated utcnow() wrapper to strip timezone info for compatibility

2. Add datetime.utcfromtimestamp() wrapper
   - Deprecated in Python 3.12
   - Created utcfromtimestamp() in salt.utils.timeutil
   - Replaced all usages in salt/modules/: status, rpm_lowpkg, dpkg_lowpkg, aptpkg
   - Fixed test file: tests/pytests/unit/states/file/test_tidied.py
   - Removed unused datetime imports

3. Fix boto3 test collection error on Windows
   - tests/unit/utils/test_boto3mod.py was accessing boto3.__version__
     even when boto3 not installed, causing NameError
   - Added HAS_BOTO3 check to version comparison skipif decorator
Use grains.get() with default value of 0 instead of direct dictionary
access to handle cases where osmajorrelease grain is not available.

Fixes test_owner and test_which failures on systems without osmajorrelease.
Ensure VirtualEnv test helper uses pip>=23.2 on Python 3.12+ to avoid
distutils import errors. Old pip versions try to import the distutils
module which was removed in Python 3.12.

This fixes test_pip_installed_pkgs_test_mode and other virtualenv-based
tests that were failing with "ModuleNotFoundError: No module named 'distutils'".
The legacy git code path in winrepo.update_git_repos() was storing
result["result"] (a boolean) instead of the target directory path.
This caused tests to fail with AttributeError when calling .endswith()
on the boolean value.

Changed to store gittarget (the actual path) to match the behavior
of the non-legacy gitfs code and what tests expect.

Fixes test_update_git_repos when GitPython/Pygit2 are not installed.
The backports module is not available in Python 3.12+ environments,
even though sys.version_info < (3, 13) evaluates to True. The test
was expecting backports to be included in thin.get_tops() output
based solely on Python version, but salt/utils/thin.py correctly
sets backports=None when the import fails.

Fixed by checking salt.utils.thin.backports is not None instead
of sys.version_info < (3, 13), matching the pattern used for
has_immutables.

Fixes test_get_tops, test_get_tops_extra_mods, and test_get_tops_so_mods
on Python 3.12.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants