Skip to content

Commit

Permalink
Reorders package managers for python ecosystem metric collection (#11040
Browse files Browse the repository at this point in the history
)

fixes python ecosystem metric collection
  • Loading branch information
sachin-sandhu authored Dec 3, 2024
1 parent b023647 commit 2cac563
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
20 changes: 14 additions & 6 deletions python/lib/dependabot/python/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,23 @@ def python_requirement_parser

sig { returns(Ecosystem::VersionManager) }
def package_manager
if Dependabot::Experiments.enabled?(:enable_file_parser_python_local)
Dependabot.logger.info("Detected package manager : #{detected_package_manager.name}")
end

@package_manager ||= detected_package_manager
end

sig { returns(Ecosystem::VersionManager) }
def detected_package_manager
setup_python_environment if Dependabot::Experiments.enabled?(:enable_file_parser_python_local)

return PipenvPackageManager.new(T.must(detect_pipenv_version)) if detect_pipenv_version

return PoetryPackageManager.new(T.must(detect_poetry_version)) if detect_poetry_version

return PipCompilePackageManager.new(T.must(detect_pipcompile_version)) if detect_pipcompile_version

return PipenvPackageManager.new(T.must(detect_pipenv_version)) if detect_pipenv_version

PipPackageManager.new(detect_pip_version)
end

Expand All @@ -123,7 +127,7 @@ def detect_poetry_version
# Detects the version of pip-compile. If the version cannot be detected, it returns nil
sig { returns(T.nilable(String)) }
def detect_pipcompile_version
if pip_compile_files
if pipcompile_in_file
package_manager = PipCompilePackageManager::NAME

version = package_manager_version(package_manager)
Expand All @@ -145,7 +149,7 @@ def detect_pipenv_version
package_manager = PipenvPackageManager::NAME

version = package_manager_version(package_manager)
.to_s.split("versions ").last&.strip
.to_s.split("version ").last&.strip

log_if_version_malformed(package_manager, version)

Expand Down Expand Up @@ -174,7 +178,6 @@ def detect_pip_version
sig { params(package_manager: String).returns(T.any(String, T.untyped)) }
def package_manager_version(package_manager)
version_info = SharedHelpers.run_shell_command("pyenv exec #{package_manager} --version")

Dependabot.logger.info("Package manager #{package_manager}, Info : #{version_info}")

version_info
Expand Down Expand Up @@ -206,6 +209,11 @@ def log_if_version_malformed(package_manager, version)

sig { returns(String) }
def python_raw_version
if Dependabot::Experiments.enabled?(:enable_file_parser_python_local)
Dependabot.logger.info("Detected python version: #{language_version_manager.python_version}")
Dependabot.logger.info("Detected python major minor version: #{language_version_manager.python_major_minor}")
end

language_version_manager.python_version
end

Expand Down Expand Up @@ -333,7 +341,7 @@ def pipcompile_in_file
end

def pipenv_files
requirement_files.any?(PipenvPackageManager::MANIFEST_FILENAME)
dependency_files.any? { |f| f.name == PipenvPackageManager::LOCKFILE_FILENAME }
end

def poetry_files
Expand Down
1 change: 1 addition & 0 deletions python/lib/dependabot/python/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class PipenvPackageManager < Dependabot::Ecosystem::VersionManager
NAME = "pipenv"

MANIFEST_FILENAME = "Pipfile"
LOCKFILE_FILENAME = "Pipfile.lock"

SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

Expand Down
4 changes: 4 additions & 0 deletions python/lib/dependabot/python/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def fetch_lowest_resolvable_security_fix_version
end

def resolver
if Dependabot::Experiments.enabled?(:enable_file_parser_python_local)
Dependabot.logger.info("Python package resolver : #{resolver_type}")
end

case resolver_type
when :pip_compile then pip_compile_version_resolver
when :pipenv then pipenv_version_resolver
Expand Down

0 comments on commit 2cac563

Please sign in to comment.