Class: Dependabot::FileUpdaters::Python::Pip::SetupFileSanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/file_updaters/python/pip/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.



13
14
15
16
# File 'lib/dependabot/file_updaters/python/pip/setup_file_sanitizer.rb', line 13

def initialize(setup_file:, setup_cfg:)
  @setup_file = setup_file
  @setup_cfg = setup_cfg
end

Instance Method Details

#sanitized_contentObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dependabot/file_updaters/python/pip/setup_file_sanitizer.rb', line 18

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=\"sanitized-package\",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