lyp 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cd933e97beb1cd0fd6fbb50a34c2eead1141ef3
4
- data.tar.gz: b0a2289da1f2688a4b91fdeb619572c53b6aab17
3
+ metadata.gz: f05a307478b3335dc0caa9e0d687b73ec0a1f4f3
4
+ data.tar.gz: e6811cd8a83c6b05a068ac1b494c41cd0f023917
5
5
  SHA512:
6
- metadata.gz: ade7918db91666a7386a9d8b1fdd5f93a8347d30b08d0528faee0ca7d44c4347f4ae03f335f65941ba441a0b771c12ce383b4e0d06e57d3a06e2471f3f490e5d
7
- data.tar.gz: 53970054a2052fa366d1e9a7d28c5698167921a4b1666b622a8c325ce31c504ec38345858c7d295733805b9f714ce404bf28f56f113806a07d2b6600d755f12f
6
+ metadata.gz: 76e91e59d3b126e5e002d7ff0e2df0983a0c59ed72bffd444615fe35a811a8bae2a9e5768aebb5a82372cc245a93bc1bc85250354b79ea87a87f862952f5b0e4
7
+ data.tar.gz: 471fa1026b5a75d2f4de797117c0f5cfb37872e97ef72b67b7e5855ebc9960ba5c06741f2723f74c97761e9bc77b931173e2b0f963a121da6ddefe8cbdd036b2
data/lib/lyp/base.rb CHANGED
@@ -6,7 +6,7 @@ module Lyp
6
6
  # before the version number.
7
7
  #
8
8
  # Accepted operators: >=, ~>
9
- PACKAGE_RE = /^([^@\>~]+)(?:@?((?:\>=|~\>)?.+))?/
9
+ PACKAGE_RE = /^([^@\>~]+)(?:@)?((?:\>=|~\>)?.+)?/
10
10
  LILYPOND_RE = /^lilypond(?:@?((?:\>=|~\>)?.+))?/
11
11
 
12
12
  LYP_DIRECTORY = File.expand_path('~/.lyp')
data/lib/lyp/cli.rb CHANGED
@@ -113,9 +113,10 @@ class Lyp::CLI < Thor
113
113
  Lyp::Lilypond.compile(args)
114
114
  end
115
115
 
116
- desc "test [<option>...]", "Runs package tests on local directory"
116
+ desc "test [<option>...] [.|PATTERN]", "Runs package tests on installed packages or local directory"
117
117
  method_option :install, aliases: '-i', type: :boolean, desc: 'Install the requested version of lilypond if not present'
118
118
  method_option :env, aliases: '-e', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
119
+ method_option :all, aliases: '-a', type: :boolean, desc: ''
119
120
  def test(*args)
120
121
  $stderr.puts "Lyp #{Lyp::VERSION}"
121
122
 
@@ -129,11 +130,17 @@ class Lyp::CLI < Thor
129
130
  Lyp::Lilypond.check_lilypond!
130
131
  end
131
132
 
132
- Lyp::Package.run_tests('.')
133
+ case args
134
+ when ['.']
135
+ Lyp::Package.run_local_tests('.')
136
+ else
137
+ Lyp::Package.run_package_tests(args)
138
+ end
133
139
  end
134
140
 
135
141
  desc "install <PACKAGE|lilypond|self>...", "Install a package or a version of lilypond. When 'install self' is invoked, lyp installs itself in ~/.lyp."
136
142
  method_option :default, aliases: '-d', type: :boolean, desc: 'Set default lilypond version'
143
+ method_option :test, aliases: '-t', type: :boolean, desc: 'Run package tests after installation'
137
144
  def install(*args)
138
145
  raise "No package specified" if args.empty?
139
146
 
@@ -146,12 +153,13 @@ class Lyp::CLI < Thor
146
153
  Lyp::Lilypond.install($1, options)
147
154
  else
148
155
  Lyp::System.test_installed_status!
149
- Lyp::Package.install(package)
156
+ Lyp::Package.install(package, options)
150
157
  end
151
158
  end
152
159
  end
153
160
 
154
161
  desc "uninstall <PACKAGE|lilypond|self>...", "Uninstall a package or a version of lilypond. When 'uninstall self' is invoked, lyp uninstalls itself from ~/.lyp."
162
+ method_option :all, aliases: '-a', type: :boolean, desc: 'Uninstall all versions'
155
163
  def uninstall(*args)
156
164
  Lyp::System.test_installed_status!
157
165
 
@@ -165,7 +173,7 @@ class Lyp::CLI < Thor
165
173
  Lyp::Lilypond.uninstall($1)
166
174
  else
167
175
  Lyp::System.test_installed_status!
168
- Lyp::Package.uninstall(package)
176
+ Lyp::Package.uninstall(package, options)
169
177
  end
170
178
  end
171
179
  end
data/lib/lyp/lilypond.rb CHANGED
@@ -6,7 +6,7 @@ require 'ruby-progressbar'
6
6
  module Lyp::Lilypond
7
7
  class << self
8
8
  def compile(argv, opts = {})
9
- fn = Lyp.wrap(argv.pop)
9
+ fn = Lyp.wrap(argv.pop, opts)
10
10
  argv << fn
11
11
 
12
12
  invoke(argv, opts)
data/lib/lyp/package.rb CHANGED
@@ -74,6 +74,12 @@ module Lyp::Package
74
74
 
75
75
  puts "\nInstalled #{package}@#{info[:version]}\n\n" unless opts[:silent]
76
76
 
77
+ if opts[:test]
78
+ FileUtils.cd(info[:path]) do
79
+ run_tests(info[:path])
80
+ end
81
+ end
82
+
77
83
  # important: return the installed version
78
84
  info[:version]
79
85
  end
@@ -147,20 +153,38 @@ module Lyp::Package
147
153
  package !~ /\// ? package : package_git_url(package), nil
148
154
  )
149
155
 
150
- if opts[:all_versions]
156
+ if opts[:all]
151
157
  Dir["#{package_path}@*"].each do |path|
152
158
  name = path.gsub("#{Lyp.packages_dir}/", '')
153
159
  puts "Uninstalling #{name}" unless opts[:silent]
154
160
  FileUtils.rm_rf(path)
155
161
  end
156
162
  else
157
- package_path += "@#{version}"
163
+ if version
164
+ package_path += "@#{version}"
165
+ else
166
+ packages = Dir["#{package_path}@*"] + Dir["#{package_path}"]
167
+ case packages.size
168
+ when 0
169
+ raise "Could not find package #{package}"
170
+ when 1
171
+ package_path = packages[0]
172
+ else
173
+ packages.each do |path|
174
+ name = path.gsub("#{Lyp.packages_dir}/", '')
175
+ puts "Uninstalling #{name}" unless opts[:silent]
176
+ FileUtils.rm_rf(path)
177
+ end
178
+ return
179
+ end
180
+ end
181
+
158
182
  if File.directory?(package_path)
159
183
  name = package_path.gsub("#{Lyp.packages_dir}/", '')
160
184
  puts "Uninstalling #{name}" unless opts[:silent]
161
185
  FileUtils.rm_rf(package_path)
162
186
  else
163
- raise "Could not find #{package}"
187
+ raise "Could not find package #{package}"
164
188
  end
165
189
  end
166
190
  end
@@ -363,27 +387,62 @@ module Lyp::Package
363
387
  (tag =~ TAG_VERSION_RE) ? $1 : nil
364
388
  end
365
389
 
