Skip to content

Commit

Permalink
Load dependencies only when needed
Browse files Browse the repository at this point in the history
This in order to improve startup time.
  • Loading branch information
noteflakes committed Dec 4, 2016
1 parent a541b46 commit 9e65bab
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
31 changes: 20 additions & 11 deletions lib/lyp.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
def req(f); require File.expand_path("lyp/#{f}", File.dirname(__FILE__)) end
def req_int(f)
require File.expand_path("lyp/#{f}", File.dirname(__FILE__))
end

req 'base'
req 'system'
req 'settings'
module Kernel
@@ext_requires = {}
def req_ext(l)
@@ext_requires[l] ||= require(l)
end
end

req 'template'
req 'resolver'
req 'wrapper'
req 'package'
req 'lilypond'
req 'transform'
req_int 'base'
req_int 'system'
req_int 'settings'

req 'windows' if Lyp::WINDOWS
req_int 'template'
req_int 'resolver'
req_int 'wrapper'
req_int 'package'
req_int 'lilypond'
req_int 'transform'

req_int 'windows' if Lyp::WINDOWS
17 changes: 10 additions & 7 deletions lib/lyp/lilypond.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require 'uri'
require 'open3'
require 'ruby-progressbar'

module Lyp::Lilypond
class << self
NO_ARGUMENT_OPTIONS_REGEXP = /^\-([REnFOcSA]+)(.+)/
Expand Down Expand Up @@ -208,10 +204,14 @@ def select_default_lilypond!
end

def get_session_settings
YAML.load(IO.read(session_settings_filename)) rescue {}
req_ext('yaml')
settings = YAML.load(IO.read(session_settings_filename)) rescue {}
settings = {} unless settings.is_a?(Hash)
settings
end

def set_session_settings(settings)
req_ext('yaml')
File.open(session_settings_filename, 'w+') do |f|
f << YAML.dump(settings)
end
Expand Down Expand Up @@ -314,7 +314,7 @@ def get_system_lilyponds_paths

# Returns a list of versions of lilyponds available for download
def search(version_specifier = nil)
require 'open-uri'
req_ext 'open-uri'

platform = detect_lilypond_platform
url = "#{BASE_URL}/#{platform}/"
Expand Down Expand Up @@ -452,12 +452,14 @@ def lilypond_install_url(platform, version, opts)
end

def temp_install_filename(url)
req_ext('uri')
u = URI(url)
"#{Lyp::TMP_ROOT}/#{File.basename(u.path)}"
end

def download_lilypond(url, fn, opts)
require 'httpclient'
req_ext 'ruby-progressbar'
req_ext 'httpclient'

STDERR.puts "Downloading #{url}" unless opts[:silent]

Expand Down Expand Up @@ -700,6 +702,7 @@ def uninstall_lilypond_version(path)
end

def exec(cmd, raise_on_failure = true)
req_ext('open3')
$_out = ""
$_err = ""
success = nil
Expand Down
6 changes: 2 additions & 4 deletions lib/lyp/package.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require 'fileutils'
require 'open-uri'
require 'yaml'

module Lyp::Package
class << self

Expand Down Expand Up @@ -371,6 +367,8 @@ def list_lyp_index(pattern = nil)
end

def lyp_index
req_ext 'yaml'
req_ext 'open-uri'
@lyp_index ||= YAML.load(open(LYP_INDEX_URL))
end

Expand Down
6 changes: 4 additions & 2 deletions lib/lyp/settings.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'yaml'

module Lyp::Settings
class << self
def load
req_ext 'yaml'
@settings = YAML.load(IO.read(Lyp.settings_file)) rescue {}
end

def save
req_ext 'yaml'
File.open(Lyp.settings_file, 'w+') {|f| f << YAML.dump(@settings)}
end

Expand All @@ -33,11 +33,13 @@ def []=(path, value)
end

def get_value(path, default = nil)
req_ext 'yaml'
v = self[path]
v ? YAML.load(v) : default
end

def set_value(path, value)
req_ext 'yaml'
self[path] = YAML.dump(value)
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/lyp/system.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'fileutils'

module Lyp::System
class << self
RUGGED_REQ = Lyp.version_req('>=0.23.0')
Expand All @@ -26,7 +24,7 @@ def find_rugged_gem

def require_rugged_gem
gem 'rugged', RUGGED_REQ.to_s
require 'rugged'
req_ext 'rugged'
end

def use_git_based_rugged_gem
Expand Down
2 changes: 0 additions & 2 deletions lib/lyp/templates/deps_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
`
end

require 'fileutils'

user_filename = File.expand_path(_[:user_file])
user_dirname = File.dirname(user_filename)

Expand Down
2 changes: 0 additions & 2 deletions lib/lyp/transform.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'fileutils'

module Lyp::Transform
class << self
R = Lyp::DependencyResolver
Expand Down
2 changes: 0 additions & 2 deletions lib/lyp/wrapper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'tempfile'

module Lyp
WRAPPER_TEMPLATE = Lyp::Template.new(IO.read(
File.expand_path('templates/deps_wrapper.rb', File.dirname(__FILE__))
Expand Down

0 comments on commit 9e65bab

Please sign in to comment.