lyp 1.2.1 → 1.3.0

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: ef089fcb7702e57734c1496c8df3b81ed9d9e261
4
- data.tar.gz: b0e77559e40e9c485863a4695774892aa01a2941
3
+ metadata.gz: fdcd618c84a8c0ec5925b02d2e05fb62ee438f63
4
+ data.tar.gz: dda515b6fb0fc79f7ee868100323ff19a40d9742
5
5
  SHA512:
6
- metadata.gz: 4f01ffb644327f54961b91565f5728d65d2e8e6ce30b02bff24426fca36c8bdd28c1bd6d13471865e2e4ae51c42a9a957c7b881aeb45406f5355c268af79378f
7
- data.tar.gz: 2d07b484694dd7fd1a062c45a33e19ed988dcbff93a0a2d3eee638e9bb421dd8e13a0524131162707361afa276c7669e89b05d57c5d716935d2cee086c8780e0
6
+ metadata.gz: 52a2954b3b7456fcda5e1d4e729e235c6c7aca2505b3f82d55e3ff467332b3a2094792db66783fd0d7fb4cefe28f02c21848c45ce2466d22dba057bc1e42232f
7
+ data.tar.gz: c9c533504e0a696bf0b7dfc6bbf5cbb2eabe9345a35ece672385340b9c0dea2c9840e15c3259a9370f84cfc371689c4f2e620aaffb312c1428f3cd30223979b2
data/README.md CHANGED
@@ -38,27 +38,46 @@ __No hassle Lilypond installation__: With lyp you can also install any version o
38
38
  - [Testing packages](#testing-packages)
39
39
  - [Publishing packages](#publishing-packages)
40
40
  - [Installing and Using Lilypond](#installing-and-using-lilypond)
41
- - [Installing/uninstalling a version of Lilypond](#installing-uninstalling a version of lilypond)
41
+ - [Installing/uninstalling a version of Lilypond](#installinguninstalling-a-version-of-lilypond)
42
42
  - [Showing the list of installed Lilypond versions](#showing-the-list-of-installed-lilypond-versions)
43
43
  - [Showing available Lilypond versions](#Showing-available-lilypond-versions)
44
44
  - [Switching between Lilypond versions](#switching-between-lilypond-versions)
45
45
  - [Running Lilypond](#running-lilypond)
46
+ - [Command Reference](#command-reference)
47
+ - [lyp accelerate](#lyp-accelerate) - rewrite gem binaries for faster execution
48
+ - [lyp benchmark](#lyp-benchmark) - benchmark installed versions of Lilypnd
49
+ - [lyp cleanup](#lyp-cleanup) - cleanup temporary files
50
+ - [lyp compile](#lyp-compile) - compile Lilypond source files
51
+ - [lyp deps](#lyp-deps) - show dependencies for a given source file
52
+ - [lyp exec](#lyp-exec) - execute a Lilypond script
53
+ - [lyp flatten](#lyp-flatten) - flatten a Lilypond project by inlining includes
54
+ - [lyp install](#lyp-install) - install package or Lilypond
55
+ - [lyp list](#lyp-list) - list installed packages or Lilyponds
56
+ - [lyp resolve](#lyp-resolve) - resolve and install dependencies for a given source file
57
+ - [lyp search](#lyp-search) - search for packages or Lilyponds
58
+ - [lyp test](#lyp-test) - run Lilypond test files
59
+ - [lyp uninstall](#lyp-uninstall) - uninstall packages or Lilyponds
60
+ - [lyp update](#lyp-update) - update packages
61
+ - [lyp use](#lyp-use) - switch between installed Lilyponds
62
+ - [lyp version](#lyp-version) - show lyp version
63
+ - [lyp watch](#lyp-watch) - watch files and directories and recompile on change
64
+ - [lyp which](#lyp-which) - show location of packages or Lilyponds
46
65
  - [Contributing](#contributing)
47
66
 
48
67
  ## Installation
49
68
 
50
69
  ### System requirements
51
70
 
52
- Lyp is tested to work on Linux, MacOS and Windows 7+.
71
+ Lyp is tested to work on Linux, macOS and Windows 7+.
53
72
 
54
73
  ### Installing lyp as a Ruby gem
55
74
 
56
- _Note_: A recent version of Ruby (2.0.0 or later) is included in MacOS 10.9.0 or later.
75
+ _Note_: A recent version of Ruby (2.0.0 or later) is included in macOS 10.9.0 or later.
57
76
 
58
77
  If you have a recent (>=1.9.3) version of Ruby on your machine, you can install lyp as a gem.
59
78
 
60
79
  ```bash
61
- # Linux/MacOS:
80
+ # Linux/macOS:
62
81
  $ gem install lyp
63
82
 
64
83
  # Windows:
@@ -88,7 +107,7 @@ Windows users can simply download the latest Windows [release](https://github.co
88
107
 
89
108
  ### Manually installing releases
90
109
 
91
- (This section is for Linux / MacOS users.)
110
+ (This section is for Linux / macOS users.)
92
111
 
93
112
  If you feel uneasy about piping curl output to bash, you can install lyp yourself by downloading a [release](https://github.com/noteflakes/lyp/releases), untarring it, and running `lyp install self`:
94
113
 
@@ -575,6 +594,177 @@ Once one or more versions of Lilypond are installed, the Lilypond command may be
575
594
  $ lilypond --ulatest myfile.ly
576
595
  ```
577
596
 
597
+ ## Command Reference
598
+
599
+ ### lyp accelerate
600
+
601
+ Synopsis: `lyp accelerate`
602
+
603
+ __Power users__: rewrite gem binaries for faster execution. When lyp is installed as a gem, the Rubygems system creates wrapper script files for `lyp` and `lilypond` which incur a performance penalty that adds up to 200msecs per invocation. Use this command to rewrite the gem binaries so as to improve their running time.
604
+
605
+ ### lyp benchmark
606
+
607
+ Synopsis: `lyp benchmark FILE`
608
+
609
+ __Power users__: benchmark the running time of all installed versions of Lilypond using the given source file. This command accepts all Lilypond command line switches.
610
+
611
+ ### lyp cleanup
612
+
613
+ Synopsis: `lyp cleanup`
614
+
615
+ Cleanup temporary files. lyp keeps a bunch of temporary directories and files under the system temporary directory, usually at `/tmp/lyp`. These include wrapper files, git repositories for installed packages, Lilypond archive files etc. These will normally be cleaned up by the OS after a period of time, but you can use this command to delete the entire content of this directory if you need the disk space.
616
+
617
+ ### lyp compile
618
+
619
+ Synopsis: `lyp compile ... FILE`
620
+
621
+ Shorthand: `lyp c`
622
+
623
+ Compiles Lilypond source files. This command is synonymous to running `lilypond`. You can pass along any switches accepted by Lilypond. In addition, lyp adds a few options to provide additional functionality:
624
+
625
+ - `--auto-install-deps`/`-a`: install any missing dependencies
626
+ - `--cropped`/`-c`: crop output (requires setting 0 margins)
627
+ - `--env`/`-E`: use the Lilypond version specified in the `LILYPOND_VERSION` environment variable:
628
+
629
+ ```bash
630
+ $ LILYPOND_VERSION=2.19.50 lyp c mysuperscore.ly
631
+ ```
632
+
633
+ - `--force-version`/`-F`: use Lilypond version specified in user file
634
+ - `--install`/`-n`: install version of Lilypond if not found (if the required version was overriden using any of `--env`, `--force-version` or `--use`)
635
+ - `--open`/`-O`: open output file after compilation
636
+ - `--raw`/`-R`: run Lilypond "raw" (no pre-processing of dependencies)
637
+ - `--require=PACKAGE`/`-rPACKAGE`: preload the specified package
638
+
639
+ ```bash
640
+ $ lyp -rassert mytests.ly
641
+ ```
642
+
643
+ - `--snippet`/`-S`: produce png cropped images at 600dpi (equivalent to `--cropped --png -dresolution=600`)
644
+ - `--use=VERSION`/`-uVERSION`: use the given version of Lilypond:
645
+
646
+ ```bash
647
+ $ lyp c -u2.19.53 myfile.ly
648
+ # automatically install given version of Lilypond
649
+ $ lyp c -nu2.19.53 myfile.ly
650
+ ```
651
+
652
+ ### lyp deps
653
+
654
+ Synopsis: `lyp deps FILE`
655
+
656
+ Shows dependencies for a given source file.
657
+
658
+ ### lyp exec
659
+
660
+ Synopsis: `lyp exec SCRIPT ...`
661
+
662
+ Shorthand: `lyp x`
663
+
664
+ Runs a Lilypond script (using the currently selected version of Lilypond).
665
+
666
+ ### lyp flatten
667
+
668
+ Synopsis: `lyp flatten FILE`
669
+
670
+ Flattens a source file and all included files into a single file.
671
+
672
+ ### lyp install
673
+
674
+ Synopsis: `lyp install PACKAGE|lilypond@VERSION`
675
+
676
+ Shorthand: `lyp i`
677
+
678
+ Installs a package or a Lilypond. See [installing packages](#installing-packages) and [installing versions of Lilypond](#installing-and-using-lilypond) above.
679
+
680
+ ### lyp list
681
+
682
+ Synopsis: `lyp list [PACKAGE|lilypond]`
683
+
684
+ Shorthand: `lyp l`
685
+
686
+ Lists installed packages or Lilyponds.
687
+
688
+ ### lyp resolve
689
+
690
+ Synopsis: `lyp resolve FILE``
691
+
692
+ Resolves and optionally installs all dependencies for a given source file. To install required dependencies use the `--all`/`-a` switch:
693
+
694
+ ```bash
695
+ $ lyp resolve -a myfile.ly
696
+ ```
697
+
698
+ ### lyp search
699
+
700
+ Synopsis: `lyp search PACKAGE|lilypond``
701
+
702
+ Shorthand: `lyp s`
703
+
704
+ Searches for packages or versions of Lilypond.
705
+
706
+ ### lyp test
707
+
708
+ Synopsis: `lyp test DIRECTORY`
709
+
710
+ Shorthand: `lyp t`
711
+
712
+ Runs Lilypond tests by compiling all files in the given directory matching the pattern `*-test.ly`.
713
+
714
+ ### lyp uninstall
715
+
716
+ Synopsis: `lyp uninstall PACKAGE|lilypond@VERSION`
717
+
718
+ Shorthand: `lyp u`
719
+
720
+ Uninstalls a package or a Lilypond.
721
+
722
+ ### lyp update
723
+
724
+ Synopsis: `lyp update PACKAGE`
725
+
726
+ Updates an installed package to its latest available version.
727
+
728
+ ### lyp use
729
+
730
+ Synopsis: `lyp use VERSION``
731
+
732
+ Shorthand: `lyp U`
733
+
734
+ Switches to a different version of Lilypond. To set the default version, use the `--default` switch:
735
+
736
+ ```bash
737
+ $ lyp use --default 2.19.52
738
+ ```
739
+
740
+ ### lyp version
741
+
742
+ Synopsis: `lyp version``
743
+
744
+ Shorthand: `lyp -v``
745
+
746
+ Displays the version of lyp.
747
+
748
+ ### lyp watch
749
+
750
+ Synopsis: `lyp watch DIRECTORY|FILE...``
751
+
752
+ Shorthand: `lyp w`
753
+
754
+ Watches one or more directories or files and recompiles any files that have been modified. To watch a directory of include files and always recompile the same project file, use the `--target`/`-t` switch:
755
+
756
+ ```bash
757
+ $ lyp watch bwv35 --target bwv35/score.ly
758
+ ```
759
+
760
+ This command accepts all Lilypond command line switches.
761
+
762
+ ### lyp which
763
+
764
+ Synopsis: `lyp which PACKAGE|lilypond`
765
+
766
+ Shows the location of the given package or the currently selected Lilypond.
767
+
578
768
  ## Contributing
579
769
 
580
770
  Lyp is written in Ruby, and its code is [available on github](https://github.com/noteflakes/lyp). To hack on it, simply clone the repository. To run the specs:
@@ -1,6 +1,15 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- LYP_VERSION="1.2.1"
3
+ echo "Detecting latest lyp version..."
4
+ LATEST_RELEASE=`curl -s https://github.com/noteflakes/lyp/releases/latest`
5
+ VERSION_REGEX="tag/v([0-9\.]+)"
6
+ if [[ $LATEST_RELEASE =~ $VERSION_REGEX ]]
7
+ then
8
+ LYP_VERSION="${BASH_REMATCH[1]}"
9
+ else
10
+ echo "Could not get latest version from GitHub."
11
+ fi
12
+
4
13
  WORKDIR="/tmp/lyp-release-installer"
5
14
  URL_BASE="https://github.com/noteflakes/lyp/releases/download/v$LYP_VERSION"
6
15
 
data/lib/lyp.rb CHANGED
@@ -1,23 +1,24 @@
1
- def req_int(f)
2
- require File.expand_path("lyp/#{f}", File.dirname(__FILE__))
3
- end
4
-
5
1
  module Kernel
6
2
  @@ext_requires = {}
7
3
  def req_ext(l)
8
4
  @@ext_requires[l] ||= require(l)
9
5
  end
10
- end
11
6
 
12
- req_int 'base'
13
- req_int 'system'
14
- req_int 'settings'
7
+ LYP_RB_DIR = File.expand_path("lyp", File.dirname(__FILE__))
8
+ def req_int(f)
9
+ require File.join(LYP_RB_DIR, f)
10
+ end
11
+ end
12
+
13
+ Kernel.req_int 'base'
14
+ Kernel.req_int 'system'
15
+ Kernel.req_int 'settings'
15
16
 
16
- req_int 'template'
17
- req_int 'resolver'
18
- req_int 'wrapper'
19
- req_int 'package'
20
- req_int 'lilypond'
21
- req_int 'transform'
17
+ Kernel.req_int 'template'
18
+ Kernel.req_int 'resolver'
19
+ Kernel.req_int 'wrapper'
20
+ Kernel.req_int 'package'
21
+ Kernel.req_int 'lilypond'
22
+ Kernel.req_int 'transform'
22
23
 
23
- req_int 'windows' if Lyp::WINDOWS
24
+ Kernel.req_int 'windows' if Lyp::WINDOWS
data/lib/lyp/cli.rb CHANGED
@@ -43,29 +43,20 @@ $cmd_options = {}
43
43
 
44
44
  class Lyp::CLI < Thor
45
45
  package_name "lyp"
46
- map "-v" => :version
47
- check_unknown_options! :except => :compile
46
+ map "-v" => :version,
47
+ "c" => :compile,
48
+ "i" => :install,
49
+ "l" => :list,
50
+ "s" => :search,
51
+ "t" => :test,
52
+ "u" => :uninstall,
53
+ "U" => :use,
54
+ "w" => :watch,
55
+ "x" => :exec
56
+
57
+ check_unknown_options! :except => [:compile, :watch, :benchmark]
48
58
  class_option :verbose, aliases: '-V', :type => :boolean, desc: 'show verbose output'
49
59
 
50
- desc "version", "show Lyp version"
51
- def version
52
- $stderr.puts "Lyp #{Lyp::VERSION}"
53
- end
54
-
55
- desc "search [PATTERN|lilypond]", "List available packages matching PATTERN or versions of lilypond"
56
- def search(pattern = '')
57
- $cmd_options = options
58
-
59
- pattern =~ Lyp::PACKAGE_RE
60
- package, version = $1, $2
61
-
62
- if package == 'lilypond'
63
- search_lilypond(version)
64
- else
65
- search_package(pattern)
66
- end
67
- end
68
-
69
60
  no_commands do
70
61
  def search_lilypond(version)
71
62
  versions = Lyp::Lilypond.search(version)
@@ -99,17 +90,68 @@ class Lyp::CLI < Thor
99
90
  end
100
91
  end
101
92
 
102
- desc "compile [<option>...] <FILE>", "Invoke lilypond with given file"
93
+ desc "accelerate", "Rewrite gem binaries to make lyp faster"
94
+ def accelerate
95
+ unless Lyp::System.is_gem?
96
+ puts "Lyp is not installed as a gem."
97
+ exit 1
98
+ end
99
+
100
+ Lyp::System.rewrite_gem_scripts
101
+ end
102
+
103
+ desc "benchmark FILE", "Benchmark all installed versions of Lilypond"
104
+ def benchmark(*argv)
105
+ list = Lyp::Lilypond.list
106
+ if list.empty?
107
+ puts Lyp::LILYPOND_NOT_FOUND_MSG
108
+ else
109
+ list.each do |info|
110
+ Lyp::Lilypond.force_version!(info[:version])
111
+ t1 = Time.now
112
+ compile("--invoke-quiet", *argv)
113
+ t2 = Time.now
114
+ puts "%-7s: %.3gs" % [info[:version], t2-t1]
115
+ end
116
+ end
117
+ end
118
+
119
+ desc "cleanup", "Cleanup temporary files"
120
+ def cleanup
121
+ $stderr.puts "Lyp #{Lyp::VERSION}"
122
+ Dir["#{Lyp::TMP_ROOT}/*"].each do |fn|
123
+ puts "Cleaning up #{fn}"
124
+ FileUtils.rm_rf(fn)
125
+ end
126
+ end
127
+
128
+ desc "compile [<option>...] <FILE>", "compile given file Lilypond source file"
103
129
  def compile(*argv)
104
130
  opts, argv = Lyp::Lilypond.preprocess_argv(argv)
105
131
 
106
132
  lilypond_path = Lyp::Lilypond.select_lilypond_version(opts, argv.last)
107
133
 
108
- $stderr.puts "Lyp #{Lyp::VERSION}"
134
+ $stderr.puts "Lyp #{Lyp::VERSION}" unless opts[:mode] == :quiet
109
135
  Lyp::System.test_installed_status!
110
136
  Lyp::Lilypond.compile(argv, opts)
111
137
  end
112
138
 
139
+ desc "deps FILE", "List dependencies found in user's files"
140
+ def deps(fn)
141
+ $cmd_options = options
142
+
143
+ resolver = Lyp::DependencyResolver.new(fn)
144
+ tree = resolver.compile_dependency_tree(ignore_missing: true)
145
+ tree.dependencies.each do |package, spec|
146
+ versions = spec.versions.keys.map {|k| k =~ Lyp::PACKAGE_RE; $2 }.sort
147
+ if versions.empty?
148
+ puts " #{spec.clause} => (no local version found)"
149
+ else
150
+ puts " #{spec.clause} => #{versions.join(', ')}"
151
+ end
152
+ end
153
+ end
154
+
113
155
  desc "exec <CMD> [<options>...]", "Execute a lilypond script"
114
156
  def exec(*argv)
115
157
  $stderr.puts "Lyp #{Lyp::VERSION}"
@@ -117,38 +159,15 @@ class Lyp::CLI < Thor
117
159
  Lyp::Lilypond.invoke_script(argv, {})
118
160
  end
119
161
 
120
- desc "test [<option>...] [.|PATTERN]", "Run package tests on installed packages or local directory"
121
- method_option :install, aliases: '-n', type: :boolean, desc: 'Install the requested version of Lilypond if not present'
122
- method_option :env, aliases: '-E', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
123
- method_option :use, aliases: '-u', type: :string, desc: 'Use specified version'
124
- def test(*args)
125
- $cmd_options = options
126
- test_opts = options.dup
127
-
128
- if test_opts[:env]
129
- unless ENV['LILYPOND_VERSION']
130
- STDERR.puts "$LILYPOND_VERSION not set"
131
- exit 1
132
- end
133
- test_opts[:use] = ENV['LILYPOND_VERSION']
134
- end
135
-
136
- if test_opts[:use]
137
- if test_opts[:install]
138
- Lyp::Lilypond.install_if_missing(test_opts[:use], no_version_test: true)
139
- end
140
- Lyp::Lilypond.force_version!(test_opts[:use])
141
- end
142
-
143
- # check lilypond default / current settings
144
- Lyp::Lilypond.check_lilypond!
145
-
146
- $stderr.puts "Lyp #{Lyp::VERSION}"
147
- case args
148
- when ['.']
149
- Lyp::Package.run_local_tests('.')
162
+ desc "flatten FILE", "Flatten a file and included files into a single output file"
163
+ def flatten(input_path, output_path = nil)
164
+ input_path = File.expand_path(input_path)
165
+ output_path = File.expand_path(output_path) if output_path
166
+ flat = Lyp::Transform.flatten(input_path)
167
+ if output_path
168
+ File.open(output_path, 'w+') {|f| f << flat}
150
169
  else
151
- Lyp::Package.run_package_tests(args)
170
+ puts flat
152
171
  end
153
172
  end
154
173
 
@@ -184,50 +203,6 @@ class Lyp::CLI < Thor
184
203
  end
185
204
  end
186
205
 
187
- desc "update <PACKAGE>...", "Install a package after removing all previous versions"
188
- method_option :default, aliases: '-d', type: :boolean, desc: 'Set default Lilypond version'
189
- method_option :test, aliases: '-t', type: :boolean, desc: 'Run package tests after installation'
190
- def update(*args)
191
- invoke 'install', args, options.merge(update: true)
192
- end
193
-
194
- desc "uninstall <PACKAGE|lilypond|self>...", "Uninstall a package or a version of Lilypond. When 'uninstall self' is invoked, lyp uninstalls itself from ~/.lyp."
195
- method_option :all, aliases: '-a', type: :boolean, desc: 'Uninstall all versions'
196
- def uninstall(*args)
197
- $cmd_options = options
198
-
199
- Lyp::System.test_installed_status!
200
-
201
- raise "No package specified" if args.empty?
202
- args.each do |package|
203
- case package
204
- when 'self'
205
- Lyp::System.uninstall!
206
- when Lyp::LILYPOND_RE
207
- Lyp::System.test_installed_status!
208
- Lyp::Lilypond.uninstall($1, options)
209
- else
210
- Lyp::System.test_installed_status!
211
- Lyp::Package.uninstall(package, options)
212
- end
213
- end
214
- end
215
-
216
- desc "use [lilypond@]<VERSION>", "Switch version of Lilypond"
217
- method_option :default, aliases: '-d', type: :boolean, desc: 'Set default Lilypond version'
218
- def use(version)
219
- $cmd_options = options
220
-
221
- Lyp::System.test_installed_status!
222
-
223
- if version =~ Lyp::LILYPOND_RE
224
- version = $1
225
- end
226
-
227
- lilypond = Lyp::Lilypond.use(version, options)
228
- puts "Using Lilypond version #{lilypond[:version]}"
229
- end
230
-
231
206
  desc "list [PATTERN|lilypond]", "List installed packages matching PATTERN or versions of Lilypond"
232
207
  def list(pattern = nil)
233
208
  $cmd_options = options
@@ -265,83 +240,174 @@ class Lyp::CLI < Thor
265
240
  end
266
241
  end
267
242
 
268
- desc "which [PATTERN|lilypond]", "List locations of installed packages matching PATTERN or versions of Lilypond"
269
- def which(pattern = nil)
243
+ desc "resolve FILE", "Resolve and install missing dependencies found in user's files"
244
+ method_option :all, aliases: '-a', type: :boolean, desc: 'Install all found dependencies'
245
+ def resolve(fn)
270
246
  $cmd_options = options
271
247
 
272
- Lyp::System.test_installed_status!
248
+ resolver = Lyp::DependencyResolver.new(fn)
249
+ tree = resolver.compile_dependency_tree(ignore_missing: true)
250
+ tree.dependencies.each do |package, spec|
251
+ if options[:all] || spec.versions.empty?
252
+ Lyp::Package.install(spec.clause)
253
+ end
254
+ end
255
+ end
273
256
 
274
- if pattern == 'lilypond'
275
- current = Lyp::Lilypond.current_lilypond
276
- if current
277
- puts Lyp::Lilypond.current_lilypond
278
- else
279
- puts Lyp::LILYPOND_NOT_FOUND_MSG
257
+ desc "search [PATTERN|lilypond]", "List available packages matching PATTERN or versions of lilypond"
258
+ def search(pattern = '')
259
+ $cmd_options = options
260
+
261
+ pattern =~ Lyp::PACKAGE_RE
262
+ package, version = $1, $2
263
+
264
+ if package == 'lilypond'
265
+ search_lilypond(version)
266
+ else
267
+ search_package(pattern)
268
+ end
269
+ end
270
+
271
+ desc "test [<option>...] [.|PATTERN]", "Run package tests on installed packages or local directory"
272
+ method_option :install, aliases: '-n', type: :boolean, desc: 'Install the requested version of Lilypond if not present'
273
+ method_option :env, aliases: '-E', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
274
+ method_option :use, aliases: '-u', type: :string, desc: 'Use specified version'
275
+ def test(*args)
276
+ $cmd_options = options
277
+ test_opts = options.dup
278
+
279
+ if test_opts[:env]
280
+ unless ENV['LILYPOND_VERSION']
281
+ STDERR.puts "$LILYPOND_VERSION not set"
282
+ exit 1
280
283
  end
284
+ test_opts[:use] = ENV['LILYPOND_VERSION']
285
+ end
286
+
287
+ if test_opts[:use]
288
+ if test_opts[:install]
289
+ Lyp::Lilypond.install_if_missing(test_opts[:use], no_version_test: true)
290
+ end
291
+ Lyp::Lilypond.force_version!(test_opts[:use])
292
+ end
293
+
294
+ # check lilypond default / current settings
295
+ Lyp::Lilypond.check_lilypond!
296
+
297
+ $stderr.puts "Lyp #{Lyp::VERSION}"
298
+ case args
299
+ when ['.']
300
+ Lyp::Package.run_local_tests('.')
281
301
  else
282
- Lyp::Package.which(args.first).each {|p| puts p}
302
+ Lyp::Package.run_package_tests(args)
283
303
  end
284
304
  end
285
305
 
286
- desc "deps FILE", "List dependencies found in user's files"
287
- def deps(fn)
306
+ desc "uninstall <PACKAGE|lilypond|self>...", "Uninstall a package or a version of Lilypond. When 'uninstall self' is invoked, lyp uninstalls itself from ~/.lyp."
307
+ method_option :all, aliases: '-a', type: :boolean, desc: 'Uninstall all versions'
308
+ def uninstall(*args)
288
309
  $cmd_options = options
289
310
 
290
- resolver = Lyp::DependencyResolver.new(fn)
291
- tree = resolver.compile_dependency_tree(ignore_missing: true)
292
- tree.dependencies.each do |package, spec|
293
- versions = spec.versions.keys.map {|k| k =~ Lyp::PACKAGE_RE; $2 }.sort
294
- if versions.empty?
295
- puts " #{spec.clause} => (no local version found)"
311
+ Lyp::System.test_installed_status!
312
+
313
+ raise "No package specified" if args.empty?
314
+ args.each do |package|
315
+ case package
316
+ when 'self'
317
+ Lyp::System.uninstall!
318
+ when Lyp::LILYPOND_RE
319
+ Lyp::System.test_installed_status!
320
+ Lyp::Lilypond.uninstall($1, options)
296
321
  else
297
- puts " #{spec.clause} => #{versions.join(', ')}"
322
+ Lyp::System.test_installed_status!
323
+ Lyp::Package.uninstall(package, options)
298
324
  end
299
325
  end
300
326
  end
301
327
 
302
- desc "resolve FILE", "Resolve and install missing dependencies found in user's files"
303
- method_option :all, aliases: '-a', type: :boolean, desc: 'Install all found dependencies'
304
- def resolve(fn)
328
+ desc "update <PACKAGE>...", "Install a package after removing all previous versions"
329
+ method_option :default, aliases: '-d', type: :boolean, desc: 'Set default Lilypond version'
330
+ method_option :test, aliases: '-t', type: :boolean, desc: 'Run package tests after installation'
331
+ def update(*args)
332
+ invoke 'install', args, options.merge(update: true)
333
+ end
334
+
335
+ desc "use [lilypond@]<VERSION>", "Switch version of Lilypond"
336
+ method_option :default, aliases: '-d', type: :boolean, desc: 'Set default Lilypond version'
337
+ def use(version)
305
338
  $cmd_options = options
306
339
 
307
- resolver = Lyp::DependencyResolver.new(fn)
308
- tree = resolver.compile_dependency_tree(ignore_missing: true)
309
- tree.dependencies.each do |package, spec|
310
- if options[:all] || spec.versions.empty?
311
- Lyp::Package.install(spec.clause)
312
- end
340
+ Lyp::System.test_installed_status!
341
+
342
+ if version =~ Lyp::LILYPOND_RE
343
+ version = $1
313
344
  end
345
+
346
+ lilypond = Lyp::Lilypond.use(version, options)
347
+ puts "Using Lilypond version #{lilypond[:version]}"
314
348
  end
315
349
 
316
- desc "cleanup", "Cleanup temporary files"
317
- def cleanup
350
+ desc "version", "show Lyp version"
351
+ def version
318
352
  $stderr.puts "Lyp #{Lyp::VERSION}"
319
- Dir["#{Lyp::TMP_ROOT}/*"].each do |fn|
320
- puts "Cleaning up #{fn}"
321
- FileUtils.rm_rf(fn)
322
- end
323
353
  end
324
354
 
325
- desc "flatten FILE", "Flatten a file and included files into a single output file"
326
- def flatten(input_path, output_path = nil)
327
- input_path = File.expand_path(input_path)
328
- output_path = File.expand_path(output_path) if output_path
329
- flat = Lyp::Transform.flatten(input_path)
330
- if output_path
331
- File.open(output_path, 'w+') {|f| f << flat}
332
- else
333
- puts flat
355
+ desc "watch PATH...", "Watch files and directories and recompile when a file changes"
356
+ method_option :target, aliases: '-t', type: :string, desc: 'Set compile target'
357
+ def watch(*paths)
358
+ req_ext "directory_watcher"
359
+
360
+ recompile_proc = lambda do |path|
361
+ puts "#{path} changed"
362
+ path = options[:target] || path
363
+ puts "recompile #{path}"
364
+ if path =~ /\.(i?)ly$/
365
+ compile("--invoke-system", path)
366
+ end
334
367
  end
335
- end
336
368
 
337
- desc "accelerate", "Rewrite gem binaries to make lyp faster"
338
- def accelerate
339
- unless Lyp::System.is_gem?
340
- puts "Lyp is not installed as a gem."
341
- exit 1
369
+ target = options[:target]
370
+
371
+ watchers = paths.map do |path|
372
+ if File.directory?(path)
373
+ glob = ["**/*.ly", "**/*.ily", "**/*.scm"]
374
+ else
375
+ glob = [File.basename(path)]
376
+ path = File.dirname(path)
377
+ end
378
+
379
+ puts "Watching #{path}"
380
+ puts "glob: #{glob.inspect}"
381
+ w = DirectoryWatcher.new(path, glob: glob, pre_load: true).tap do |w|
382
+ w.interval = 0.1
383
+ w.add_observer do |*events|
384
+ events.each {|e| recompile_proc[e.path] if e.type == :modified}
385
+ end
386
+ w.start
387
+ end
342
388
  end
343
389
 
344
- Lyp::System.rewrite_gem_scripts
390
+ trap("INT") {watchers.each {|w| w.stop}; puts; exit}
391
+ puts "Press ^C to exit"
392
+ loop {sleep 1}
393
+ end
394
+
395
+ desc "which [PATTERN|lilypond]", "List locations of installed packages matching PATTERN or versions of Lilypond"
396
+ def which(pattern = nil)
397
+ $cmd_options = options
398
+
399
+ Lyp::System.test_installed_status!
400
+
401
+ if pattern == 'lilypond'
402
+ current = Lyp::Lilypond.current_lilypond
403
+ if current
404
+ puts Lyp::Lilypond.current_lilypond
405
+ else
406
+ puts Lyp::LILYPOND_NOT_FOUND_MSG
407
+ end
408
+ else
409
+ Lyp::Package.which(args.first).each {|p| puts p}
410
+ end
345
411
  end
346
412
 
347
413
  def self.run
data/lib/lyp/lilypond.rb CHANGED
@@ -52,6 +52,10 @@ module Lyp::Lilypond
52
52
  options[:use_version] = argv.shift
53
53
  when /^(?:\-u|\-\-use\=)"?([^\s]+)"?/
54
54
  options[:use_version] = $1
55
+ when '--invoke-system'
56
+ options[:mode] = :system
57
+ when '--invoke-quiet'
58
+ options[:mode] = :quiet
55
59
  else
56
60
  argv_clean << arg
57
61
  end
@@ -108,6 +112,8 @@ module Lyp::Lilypond
108
112
  case opts[:mode]
109
113
  when :system
110
114
  system("#{lilypond} #{argv.join(" ")}")
115
+ when :quiet
116
+ `#{lilypond} #{argv.join(" ")} > /dev/null 2>&1`
111
117
  when :spawn
112
118
  pid = spawn(lilypond, *argv, opts[:spawn_opts] || {})
113
119
  Process.detach(pid)
data/lib/lyp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lyp
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  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: 1.2.1
4
+ version: 1.3.0
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-12-21 00:00:00.000000000 Z
11
+ date: 2016-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -84,6 +84,20 @@ dependencies:
84
84
  - - '='
85
85
  - !ruby/object:Gem::Version
86
86
  version: 0.23.0
87
+ - !ruby/object:Gem::Dependency
88
+ name: directory_watcher
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.5.1
94
+ type: :runtime
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '='
99
+ - !ruby/object:Gem::Version
100
+ version: 1.5.1
87
101
  description: Lyp is a tool for managing lilypond versions and lilypond packages
88
102
  email: ciconia@gmail.com
89
103
  executables: