lyp 0.3.5 → 0.3.6

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: e45125d6f5c577945a68e0f18d81d3202495a52c
4
- data.tar.gz: 24379cc9ee854d468587469286a6c5e306e39f7e
3
+ metadata.gz: b8e7eff9d0273f1f122a7cef54b14742090cbc56
4
+ data.tar.gz: c2c62ae013980d248bc3b1f7f3c2640000b387d3
5
5
  SHA512:
6
- metadata.gz: 6201fa84a3a6f5458d5caf4f8cc85135def441229c8cebd8f32269496b8f8a49353edd50477961bac05376497710e3b196ae9eb4b47f8f6b97935d555c595f28
7
- data.tar.gz: 74f2e49025ce8b1049e348c28666fc7d0181fc0a603066fcc994d49b47298b3b357c65576f8c43a8ebea3542d5c1bf34b48a890179451dfbfb44eaab41bda642
6
+ metadata.gz: 55d99aabb7837d1d4bb7ef91d8a96daadecc84fefe292b0796ba68d45961213fbc5d6161dc6412d43a7d903cd9524dc28dd27ae864f10e8463cb72ad6c856f42
7
+ data.tar.gz: ed708b1226d8611769fd14f559113c907c47834f32d51c19ce0908cffa0ec9cac4c9261603fe073b9659d0dedb2f22d3d5b11516b048cf5b4cb606ff769e6253
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- LYP_VERSION="0.3.5"
3
+ LYP_VERSION="0.3.6"
4
4
  WORKDIR="/tmp/lyp-release-installer"
5
5
  URL_BASE="https://github.com/noteflakes/lyp/releases/download/v$LYP_VERSION"
6
6
 
data/bin/lilypond CHANGED
@@ -5,54 +5,9 @@ $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
5
5
  require 'lyp/version'
6
6
  require 'lyp'
7
7
 
8
- def process_argv
9
- options = {}
10
- argv = ARGV.dup # copy for iterating
11
- argv_clean = []
12
- while arg = argv.shift
13
- case arg
14
- when '-r', '--raw'
15
- options[:raw] = true
16
- when '-E', '--env'
17
- unless ENV['LILYPOND_VERSION']
18
- STDERR.puts "$LILYPOND_VERSION not set"
19
- exit 1
20
- end
21
- options[:use_version] = ENV['LILYPOND_VERSION']
22
- when '-u', '--use'
23
- options[:use_version] = argv.shift
24
- when /^(?:\-u|\-\-use\=)"?([^\s]+)"?/
25
- options[:use_version] = $1
26
- when '-n', '--install'
27
- options[:install] = true
28
- else
29
- argv_clean << arg
30
- end
31
- end
32
-
33
- [options, argv_clean]
34
- end
35
- $options, $argv = process_argv
8
+ $options, $argv = Lyp::Lilypond.preprocess_argv(ARGV)
36
9
 
37
- def get_lilypond_path
38
- if $options[:use_version]
39
- if $options[:install]
40
- Lyp::Lilypond.install_if_missing($options[:use_version])
41
- end
42
- Lyp::Lilypond.force_version!($options[:use_version])
43
- end
44
- Lyp::Lilypond.check_lilypond!
45
- Lyp::Lilypond.current_lilypond.tap do |path|
46
- unless path && File.file?(path)
47
- STDERR.puts "No version of lilypond found. To install lilypond run 'lyp install lilypond'."
48
- exit 1
49
- end
50
- end
51
- rescue => e
52
- STDERR.puts e.message
53
- exit 1
54
- end
55
- $lilypond_path = get_lilypond_path
10
+ $lilypond_path = Lyp::Lilypond.select_lilypond_version($options)
56
11
 
57
12
  if $options[:raw]
58
13
  exec("#{$lilypond_path} #{$argv.join(' ')}")
@@ -68,10 +23,11 @@ LILYPOND_HELP_SWITCHES = %w{
68
23
  }
69
24
  LYP_LY_HELP = <<EOF
70
25
  Lyp-provided options:
71
- -r, --raw run raw lilypond (no pre-processing)
72
26
  -E, --env use version specified in $LILYPOND_VERSION
27
+ -n, --install install the specified version if not found
28
+ -R, --raw run raw lilypond (no pre-processing)
29
+ -r, --require=PACKAGE preload the specified package
73
30
  -u, --use=VERSION use the given version of lilypond
74
- -n, --install install the given version if not found
75
31
  EOF
