Replace deprecated distutils and pkg_resources with modern alternatives#1160
Open
dhruvildarji wants to merge 1 commit into
Open
Conversation
- Replace `distutils.version.LooseVersion` fallback with direct `packaging.version.Version` import (distutils was removed in Python 3.12) - Replace `pkg_resources` fallback with direct `importlib.metadata` import (available since Python 3.8, which is already the minimum for numpy 1.24) - Add `packaging` as an explicit dependency in requirements.txt Fixes carla-simulator#1128 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
distutils.version.LooseVersionfallback with directpackaging.version.Versionimport (distutilswas removed in Python 3.12)pkg_resourcesfallback with directimportlib.metadata.metadataimport (available since Python 3.8, which is already the minimum required by numpy 1.24.4)packagingas an explicit dependency inrequirements.txtMotivation
The
distutilsmodule was deprecated in Python 3.10 and removed entirely in Python 3.12 (PEP 632). Similarly,pkg_resourcesfromsetuptoolsis deprecated in favor ofimportlib.metadata(available since Python 3.8).Since the project already requires Python 3.8+ (numpy 1.24.4 requires it), both
packaging.version.Versionandimportlib.metadataare guaranteed to be available, making the try/except fallbacks unnecessary.This partially addresses #1128 by removing deprecated imports that cause warnings and failures on newer Python versions.
Changes
scenario_runner.py: Replacedtry/exceptimport blocks with direct importsrequirements.txt: Addedpackagingas an explicit dependency (was previously only used if available)Test plan
python scenario_runner.py --helpruns without import errors on Python 3.8+pip install -r requirements.txtsucceeds and includespackagingThis change is