[DRE-commits] [librarian-puppet] 22/153: Issue #234 Use organization-module instead organization/module

Stig Sandbeck Mathisen ssm at debian.org
Wed Jun 1 20:30:35 UTC 2016


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository librarian-puppet.

commit f83600242c6930af108b855ae8980b3c3a5c007a
Author: Carlos Sanchez <csanchez at maestrodev.com>
Date:   Thu Jul 10 09:44:01 2014 +0200

    Issue #234 Use organization-module instead organization/module
    
    It is the official naming based on http://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html
---
 Changelog.md                                      |  8 ++++++++
 README.md                                         | 22 ++++++++++----------
 features/install.feature                          |  1 +
 features/install/forge.feature                    | 18 +++++++++++++++-
 features/outdated.feature                         |  4 ++--
 features/update.feature                           | 25 ++++++++++++++++++++++-
 lib/librarian/puppet/extension.rb                 | 18 ++++++++++++++--
 lib/librarian/puppet/lockfile/parser.rb           |  8 +++++---
 lib/librarian/puppet/source/forge.rb              |  2 +-
 lib/librarian/puppet/source/forge/repo.rb         |  2 +-
 lib/librarian/puppet/source/forge/repo_v3.rb      |  4 ++--
 lib/librarian/puppet/source/githubtarball.rb      |  2 +-
 lib/librarian/puppet/source/githubtarball/repo.rb | 16 +++++++++------
 lib/librarian/puppet/source/local.rb              |  6 +++---
 lib/librarian/puppet/source/repo.rb               |  2 +-
 lib/librarian/puppet/templates/Puppetfile         |  8 ++++----
 lib/librarian/puppet/util.rb                      |  5 +++++
 17 files changed, 112 insertions(+), 39 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index fcb5580..ed5f8aa 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -2,6 +2,10 @@
 
 ## 1.1.x: Requires Ruby >= 1.9, uses Puppet Forge API v3
 
+### 1.1.3
+
+ * [Issue #234](https://github.com/rodjek/librarian-puppet/issues/234) Use organization-module instead of organization/module
+
 ### 1.1.2
 
  * [Issue #231](https://github.com/rodjek/librarian-puppet/issues/231) Only use the GITHUB_API_TOKEN if it's not empty
@@ -20,6 +24,10 @@
 
 ## 1.0.x: Works on Ruby 1.8, using Puppet Forge API v1
 
+### 1.0.5
+
+ * [Issue #234](https://github.com/rodjek/librarian-puppet/issues/234) Use organization-module instead of organization/module
+
 ### 1.0.4
 
  * [Issue #231](https://github.com/rodjek/librarian-puppet/issues/231) Only use the GITHUB_API_TOKEN if it's not empty
diff --git a/README.md b/README.md
index 6ac46ca..b7b83df 100644
--- a/README.md
+++ b/README.md
@@ -54,16 +54,16 @@ This Puppetfile will download all the dependencies listed in your Modulefile fro
 
     forge "https://forge.puppetlabs.com"
 
-    mod "puppetlabs/razor"
-    mod "puppetlabs/ntp", "0.0.3"
+    mod 'puppetlabs-razor'
+    mod 'puppetlabs-ntp', "0.0.3"
 
-    mod "puppetlabs/apt",
+    mod 'puppetlabs-apt',
       :git => "git://github.com/puppetlabs/puppetlabs-apt.git"
 
-    mod "puppetlabs/stdlib",
+    mod 'puppetlabs-stdlib',
       :git => "git://github.com/puppetlabs/puppetlabs-stdlib.git"
 
-    mod 'puppetlabs/apache', '0.6.0',
+    mod 'puppetlabs-apache', '0.6.0',
       :github_tarball => 'puppetlabs/puppetlabs-apache'
 
 
@@ -80,29 +80,29 @@ This declares that we want to use the official Puppet Labs Forge as our default
 source when pulling down modules.  If you run your own local forge, you may
 want to change this.
 
-    mod "puppetlabs/razor"
+    mod 'puppetlabs-razor'
 
 Pull in the latest version of the Puppet Labs Razor module from the default
 source.
 
-    mod "puppetlabs/ntp", "0.0.3"
+    mod 'puppetlabs-ntp', "0.0.3"
 
 Pull in version 0.0.3 of the Puppet Labs NTP module from the default source.
 
-    mod "puppetlabs/apt",
+    mod 'puppetlabs-apt',
       :git => "git://github.com/puppetlabs/puppetlabs-apt.git"
 
 Our puppet infrastructure repository depends on the `apt` module from the
 Puppet Labs GitHub repos and checks out the `master` branch.
 
-    mod "puppetlabs/apt",
+    mod 'puppetlabs-apt',
       :git => "git://github.com/puppetlabs/puppetlabs-apt.git",
       :ref => '0.0.3'
 
 Our puppet infrastructure repository depends on the `apt` module from the
 Puppet Labs GitHub repos and checks out a tag of `0.0.3`.
 
-    mod "puppetlabs/apt",
+    mod 'puppetlabs-apt',
       :git => "git://github.com/puppetlabs/puppetlabs-apt.git",
       :ref => 'feature/master/dans_refactor'
 
@@ -124,7 +124,7 @@ with many modules in it. If we need a module from such a repository, we can
 use the `:path =>` option here to help Librarian-puppet drill down and find the
 module subdirectory.
 
-    mod "puppetlabs/apt",
+    mod 'puppetlabs-apt',
       :git => "git://github.com/fake/puppet-modules.git",
       :path => "modules/apt"
 
diff --git a/features/install.feature b/features/install.feature
index dba98ab..3fbbf84 100644
--- a/features/install.feature
+++ b/features/install.feature
@@ -20,3 +20,4 @@ Feature: cli/install
     Then the exit status should be 0
     And the file "modules/stdlib/Modulefile" should match /version *'3\.0\.0'/
     And the output should not contain "Executing puppet module install for puppetlabs/stdlib"
+    And the output should not contain "Executing puppet module install for puppetlabs-stdlib"
diff --git a/features/install/forge.feature b/features/install/forge.feature
index bf02fb1..74b83aa 100644
--- a/features/install/forge.feature
+++ b/features/install/forge.feature
@@ -119,7 +119,7 @@ Feature: cli/install/forge
     Then the exit status should be 1
     And the output should match:
       """
-      Unable to find module 'puppetlabs/xxxxx' on http(s)?://forge(api)?.puppetlabs.com
+      Unable to find module 'puppetlabs-xxxxx' on http(s)?://forge(api)?.puppetlabs.com
       """
 
   Scenario: Install a module with conflicts
@@ -161,6 +161,22 @@ Feature: cli/install/forge
     Then the exit status should be 0
     And the file "modules/postgresql/Modulefile" should match /name *'puppetlabs-postgresql'/
 
+  Scenario: Source dependencies from Modulefile using dash instead of slash
+    Given a file named "Puppetfile" with:
+    """
+    forge "http://forge.puppetlabs.com"
+
+    modulefile
+    """
+    And a file named "Modulefile" with:
+    """
+    name "random name"
+    dependency "puppetlabs-postgresql", "2.4.1"
+    """
+    When I run `librarian-puppet install`
+    Then the exit status should be 0
+    And the file "modules/postgresql/Modulefile" should match /name *'puppetlabs-postgresql'/
+
   Scenario: Installing a module with duplicated dependencies
     Given a file named "Puppetfile" with:
     """
diff --git a/features/outdated.feature b/features/outdated.feature
index 3fae18f..2db9db8 100644
--- a/features/outdated.feature
+++ b/features/outdated.feature
@@ -22,7 +22,7 @@ Feature: cli/outdated
     Then the exit status should be 0
     And the output should match:
     """
-    ^puppetlabs/stdlib \(3\.1\.0 -> [\.\d]+\)$
+    ^puppetlabs-stdlib \(3\.1\.0 -> [\.\d]+\)$
     """
 
   Scenario: Running outdated with git modules
@@ -55,6 +55,6 @@ Feature: cli/outdated
     Then the exit status should be 0
     And PENDING the output should match:
     # """
-    # ^puppetlabs/stdlib \(3\.1\.0 -> [\.\d]+\)$
+    # ^puppetlabs-stdlib \(3\.1\.0 -> [\.\d]+\)$
     # ^test .*$
     # """
diff --git a/features/update.feature b/features/update.feature
index 3107036..576196d 100644
--- a/features/update.feature
+++ b/features/update.feature
@@ -18,7 +18,30 @@ Feature: cli/update
     DEPENDENCIES
       puppetlabs/stdlib (~> 3.0)
     """
-    When I run `librarian-puppet update puppetlabs/stdlib`
+    When I run `librarian-puppet update puppetlabs-stdlib`
+    Then the exit status should be 0
+    And the file "Puppetfile.lock" should match /puppetlabs.stdlib \(3\.1\.1\)/
+    And the file "modules/stdlib/Modulefile" should match /name *'puppetlabs-stdlib'/
+    And the file "modules/stdlib/Modulefile" should match /version *'3\.1\.1'/
+
+  Scenario: Updating a module using organization/module
+    Given a file named "Puppetfile" with:
+    """
+    forge "http://forge.puppetlabs.com"
+
+    mod 'puppetlabs/stdlib', '3.1.x'
+    """
+    And a file named "Puppetfile.lock" with:
+    """
+    FORGE
+      remote: http://forge.puppetlabs.com
+      specs:
+        puppetlabs/stdlib (3.1.0)
+
+    DEPENDENCIES
+      puppetlabs/stdlib (~> 3.0)
+    """
+    When I run `librarian-puppet update --verbose puppetlabs/stdlib`
     Then the exit status should be 0
     And the file "Puppetfile.lock" should match /puppetlabs.stdlib \(3\.1\.1\)/
     And the file "modules/stdlib/Modulefile" should match /name *'puppetlabs-stdlib'/
diff --git a/lib/librarian/puppet/extension.rb b/lib/librarian/puppet/extension.rb
index 1654d79..bda6d21 100644
--- a/lib/librarian/puppet/extension.rb
+++ b/lib/librarian/puppet/extension.rb
@@ -8,6 +8,19 @@ module Librarian
   end
 
   class Dependency
+    include Librarian::Puppet::Util
+
+    def initialize(name, requirement, source)
+      assert_name_valid! name
+
+      # let's settle on provider-module syntax instead of provider/module
+      self.name = normalize_name(name)
+      self.requirement = Requirement.new(requirement)
+      self.source = source
+
+      @manifests = nil
+    end
+
     class Requirement
       def initialize(*args)
         args = initialize_normalize_args(args)
@@ -84,6 +97,8 @@ module Librarian
   end
 
   class ManifestSet
+    include Librarian::Puppet::Util
+
     private
 
     # Check if module doesn't exist and fail fast
@@ -93,7 +108,7 @@ module Librarian
 
       deps = Set.new
       until names.empty?
-        name = names.shift
+        name = normalize_name(names.shift)
         next if deps.include?(name)
 
         deps << name
@@ -105,7 +120,6 @@ module Librarian
   end
 
   class Manifest
-
     class PreReleaseVersion
 
       # Compares pre-release component ids using Semver 2.0.0 spec
diff --git a/lib/librarian/puppet/lockfile/parser.rb b/lib/librarian/puppet/lockfile/parser.rb
index 3ed5aeb..c25e8b2 100644
--- a/lib/librarian/puppet/lockfile/parser.rb
+++ b/lib/librarian/puppet/lockfile/parser.rb
@@ -5,6 +5,7 @@ require 'librarian/manifest_set'
 module Librarian
   class Lockfile
     class Parser
+      include Librarian::Puppet::Util
 
       def parse(string)
         string = string.dup
@@ -26,8 +27,8 @@ module Librarian
           manifests = {}
           while lines.first =~ /^ {4}([\w\-\/]+) \((.*)\)$/ # This change allows forward slash
             lines.shift
-            name = $1
-            manifests[name] = {:version => $2, :dependencies => {}}
+            name, version = normalize_name($1), $2
+            manifests[name] = {:version => version, :dependencies => {}}
             while lines.first =~ /^ {6}([\w\-\/]+) \((.*)\)$/
               lines.shift
               manifests[name][:dependencies][$1] = $2.split(/,\s*/)
@@ -42,9 +43,10 @@ module Librarian
         dependencies = []
         while lines.first =~ /^ {2}([\w\-\/]+)(?: \((.*)\))?$/ # This change allows forward slash
           lines.shift
-          name, requirement = $1, $2.split(/,\s*/)
+          name, requirement = normalize_name($1), $2.split(/,\s*/)
           dependencies << Dependency.new(name, requirement, manifests_index[name].source)
         end
+
         Resolution.new(dependencies, manifests)
       end
 
diff --git a/lib/librarian/puppet/source/forge.rb b/lib/librarian/puppet/source/forge.rb
index 419131f..59c3926 100644
--- a/lib/librarian/puppet/source/forge.rb
+++ b/lib/librarian/puppet/source/forge.rb
@@ -121,7 +121,7 @@ module Librarian
         end
 
         def install_path(name)
-          environment.install_path.join(name.split('/').last)
+          environment.install_path.join(name.split('-').last)
         end
 
         def fetch_version(name, version_uri)
diff --git a/lib/librarian/puppet/source/forge/repo.rb b/lib/librarian/puppet/source/forge/repo.rb
index 186c2c5..55837b1 100644
--- a/lib/librarian/puppet/source/forge/repo.rb
+++ b/lib/librarian/puppet/source/forge/repo.rb
@@ -59,7 +59,7 @@ module Librarian
               install_path.rmtree
             end
 
-            unpacked_path = version_unpacked_cache_path(version).join(name.split('/').last)
+            unpacked_path = version_unpacked_cache_path(version).join(name.split('-').last)
 
             unless unpacked_path.exist?
               raise Error, "#{unpacked_path} does not exist, something went wrong. Try removing it manually"
diff --git a/lib/librarian/puppet/source/forge/repo_v3.rb b/lib/librarian/puppet/source/forge/repo_v3.rb
index 3025d89..de9b2f8 100644
--- a/lib/librarian/puppet/source/forge/repo_v3.rb
+++ b/lib/librarian/puppet/source/forge/repo_v3.rb
@@ -25,7 +25,7 @@ module Librarian
             else
               # should never get here as we use one repo object for each module (to be changed in the future)
               debug { "Looking up url for #{name}@#{version}" }
-              release = PuppetForge::Release.find("#{name.sub('/','-')}-#{version}")
+              release = PuppetForge::Release.find("#{name}-#{version}")
             end
             "#{source}#{release.file_uri}"
           end
@@ -33,7 +33,7 @@ module Librarian
         private
 
           def get_module
-            @module ||= PuppetForge::Module.find(name.sub('/','-'))
+            @module ||= PuppetForge::Module.find(name)
             raise(Error, "Unable to find module '#{name}' on #{source}") unless @module
             @module
           end
diff --git a/lib/librarian/puppet/source/githubtarball.rb b/lib/librarian/puppet/source/githubtarball.rb
index 2e720fc..7b6fc2a 100644
--- a/lib/librarian/puppet/source/githubtarball.rb
+++ b/lib/librarian/puppet/source/githubtarball.rb
@@ -98,7 +98,7 @@ module Librarian
         end
 
         def install_path(name)
-          environment.install_path.join(name.split('/').last)
+          environment.install_path.join(name.split('-').last)
         end
 
         def fetch_version(name, version_uri)
diff --git a/lib/librarian/puppet/source/githubtarball/repo.rb b/lib/librarian/puppet/source/githubtarball/repo.rb
index d9e61c7..09a62c6 100644
--- a/lib/librarian/puppet/source/githubtarball/repo.rb
+++ b/lib/librarian/puppet/source/githubtarball/repo.rb
@@ -40,11 +40,11 @@ module Librarian
           end
 
           def install_version!(version, install_path)
-            if environment.local? && !vendored?(source.uri.to_s, version)
+            if environment.local? && !vendored?(vendored_name, version)
               raise Error, "Could not find a local copy of #{source.uri} at #{version}."
             end
 
-            vendor_cache(source.uri.to_s, version) unless vendored?(source.uri.to_s, version)
+            vendor_cache(source.uri.to_s, version) unless vendored?(vendored_name, version)
 
             cache_version_unpacked! version
 
@@ -62,19 +62,19 @@ module Librarian
 
             path.mkpath
 
-            target = vendored?(source.uri.to_s, version) ? vendored_path(source.uri.to_s, version) : name
+            target = vendored?(vendored_name, version) ? vendored_path(vendored_name, version) : name
 
             Librarian::Posix.run!(%W{tar xzf #{target} -C #{path}})
           end
 
           def vendor_cache(name, version)
-            clean_up_old_cached_versions(name)
+            clean_up_old_cached_versions(vendored_name(name))
 
             url = "https://api.github.com/repos/#{name}/tarball/#{version}"
             add_api_token_to_url(url)
 
             environment.vendor!
-            File.open(vendored_path(name, version).to_s, 'wb') do |f|
+            File.open(vendored_path(vendored_name(name), version).to_s, 'wb') do |f|
               begin
                 debug { "Downloading <#{url}> to <#{f.path}>" }
                 open(url,
@@ -90,7 +90,7 @@ module Librarian
           end
 
           def clean_up_old_cached_versions(name)
-            Dir["#{environment.vendor_cache}/#{name.sub('/', '-')}*.tar.gz"].each do |old_version|
+            Dir["#{environment.vendor_cache}/#{name}*.tar.gz"].each do |old_version|
               FileUtils.rm old_version
             end
           end
@@ -159,6 +159,10 @@ module Librarian
             options[:headers].each { |k, v| request.add_field k, v }
             http.request(request)
           end
+
+          def vendored_name(name = source.uri.to_s)
+            name.sub('/','-')
+          end
         end
       end
     end
diff --git a/lib/librarian/puppet/source/local.rb b/lib/librarian/puppet/source/local.rb
index 2662f65..abfee66 100644
--- a/lib/librarian/puppet/source/local.rb
+++ b/lib/librarian/puppet/source/local.rb
@@ -26,11 +26,11 @@ module Librarian
           found_path = found_path(name)
           raise Error, "Path for #{name} doesn't contain a puppet module" if found_path.nil?
 
-          unless name.include? '/'
-            warn { "Invalid module name '#{name}', you should qualify it with 'ORGANIZATION/#{name}' for resolution to work correctly" }
+          unless name.include? '/' or name.include? '-'
+            warn { "Invalid module name '#{name}', you should qualify it with 'ORGANIZATION-#{name}' for resolution to work correctly" }
           end
 
-          install_path = environment.install_path.join(name.split('/').last)
+          install_path = environment.install_path.join(name.split('-').last)
           if install_path.exist?
             debug { "Deleting #{relative_path_to(install_path)}" }
             install_path.rmtree
diff --git a/lib/librarian/puppet/source/repo.rb b/lib/librarian/puppet/source/repo.rb
index 8c9dc26..0a32b05 100644
--- a/lib/librarian/puppet/source/repo.rb
+++ b/lib/librarian/puppet/source/repo.rb
@@ -29,7 +29,7 @@ module Librarian
         end
 
         def vendored_path(name, version)
-          environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz")
+          environment.vendor_cache.join("#{name}-#{version}.tar.gz")
         end
 
       end
diff --git a/lib/librarian/puppet/templates/Puppetfile b/lib/librarian/puppet/templates/Puppetfile
index 09c6b07..8148f47 100644
--- a/lib/librarian/puppet/templates/Puppetfile
+++ b/lib/librarian/puppet/templates/Puppetfile
@@ -7,16 +7,16 @@ forge "https://forgeapi.puppetlabs.com"
 modulefile
 
 # A module from the Puppet Forge
-# mod 'puppetlabs/stdlib'
+# mod 'puppetlabs-stdlib'
 
 # A module from git
-# mod 'puppetlabs/ntp',
+# mod 'puppetlabs-ntp',
 #   :git => 'git://github.com/puppetlabs/puppetlabs-ntp.git'
 
 # A module from a git branch/tag
-# mod 'puppetlabs/apt',
+# mod 'puppetlabs-apt',
 #   :git => 'https://github.com/puppetlabs/puppetlabs-apt.git',
 #   :ref => '1.4.x'
 
 # A module from Github pre-packaged tarball
-# mod 'puppetlabs/apache', '0.6.0', :github_tarball => 'puppetlabs/puppetlabs-apache'
+# mod 'puppetlabs-apache', '0.6.0', :github_tarball => 'puppetlabs/puppetlabs-apache'
diff --git a/lib/librarian/puppet/util.rb b/lib/librarian/puppet/util.rb
index 57833af..b251719 100644
--- a/lib/librarian/puppet/util.rb
+++ b/lib/librarian/puppet/util.rb
@@ -33,6 +33,11 @@ module Librarian
         new_uri.password = nil
         new_uri
       end
+
+      # normalize module name to use organization-module instead of organization/module
+      def normalize_name(name)
+        name.sub('/','-')
+      end
     end
   end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git



More information about the Pkg-ruby-extras-commits mailing list