Skip to content

Commit 207a7dc

Browse files
committed
Support pip freeze URL format
`pip freeze` (https://pip.pypa.io/en/stable/cli/pip_freeze/) "outputs installed packages in requirements format" (https://pip.pypa.io/en/stable/reference/requirement-specifiers/). As of pip 19.1, pip also supports specifying a requirement as a URL, and, for packages that were installed using URL format, `pip freeze` will output package requirements in URL format. However, Puppet's `pip freeze` parser doesn't support URL format, so it doesn't realize that a package is installed if it uses URL format, causing every `puppet agent` run to attempt to reinstall the package. This PR adds support for parsing `pip freeze` URL format.
1 parent d068941 commit 207a7dc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/puppet/provider/package/pip.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ def self.instances(target_command = nil)
101101

102102
# Parse lines of output from `pip freeze`, which are structured as:
103103
# _package_==_version_ or _package_===_version_
104+
# or _package_ @ someURL@_version_
104105
def self.parse(line)
105106
if line.chomp =~ /^([^=]+)===?([^=]+)$/
106107
{ :ensure => Regexp.last_match(2), :name => Regexp.last_match(1), :provider => name }
108+
elsif line.chomp =~ /^([^@]+) @ [^@]+@(.+)$/
109+
{ :ensure => Regexp.last_match(2), :name => Regexp.last_match(1), :provider => name }
107110
end
108111
end
109112

spec/unit/provider/package/pip_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
})
3939
end
4040

41+
it "should correctly parse URL format" do
42+
expect(described_class.parse("real_package @ git+https://github.com/example/test.git@6b4e203b66c1de7345984882e2b13bf87c700095")).to eq({
43+
:ensure => "6b4e203b66c1de7345984882e2b13bf87c700095",
44+
:name => "real_package",
45+
:provider => :pip,
46+
})
47+
end
48+
4149
it "should return nil on invalid input" do
4250
expect(described_class.parse("foo")).to eq(nil)
4351
end

0 commit comments

Comments
 (0)