lyp 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lilypond +4 -2
- data/lib/lyp/cli.rb +39 -31
- data/lib/lyp/lilypond.rb +106 -104
- data/lib/lyp/package.rb +88 -85
- data/lib/lyp/resolver.rb +487 -445
- data/lib/lyp/version.rb +1 -1
- data/lib/lyp/wrapper.rb +6 -6
- metadata +2 -2
data/lib/lyp/package.rb
CHANGED
@@ -4,12 +4,12 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
module Lyp::Package
|
6
6
|
class << self
|
7
|
-
|
7
|
+
|
8
8
|
def list(pattern = nil)
|
9
9
|
packages = Dir["#{Lyp.packages_dir}/**/package.ly"].map do |path|
|
10
10
|
File.dirname(path).gsub("#{Lyp.packages_dir}/", '')
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
if pattern
|
14
14
|
if (pattern =~ /[@\>\<\=\~]/) && (pattern =~ Lyp::PACKAGE_RE)
|
15
15
|
package, version = $1, $2
|
@@ -17,9 +17,9 @@ module Lyp::Package
|
|
17
17
|
packages.select! do |p|
|
18
18
|
p =~ Lyp::PACKAGE_RE
|
19
19
|
p_pack, p_ver = $1, $2
|
20
|
-
|
20
|
+
|
21
21
|
next false unless p_pack == package
|
22
|
-
|
22
|
+
|
23
23
|
if req && (p_gemver = Gem::Version.new(p_ver) rescue nil)
|
24
24
|
req =~ p_gemver
|
25
25
|
else
|
@@ -33,7 +33,7 @@ module Lyp::Package
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
packages.sort do |x, y|
|
38
38
|
x =~ Lyp::PACKAGE_RE; x_package, x_version = $1, $2
|
39
39
|
y =~ Lyp::PACKAGE_RE; y_package, y_version = $1, $2
|
@@ -48,29 +48,29 @@ module Lyp::Package
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def which(pattern = nil)
|
53
53
|
list(pattern).map {|p| "#{Lyp.packages_dir}/#{p}" }
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def install(package_specifier, opts = {})
|
57
57
|
unless package_specifier =~ Lyp::PACKAGE_RE
|
58
58
|
raise "Invalid package specifier #{package_specifier}"
|
59
59
|
end
|
60
60
|
package, version = $1, $2
|
61
|
-
|
61
|
+
|
62
62
|
if version =~ /\:/
|
63
63
|
info = install_from_local_files(package, version, opts)
|
64
64
|
else
|
65
65
|
info = install_from_repository(package, version, opts)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
install_package_dependencies(info[:path], opts)
|
69
|
-
|
69
|
+
|
70
70
|
if File.directory?(File.join(info[:path], 'fonts'))
|
71
71
|
install_package_fonts(info[:path], opts)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
unless opts[:silent]
|
75
75
|
if info[:local_path]
|
76
76
|
puts "\nInstalled #{package}@#{info[:version]} => #{info[:local_path]}\n\n"
|
@@ -78,24 +78,24 @@ module Lyp::Package
|
|
78
78
|
puts "\nInstalled #{package}@#{info[:version]}\n\n"
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
if opts[:test]
|
83
83
|
FileUtils.cd(info[:path]) do
|
84
84
|
run_tests(info[:path])
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
# important: return the installed version
|
89
89
|
info[:version]
|
90
90
|
end
|
91
|
-
|
92
|
-
LOCAL_PACKAGE_WRAPPER =
|
91
|
+
|
92
|
+
LOCAL_PACKAGE_WRAPPER =
|
93
93
|
"#(set! lyp:current-package-dir \"%s\")\n\\pinclude \"%s\"\n"
|
94
|
-
|
94
|
+
|
95
95
|
def install_from_local_files(package, version, opts)
|
96
96
|
version =~ /^([^\:]+)\:(.+)$/
|
97
97
|
version, local_path = $1, $2
|
98
|
-
|
98
|
+
|
99
99
|
entry_point_path = nil
|
100
100
|
local_path = File.expand_path(local_path)
|
101
101
|
if File.directory?(local_path)
|
@@ -110,11 +110,11 @@ module Lyp::Package
|
|
110
110
|
else
|
111
111
|
raise "Could not find #{local_path}"
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
entry_point_dirname = File.dirname(entry_point_path)
|
115
115
|
package_path = "#{Lyp.packages_dir}/#{package}@#{version}"
|
116
116
|
package_ly_path = "#{package_path}/package.ly"
|
117
|
-
|
117
|
+
|
118
118
|
FileUtils.rm_rf(package_path)
|
119
119
|
FileUtils.mkdir_p(package_path)
|
120
120
|
File.open(package_ly_path, 'w+') do |f|
|
@@ -122,12 +122,12 @@ module Lyp::Package
|
|
122
122
|
end
|
123
123
|
|
124
124
|
prepare_local_package_fonts(local_path, package_path)
|
125
|
-
|
125
|
+
|
126
126
|
load_package_ext_file("#{package}@#{version}", local_path)
|
127
|
-
|
127
|
+
|
128
128
|
{version: version, path: package_path, local_path: local_path}
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
def prepare_local_package_fonts(local_path, package_path)
|
132
132
|
# create fonts directory symlink if needed
|
133
133
|
fonts_path = File.join(local_path, 'fonts')
|
@@ -135,28 +135,28 @@ module Lyp::Package
|
|
135
135
|
FileUtils.ln_sf(fonts_path, File.join(package_path, 'fonts'))
|
136
136
|
end
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
def install_from_repository(package, version, opts)
|
140
140
|
url = package_git_url(package)
|
141
141
|
tmp_path = git_url_to_temp_path(url)
|
142
|
-
|
142
|
+
|
143
143
|
repo = package_repository(url, tmp_path, opts)
|
144
144
|
version = checkout_package_version(repo, version, opts)
|
145
|
-
|
145
|
+
|
146
146
|
# Copy files
|
147
147
|
package_path = git_url_to_package_path(
|
148
148
|
package !~ /\// ? package : url, version
|
149
149
|
)
|
150
|
-
|
150
|
+
|
151
151
|
FileUtils.mkdir_p(File.dirname(package_path))
|
152
152
|
FileUtils.rm_rf(package_path)
|
153
153
|
FileUtils.cp_r(tmp_path, package_path)
|
154
|
-
|
154
|
+
|
155
155
|
load_package_ext_file("#{package}@#{version}", package_path)
|
156
|
-
|
156
|
+
|
157
157
|
{version: version, path: package_path}
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
def load_package_ext_file(package, path)
|
161
161
|
ext_path = File.join(path, 'ext.rb')
|
162
162
|
if File.file?(ext_path)
|
@@ -165,7 +165,7 @@ module Lyp::Package
|
|
165
165
|
load_extension(ext_path)
|
166
166
|
end
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
def uninstall(package, opts = {})
|
170
170
|
unless package =~ Lyp::PACKAGE_RE
|
171
171
|
raise "Invalid package specifier #{package}"
|
@@ -174,14 +174,14 @@ module Lyp::Package
|
|
174
174
|
package_path = git_url_to_package_path(
|
175
175
|
package !~ /\// ? package : package_git_url(package), nil
|
176
176
|
)
|
177
|
-
|
177
|
+
|
178
178
|
if opts[:all]
|
179
179
|
Dir["#{package_path}@*"].each do |path|
|
180
180
|
name = path.gsub("#{Lyp.packages_dir}/", '')
|
181
181
|
puts "Uninstalling #{name}" unless opts[:silent]
|
182
182
|
FileUtils.rm_rf(path)
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
Dir["#{Lyp.ext_dir}/#{File.basename(package_path)}*.rb"].each do |path|
|
186
186
|
FileUtils.rm_f(path)
|
187
187
|
end
|
@@ -204,12 +204,12 @@ module Lyp::Package
|
|
204
204
|
return
|
205
205
|
end
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
if File.directory?(package_path)
|
209
209
|
name = package_path.gsub("#{Lyp.packages_dir}/", '')
|
210
210
|
puts "Uninstalling #{name}" unless opts[:silent]
|
211
211
|
FileUtils.rm_rf(package_path)
|
212
|
-
|
212
|
+
|
213
213
|
Dir["#{Lyp.ext_dir}/#{File.basename(package_path)}.rb"].each do |path|
|
214
214
|
FileUtils.rm_f(path)
|
215
215
|
end
|
@@ -218,10 +218,10 @@ module Lyp::Package
|
|
218
218
|
end
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
def package_repository(url, tmp_path, opts = {})
|
223
223
|
Lyp::System.test_rugged_gem!
|
224
|
-
|
224
|
+
|
225
225
|
# Create repository
|
226
226
|
if File.directory?(tmp_path)
|
227
227
|
begin
|
@@ -232,7 +232,7 @@ module Lyp::Package
|
|
232
232
|
# ignore and try to clone
|
233
233
|
end
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
FileUtils.rm_rf(File.dirname(tmp_path))
|
237
237
|
FileUtils.mkdir_p(File.dirname(tmp_path))
|
238
238
|
puts "Cloning #{url}..." unless opts[:silent]
|
@@ -240,46 +240,46 @@ module Lyp::Package
|
|
240
240
|
rescue => e
|
241
241
|
raise "Could not clone repository (please check that the package URL is correct.)"
|
242
242
|
end
|
243
|
-
|
243
|
+
|
244
244
|
def checkout_package_version(repo, version, opts = {})
|
245
245
|
# Select commit to checkout
|
246
246
|
checkout_ref = select_checkout_ref(repo, version)
|
247
247
|
unless checkout_ref
|
248
248
|
raise "Could not find tag matching #{version}"
|
249
249
|
end
|
250
|
-
|
250
|
+
|
251
251
|
begin
|
252
252
|
repo.checkout(checkout_ref, strategy: :force)
|
253
253
|
rescue
|
254
254
|
raise "Invalid version specified (#{version})"
|
255
255
|
end
|
256
|
-
|
256
|
+
|
257
257
|
tag_version(checkout_ref) || version
|
258
258
|
end
|
259
|
-
|
259
|
+
|
260
260
|
def install_package_dependencies(package_path, opts = {})
|
261
261
|
# Install any missing sub-dependencies
|
262
262
|
sub_deps = []
|
263
|
-
|
264
|
-
resolver = Lyp::
|
265
|
-
deps_tree = resolver.
|
266
|
-
deps_tree
|
267
|
-
sub_deps <<
|
263
|
+
|
264
|
+
resolver = Lyp::DependencyResolver.new("#{package_path}/package.ly")
|
265
|
+
deps_tree = resolver.compile_dependency_tree(ignore_missing: true)
|
266
|
+
deps_tree.dependencies.each do |package_name, spec|
|
267
|
+
sub_deps << spec.clause if spec.versions.empty?
|
268
268
|
end
|
269
269
|
sub_deps.each {|d| install(d, opts)}
|
270
270
|
end
|
271
271
|
|
272
272
|
SYSTEM_LILYPOND_PROMPT = <<-EOF.gsub(/^\s{6}/, '').chomp
|
273
|
-
Do you wish to install the package fonts on the system-installed lilypond
|
274
|
-
version %s (this might require sudo password)? (y/n):
|
273
|
+
Do you wish to install the package fonts on the system-installed lilypond
|
274
|
+
version %s (this might require sudo password)? (y/n):
|
275
275
|
EOF
|
276
|
-
|
276
|
+
|
277
277
|
def install_package_fonts(package_path, opts = {})
|
278
278
|
puts "Installing package fonts..." unless opts[:silent]
|
279
279
|
available_on_versions = []
|
280
|
-
|
280
|
+
|
281
281
|
req = Lyp::FONT_COPY_REQ
|
282
|
-
|
282
|
+
|
283
283
|
Lyp::Lilypond.list.each do |lilypond|
|
284
284
|
next unless req =~ Gem::Version.new(lilypond[:version])
|
285
285
|
|
@@ -289,7 +289,7 @@ module Lyp::Package
|
|
289
289
|
|
290
290
|
ly_fonts_dir = File.join(lilypond[:data_path], 'fonts')
|
291
291
|
package_fonts_dir = File.join(package_path, 'fonts')
|
292
|
-
|
292
|
+
|
293
293
|
if lilypond[:system]
|
294
294
|
if Lyp::Lilypond.patch_system_lilypond_font_scm(lilypond, opts)
|
295
295
|
available_on_versions << lilypond[:version]
|
@@ -297,15 +297,18 @@ module Lyp::Package
|
|
297
297
|
else
|
298
298
|
available_on_versions << lilypond[:version]
|
299
299
|
end
|
300
|
-
|
301
|
-
Dir["#{package_fonts_dir}
|
300
|
+
|
301
|
+
Dir["#{package_fonts_dir}/*/**"].each do |fn|
|
302
|
+
next unless File.file?(fn)
|
302
303
|
target_fn = case File.extname(fn)
|
303
304
|
when '.otf'
|
304
305
|
File.join(ly_fonts_dir, 'otf', File.basename(fn))
|
305
306
|
when '.svg', '.woff'
|
306
307
|
File.join(ly_fonts_dir, 'svg', File.basename(fn))
|
308
|
+
else
|
309
|
+
next
|
307
310
|
end
|
308
|
-
|
311
|
+
|
309
312
|
if File.writable?(File.dirname(target_fn))
|
310
313
|
FileUtils.cp(fn, target_fn)
|
311
314
|
else
|
@@ -319,7 +322,7 @@ module Lyp::Package
|
|
319
322
|
end
|
320
323
|
|
321
324
|
end
|
322
|
-
|
325
|
+
|
323
326
|
def package_git_url(package, search_index = true)
|
324
327
|
case package
|
325
328
|
when /^(?:(?:[^\:]+)|http|https)\:/
|
@@ -338,30 +341,30 @@ module Lyp::Package
|
|
338
341
|
end
|
339
342
|
end
|
340
343
|
end
|
341
|
-
|
344
|
+
|
342
345
|
LYP_INDEX_URL = "https://raw.githubusercontent.com/lyp-packages/index/master/index.yaml"
|
343
|
-
|
346
|
+
|
344
347
|
def search_lyp_index(package)
|
345
348
|
entry = lyp_index['packages'][package]
|
346
349
|
entry && entry['url']
|
347
350
|
end
|
348
|
-
|
351
|
+
|
349
352
|
def list_lyp_index(pattern = nil)
|
350
353
|
list = lyp_index['packages'].inject([]) do |m, kv|
|
351
354
|
m << kv[1].merge('name' => kv[0])
|
352
355
|
end
|
353
|
-
|
356
|
+
|
354
357
|
if pattern
|
355
358
|
list.select! {|p| p['name'] =~ /#{pattern}/}
|
356
359
|
end
|
357
|
-
|
360
|
+
|
358
361
|
list.sort_by {|p| p['name']}
|
359
362
|
end
|
360
|
-
|
363
|
+
|
361
364
|
def lyp_index
|
362
365
|
@lyp_index ||= YAML.load(open(LYP_INDEX_URL))
|
363
366
|
end
|
364
|
-
|
367
|
+
|
365
368
|
TEMP_REPO_ROOT_PATH = "#{Lyp::TMP_ROOT}/repos"
|
366
369
|
|
367
370
|
def git_url_to_temp_path(url)
|
@@ -376,10 +379,10 @@ module Lyp::Package
|
|
376
379
|
raise "Invalid URL #{url}"
|
377
380
|
end
|
378
381
|
end
|
379
|
-
|
382
|
+
|
380
383
|
def git_url_to_package_path(url, version)
|
381
384
|
# version = 'head' if version.nil? || (version == '')
|
382
|
-
|
385
|
+
|
383
386
|
package_path = case url
|
384
387
|
when /^(?:http|https)\:(?:\/\/)?(.+)$/
|
385
388
|
path = $1.gsub(/\.git$/, '')
|
@@ -394,13 +397,13 @@ module Lyp::Package
|
|
394
397
|
raise "Invalid URL #{url}"
|
395
398
|
end
|
396
399
|
end
|
397
|
-
|
400
|
+
|
398
401
|
package_path += "@#{version}" if version
|
399
402
|
package_path
|
400
403
|
end
|
401
|
-
|
404
|
+
|
402
405
|
TAG_VERSION_RE = /^v?(\d.*)$/
|
403
|
-
|
406
|
+
|
404
407
|
def select_checkout_ref(repo, version_specifier)
|
405
408
|
case version_specifier
|
406
409
|
when nil, '', 'latest'
|
@@ -419,17 +422,17 @@ module Lyp::Package
|
|
419
422
|
version_specifier
|
420
423
|
end
|
421
424
|
end
|
422
|
-
|
425
|
+
|
423
426
|
def highest_versioned_tag(repo)
|
424
427
|
tag = repo_tags(repo).select {|t| Gem::Version.new(tag_version(t.name)) rescue nil}.last
|
425
428
|
tag && tag.name
|
426
429
|
end
|
427
|
-
|
430
|
+
|
428
431
|
# Returns a list of tags sorted by version
|
429
432
|
def repo_tags(repo)
|
430
433
|
tags = []
|
431
434
|
repo.tags.each {|t| tags << t}
|
432
|
-
|
435
|
+
|
433
436
|
tags.sort do |x, y|
|
434
437
|
x_version, y_version = tag_version(x.name), tag_version(y.name)
|
435
438
|
if x_version && y_version
|
@@ -439,11 +442,11 @@ module Lyp::Package
|
|
439
442
|
end
|
440
443
|
end
|
441
444
|
end
|
442
|
-
|
445
|
+
|
443
446
|
def tag_version(tag)
|
444
447
|
(tag =~ TAG_VERSION_RE) ? $1 : nil
|
445
448
|
end
|
446
|
-
|
449
|
+
|
447
450
|
# Runs all tests found in local directory
|
448
451
|
def run_local_tests(dir, opts = {})
|
449
452
|
package_dir = File.expand_path(dir)
|
@@ -453,11 +456,11 @@ module Lyp::Package
|
|
453
456
|
end
|
454
457
|
end
|
455
458
|
end
|
456
|
-
|
459
|
+
|
457
460
|
def find_test_files(dir)
|
458
461
|
Dir["#{dir}/**/*_test.ly", "#{dir}/**/*-test.ly"]
|
459
462
|
end
|
460
|
-
|
463
|
+
|
461
464
|
# This method runs tests by yielding the test statistics.
|
462
465
|
# The caller should then call #perform_test to run each test file.
|
463
466
|
def run_tests(opts = {})
|
@@ -466,9 +469,9 @@ module Lyp::Package
|
|
466
469
|
test_count: 0,
|
467
470
|
fail_count: 0
|
468
471
|
}
|
469
|
-
|
472
|
+
|
470
473
|
yield stats
|
471
|
-
|
474
|
+
|
472
475
|
if stats[:test_count] == 0
|
473
476
|
STDERR.puts "No test files found" unless opts[:silent]
|
474
477
|
else
|
@@ -477,23 +480,23 @@ module Lyp::Package
|
|
477
480
|
] unless opts[:silent]
|
478
481
|
exit(stats[:fail_count] > 0 ? 1 : 0) unless opts[:dont_exit]
|
479
482
|
end
|
480
|
-
|
483
|
+
|
481
484
|
stats
|
482
485
|
end
|
483
|
-
|
486
|
+
|
484
487
|
def perform_test(fn, stats)
|
485
488
|
stats[:test_count] += 1
|
486
489
|
unless Lyp::Lilypond.compile([fn], mode: :system)
|
487
490
|
stats[:fail_count] += 1
|
488
491
|
end
|
489
492
|
end
|
490
|
-
|
493
|
+
|
491
494
|
def run_package_tests(patterns, opts = {})
|
492
495
|
patterns = [''] if patterns.empty?
|
493
496
|
packages = patterns.inject([]) do |m, pat|
|
494
497
|
m += Dir["#{Lyp.packages_dir}/#{pat}*"]
|
495
498
|
end.uniq
|
496
|
-
|
499
|
+
|
497
500
|
run_tests(opts) do |stats|
|
498
501
|
packages.each do |path|
|
499
502
|
files = find_test_files(path)
|
@@ -503,13 +506,13 @@ module Lyp::Package
|
|
503
506
|
files.each {|fn| perform_test(fn, stats)}
|
504
507
|
end
|
505
508
|
end
|
506
|
-
end
|
509
|
+
end
|
507
510
|
end
|
508
|
-
|
511
|
+
|
509
512
|
def load_all_extensions
|
510
513
|
Dir["#{Lyp.ext_dir}/*.rb"].each {|f| load_extension(f)}
|
511
514
|
end
|
512
|
-
|
515
|
+
|
513
516
|
def load_extension(path)
|
514
517
|
load(path)
|
515
518
|
rescue => e
|
@@ -526,4 +529,4 @@ module Lyp
|
|
526
529
|
|
527
530
|
FileUtils.cp(path, "#{Lyp.ext_dir}/#{$installed_package}.rb")
|
528
531
|
end
|
529
|
-
end
|
532
|
+
end
|