Class: Dependabot::Uv::FileParser

Inherits:
FileParsers::Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/uv/file_parser.rb,
lib/dependabot/uv/file_parser/pyproject_files_parser.rb,
lib/dependabot/uv/file_parser/python_requirement_parser.rb

Defined Under Namespace

Classes: PyprojectFilesParser, PythonRequirementParser

Constant Summary collapse

DEPENDENCY_GROUP_KEYS =
T.let(
  [
    {
      pipfile: "packages",
      lockfile: "default"
    },
    {
      pipfile: "dev-packages",
      lockfile: "develop"
    }
  ].freeze,
  T::Array[T::Hash[Symbol, String]]
)
REQUIREMENT_FILE_EVALUATION_ERRORS =
%w(
  InstallationError RequirementsFileParseError InvalidMarker
  InvalidRequirement ValueError RecursionError
).freeze
UNDETECTED_PACKAGE_MANAGER_VERSION =

we use this placeholder version in case we are not able to detect any uv version from shell, we are ensuring that the actual update is not blocked in any way if any metric collection exception start happening

"0.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.normalize_dependency_name(name, extras = []) ⇒ Object



92
93
94
# File 'lib/dependabot/uv/file_parser.rb', line 92

def self.normalize_dependency_name(name, extras = [])
  NameNormaliser.normalise_including_extras(name, extras)
end

Instance Method Details

#ecosystemObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/dependabot/uv/file_parser.rb', line 64

def ecosystem
  @ecosystem ||= T.let(
    Ecosystem.new(
      name: ECOSYSTEM,
      package_manager: package_manager,
      language: language
    ),
    T.nilable(Ecosystem)
  )
end

#parseObject



53
54
55
56
57
58
59
60
61
# File 'lib/dependabot/uv/file_parser.rb', line 53

def parse
  dependency_set = DependencySet.new

  dependency_set += pyproject_file_dependencies if pyproject
  dependency_set += uv_lock_file_dependencies
  dependency_set += requirement_dependencies if requirement_files.any?

  dependency_set.dependencies
end

#run_in_parsed_context(command) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dependabot/uv/file_parser.rb', line 76

def run_in_parsed_context(command)
  SharedHelpers.in_a_temporary_directory do
    dependency_files.each do |file|
      path = file.name
      FileUtils.mkdir_p(Pathname.new(path).dirname)
      File.write(path, file.content)
    end

    setup_python_environment

    SharedHelpers.run_shell_command(command, allow_unsafe_shell_command: true)
  end
end