lyp 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f4c3096919de344328ca239c4c6b2a779a292d6
4
- data.tar.gz: 1ba4797c5d48dc6fb6643f6860d152580e922c4b
3
+ metadata.gz: ec8334dffcd62c410ebf9f6630d95b9d980e0ad9
4
+ data.tar.gz: 5aa416050909fc3b7c628e799390f94a977609d0
5
5
  SHA512:
6
- metadata.gz: 6a1d79624bd39b291ef44d5fe7c1e08b9cffbd71a1dd5e7f5dedf37b05f2ad11eba83910bb93dcaaf877633a02dd12da7f9dbfd388ff2eee5465d8735e4fffae
7
- data.tar.gz: 183a7c869054c9d4c03ff73ec4f61056c6cfdf496542fe09aeb94b7012b0cdb084620e9c22f4e3405f99884827bdf04da35847fefadfe63842c338fd79b31366
6
+ metadata.gz: 2e400ff952e684c0e8ba9da536e80ee015eebe742858a83c9ff9fbf4706c14b2b233881166f22fd7f63a3e17c03b6062c141942267edd8a3d0cdbf318c76375b
7
+ data.tar.gz: 5c7632c1626e763ac4463b0c3ad66cc78386eba95933511a213b8f3e7267924201514a3fcca2467656e47b53857f7e3e8652eacb0e294402d894bd0b9f364a7c
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
+ LYP_VERSION="0.3.3"
4
+ WORKDIR="/tmp/lyp-release-installer"
5
+ URL_BASE="https://github.com/noteflakes/lyp/releases/download/v$LYP_VERSION"
6
+
3
7
  shopt -s extglob
4
8
  set -o errtrace
5
9
  set -o errexit
@@ -17,10 +21,6 @@ download() {
17
21
  fi
18
22
  }
19
23
 
20
- WORKDIR="/tmp/lyp-release-installer"
21
- LYP_VERSION="0.3.1"
22
- URL_BASE="https://github.com/noteflakes/lyp/releases/download/v$LYP_VERSION"
23
-
24
24
  PLATFORM=`uname -sp`
25
25
  case $PLATFORM in
26
26
  "Linux x86_64")
data/bin/lilypond CHANGED
@@ -29,7 +29,7 @@ def process_argv
29
29
  argv_clean << arg
30
30
  end
31
31
  end
32
-
32
+
33
33
  [options, argv_clean]
34
34
  end
35
35
  $options, $argv = process_argv
@@ -55,7 +55,7 @@ end
55
55
  $lilypond_path = get_lilypond_path
56
56
 
57
57
  if $options[:raw]
58
- exec("#{$lilypond_path} #{$argv[1..-1].join(' ')}")
58
+ exec("#{$lilypond_path} #{$argv.join(' ')}")
59
59
  end
60
60
 
61
61
  OVERRIDING_LILYPOND_SWITCHES = %w{
@@ -78,7 +78,7 @@ case $argv.first
78
78
  when nil, *OVERRIDING_LILYPOND_SWITCHES
79
79
  STDERR.puts "Lyp version #{Lyp::VERSION}"
80
80
  exec("#{$lilypond_path} #{$argv.join(' ')}")
81
-
81
+
82
82
  when *LILYPOND_HELP_SWITCHES
83
83
  STDERR.puts "Lyp version #{Lyp::VERSION}"
84
84
  puts `#{$lilypond_path} #{$argv.join(' ')}`
data/bin/lyp CHANGED
@@ -3,4 +3,7 @@
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
4
4
 
5
5
  require 'lyp'
6
- require 'lyp/cli'
6
+ require 'lyp/cli'
7
+
8
+ Lyp::Package.load_all_extensions
9
+ Lyp::CLI.run
data/lib/lyp/base.rb CHANGED
@@ -17,6 +17,7 @@ module Lyp
17
17
  LYP_DIRECTORY = File.expand_path('~/.lyp')
18
18
  LYP_BIN_DIRECTORY = File.join(LYP_DIRECTORY, 'bin')
19
19
  LYP_LIB_DIRECTORY = File.join(LYP_DIRECTORY, 'lib')
20
+ LYP_EXT_DIRECTORY = File.join(LYP_DIRECTORY, 'ext')
20
21
  DEFAULT_PACKAGE_DIRECTORY = File.join(LYP_DIRECTORY, 'packages')
21
22
  DEFAULT_LILYPONDS_DIRECTORY = File.join(LYP_DIRECTORY, 'lilyponds')
22
23
 
@@ -42,6 +43,10 @@ module Lyp
42
43
  def self.lilyponds_dir
43
44
  ensure_dir(DEFAULT_LILYPONDS_DIRECTORY)
44
45
  end
46
+
47
+ def self.ext_dir
48
+ ensure_dir(LYP_EXT_DIRECTORY)
49
+ end
45
50
 
46
51
  def self.settings_file
47
52
  ensure_dir(LYP_DIRECTORY)
data/lib/lyp/cli.rb CHANGED
@@ -64,7 +64,7 @@ class Lyp::CLI < Thor
64
64
  else
65
65
  search_package(pattern)
66
66
  end
67
- end
67
+ end
68
68
 
69
69
  no_commands do
70
70
  def search_lilypond(version)
@@ -303,12 +303,13 @@ class Lyp::CLI < Thor
303
303
  end
304
304
  end
305
305
  end
306
+
307
+ def self.run
308
+ start(ARGV)
309
+ rescue => e
310
+ puts e.message
311
+ puts e.backtrace.join("\n") if $cmd_options[:verbose]
312
+ exit(1)
313
+ end
306
314
  end
307
315
 
308
- begin
309
- Lyp::CLI.start(ARGV)
310
- rescue => e
311
- puts e.message
312
- puts e.backtrace.join("\n") if $cmd_options[:verbose]
313
- exit(1)
314
- end
data/lib/lyp/etc/lyp.ly CHANGED
@@ -1,16 +1,62 @@
1
1
  #(begin
2
+ ; file/path procedures based on code from oll-core:
3
+ ; https://github.com/openlilylib/oll-core/
4
+
5
+ (use-modules
6
+ (lily)
7
+ (ice-9 regex))
8
+
2
9
  (define lyp:path-separator "/")
3
- (define (lyp:file-join . ls) (string-join ls lyp:path-separator))
10
+ (define (lyp:join-path . ls) (string-join ls lyp:path-separator))
11
+
12
+ ; convert back-slashes to forward slashes (for use in lyp:split-path)
13
+ (define (lyp:normalize-path path)
14
+ (regexp-substitute/global #f "[\\]+" path 'pre "/" 'post)
15
+ )
16
+
17
+ (define (lyp:split-path path)
18
+ (string-split (lyp:normalize-path path) #\/))
19
+
20
+ (define lyp:absolute-path-pattern
21
+ (if (eq? PLATFORM 'windows) "^[a-zA-Z]:" "^/"))
22
+
23
+ (define (lyp:absolute-path? path)
24
+ (string-match lyp:absolute-path-pattern path))
25
+
26
+ ; return an absolute path, resolving any . or .. parts
27
+ (define (lyp:expand-path path) (let* (
28
+ ; create a path list by joining the current directory
29
+ (tmp-path (if (lyp:absolute-path? path)
30
+ path (lyp:join-path (ly-getcwd) path)))
31
+ (src-list (lyp:split-path tmp-path))
32
+ (dst-list '())
33
+ )
34
+ (for-each
35
+ (lambda (p)
36
+ (cond
37
+ ((eq? (length dst-list) 0) ; start of path
38
+ (set! dst-list (list p)))
39
+ ((or (string=? p "") (string=? p ".")) ; ignore empty part
40
+ #f)
41
+ ((string=? p "..") ; go up a level (remove last part from list)
42
+ (set! dst-list (reverse (cdr (reverse dst-list)))))
43
+ (else
44
+ (set! dst-list (append dst-list (list p))))))
45
+ src-list)
46
+ (apply lyp:join-path dst-list)
47
+ ))
48
+
49
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
50
 
5
51
  ; hash table mapping package refs to package names
6
52
  (define lyp:package-refs (make-hash-table))
7
-
53
+
8
54
  ; hash table mapping package names to package directories
9
55
  (define lyp:package-dirs (make-hash-table))
10
-
56
+
11
57
  ; hash table mapping package names to loaded state
12
58
  (define lyp:package-loaded? (make-hash-table))
13
-
59
+
14
60
  ; hash table mapping file paths to included state
15
61
  (define lyp:file-included? (make-hash-table))
16
62
 
@@ -22,7 +68,7 @@
22
68
  (or name (throw 'lyp:failure "lyp:ref->name"
23
69
  (format "Invalid package ref ~a" ref) #f))
24
70
  ))
25
-
71
+
26
72
  ; convert package reef to directory
27
73
  (define (lyp:name->dir name) (let (
28
74
  (dir (hash-ref lyp:package-dirs name))
@@ -30,71 +76,96 @@
30
76
  (or dir (throw 'lyp-failure "lyp:name->dir"
31
77
  (format "Invalid package name ~a" ref) #f))
32
78
  ))
33
-
34
- ; converts a package-relative path to absolute path. If the package is null,
35
- ; uses lyp:current-package-dir (which value is valid only on package loading)
36
- (define (lyp:package-file-path package path) (let* (
37
- (base-path (if (null? package)
38
- lyp:current-package-dir (lyp:name->dir package)))
39
- )
40
- (lyp:file-join base-path path)
41
- ))
42
-
43
- ; converts a package file reference to absolute path
44
- (define (lyp:fileref->path ref) (let* (
45
- (split (string-split ref #\:))
46
- (qualified? (eq? (length split) 2))
47
- (package (if qualified? (list-ref split 0) %nil))
48
- (path (if qualified? (list-ref split 1) (list-ref split 0)))
49
- )
50
- (lyp:package-file-path package path)
51
- ))
52
-
53
- (define (lyp:load ref) (load (lyp:fileref->path ref)))
54
-
55
- (define (lyp:include-ly-file path once-only?) (let* (
56
- (included? (and once-only? (hash-ref lyp:file-included? path)))
57
- )
58
- (if (not (file-exists? path))
59
- (throw 'lyp:failure "lyp:include-ly-file"
60
- (format "File not found ~a" path) #f)
79
+
80
+ ; Because the *location* in lilypond is kinda broken (it becomes unusable
81
+ ; when using nested includes, even in > 2.19.22, we provide an alternative
82
+ ; for keeping track of the current file, and thus be able to include files
83
+ ; using relative path names (relative to the current file).
84
+ (define lyp:last-this-file #f)
85
+ (define (lyp:this-file) (or lyp:last-this-file lyp:input-filename))
86
+ (define (lyp:this-dir) (dirname (lyp:this-file)))
87
+
88
+ (define (lyp:load path) (let* (
89
+ (current-file (lyp:this-file))
90
+ (current-dir (dirname current-file))
91
+ (abs-path (if (lyp:absolute-path? path)
92
+ path
93
+ (lyp:expand-path (lyp:join-path current-dir path))))
61
94
  )
62
- (if (not included?) (begin
63
- (hash-set! lyp:file-included? path #t)
64
- #{ \include #path #}
65
- ))
66
- ))
67
-
68
- (define (lyp:include ref)
69
- (lyp:include-ly-file (lyp:fileref->path ref) #f))
70
- (define (lyp:include-once ref)
71
- (lyp:include-ly-file (lyp:fileref->path ref) #t))
72
-
73
- (define (lyp:require ref) (let* (
74
- (name (lyp:ref->name ref))
75
- (package-dir (lyp:name->dir name))
76
- (entry-point-path (lyp:file-join package-dir "package.ly"))
77
- (loaded? (hash-ref lyp:package-loaded? name))
78
- (prev-package-dir lyp:current-package-dir)
95
+ (if (not (file-exists? abs-path))
96
+ (throw 'lyp:failure "lyp:load"
97
+ (format "File not found ~a" abs-path) #f)
79
98
  )
80
- (if (not loaded?) (begin
81
- (ly:debug "Loading package ~a at ~a" name package-dir)
82
- (set! lyp:current-package-dir package-dir)
83
- (hash-set! lyp:package-loaded? name #t)
84
- #{ \include #entry-point-path #}
85
- (set! lyp:current-package-dir prev-package-dir)
86
- ))
99
+ (set! lyp:last-this-file abs-path)
100
+ (load abs-path)
101
+ (set! lyp:last-this-file current-file)
87
102
  ))
103
+
104
+ (define (lyp:do-include parser path)
105
+ (if (defined? '*parser*)
106
+ (ly:parser-parse-string (ly:parser-clone)
107
+ (format "\\include \"~a\"" path))
108
+ (ly:parser-parse-string (ly:parser-clone parser)
109
+ (format "\\include \"~a\"" path))))
88
110
  )
89
111
 
90
112
  % command form
91
- require = #(define-void-function (parser location ref)(string?)
92
- (lyp:require ref))
93
-
113
+ require = #(define-void-function (parser location ref)(string?) (let* (
114
+ (current-file (lyp:this-file))
115
+ (name (lyp:ref->name ref))
116
+ (package-dir (lyp:name->dir name))
117
+ (entry-point-path (lyp:join-path package-dir "package.ly"))
118
+ (loaded? (hash-ref lyp:package-loaded? name))
119
+ (prev-package-dir lyp:current-package-dir)
120
+ )
121
+ (if (not loaded?) (begin
122
+ (ly:debug "Loading package ~a at ~a" name package-dir)
123
+ (set! lyp:current-package-dir package-dir)
124
+ (hash-set! lyp:package-loaded? name #t)
125
+
126
+ (set! lyp:last-this-file entry-point-path)
127
+ (lyp:do-include parser entry-point-path)
128
+ (set! lyp:last-this-file current-file)
129
+
130
+ (set! lyp:current-package-dir prev-package-dir)
131
+ ))
132
+ ))
133
+
134
+ pinclude = #(define-void-function (parser location path)(string?) (let* (
135
+ (current-file (lyp:this-file))
136
+ (current-dir (dirname current-file))
137
+ (abs-path (if (lyp:absolute-path? path)
138
+ path
139
+ (lyp:expand-path (lyp:join-path current-dir path))))
140
+ )
141
+ (ly:debug (format "\\pinclude ~a\n" abs-path))
142
+ (if (not (file-exists? abs-path))
143
+ (throw 'lyp:failure "\\pinclude"
144
+ (format "File not found ~a" abs-path) #f))
94
145
 
95
- pinclude = #(define-void-function (parser location ref)(string?)
96
- (lyp:include ref))
146
+ (hash-set! lyp:file-included? abs-path #t)
147
+ (set! lyp:last-this-file abs-path)
148
+ (lyp:do-include parser abs-path)
149
+ (set! lyp:last-this-file current-file)
150
+ ))
97
151
 
98
- pincludeOnce = #(define-void-function (parser location ref)(string?)
99
- (lyp:include-once ref))
152
+ pincludeOnce = #(define-void-function (parser location path)(string?) (let* (
153
+ (current-file (lyp:this-file))
154
+ (current-dir (dirname current-file))
155
+ (abs-path (if (lyp:absolute-path? path)
156
+ path
157
+ (lyp:expand-path (lyp:join-path current-dir path))))
158
+ (included? (hash-ref lyp:file-included? abs-path))
159
+ )
160
+ (if (not included?) (begin
161
+ (ly:debug (format "\\pincludeOnce ~a\n" abs-path))
162
+ (if (not (file-exists? abs-path))
163
+ (throw 'lyp:failure "\\pincludeOnce"
164
+ (format "File not found ~a" abs-path) #f))
100
165
 
166
+ (hash-set! lyp:file-included? abs-path #t)
167
+ (set! lyp:last-this-file abs-path)
168
+ (lyp:do-include parser abs-path)
169
+ (set! lyp:last-this-file current-file)
170
+ )
171
+ )))
data/lib/lyp/lilypond.rb CHANGED
@@ -48,6 +48,19 @@ module Lyp::Lilypond
48
48
  settings[:current]
49
49
  end
50
50
 
51
+ def current_lilypond_version
52
+ path = current_lilypond
53
+ version = File.basename(File.expand_path("#{File.dirname(path)}/../.."))
54
+
55
+ unless (Gem::Version.new(version) rescue nil)
56
+ resp = `#{path} -v`
57
+ if resp.lines.first =~ /LilyPond ([0-9\.]+)/i
58
+ version = $1
59
+ end
60
+ end
61
+ version
62
+ end
63
+
51
64
  def set_current_lilypond(path)
52
65
  settings = get_session_settings
53
66
  settings[:current] = path
@@ -560,9 +573,14 @@ module Lyp::Lilypond
560
573
  success = exit_value == 0
561
574
  end
562
575
  if !success && raise_on_failure
563
- raise "Error executing cmd #{cmd}: #{$_err}"
576
+ raise "Error executing cmd #{cmd}:\n#{parse_error_msg($_err)}"
564
577
  end
565
578
  success
566
579
  end
580
+
581
+ def parse_error_msg(msg)
582
+ (msg =~ /[^\n]+: error.+failed files: ".+"/m) ?
583
+ $& : msg
584
+ end
567
585
  end
568
586
  end
data/lib/lyp/package.rb CHANGED
@@ -72,7 +72,13 @@ module Lyp::Package
72
72
  install_package_fonts(info[:path], opts)
73
73
  end
74
74
 
75
- puts "\nInstalled #{package}@#{info[:version]}\n\n" unless opts[:silent]
75
+ unless opts[:silent]
76
+ if info[:local_path]
77
+ puts "\nInstalled #{package}@#{info[:version]} => #{info[:local_path]}\n\n"
78
+ else
79
+ puts "\nInstalled #{package}@#{info[:version]}\n\n"
80
+ end
81
+ end
76
82
 
77
83
  if opts[:test]
78
84
  FileUtils.cd(info[:path]) do
@@ -85,7 +91,7 @@ module Lyp::Package
85
91
  end
86
92
 
87
93
  LOCAL_PACKAGE_WRAPPER =
88
- "#(set! lyp:current-package-dir \"%s\")\n\\include \"%s\"\n"
94
+ "#(set! lyp:current-package-dir \"%s\")\n\\pinclude \"%s\"\n"
89
95
 
90
96
  def install_from_local_files(package, version, opts)
91
97
  version =~ /^([^\:]+)\:(.+)$/
@@ -118,7 +124,9 @@ module Lyp::Package
118
124
 
119
125
  prepare_local_package_fonts(local_path, package_path)
120
126
 
121
- {version: version, path: package_path}
127
+ load_package_ext_file("#{package}@#{version}", local_path)
128
+
129
+ {version: version, path: package_path, local_path: local_path}
122
130
  end
123
131
 
124
132
  def prepare_local_package_fonts(local_path, package_path)
@@ -145,9 +153,20 @@ module Lyp::Package
145
153
  FileUtils.rm_rf(package_path)
146
154
  FileUtils.cp_r(tmp_path, package_path)
147
155
 
156
+ load_package_ext_file("#{package}@#{version}", package_path)
157
+
148
158
  {version: version, path: package_path}
149
159
  end
150
160
 
161
+ def load_package_ext_file(package, path)
162
+ ext_path = File.join(path, 'ext.rb')
163
+ if File.file?(ext_path)
164
+ $installed_package = package
165
+ $installed_package_path = path
166
+ load_extension(ext_path)
167
+ end
168
+ end
169
+
151
170
  def uninstall(package, opts = {})
152
171
  unless package =~ Lyp::PACKAGE_RE
153
172
  raise "Invalid package specifier #{package}"
@@ -163,6 +182,10 @@ module Lyp::Package
163
182
  puts "Uninstalling #{name}" unless opts[:silent]
164
183
  FileUtils.rm_rf(path)
165
184
  end
185
+
186
+ Dir["#{Lyp.ext_dir}/#{File.basename(package_path)}*.rb"].each do |path|
187
+ FileUtils.rm_f(path)
188
+ end
166
189
  else
167
190
  if version
168
191
  package_path += "@#{version}"
@@ -187,6 +210,10 @@ module Lyp::Package
187
210
  name = package_path.gsub("#{Lyp.packages_dir}/", '')
188
211
  puts "Uninstalling #{name}" unless opts[:silent]
189
212
  FileUtils.rm_rf(package_path)
213
+
214
+ Dir["#{Lyp.ext_dir}/#{File.basename(package_path)}.rb"].each do |path|
215
+ FileUtils.rm_f(path)
216
+ end
190
217
  else
191
218
  raise "Could not find package #{package}"
192
219
  end
@@ -431,7 +458,7 @@ module Lyp::Package
431
458
 
432
459
  def perform_test(fn, stats)
433
460
  stats[:test_count] += 1
434
- unless Lyp::Lilypond.compile([fn], mode: :system, force_wrap: true)
461
+ unless Lyp::Lilypond.compile([fn], mode: :system)
435
462
  stats[:fail_count] += 1
436
463
  end
437
464
  end
@@ -453,5 +480,25 @@ module Lyp::Package
453
480
  end
454
481
  end
455
482
  end
483
+
484
+ def load_all_extensions
485
+ Dir["#{Lyp.ext_dir}/*.rb"].each {|f| load_extension(f)}
486
+ end
487
+
488
+ def load_extension(path)
489
+ load(path)
490
+ rescue => e
491
+ STDERR.puts "Error while loading extension #{path}"
492
+ STDERR.puts " #{e.message}"
493
+ end
494
+ end
495
+ end
496
+
497
+ module Lyp
498
+ def self.install_extension(path)
499
+ # install extension only when installing the package
500
+ return unless $installed_package
501
+
502
+ FileUtils.cp(path, "#{Lyp.ext_dir}/#{$installed_package}.rb")
456
503
  end
457
504
  end
data/lib/lyp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lyp
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/lyp/wrapper.rb CHANGED
@@ -11,12 +11,10 @@ module Lyp
11
11
  # copy current_package_dir option
12
12
  r[:current_package_dir] = opts[:current_package_dir]
13
13
 
14
- if !r[:package_dirs].empty? || opts[:force_wrap]
15
- FileUtils.mkdir_p("#{Lyp::TMP_ROOT}/wrappers")
16
- fn = "#{Lyp::TMP_ROOT}/wrappers/#{File.basename(fn)}"
14
+ FileUtils.mkdir_p("#{Lyp::TMP_ROOT}/wrappers")
15
+ fn = "#{Lyp::TMP_ROOT}/wrappers/#{File.basename(fn)}"
17
16
 
18
- File.open(fn, 'w+') {|f| f << WRAPPER_TEMPLATE.render(r)}
19
- end
17
+ File.open(fn, 'w+') {|f| f << WRAPPER_TEMPLATE.render(r)}
20
18
  fn
21
19
  end
22
20
  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.3.1
4
+ version: 0.3.3
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-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient