lyp 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lyp/base.rb +6 -2
- data/lib/lyp/etc/lyp.ly +97 -0
- data/lib/lyp/lilypond.rb +7 -4
- data/lib/lyp/package.rb +7 -6
- data/lib/lyp/resolver.rb +61 -18
- data/lib/lyp/templates/deps_wrapper.rb +8 -83
- data/lib/lyp/version.rb +1 -1
- data/lib/lyp/wrapper.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be34fcbc627f99a4a4e3859e3c3629f69604a621
|
4
|
+
data.tar.gz: 7141ac8c3ec2d892218022810877584f05b2afb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bfb4b6e26d1b552613791a58bfdeb9a65c338cf62efaa0cce537361d06a6fbc0b65f2c8bc422242f8707061a7f3541898fcb6cdc7701f3c873d96b1affc9f8e
|
7
|
+
data.tar.gz: 66b0af75bb43ee1fca671ccd967ec046971320a28dc30d4c5ed71dc19b99ae59f5ee5f7974a43c505e6a6d88962374149f7f2a2483eb5882da4b136d20bd4f6b
|
data/lib/lyp/base.rb
CHANGED
@@ -21,9 +21,13 @@ module Lyp
|
|
21
21
|
|
22
22
|
# Font patch filename (required for 2.18.2 <= lilypond < 2.19.12)
|
23
23
|
FONT_PATCH_FILENAME = File.expand_path('etc/font.scm', File.dirname(__FILE__))
|
24
|
-
|
25
|
-
SETTINGS_FILENAME = 'settings.yml'
|
26
24
|
|
25
|
+
# etc/lyp.ly contains lyp:* procedure definitions for loading packages and
|
26
|
+
# other support code.
|
27
|
+
LYP_LY_LIB_PATH = File.expand_path('etc/lyp.ly', File.dirname(__FILE__))
|
28
|
+
|
29
|
+
SETTINGS_FILENAME = 'settings.yml'
|
30
|
+
|
27
31
|
def self.packages_dir
|
28
32
|
ensure_dir(DEFAULT_PACKAGE_DIRECTORY)
|
29
33
|
end
|
data/lib/lyp/etc/lyp.ly
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#(begin
|
2
|
+
; hash table mapping package refs to package names
|
3
|
+
(define lyp:package-refs (make-hash-table))
|
4
|
+
|
5
|
+
; hash table mapping package names to package directories
|
6
|
+
(define lyp:package-dirs (make-hash-table))
|
7
|
+
|
8
|
+
; hash table mapping package names to loaded state
|
9
|
+
(define lyp:package-loaded? (make-hash-table))
|
10
|
+
|
11
|
+
; hash table mapping file paths to included state
|
12
|
+
(define lyp:file-included? (make-hash-table))
|
13
|
+
|
14
|
+
; convert package ref to package name
|
15
|
+
(define (lyp:ref->name ref) (let* (
|
16
|
+
(clean-ref (car (string-split ref #\:)))
|
17
|
+
(name (hash-ref lyp:package-refs clean-ref))
|
18
|
+
)
|
19
|
+
(or name (throw 'lyp:failure "lyp:ref->name"
|
20
|
+
(format "Invalid package ref ~a" ref) #f))
|
21
|
+
))
|
22
|
+
|
23
|
+
; convert package reef to directory
|
24
|
+
(define (lyp:name->dir name) (let (
|
25
|
+
(dir (hash-ref lyp:package-dirs name))
|
26
|
+
)
|
27
|
+
(or dir (throw 'lyp-failure "lyp:name->dir"
|
28
|
+
(format "Invalid package name ~a" ref) #f))
|
29
|
+
))
|
30
|
+
|
31
|
+
; converts a package-relative path to absolute path. If the package is null,
|
32
|
+
; uses lyp:current-package-dir (which value is valid only on package loading)
|
33
|
+
(define (lyp:package-file-path package path) (let* (
|
34
|
+
(base-path (if (null? package)
|
35
|
+
lyp:current-package-dir (lyp:name->dir package)))
|
36
|
+
)
|
37
|
+
(string-append base-path "/" path)
|
38
|
+
))
|
39
|
+
|
40
|
+
; converts a package file reference to absolute path
|
41
|
+
(define (lyp:fileref->path ref) (let* (
|
42
|
+
(split (string-split ref #\:))
|
43
|
+
(qualified? (eq? (length split) 2))
|
44
|
+
(package (if qualified? (list-ref split 0) %nil))
|
45
|
+
(path (if qualified? (list-ref split 1) (list-ref split 0)))
|
46
|
+
)
|
47
|
+
(lyp:package-file-path package path)
|
48
|
+
))
|
49
|
+
|
50
|
+
(define (lyp:load ref) (load (lyp:fileref->path ref)))
|
51
|
+
|
52
|
+
(define (lyp:include-ly-file path once-only?) (let* (
|
53
|
+
(included? (and once-only? (hash-ref lyp:file-included? path)))
|
54
|
+
)
|
55
|
+
(if (not (file-exists? path))
|
56
|
+
(throw 'lyp:failure "lyp:include-ly-file"
|
57
|
+
(format "File not found ~a" path) #f)
|
58
|
+
)
|
59
|
+
(if (not included?) (begin
|
60
|
+
(hash-set! lyp:file-included? path #t)
|
61
|
+
#{ \include #path #}
|
62
|
+
))
|
63
|
+
))
|
64
|
+
|
65
|
+
(define (lyp:include ref)
|
66
|
+
(lyp:include-ly-file (lyp:fileref->path ref) #f))
|
67
|
+
(define (lyp:include-once ref)
|
68
|
+
(lyp:include-ly-file (lyp:fileref->path ref) #t))
|
69
|
+
|
70
|
+
(define (lyp:require ref) (let* (
|
71
|
+
(name (lyp:ref->name ref))
|
72
|
+
(package-dir (lyp:name->dir name))
|
73
|
+
(entry-point-path (string-append package-dir "/package.ly"))
|
74
|
+
(loaded? (hash-ref lyp:package-loaded? name))
|
75
|
+
(prev-package-dir lyp:current-package-dir)
|
76
|
+
)
|
77
|
+
(if (not loaded?) (begin
|
78
|
+
(ly:debug "Loading package ~a at ~a" name package-dir)
|
79
|
+
(set! lyp:current-package-dir package-dir)
|
80
|
+
(hash-set! lyp:package-loaded? name #t)
|
81
|
+
#{ \include #entry-point-path #}
|
82
|
+
(set! lyp:current-package-dir prev-package-dir)
|
83
|
+
))
|
84
|
+
))
|
85
|
+
)
|
86
|
+
|
87
|
+
% command form
|
88
|
+
require = #(define-void-function (parser location ref)(string?)
|
89
|
+
(lyp:require ref))
|
90
|
+
|
91
|
+
|
92
|
+
pinclude = #(define-void-function (parser location ref)(string?)
|
93
|
+
(lyp:include ref))
|
94
|
+
|
95
|
+
pincludeOnce = #(define-void-function (parser location ref)(string?)
|
96
|
+
(lyp:include-once ref))
|
97
|
+
|
data/lib/lyp/lilypond.rb
CHANGED
@@ -485,15 +485,18 @@ module Lyp::Lilypond
|
|
485
485
|
FileUtils.rm_rf(lilypond_dir)
|
486
486
|
end
|
487
487
|
|
488
|
-
def exec(cmd)
|
488
|
+
def exec(cmd, raise_on_failure = true)
|
489
|
+
success = nil
|
489
490
|
Open3.popen3(cmd) do |_in, _out, _err, wait_thr|
|
490
491
|
exit_value = wait_thr.value
|
491
492
|
$_out = _out.read
|
492
493
|
$_err = _err.read
|
493
|
-
|
494
|
-
|
495
|
-
|
494
|
+
success = exit_value == 0
|
495
|
+
end
|
496
|
+
if !success && raise_on_failure
|
497
|
+
raise "Error executing cmd #{cmd}: #{$_err}"
|
496
498
|
end
|
499
|
+
success
|
497
500
|
end
|
498
501
|
end
|
499
502
|
end
|
data/lib/lyp/package.rb
CHANGED
@@ -410,13 +410,15 @@ module Lyp::Package
|
|
410
410
|
yield stats
|
411
411
|
|
412
412
|
if stats[:test_count] == 0
|
413
|
-
STDERR.puts "No test files found"
|
413
|
+
STDERR.puts "No test files found" unless opts[:silent]
|
414
414
|
else
|
415
415
|
puts "\nFinished in %.2g seconds\n%d files, %d failures" % [
|
416
416
|
Time.now - stats[:start], stats[:test_count], stats[:fail_count]
|
417
|
-
|
418
|
-
exit(stats[:fail_count] > 0 ? 1 : 0)
|
417
|
+
] unless opts[:silent]
|
418
|
+
exit(stats[:fail_count] > 0 ? 1 : 0) unless opts[:dont_exit]
|
419
419
|
end
|
420
|
+
|
421
|
+
stats
|
420
422
|
end
|
421
423
|
|
422
424
|
def perform_test(fn, stats)
|
@@ -426,14 +428,13 @@ module Lyp::Package
|
|
426
428
|
end
|
427
429
|
end
|
428
430
|
|
429
|
-
|
430
|
-
def run_package_tests(patterns)
|
431
|
+
def run_package_tests(patterns, opts = {})
|
431
432
|
patterns = [''] if patterns.empty?
|
432
433
|
packages = patterns.inject([]) do |m, pat|
|
433
434
|
m += Dir["#{Lyp.packages_dir}/#{pat}*"]
|
434
435
|
end.uniq
|
435
436
|
|
436
|
-
run_tests do |stats|
|
437
|
+
run_tests(opts) do |stats|
|
437
438
|
packages.each do |path|
|
438
439
|
files = Dir["#{path}/**/*_test.ly"]
|
439
440
|
next if files.empty?
|
data/lib/lyp/resolver.rb
CHANGED
@@ -12,22 +12,27 @@ class Lyp::Resolver
|
|
12
12
|
|
13
13
|
definite_versions = resolve_tree(tree)
|
14
14
|
specifier_map = map_specifiers_to_versions(tree)
|
15
|
+
|
16
|
+
refs, dirs = {}, {}
|
17
|
+
definite_versions.each do |v|
|
18
|
+
package = v =~ Lyp::PACKAGE_RE && $1
|
15
19
|
|
20
|
+
specifier_map[package].each_key {|s| refs[s] = package}
|
21
|
+
dirs[package] = File.dirname(tree[:available_packages][v][:path])
|
22
|
+
end
|
23
|
+
|
16
24
|
{
|
17
25
|
user_file: @user_file,
|
18
26
|
definite_versions: definite_versions,
|
19
|
-
|
20
|
-
|
21
|
-
path = tree[:available_packages][v][:path]
|
22
|
-
specifier_map[package].each_key {|s| h[s] = path}
|
23
|
-
h
|
24
|
-
end
|
27
|
+
package_refs: refs,
|
28
|
+
package_dirs: dirs
|
25
29
|
}
|
26
30
|
end
|
27
31
|
|
28
|
-
DEP_RE = /\\(require|include|pinclude) "([^"]+)"/.freeze
|
32
|
+
DEP_RE = /\\(require|include|pinclude|pincludeOnce) "([^"]+)"/.freeze
|
29
33
|
INCLUDE = "include".freeze
|
30
34
|
PINCLUDE = "pinclude".freeze
|
35
|
+
PINCLUDE_ONCE = "pincludeOnce".freeze
|
31
36
|
REQUIRE = "require".freeze
|
32
37
|
|
33
38
|
# Each "leaf" on the dependency tree is a hash of the following structure:
|
@@ -80,13 +85,39 @@ class Lyp::Resolver
|
|
80
85
|
dir = File.dirname(path)
|
81
86
|
|
82
87
|
# Parse lilypond file for \include and \require
|
83
|
-
ly_content.scan(DEP_RE) do |type,
|
88
|
+
ly_content.scan(DEP_RE) do |type, ref|
|
84
89
|
case type
|
85
|
-
when INCLUDE, PINCLUDE
|
86
|
-
|
90
|
+
when INCLUDE, PINCLUDE, PINCLUDE_ONCE
|
91
|
+
# a package would normally use a plain \pinclude or \pincludeOnce
|
92
|
+
# command to include package files, e.g. \pinclude "inc/init.ly".
|
93
|
+
#
|
94
|
+
# But a package can also qualify the file reference with the package
|
95
|
+
# name, in order to be able to load files after the package has already
|
96
|
+
# been loaded, e.g. \pinclude "mypack:inc/init.ly"
|
97
|
+
if ref =~ /^([^\:]+)\:(.+)$/
|
98
|
+
# ignore null package (used for testing purposes only)
|
99
|
+
next if $1 == 'null'
|
100
|
+
ref = $2
|
101
|
+
end
|
102
|
+
qualified_path = File.expand_path(ref, dir)
|
87
103
|
queue_file_for_processing(qualified_path, tree, leaf)
|
88
104
|
when REQUIRE
|
89
|
-
|
105
|
+
forced_path = nil
|
106
|
+
if ref =~ /^([^\:]+)\:(.+)$/
|
107
|
+
ref = $1
|
108
|
+
forced_path = File.expand_path($2, dir)
|
109
|
+
end
|
110
|
+
|
111
|
+
ref =~ Lyp::PACKAGE_RE
|
112
|
+
package, version = $1, $2
|
113
|
+
next if package == 'null'
|
114
|
+
|
115
|
+
# set forced path if applicable
|
116
|
+
if forced_path
|
117
|
+
set_forced_package_path(tree, package, forced_path)
|
118
|
+
end
|
119
|
+
|
120
|
+
find_package_versions(ref, tree, leaf, opts)
|
90
121
|
end
|
91
122
|
end
|
92
123
|
|
@@ -166,11 +197,19 @@ class Lyp::Resolver
|
|
166
197
|
tree[:available_packages] ||= get_available_packages(Lyp.packages_dir)
|
167
198
|
end
|
168
199
|
|
200
|
+
def set_forced_package_path(tree, package, path)
|
201
|
+
@opts[:forced_package_paths] ||= {}
|
202
|
+
@opts[:forced_package_paths][package] = path
|
203
|
+
|
204
|
+
available_packages(tree)["#{package}@forced"] = {
|
205
|
+
path: File.join(path, MAIN_PACKAGE_FILE),
|
206
|
+
dependencies: {}
|
207
|
+
}
|
208
|
+
end
|
209
|
+
|
169
210
|
# Return a hash of all packages found in the packages directory, creating a
|
170
211
|
# leaf for each package
|
171
212
|
def get_available_packages(dir)
|
172
|
-
forced_paths = @opts[:forced_package_paths] || {}
|
173
|
-
|
174
213
|
packages = Dir["#{Lyp.packages_dir}/*"].inject({}) do |m, p|
|
175
214
|
name = File.basename(p)
|
176
215
|
|
@@ -181,11 +220,15 @@ class Lyp::Resolver
|
|
181
220
|
m
|
182
221
|
end
|
183
222
|
|
184
|
-
forced_paths
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
223
|
+
forced_paths = @opts[:forced_package_paths] || {}
|
224
|
+
|
225
|
+
if @opts[:forced_package_paths]
|
226
|
+
@opts[:forced_package_paths].each do |package, path|
|
227
|
+
packages["#{package}@forced"] = {
|
228
|
+
path: File.join(path, MAIN_PACKAGE_FILE),
|
229
|
+
dependencies: {}
|
230
|
+
}
|
231
|
+
end
|
189
232
|
end
|
190
233
|
|
191
234
|
packages
|
@@ -25,104 +25,29 @@ current_package_dir = _[:current_package_dir] || FileUtils.pwd
|
|
25
25
|
# lyp:file-included - a hash table for keeping track of include files
|
26
26
|
|
27
27
|
`
|
28
|
+
#(ly:set-option 'relative-includes #t)
|
29
|
+
\include "{{Lyp::LYP_LY_LIB_PATH}}"
|
30
|
+
|
28
31
|
#(begin
|
29
32
|
(define lyp:input-filename "{{user_filename}}")
|
30
33
|
(define lyp:input-dirname "{{user_dirname}}")
|
31
34
|
(define lyp:current-package-dir "{{current_package_dir}}")
|
32
|
-
|
35
|
+
`
|
33
36
|
|
34
|
-
_[:
|
37
|
+
_[:package_refs].each do |spec, path|
|
35
38
|
`
|
36
39
|
(hash-set! lyp:package-refs "{{spec}}" "{{path}}")`
|
37
40
|
end
|
38
41
|
|
39
|
-
|
40
|
-
# package is loaded only once.
|
41
|
-
|
42
|
-
# package-loaded is hash table used for tracking loaded packages, so each
|
43
|
-
# package is loaded only once.
|
44
|
-
|
45
|
-
`
|
46
|
-
(define lyp:package-loaded (make-hash-table))
|
47
|
-
(define lyp:file-included (make-hash-table))
|
48
|
-
)
|
49
|
-
`
|
50
|
-
|
51
|
-
# define the \require command for loading packages
|
52
|
-
`
|
53
|
-
require = #(define-void-function (parser location package)(string?)
|
54
|
-
(let*
|
55
|
-
(
|
56
|
-
(path (hash-ref lyp:package-refs package))
|
57
|
-
(loaded? (hash-ref lyp:package-loaded path))
|
58
|
-
(package-dir (dirname path))
|
59
|
-
(prev-package-dir lyp:current-package-dir)
|
60
|
-
)
|
61
|
-
(if (and path (not loaded?)) (begin
|
62
|
-
(if (not (file-exists? path)) (
|
63
|
-
(ly:error "Failed to load package ~a (file not found ~a)" package path)
|
64
|
-
))
|
65
|
-
(ly:debug "Loading package ~a at ~a" package package-dir)
|
66
|
-
(set! lyp:current-package-dir package-dir)
|
67
|
-
(hash-set! lyp:package-loaded path #t)
|
68
|
-
#{ \include #path #}
|
69
|
-
(set! lyp:current-package-dir prev-package-dir)
|
70
|
-
))
|
71
|
-
)
|
72
|
-
)
|
42
|
+
_[:package_dirs].each do |package, path|
|
73
43
|
`
|
44
|
+
(hash-set! lyp:package-dirs "{{package}}" "{{path}}")`
|
45
|
+
end
|
74
46
|
|
75
|
-
# define the \pinclude command for including files inside the current package
|
76
|
-
|
77
|
-
`
|
78
|
-
pinclude = #(define-void-function (parser location path)(string?)
|
79
|
-
(let*
|
80
|
-
(
|
81
|
-
(full-path (format "~a/~a" lyp:current-package-dir path))
|
82
|
-
)
|
83
|
-
(begin
|
84
|
-
(if (not (file-exists? full-path)) (
|
85
|
-
(ly:error "File not found ~a" full-path)
|
86
|
-
))
|
87
|
-
(hash-set! lyp:file-included full-path #t)
|
88
|
-
#{ \include #full-path #}
|
89
|
-
)
|
90
|
-
)
|
91
|
-
)
|
92
|
-
|
93
|
-
pincludeOnce = #(define-void-function (parser location path)(string?)
|
94
|
-
(let*
|
95
|
-
(
|
96
|
-
(full-path (format "~a/~a" lyp:current-package-dir path))
|
97
|
-
(loaded? (hash-ref lyp:file-included full-path))
|
98
|
-
)
|
99
|
-
(if (and full-path (not loaded?)) (begin
|
100
|
-
(if (not (file-exists? full-path)) (
|
101
|
-
(ly:error "File not found ~a" full-path)
|
102
|
-
))
|
103
|
-
(hash-set! lyp:file-included full-path #t)
|
104
|
-
#{ \include #full-path #}
|
105
|
-
))
|
106
|
-
)
|
107
|
-
)
|
108
|
-
`
|
109
47
|
|
110
|
-
# define the \pload scheme function, for loading scheme files inside the current
|
111
|
-
# package
|
112
48
|
`
|
113
|
-
#(define (pload path)
|
114
|
-
(let*
|
115
|
-
(
|
116
|
-
(full-path (format "~a/~a" lyp:current-package-dir path))
|
117
|
-
)
|
118
|
-
(load full-path)
|
119
|
-
)
|
120
49
|
)
|
121
|
-
`
|
122
50
|
|
123
|
-
# load the user's file
|
124
|
-
`
|
125
|
-
#(ly:set-option 'relative-includes #t)
|
126
51
|
#(ly:debug "package loader is ready")
|
127
52
|
\include "{{user_filename}}"
|
128
53
|
`
|
data/lib/lyp/version.rb
CHANGED
data/lib/lyp/wrapper.rb
CHANGED
@@ -11,7 +11,7 @@ module Lyp
|
|
11
11
|
# copy current_package_dir option
|
12
12
|
r[:current_package_dir] = opts[:current_package_dir]
|
13
13
|
|
14
|
-
if !r[:
|
14
|
+
if !r[:package_dirs].empty? || opts[:force_wrap]
|
15
15
|
FileUtils.mkdir_p('/tmp/lyp/wrappers')
|
16
16
|
fn = "/tmp/lyp/wrappers/#{File.basename(fn)}"
|
17
17
|
|
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.2.
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/lyp/base.rb
|
138
138
|
- lib/lyp/cli.rb
|
139
139
|
- lib/lyp/etc/font.scm
|
140
|
+
- lib/lyp/etc/lyp.ly
|
140
141
|
- lib/lyp/git_based_rugged.rb
|
141
142
|
- lib/lyp/lilypond.rb
|
142
143
|
- lib/lyp/package.rb
|