Class: Dependabot::Python::FileUpdater::SetupFileSanitizer

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/python/file_updater/setup_file_sanitizer.rb

Overview

Take a setup.py, parses it (carefully!) and then create a new, clean setup.py using only the information which will appear in the lockfile.

Instance Method Summary collapse

Constructor Details

#initialize(setup_file:, setup_cfg:) ⇒ SetupFileSanitizer

Returns a new instance of SetupFileSanitizer.



22
23
24
25
26
27
28
29
# File 'lib/dependabot/python/file_updater/setup_file_sanitizer.rb', line 22

def initialize(setup_file:, setup_cfg:)
  @setup_file = T.let(setup_file, T.nilable(Dependabot::DependencyFile))
  @setup_cfg = T.let(setup_cfg, T.nilable(Dependabot::DependencyFile))
  @install_requires_array = T.let(nil, T.nilable(T::Array[String]))
  @setup_requires_array = T.let(nil, T.nilable(T::Array[String]))
  @extras_require_hash = T.let(nil, T.nilable(T::Hash[String, T::Array[String]]))
  @parsed_setup_file = T.let(nil, T.nilable(Dependabot::FileParsers::Base::DependencySet))
end

Instance Method Details

#sanitized_contentObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/python/file_updater/setup_file_sanitizer.rb', line 32

def sanitized_content
  # The part of the setup.py that Pipenv cares about appears to be the
  # install_requires. A name and version are required by don't end up
  # in the lockfile.
  content =
    "from setuptools import setup\n\n" \
    "setup(name=\"#{package_name}\",version=\"0.0.1\"," \
    "install_requires=#{install_requires_array.to_json}," \
    "extras_require=#{extras_require_hash.to_json}"

  content += ',setup_requires=["pbr"],pbr=True' if include_pbr?
  content + ")"
end