366
- def run_tests(dir, opts = {})
367
- t1 = Time.now
368
- test_count = 0
369
- fail_count = 0
370
-
371
- Dir["#{dir}/**/*_test.ly"].each do |fn|
372
- test_count += 1
373
-
374
- unless Lyp::Lilypond.compile([fn], mode: :system)
375
- fail_count += 1
390
+ # Runs all tests found in local directory
391
+ def run_local_tests(dir, opts = {})
392
+ package_dir = File.expand_path(dir)
393
+ test_files = Dir["#{package_dir}/**/*_test.ly"]
394
+ run_tests(opts) do |stats|
395
+ test_files.each do |f|
396
+ perform_test(f, stats)
376
397
  end
377
398
  end
399
+ end
400
+
401
+ # This method runs tests by yielding the test statistics.
402
+ # The caller should then call #perform_test to run each test file.
403
+ def run_tests(opts = {})
404
+ stats = {
405
+ start: Time.now,
406
+ test_count: 0,
407
+ fail_count: 0
408
+ }
378
409
 
379
- if test_count == 0
410
+ yield stats
411
+
412
+ if stats[:test_count] == 0
380
413
  STDERR.puts "No test files found"
381
414
  else
382
415
  puts "\nFinished in %.2g seconds\n%d files, %d failures" % [
383
- Time.now - t1, test_count, fail_count
416
+ Time.now - stats[:start], stats[:test_count], stats[:fail_count]
384
417
  ]
385
- exit(fail_count > 0 ? 1 : 0)
418
+ exit(stats[:fail_count] > 0 ? 1 : 0)
419
+ end
420
+ end
421
+
422
+ def perform_test(fn, stats)
423
+ stats[:test_count] += 1
424
+ unless Lyp::Lilypond.compile([fn], mode: :system, force_wrap: true)
425
+ stats[:fail_count] += 1
386
426
  end
387
427
  end
428
+
429
+
430
+ def run_package_tests(patterns)
431
+ patterns = [''] if patterns.empty?
432
+ packages = patterns.inject([]) do |m, pat|
433
+ m += Dir["#{Lyp.packages_dir}/#{pat}*"]
434
+ end.uniq
435
+
436
+ run_tests do |stats|
437
+ packages.each do |path|
438
+ files = Dir["#{path}/**/*_test.ly"]
439
+ next if files.empty?
440
+
441
+ FileUtils.cd(path) do
442
+ files.each {|fn| perform_test(fn, stats)}
443
+ end
444
+ end
445
+ end
446
+ end
388
447
  end
389
448
  end
data/lib/lyp/resolver.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  class Lyp::Resolver
2
- def initialize(user_file)
2
+ def initialize(user_file, opts = {})
3
3
  @user_file = user_file
4
+ @opts = opts
4
5
  end
5
6
 
6
7
  # Resolving package dependencies involves two stages:
@@ -108,7 +109,7 @@ class Lyp::Resolver
108
109
  return {} unless ref =~ Lyp::PACKAGE_RE
109
110
  ref_package = $1
110
111
  version_clause = $2
111
-
112
+
112
113
  matches = find_matching_packages(ref, tree)
113
114
 
114
115
  # Raise if no match found and we're at top of the tree
@@ -137,12 +138,17 @@ class Lyp::Resolver
137
138
 
138
139
  req_package = $1
139
140
  req_version = $2
140
- req = Gem::Requirement.new(req_version || '>=0')
141
141
 
142
+ req = nil
143
+ if @opts[:forced_package_paths] && @opts[:forced_package_paths][req_package]
144
+ req_version = 'forced'
145
+ end
146
+
147
+ req = Gem::Requirement.new(req_version || '>=0') rescue nil
142
148
  available_packages(tree).select do |package, sub_tree|
143
149
  if (package =~ Lyp::PACKAGE_RE) && (req_package == $1)
144
150
  version = Gem::Version.new($2 || '0') rescue nil
145
- if version.nil?
151
+ if version.nil? || req.nil?
146
152
  req_version.nil? || (req_version == $2)
147
153
  else
148
154
  req =~ version
@@ -163,14 +169,26 @@ class Lyp::Resolver
163
169
  # Return a hash of all packages found in the packages directory, creating a
164
170
  # leaf for each package
165
171
  def get_available_packages(dir)
166
- Dir["#{Lyp.packages_dir}/*"].inject({}) do |m, p|
167
- m[File.basename(p)] = {
172
+ forced_paths = @opts[:forced_package_paths] || {}
173
+
174
+ packages = Dir["#{Lyp.packages_dir}/*"].inject({}) do |m, p|
175
+ name = File.basename(p)
176
+
177
+ m[name] = {
168
178
  path: File.join(p, MAIN_PACKAGE_FILE),
169
- dependencies: {},
170
-
179
+ dependencies: {}
171
180
  }
172
181
  m
173
182
  end
183
+
184
+ forced_paths.each do |package, path|
185
+ packages["#{package}@forced"] = {
186
+ path: File.join(path, MAIN_PACKAGE_FILE),
187
+ dependencies: {}
188
+ }
189
+ end
190
+
191
+ packages
174
192
  end
175
193
 
176
194
  # Recursively remove any dependency for which no version is locally
@@ -391,7 +409,7 @@ class Lyp::Resolver
391
409
 
392
410
  map = lambda do |m, p|
393
411
  if p =~ Lyp::PACKAGE_RE
394
- m[$1] = versions[p] ||= Gem::Version.new($2 || '0.0')
412
+ m[$1] = versions[p] ||= (Gem::Version.new($2 || '0.0') rescue nil)
395
413
  end
396
414
  m
397
415
  end
@@ -12,6 +12,8 @@ require 'fileutils'
12
12
  user_filename = File.expand_path(_[:user_file])
13
13
  user_dirname = File.dirname(user_filename)
14
14
 
15
+ current_package_dir = _[:current_package_dir] || FileUtils.pwd
16
+
15
17
  # The wrapper defines a few global variables:
16
18
  #
17
19
  # lyp-input-filename - the absolute path to the input file name
@@ -28,7 +30,7 @@ user_dirname = File.dirname(user_filename)
28
30
  (define lyp-input-filename "{{user_filename}}")
29
31
  (define lyp-input-dirname "{{user_dirname}}")
30
32
  (define lyp-cwd "{{FileUtils.pwd}}")
31
- (define lyp-current-package-dir "")
33
+ (define lyp-current-package-dir "{{current_package_dir}}")
32
34
  (define lyp-package-refs (make-hash-table))`
33
35
 
34
36
  _[:package_paths].each do |spec, path|
@@ -107,6 +109,7 @@ pinclude = #(define-void-function (parser location path)(string?)
107
109
 
108
110
  # load the user's file
109
111
  `
112
+ #(ly:set-option 'relative-includes #t)
110
113
  #(ly:debug "package loader is ready")
111
114
  \include "{{user_filename}}"
112
115
  `
data/lib/lyp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lyp
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/lyp/wrapper.rb CHANGED
@@ -5,13 +5,15 @@ module Lyp
5
5
  File.expand_path('templates/deps_wrapper.rb', File.dirname(__FILE__))
6
6
  ))
7
7
 
8
- def self.wrap(fn)
8
+ def self.wrap(fn, opts = {})
9
9
  r = Lyp::Resolver.new(fn).resolve_package_dependencies
10
10
 
11
- unless r[:package_paths].empty?
11
+ # copy current_package_dir option
12
+ r[:current_package_dir] = opts[:current_package_dir]
13
+
14
+ if !r[:package_paths].empty? || opts[:force_wrap]
12
15
  FileUtils.mkdir_p('/tmp/lyp/wrappers')
13
16
  fn = "/tmp/lyp/wrappers/#{File.basename(fn)}"
14
- #Tempfile.new('lyp-deps-wrapper.ly').path
15
17
 
16
18
  File.open(fn, 'w+') {|f| f << WRAPPER_TEMPLATE.render(r)}
17
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline