Skip to content

Commit

Permalink
Merge pull request #1413 from dependabot/fetch-setup-files-with-dir
Browse files Browse the repository at this point in the history
Python: Fetch path dependency files relative to directory they're required in
  • Loading branch information
rebelagentm authored Sep 30, 2019
2 parents 9e356bb + 0c85be1 commit 8352984
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
7 changes: 6 additions & 1 deletion python/lib/dependabot/python/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ def parse_path_setup_paths(req_file)
map(&:strip).
reject { |p| p.include?("://") || p.include?("git@") }

uneditable_reqs + editable_reqs
current_dir = File.dirname(req_file.name)

(uneditable_reqs + editable_reqs).map do |path|
path = File.join(current_dir, path) unless current_dir == "."
Pathname.new(path).cleanpath.to_path
end
end

def pipfile_path_setup_file_paths
Expand Down
26 changes: 22 additions & 4 deletions python/spec/dependabot/python/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,13 @@
headers: { "content-type" => "application/json" }
)
stub_request(:get, url + "more_requirements.txt?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
body: fixture("github", "requirements_content.json"),
headers: { "content-type" => "application/json" }
)
stub_request(:get, url + "no_dot/more_requirements.txt?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
Expand All @@ -865,26 +872,37 @@
),
headers: { "content-type" => "application/json" }
)
stub_request(:get, url + "no_dot/more_requirements.txt?ref=sha").
stub_request(:get, url + "comment_more_requirements.txt?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
body: fixture("github", "requirements_content.json"),
headers: { "content-type" => "application/json" }
)
stub_request(:get, url + "comment_more_requirements.txt?ref=sha").

stub_request(:get, url + "no_dot?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(status: 200, body: repo_contents, headers: json_header)
stub_request(:get, url + "no_dot/setup.py?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
body: fixture("github", "requirements_content.json"),
body: fixture("github", "setup_content.json"),
headers: { "content-type" => "application/json" }
)
stub_request(:get, url + "no_dot/setup.cfg?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(
status: 404,
body: fixture("github", "setup_content.json"),
headers: { "content-type" => "application/json" }
)
end

it "fetches the setup.py" do
expect(file_fetcher_instance.files.count).to eq(5)
expect(file_fetcher_instance.files.map(&:name)).
to include("setup.py")
to include("no_dot/setup.py")
end
end

Expand Down

0 comments on commit 8352984

Please sign in to comment.