76
32
 
77
33
  case $argv.first
data/lib/lyp/cli.rb CHANGED
@@ -45,7 +45,7 @@ class Lyp::CLI < Thor
45
45
  package_name "lyp"
46
46
  map "-v" => :version
47
47
  check_unknown_options! :except => :compile
48
- class_option :verbose, aliases: '-V', :type => :boolean
48
+ class_option :verbose, aliases: '-V', :type => :boolean, desc: 'show verbose output'
49
49
 
50
50
  desc "version", "show Lyp version"
51
51
  def version
@@ -100,33 +100,14 @@ class Lyp::CLI < Thor
100
100
  end
101
101
 
102
102
  desc "compile [<option>...] <FILE>", "Invokes lilypond with given file"
103
- method_option :install, aliases: '-n', type: :boolean, desc: 'Install the requested version of lilypond if not present'
104
- method_option :env, aliases: '-E', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
105
- method_option :use, aliases: '-u', type: :string, desc: 'Use specified version'
106
- def compile(*args)
107
- $cmd_options = options
103
+ def compile(*argv)
104
+ opts, argv = Lyp::Lilypond.preprocess_argv(argv)
108
105
 
109
- if options[:env]
110
- unless ENV['LILYPOND_VERSION']
111
- STDERR.puts "$LILYPOND_VERSION not set"
112
- exit 1
113
- end
114
- options[:use] = ENV['LILYPOND_VERSION']
115
- end
116
-
117
- if options[:use]
118
- if options[:install]
119
- Lyp::Lilypond.install_if_missing(options[:use], no_version_test: true)
120
- end
121
- Lyp::Lilypond.force_version!(options[:use])
122
- end
106
+ lilypond_path = Lyp::Lilypond.select_lilypond_version(opts)
123
107
 
124
- # check lilypond default / current settings
125
- Lyp::Lilypond.check_lilypond!
126
-
127
108
  $stderr.puts "Lyp #{Lyp::VERSION}"
128
109
  Lyp::System.test_installed_status!
129
- Lyp::Lilypond.compile(args)
110
+ Lyp::Lilypond.compile(argv, opts)
130
111
  end
131
112
 
132
113
  desc "test [<option>...] [.|PATTERN]", "Runs package tests on installed packages or local directory"
data/lib/lyp/etc/lyp.ly CHANGED
@@ -96,62 +96,59 @@
96
96
  (throw 'lyp:failure "lyp:load"
97
97
  (format "File not found ~a" abs-path) #f)
98
98
  )
99
+ (ly:debug (format "lyp:load ~a\n" abs-path))
99
100
  (set! lyp:last-this-file abs-path)
100
101
  (load abs-path)
101
102
  (set! lyp:last-this-file current-file)
102
103
  ))
103
104
 
104
- (define (lyp:do-include parser path)
105
+ (define (lyp:fmt-include path)
106
+ (format "#(set! lyp:last-this-file \"~A\")\n\\include \"~A\"\n#(set! lyp:last-this-file \"~A\")\n"
107
+ path path (lyp:this-file)))
108
+
109
+ (define (lyp:fmt-require entry-point-path package-dir)
110
+ (format "#(set! lyp:current-package-dir \"~A\")\n~A#(set! lyp:current-package-dir \"~A\")\n"
111
+ package-dir (lyp:fmt-include entry-point-path) lyp:current-package-dir))
112
+
113
+ ; helper function to cover API changes from 2.18 to 2.19
114
+ (define (lyp:include-string str)
105
115
  (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))))
116
+ (ly:parser-include-string str)
117
+ (ly:parser-include-string parser str)))
110
118
  )
111
119
 
112
120
  % command form
113
121
  require = #(define-void-function (parser location ref)(string?) (let* (
114
- (current-file (lyp:this-file))
115
122
  (name (lyp:ref->name ref))
116
123
  (package-dir (lyp:name->dir name))
117
124
  (entry-point-path (lyp:join-path package-dir "package.ly"))
118
125
  (loaded? (hash-ref lyp:package-loaded? name))
119
- (prev-package-dir lyp:current-package-dir)
120
126
  )
121
127
  (if (not loaded?) (begin
122
128
  (ly:debug "Loading package ~a at ~a" name package-dir)
123
- (set! lyp:current-package-dir package-dir)
124
129
  (hash-set! lyp:package-loaded? name #t)
125
130
 
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
+ (lyp:include-string (lyp:fmt-require entry-point-path package-dir))
131
132
  ))
132
133
  ))
133
134
 
134
135
  pinclude = #(define-void-function (parser location path)(string?) (let* (
135
- (current-file (lyp:this-file))
136
- (current-dir (dirname current-file))
136
+ (current-dir (lyp:this-dir))
137
137
  (abs-path (if (lyp:absolute-path? path)
138
138
  path
139
139
  (lyp:expand-path (lyp:join-path current-dir path))))
140
140
  )
141
- (ly:debug (format "\\pinclude ~a\n" abs-path))
141
+ (ly:debug "\\pinclude ~a\n" abs-path)
142
142
  (if (not (file-exists? abs-path))
143
143
  (throw 'lyp:failure "\\pinclude"
144
144
  (format "File not found ~a" abs-path) #f))
145
145
 
146
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)
147
+ (lyp:include-string (lyp:fmt-include abs-path))
150
148
  ))
151
149
 
152
150
  pincludeOnce = #(define-void-function (parser location path)(string?) (let* (
153
- (current-file (lyp:this-file))
154
- (current-dir (dirname current-file))
151
+ (current-dir (lyp:this-dir))
155
152
  (abs-path (if (lyp:absolute-path? path)
156
153
  path
157
154
  (lyp:expand-path (lyp:join-path current-dir path))))
@@ -164,8 +161,6 @@ pincludeOnce = #(define-void-function (parser location path)(string?) (let* (
164
161
  (format "File not found ~a" abs-path) #f))
165
162
 
166
163
  (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)
164
+ (lyp:include-string (lyp:fmt-include abs-path))
170
165
  )
171
166
  )))
data/lib/lyp/lilypond.rb CHANGED
@@ -4,6 +4,59 @@ require 'ruby-progressbar'
4
4
 
5
5
  module Lyp::Lilypond
6
6
  class << self
7
+ def preprocess_argv(argv)
8
+ options = {}
9
+ argv = argv.dup # copy for iterating
10
+ argv_clean = []
11
+ while arg = argv.shift
12
+ case arg
13
+ when '-R', '--raw'
14
+ options[:raw] = true
15
+ when '-r', '--require'
16
+ options[:ext_require] ||= []
17
+ options[:ext_require] << argv.shift
18
+ when /^(?:\-r|\-\-require\=)"?([^\s]+)"?/
19
+ options[:ext_require] ||= []
20
+ options[:ext_require] << $1
21
+ when '-E', '--env'
22
+ unless ENV['LILYPOND_VERSION']
23
+ STDERR.puts "$LILYPOND_VERSION not set"
24
+ exit 1
25
+ end
26
+ options[:use_version] = ENV['LILYPOND_VERSION']
27
+ when '-u', '--use'
28
+ options[:use_version] = argv.shift
29
+ when /^(?:\-u|\-\-use\=)"?([^\s]+)"?/
30
+ options[:use_version] = $1
31
+ when '-n', '--install'
32
+ options[:install] = true
33
+ else
34
+ argv_clean << arg
35
+ end
36
+ end
37
+
38
+ [options, argv_clean]
39
+ end
40
+
41
+ def select_lilypond_version(opts)
42
+ if opts[:use_version]
43
+ if opts[:install]
44
+ Lyp::Lilypond.install_if_missing(opts[:use_version])
45
+ end
46
+ Lyp::Lilypond.force_version!(opts[:use_version])
47
+ end
48
+ Lyp::Lilypond.check_lilypond!
49
+ Lyp::Lilypond.current_lilypond.tap do |path|
50
+ unless path && File.file?(path)
51
+ STDERR.puts "No version of lilypond found. To install lilypond run 'lyp install lilypond'."
52
+ exit 1
53
+ end
54
+ end
55
+ rescue => e
56
+ STDERR.puts e.message
57
+ exit 1
58
+ end
59
+
7
60
  def compile(argv, opts = {})
8
61
  unless argv.last == '-'
9
62
  fn = Lyp.wrap(argv.pop, opts)
data/lib/lyp/resolver.rb CHANGED
@@ -2,6 +2,7 @@ class Lyp::Resolver
2
2
  def initialize(user_file, opts = {})
3
3
  @user_file = user_file
4
4
  @opts = opts
5
+ @ext_require = @opts[:ext_require]
5
6
  end
6
7
 
7
8
  # Resolving package dependencies involves two stages:
@@ -25,7 +26,8 @@ class Lyp::Resolver
25
26
  user_file: @user_file,
26
27
  definite_versions: definite_versions,
27
28
  package_refs: refs,
28
- package_dirs: dirs
29
+ package_dirs: dirs,
30
+ preload: @opts[:ext_require]
29
31
  }
30
32
  end
31
33
 
@@ -88,37 +90,18 @@ class Lyp::Resolver
88
90
  ly_content.scan(DEP_RE) do |type, ref|
89
91
  case type
90
92
  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)
103
- queue_file_for_processing(qualified_path, tree, leaf)
93
+ process_include_command(ref, dir, tree, leaf, opts)
104
94
  when REQUIRE
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
95
+ process_require_command(ref, dir, tree, leaf, opts)
96
+ end
97
+ end
119
98
 
120
- find_package_versions(ref, tree, leaf, opts)
99
+ # process any external requires (supplied using the -r command line option)
100
+ if @ext_require
101
+ @ext_require.each do |p|
102
+ process_require_command(p, dir, tree, leaf, opts)
121
103
  end
104
+ @ext_require = nil
122
105
  end
123
106
 
124
107
  tree[:processed_files][path] = true
@@ -126,6 +109,41 @@ class Lyp::Resolver
126
109
  raise "Cannot find file #{path}"
127
110
  end
128
111
 
112
+ def process_include_command(ref, dir, tree, leaf, opts)
113
+ # a package would normally use a plain \pinclude or \pincludeOnce
114
+ # command to include package files, e.g. \pinclude "inc/init.ly".
115
+ #
116
+ # But a package can also qualify the file reference with the package
117
+ # name, in order to be able to load files after the package has already
118
+ # been loaded, e.g. \pinclude "mypack:inc/init.ly"
119
+ if ref =~ /^([^\:]+)\:(.+)$/
120
+ # ignore null package (used for testing purposes only)
121
+ return if $1 == 'null'
122
+ ref = $2
123
+ end
124
+ qualified_path = File.expand_path(ref, dir)
125
+ queue_file_for_processing(qualified_path, tree, leaf)
126
+ end
127
+
128
+ def process_require_command(ref, dir, tree, leaf, opts)
129
+ forced_path = nil
130
+ if ref =~ /^([^\:]+)\:(.+)$/
131
+ ref = $1
132
+ forced_path = File.expand_path($2, dir)
133
+ end
134
+
135
+ ref =~ Lyp::PACKAGE_RE
136
+ package, version = $1, $2
137
+ return if package == 'null'
138
+
139
+ # set forced path if applicable
140
+ if forced_path
141
+ set_forced_package_path(tree, package, forced_path)
142
+ end
143
+
144
+ find_package_versions(ref, tree, leaf, opts)
145
+ end
146
+
129
147
  def queue_file_for_processing(path, tree, leaf)
130
148
  (tree[:queue] ||= []) << {path: path, leaf: leaf}
131
149
  end
@@ -50,10 +50,21 @@ _[:package_dirs].each do |package, path|
50
50
  (hash-set! lyp:package-dirs "{{package}}" {{quote_path[path]}})`
51
51
  end
52
52
 
53
-
54
53
  `
55
54
  )
56
55
 
57
56
  #(ly:debug "package loader is ready")
57
+ `
58
+
59
+ if _[:preload]
60
+ _[:preload].each do |package|
61
+ `
62
+ \require "{{package}}"
63
+ `
64
+ end
65
+ end
66
+
67
+ `
58
68
  \include {{quote_path[user_filename]}}
59
- `
69
+ `
70
+
data/lib/lyp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lyp
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/lyp/wrapper.rb CHANGED
@@ -6,7 +6,7 @@ module Lyp
6
6
  ))
7
7
 
8
8
  def self.wrap(fn, opts = {})
9
- r = Lyp::Resolver.new(fn).resolve_package_dependencies
9
+ r = Lyp::Resolver.new(fn, opts).resolve_package_dependencies
10
10
 
11
11
  # copy current_package_dir option
12
12
  r[:current_package_dir] = opts[:current_package_dir]
@@ -15,6 +15,7 @@ module Lyp
15
15
  fn = "#{Lyp::TMP_ROOT}/wrappers/#{File.basename(fn)}"
16
16
 
17
17
  File.open(fn, 'w+') {|f| f << WRAPPER_TEMPLATE.render(r)}
18
+
18
19
  fn
19
20
  end
20
21
  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.5
4
+ version: 0.3.6
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-03-01 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient