Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Relax polisher dependencies, gracefully fail if deps are missing
Browse files Browse the repository at this point in the history
Now polisher gem contains minimal runtime deps w/ mechanism
to catch runtime load errors. Components missing reqs will
not be accessible / calling methods on them will indicate
to install optional dependencies
  • Loading branch information
movitto committed Apr 22, 2014
1 parent 97f9f48 commit b47b986
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 14 deletions.
3 changes: 0 additions & 3 deletions bin/git_gem_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
# Copyright (C) 2013-2014 Red Hat, Inc.

require 'colored'
require 'curb'
require 'json'
require 'optparse'
require 'nokogiri'

require 'polisher/git'
require 'polisher/gem'
Expand Down
11 changes: 11 additions & 0 deletions lib/polisher/errata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'json'
require 'curb'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Errata = Polisher::MissingComponent

else
require 'polisher/core'

module Polisher
Expand Down Expand Up @@ -73,3 +83,4 @@ def self.build_version(build, name)
end
end
end
end # (!skip_module)
12 changes: 12 additions & 0 deletions lib/polisher/fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'curb'
require 'pkgwat'
require 'nokogiri'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Fedora = Polisher::MissingComponent

else
require 'polisher/bodhi'

module Polisher
Expand Down Expand Up @@ -44,3 +55,4 @@ def self.versions_for(name, &bl)
end
end # class Fedora
end # module Polisher
end # (!skip_module)
11 changes: 11 additions & 0 deletions lib/polisher/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'curb'
require 'json'
require 'yaml'
Expand All @@ -12,7 +14,15 @@
require 'awesome_spawn'
require 'rubygems/installer'
require 'active_support/core_ext'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Gem = Polisher::MissingComponent

else
require 'polisher/version_checker'
require 'polisher/gem_cache'
require 'polisher/vendor'
Expand Down Expand Up @@ -310,3 +320,4 @@ def diff(other)

end # class Gem
end # module Polisher
end # (!skip_module)
11 changes: 11 additions & 0 deletions lib/polisher/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'bundler'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Gemfil = Polisher::MissingComponent

else
require 'polisher/git'
require 'polisher/gem'
require 'polisher/version_checker'
Expand Down Expand Up @@ -96,3 +106,4 @@ def patched
end
end # class Gemfile
end # module Polisher
end # (!skip_module)
13 changes: 12 additions & 1 deletion lib/polisher/git/pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'awesome_spawn'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Git::Pkg = Polisher::MissingComponent

else
require 'polisher/error'
require 'polisher/git/repo'
require 'polisher/rpm/spec'

module Polisher
module Git
# Git Repository
# Git Based Package
class Pkg < Repo
attr_accessor :name
attr_accessor :version
Expand Down Expand Up @@ -189,3 +199,4 @@ def self.version_for(name, &bl)
end # module Pkg
end # module Git
end # module Polisher
end # (!skip_module)
13 changes: 13 additions & 0 deletions lib/polisher/git/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'awesome_spawn'

rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Git::Repo = Polisher::MissingComponent

else
require 'polisher/core'
require 'polisher/git_cache'

Expand Down Expand Up @@ -72,3 +84,4 @@ def commit(msg)
end # class Repo
end # module Git
end # module Polisher
end # (!skip_module)
12 changes: 12 additions & 0 deletions lib/polisher/koji.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'xmlrpc/client'
require 'active_support/core_ext/kernel/reporting'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Koji = Polisher::MissingComponent

else
silence_warnings do
XMLRPC::Config::ENABLE_NIL_PARSER = true
XMLRPC::Config::ENABLE_NIL_CREATE = true
Expand Down Expand Up @@ -104,3 +115,4 @@ def self.diff(tag1, tag2)
end
end
end
end # (!skip_module)
12 changes: 12 additions & 0 deletions lib/polisher/missing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Polisher "Missing" Component
#
# Licensed under the MIT license
# Copyright (C) 2014 Red Hat, Inc.

module Polisher
class MissingComponent
def method_missing(method_id, *args, &bl)
raise "polisher is missing a dependency - cannot invoke #{method_id} on #{self}"
end
end # class MissingComponent
end # module Polisher
11 changes: 11 additions & 0 deletions lib/polisher/rpm/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'gem2rpm'
require 'versionomy'
require 'active_support/core_ext'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::RPM::Requirement = Polisher::MissingComponent

else
require 'polisher/core'
require 'polisher/gem'

Expand Down Expand Up @@ -186,3 +196,4 @@ def gem_name
end # class Requirement
end # module RPM
end
end # (!skip_module)
11 changes: 11 additions & 0 deletions lib/polisher/rpm/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'gem2rpm'
require 'versionomy'
require 'active_support/core_ext'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::RPM::Spec = Polisher::MissingComponent

else
require 'polisher/core'
require 'polisher/gem'
require 'polisher/rpm/requirement'
Expand Down Expand Up @@ -379,3 +389,4 @@ def compare(upstream_source)
end # class Spec
end # module RPM
end # module Polisher
end # (!skip_module)
11 changes: 11 additions & 0 deletions lib/polisher/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

skip_module = false
begin
require 'awesome_spawn'
rescue LoadError
skip_module = true
end

if skip_module
require 'polisher/missing'
Polisher::Yum = Polisher::MissingComponent

else
module Polisher
class Yum
YUM_CMD = '/usr/bin/yum'
Expand All @@ -28,3 +38,4 @@ def self.version_for(name, &bl)
end
end
end
end # (!skip_module)
19 changes: 9 additions & 10 deletions polisher.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ Gem::Specification.new do |s|
'git_gem_updater.rb', 'ruby_rpm_spec_updater.rb']
s.require_paths = ['lib']

# TODO tighten up deps, some may be optional
s.add_dependency('json')
s.add_dependency('curb')
s.add_dependency('activesupport')
s.add_dependency('i18n')
s.add_dependency('bundler')
s.add_dependency('pkgwat')
s.add_dependency('colored')
s.add_dependency('awesome_spawn')
s.add_dependency('gem2rpm')
s.add_dependency('versionomy')
s.add_development_dependency('rspec', '>= 2.0.0')
s.add_development_dependency('coveralls')
s.add_development_dependency('json')
s.add_development_dependency('curb')
s.add_development_dependency('activesupport')
s.add_development_dependency('i18n')
s.add_development_dependency('bundler')
s.add_development_dependency('pkgwat')
s.add_development_dependency('awesome_spawn')
s.add_development_dependency('gem2rpm')
s.add_development_dependency('versionomy')
end

0 comments on commit b47b986

Please sign in to comment.