Skip to content

Commit

Permalink
Support pip freeze URL format
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
smokris committed Mar 3, 2024
1 parent d068941 commit 207a7dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/puppet/provider/package/pip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ def self.instances(target_command = nil)

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

Expand Down
8 changes: 8 additions & 0 deletions spec/unit/provider/package/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
})
end

it "should correctly parse URL format" do
expect(described_class.parse("real_package @ git+https://github.com/example/test.git@6b4e203b66c1de7345984882e2b13bf87c700095")).to eq({
:ensure => "6b4e203b66c1de7345984882e2b13bf87c700095",
:name => "real_package",
:provider => :pip,
})
end

it "should return nil on invalid input" do
expect(described_class.parse("foo")).to eq(nil)
end
Expand Down

0 comments on commit 207a7dc

Please sign in to comment.