lyp 0.2.1 → 0.2.2

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: be34fcbc627f99a4a4e3859e3c3629f69604a621
4
- data.tar.gz: 7141ac8c3ec2d892218022810877584f05b2afb2
3
+ metadata.gz: 86f269cc3a5d4371afd93fdb52179687f39e004d
4
+ data.tar.gz: b7e7ab100e40d0be46b4d61c4d3a2aa1aa371c38
5
5
  SHA512:
6
- metadata.gz: 1bfb4b6e26d1b552613791a58bfdeb9a65c338cf62efaa0cce537361d06a6fbc0b65f2c8bc422242f8707061a7f3541898fcb6cdc7701f3c873d96b1affc9f8e
7
- data.tar.gz: 66b0af75bb43ee1fca671ccd967ec046971320a28dc30d4c5ed71dc19b99ae59f5ee5f7974a43c505e6a6d88962374149f7f2a2483eb5882da4b136d20bd4f6b
6
+ metadata.gz: 64f17f1ca324b90ca147fc5bd41c77e52f42bc960b145204ecffb3926deda54e84930881a1f1d809e458151f27d94d17f025474cc06c40c9b6a2d7f87a34ff73
7
+ data.tar.gz: 81ec32c68983e53bd1eff21e524ff2f1143c97dae6b4ba8017055da48b40839da4dae9591b147a47f2f36b8ceb9f7e4fb0456aeeef1e834a289b78f3e6d9dfbf
data/README.md CHANGED
@@ -16,6 +16,7 @@ __No hassle Lilypond installation__: With lyp you can also install any version o
16
16
  - [Working with packages](#working-with-packages)
17
17
  - [What constitutes a package?](#what-constitutes-a-package)
18
18
  - [Installing packages](#installing-packages)
19
+ - [Automatic package installation](#automatic-package-installation)
19
20
  - [Package references](#package-references)
20
21
  - [Version specifiers](#version-specifiers)
21
22
  - [Using packages](#using-packages)
@@ -25,7 +26,12 @@ __No hassle Lilypond installation__: With lyp you can also install any version o
25
26
  - [Including fonts](#including-fonts)
26
27
  - [Testing packages](#testing-packages)
27
28
  - [Publishing packages](#publishing-packages)
28
- - [Installing and switching Lilypond versions](#installing-and-switching-lilypond-versions)
29
+ - [Installing and Using Lilypond](#installing-and-using-lilypond)
30
+ - [Installing/uninstalling a version of lilypond](#installing-uninstalling a version of lilypond)
31
+ - [Showing the list of installed lilypond versions](#showing-the-list-of-installed-lilypond-versions)
32
+ - [Showing available lilypond versions](#Showing-available-lilypond-versions)
33
+ - [Switching between lilypond versions](#switching-between-lilypond-versions)
34
+ - [Running lilypond](#running-lilypond)
29
35
  - [Contributing](#contributing)
30
36
 
31
37
  ## Installation
@@ -37,27 +43,38 @@ __No hassle Lilypond installation__: With lyp you can also install any version o
37
43
  If you have a recent (>=1.9.3) version of Ruby on your machine, you can install lyp as a gem:
38
44
 
39
45
  ```bash
40
- gem install lyp
41
- lyp install self
46
+ $ gem install lyp
47
+ $ lyp install self
42
48
  ```
43
49
 
44
50
  The `lyp install self` command is needed in order to setup the `~/.lyp` working directory and add the lyp binaries directory to your `PATH` (see below), by adding a line of code to your shell profile file.
45
51
 
46
52
  #### Installing lyp without Ruby
47
53
 
48
- If you don't have Ruby on your machine you can install lyp as a stand alone package using the [install script](https://raw.githubusercontent.com/noteflakes/lyp/master/bin/install_release.sh):
54
+ If you don't have Ruby on your machine you can install lyp as a stand alone package using the install script ([view source](https://git.io/getlyp)):
49
55
 
50
56
  ```bash
51
- curl -sSL https://git.io/getlyp | bash
57
+ $ curl -sSL https://git.io/getlyp | bash
52
58
  ```
53
59
 
54
60
  or with Wget:
55
61
 
56
62
  ```bash
57
- wget -qO- https://git.io/getlyp | bash
63
+ $ wget -qO- https://git.io/getlyp | bash
58
64
  ```
59
65
 
60
- **Note**: installing the standalone release of lyp requires having git on your machine.
66
+ 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`:
67
+
68
+ ```bash
69
+ $ cd /Downloads
70
+ # assuming linux-64 platform
71
+ $ tar -xzf lyp-0.2.1-linux-x86_64.tar.gz
72
+ $ lyp-0.2.1-linux-x86_64/lyp install self
73
+ ```
74
+
75
+ https://github.com/noteflakes/lyp/releases/download/v0.2.1/lyp-0.2.1-linux-x86_64.tar.gz
76
+
77
+ **Note**: using the standalone release of lyp requires having git on your machine.
61
78
 
62
79
  ### How lyp works
63
80
 
@@ -69,12 +86,14 @@ Lyp sets up a working directory in `~/.lyp` where it keeps its binaries, instal
69
86
  - Create a wrapper lilypond file that loads the packages.
70
87
  - Invoke the selected version of lilypond.
71
88
 
89
+ For more information on running lilypond see the section on [Running lilypond](#running-lilypond).
90
+
72
91
  ### Uninstalling
73
92
 
74
93
  In order to remove lyp from your system use the `uninstall self` command:
75
94
 
76
95
  ```bash
77
- lyp uninstall self
96
+ $ lyp uninstall self
78
97
  ```
79
98
 
80
99
  This command will undo the changes made to your shell profile file, and remove any binaries from `~/.lyp/bin`.
@@ -82,7 +101,7 @@ This command will undo the changes made to your shell profile file, and remove a
82
101
  In order to completely remove all files in `~/.lyp` you can simply delete the directory:
83
102
 
84
103
  ```bash
85
- rm -rf ~/.lyp
104
+ $ rm -rf ~/.lyp
86
105
  ```
87
106
 
88
107
  ## Working with Packages
@@ -102,31 +121,77 @@ Lilypond packages are expected to be published as git repositories. The packages
102
121
  In order to install a package, use the `lyp install` command:
103
122
 
104
123
  ```bash
105
- lyp install dummy # install latest version of package dummy
106
- lyp install github.com/ciconia/mypack@0.2.0 # install version 0.2.0
107
- lyp install mypack>=0.1.0 # install version 0.1.0 or higher
108
- lyp install mypack@dev:~/repo/mypack # install from local opath
124
+ # install latest version of package dummy
125
+ $ lyp install dummy
126
+
127
+ # install version 0.2.0
128
+ $ lyp install github.com/ciconia/mypack@0.2.0
129
+
130
+ # install version 0.1.0 or higher
131
+ $ lyp install "mypack>=0.1.0"
132
+
133
+ # install from local path (see section below on developing packages)
134
+ $ lyp install mypack@dev:~/repo/mypack
109
135
  ```
110
136
 
111
137
  To uninstall the package, use the `lyp uninstall` command:
112
138
 
113
139
  ```bash
114
- lyp uninstall dummy@0.1.0 # uninstall version 0.1.0
115
- lyp uninstall -a dummy # uninstall all versions of dummy
140
+ # uninstall version 0.1.0
141
+ $ lyp uninstall dummy@0.1.0
142
+
143
+ # uninstall all versions of dummy
144
+ $ lyp uninstall -a dummy
116
145
  ```
117
146
 
118
147
  To list currently installed packages use `lyp list` command:
119
148
 
120
149
  ```bash
121
- lyp list # list all installed packages
122
- lyp list font # list all installed packages matching the pattern 'font'
150
+ # list all installed packages
151
+ $ lyp list
152
+
153
+ # list all installed packages matching the pattern 'font'
154
+ $ lyp list font
123
155
  ```
124
156
 
125
157
  To list packages available on the lyp package index use the `lyp search` command:
126
158
 
127
159
  ```bash
128
- lyp search # list all packages in index
129
- lyp search stylesheet # list available packages matching pattern 'stylesheet'
160
+ # list all packages in index
161
+ lyp search
162
+
163
+ # list available packages matching pattern 'stylesheet'
164
+ lyp search stylesheet
165
+ ```
166
+
167
+ ### Automatic package installation
168
+
169
+ An easier way to install packages is by using the `lyp resolve` command, which installs all packages required for a given input file. Suppose a lilypond called `test.ly` with the following content:
170
+
171
+ ```lilypond
172
+ \version "2.19.35"
173
+ \require "assert"
174
+
175
+ #(assert-eq? 1 1)
176
+ #(assert:summary)
177
+ ```
178
+
179
+ To install the `assert` package required in the file we run:
180
+
181
+ ```bash
182
+ $ lyp resolve test.ly
183
+ #=>
184
+ Cloning https://github.com/noteflakes/lyp-assert.git...
185
+
186
+ Installed assert@0.2.0
187
+ ```
188
+
189
+ Package dependencies for a given input file can be shown using the `lyp deps` command:
190
+
191
+ ```bash
192
+ $ lyp deps test.ly
193
+ #=>
194
+ assert => 0.2.0
130
195
  ```
131
196
 
132
197
  ### Package references
@@ -134,16 +199,21 @@ lyp search stylesheet # list available packages matching pattern 'stylesheet'
134
199
  A package is normally referenced by its git URL. Lyp lets you provide either fully- or partially qualified URLs. A package hosted on github can be also referenced by the user/repository pair. The following are all equivalent:
135
200
 
136
201
  ```bash
137
- lyp install https://github.com/noteflakes/lyp-package-template.git
138
- lyp install https://github.com/noteflakes/lyp-package-template
139
- lyp install github.com/noteflakes/lyp-package-template
140
- lyp install noteflakes/lyp-package-template
202
+ # Fully-qualified URLs
203
+ $ lyp install https://github.com/noteflakes/lyp-package-template.git
204
+ $ lyp install https://github.com/noteflakes/lyp-package-template
205
+
206
+ # Partially-qualified URL
207
+ $ lyp install github.com/noteflakes/lyp-package-template
208
+
209
+ # Github repository id
210
+ $ lyp install noteflakes/lyp-package-template
141
211
  ```
142
212
 
143
213
  In addition, lyp also provides an [index of publically available package](https://github.com/noteflakes/lyp-index), which maps a package name to its URL (see also below). Using the index, packages are referenced by their published name instead of by their git URL:
144
214
 
145
215
  ```bash
146
- lyp install dummy
216
+ $ lyp install dummy
147
217
  ```
148
218
 
149
219
  To get a list of all available packages on the index, use the `lyp search` command.
@@ -169,21 +239,23 @@ Version constraints specify a range of versions to use. Lyp currently supports t
169
239
  Version specifiers could be used when installing, listing and requiring packages, and also for specifying versions of lilypond (see below). For example:
170
240
 
171
241
  ```bash
172
- lyp install "dummy~>0.2.0"
242
+ $ lyp install "dummy~>0.2.0"
173
243
  ```
174
244
 
175
- (__Note__: that when using version constraints you should put the package specifier in quotes)
245
+ **Note**: when using version constraints you should put the package specifier in quotes for bash properly parse the command.
176
246
 
177
- ### Using packages
247
+ ### Requiring packages
178
248
 
179
- To include a package in your lilypond code, use ther `\require` command:
249
+ To include a package in your lilypond code, use the `\require` command:
180
250
 
181
251
  ```lilypond
182
252
  \require "dummy"
183
253
  \require "github.com/lulu/mypack>=0.4.0"
184
254
  ```
185
255
 
186
- It is important to note that once you use `\require` in your code, you will have to compile it using the lilypond wrapper provided by lyp. It will not pass compilation using plain lilypond.
256
+ **Note**: once you use `\require` in your code, you will have to compile it using the lilypond wrapper provided by lyp. It will not pass compilation using plain lilypond.
257
+
258
+ Once the package requirements are defined, you can either install packages manually using [`lyp install`](#installing-packages), or automatically using [`lyp resolve`](#automatic-package-installation) as described above.
187
259
 
188
260
  ## Developing packages
189
261
 
@@ -195,18 +267,24 @@ To create a lilypond package:
195
267
  - Test & debug your code (see below).
196
268
  - Publish your package (see below).
197
269
 
198
- To test your package with an actual input file, you can install it from a local path (for more on testing [see below](#testing)). Suppose your package is at ~/repo/mypack:
270
+ To test your package with an actual input file, you can install it from a local path (for more on testing see [below](#testing-packages)). Suppose your package is at ~/repo/mypack:
199
271
 
200
272
  ```bash
201
- lyp install mypack@dev:~/repo/mypack
273
+ $ lyp install mypack@dev:~/repo/mypack
202
274
  ```
203
275
 
204
- This will create a `mypack@dev` package referencing your local files, which you can then reference from a test file in your package using the `\require` command:
276
+ This will create a `mypack@dev` package referencing your local files, which you can then reference normally from an input file using the `\require` command:
205
277
 
206
278
  ```lilypond
207
279
  \require "mypack@dev"
208
280
  ```
209
281
 
282
+ If the input file is residing inside your package (for example, [test files](#testing-packages)), you can require your package by specifying a relative path. Suppose the input file is at `mypack/test/mypack_test.ly`:
283
+
284
+ ```lilypond
285
+ \require "mypack:.."
286
+ ```
287
+
210
288
  ### The package interface
211
289
 
212
290
  In order to facilitate writing complex packages, lyp defines a few variables and functions:
@@ -224,13 +302,13 @@ Lyp provides the `\pinclude` and `\pincludeOnce` commands for including files re
224
302
  \pinclude "inc/template.ily"
225
303
  ```
226
304
 
227
- Lyp also defines a `pload` scheme function for loading scheme files using relative paths without adding directories to the `%load-path`:
305
+ Lyp also defines a `lyp:load` scheme function for loading scheme files using relative paths without adding directories to the `%load-path`:
228
306
 
229
307
  ```lilypond
230
- #(if (not (defined? 'mypack:init))(pload "scm/init.scm"))
308
+ #(if (not (defined? 'mypack:init))(lyp:load "scm/init.scm"))
231
309
  ```
232
310
 
233
- Loading scheme files that way is better, because this way one avoids possible name clashes, which may lead to unexpected behavior.
311
+ Loading scheme files that way is a better technique than adding directorys to `%load-path`, because this way one avoids possible name clashes, which may lead to unexpected behavior.
234
312
 
235
313
  ### Including fonts
236
314
 
@@ -243,8 +321,8 @@ Lyp also supports automatic installation of fonts, based on work by [Abraham Lei
243
321
  Packages can be tested by using the `lyp test` command, which will compile any file found inside the package directory ending in `_test.ly`:
244
322
 
245
323
  ```bash
246
- cd mypack
247
- lyp test .
324
+ $ cd mypack
325
+ $ lyp test .
248
326
  ```
249
327
 
250
328
  A test file can either be a simple lilypond file which includes the package files and results in a lilypond score, or a lilypond file that performs unit tests on scheme code.
@@ -257,58 +335,174 @@ In order for your package to be available to all users, you'll need to first pus
257
335
 
258
336
  You can also add your package to the lyp [public package index](https://github.com/noteflakes/lyp-index), by cloning it, editing [index.yaml](https://github.com/noteflakes/lyp-index/blob/master/index.yaml), and creating a pull request.
259
337
 
260
- ## Installing and switching Lilypond versions
338
+ ## Installing and Using Lilypond
339
+
340
+ ### Installing/uninstalling a version of lilypond
261
341
 
262
342
  When installing lilypond, the specific version to download can be specified in different ways:
263
343
 
264
344
  ```bash
265
- lyp install lilypond % latest stable version
266
- lyp install lilypond@stable % latest stable version
267
- lyp install lilypond@unstable % latest stable version
268
- lyp install lilypond@latest % latest version
269
- lyp install lilypond@2.18.1 % version 2.18.1
270
- lyp install "lilypond>=2.19.27" % highest version higher than 2.19.27
271
- lyp install "lilypond~>2.18.1" % highest 2.18 version higher than 2.18.1
345
+ # latest stable version
346
+ $ lyp install lilypond
347
+
348
+ # latest stable version
349
+ $ lyp install lilypond@stable
350
+
351
+ # latest stable version
352
+ $ lyp install lilypond@unstable
353
+
354
+ # latest version
355
+ $ lyp install lilypond@latest
356
+
357
+ # version 2.18.1
358
+ $ lyp install lilypond@2.18.1
359
+
360
+ # highest version higher than 2.19.27
361
+ $ lyp install "lilypond>=2.19.27"
362
+
363
+ # highest 2.18 version higher than 2.18.1
364
+ $ lyp install "lilypond~>2.18.1"
365
+ ```
366
+
367
+ To uninstall a version lilypond use `lyp uninstall`
368
+
369
+ ```bash
370
+ $ lyp uninstall lilypond@2.18.2
272
371
  ```
273
372
 
373
+ ### Showing the list of installed lilypond versions
374
+
274
375
  To display all installed versions of lilypond, use the `list` command:
275
376
 
276
377
  ```bash
277
- lyp list lilypond
378
+ $ lyp list lilypond
379
+ ```
380
+
381
+ The output will look as follows:
382
+
278
383
  ```
384
+ Lilypond versions:
279
385
 
280
- This will also list any versions of lilypond found outside of the `~/.lyp` directory.
386
+ => 2.18.2
387
+ 2.19.12
388
+ * 2.19.35
389
+
390
+ # => - current
391
+ # =* - current && default
392
+ # * - default
393
+ ```
394
+
395
+ (For current, default settings see below)
396
+
397
+ This will also list any versions of lilypond found on the user's `$PATH` outside of the `~/.lyp` directory (these versions will be marked as 'system' versions).
398
+
399
+ ### Showing available lilypond versions
281
400
 
282
401
  You can also list available versions of lilypond by using the `search` command:
283
402
 
284
403
  ```bash
285
- lyp search lilypond # display all available versions of lilypond
286
- lyp search "lilypond>=2.19" # display all available versions higher than 2.19
287
- lyp search "lilypond@stable" # display all available stable versions
404
+ # display all available versions of lilypond
405
+ $ lyp search lilypond
406
+
407
+ # display all available versions higher than 2.19
408
+ $ lyp search "lilypond>=2.19"
409
+
410
+ # display all available stable versions
411
+ $ lyp search "lilypond@stable"
288
412
  ````
289
413
 
414
+ The output will look as follows:
415
+
416
+ ```
417
+ Available versions of lilypond@stable:
418
+
419
+ 2.8.8
420
+ 2.10.0
421
+ 2.10.33
422
+ 2.12.0
423
+ 2.12.3
424
+ 2.14.0
425
+ 2.14.2
426
+ 2.16.0
427
+ 2.16.1
428
+ 2.16.2
429
+ 2.18.0
430
+ 2.18.1
431
+ * 2.18.2
432
+
433
+ * Currently installed
434
+ ```
435
+
436
+ ### Switching between lilypond versions
437
+
290
438
  To switch between versions use the `lyp use`. The same version specifiers could be used as for the `lyp install` command:
291
439
 
292
440
  ```bash
293
- lyp use lilypond@2.18.2 % or without the 'lilypond' identifier:
294
- lyp use stable % use latest stable version
295
- lyp use unstable % use latest unstable version
441
+ $ lyp use lilypond@2.18.2 # the 'lilypond' identifier is optional
442
+
443
+ # use latest stable/unstable versions
444
+ $ lyp use stable
445
+ $ lyp use unstable
296
446
  ```
297
447
 
298
- The setting of the current lilypond version to use will be maintained for the current shell session.
448
+ **Note**: The setting of the current lilypond version to use will be maintained for the current shell session.
299
449
 
300
450
  In order to switch the default version of lilypond to use, add the `--default` switch:
301
451
 
302
452
  ```bash
303
- lyp use --default 2.19.35
453
+ $ lyp use --default 2.19.35
454
+ ```
455
+
456
+ The version used can be further controlled using the `--use` and `--env` options passed to `lilypond` (see below).
457
+
458
+ As discussed [above](#showing-the-list-of-installed-lilypond-versions), the `lyp list lilypond` command displays the current and default settings. You can also display the path to the currently selected version by running `lyp which lilypond`:
459
+
460
+ ```bash
461
+ $ lyp which lilypond
462
+ #=> /Users/sharon/.lyp/lilyponds/2.18.2/bin/lilypond
304
463
  ```
305
464
 
465
+ ### Running lilypond
466
+
467
+ Once one or more versions of lilypond are installed, the lilypond command may be used normally to compile lilypond files. Lyp adds a few extra options:
468
+
469
+ - `--use`, `-u` - use a specific version of lilypond:
470
+
471
+ ```bash
472
+ $ lilypond --use=2.19.12 ...
473
+
474
+ # version constraints can also be used:
475
+ $ lilypond --use=">=2.19.12" ...
476
+ $ lilypond --use=stable ...
477
+ $ lilypond --use=latest ...
478
+ ```
479
+
480
+ - `--env`, `-E` - use a version set by the `$LILYPOND_VERSION` environment variable:
481
+
482
+ ```bash
483
+ $ LILYPOND_VERSION=2.18.2 lilypond --env ...
484
+ ```
485
+
486
+ - `--install`, `-n` - install the specified version of lilypond if not present. This option works only in conjunction with `--env` or `--use`:
487
+
488
+ ```bash
489
+ $ lilypond -u2.19.35 -n ...
490
+ ```
491
+
492
+ - `--raw`, `-r` - do not pre-process input file (no scanning for dependencies, no wrapping).
493
+
494
+ ```bash
495
+ $ lilypond --raw ...
496
+ ```
497
+
306
498
  ## Contributing
307
499
 
308
- Lyp is written in Ruby, and its code is [available on github](https://github.com/noteflakes/lyp). To hack on it, siply clone the repository. To run the specs:
500
+ 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:
309
501
 
310
502
  ```bash
311
- rspec
503
+ $ cd lyp
504
+ $ bundle install # needs to be run only once
505
+ $ rspec
312
506
  ```
313
507
 
314
508
  Please feel free to submit issues and pull requests.
@@ -4,11 +4,8 @@ shopt -s extglob
4
4
  set -o errtrace
5
5
  set -o errexit
6
6
 
7
- fail() { log "\nERROR: $*\n" ; exit 1 ; }
8
-
9
- has() {
10
- type "$1" > /dev/null 2>&1
11
- }
7
+ fail() { log "\nERROR: $*\n" ; exit 1 }
8
+ has() { type "$1" > /dev/null 2>&1 }
12
9
 
13
10
  download() {
14
11
  if has "curl"; then
@@ -21,7 +18,7 @@ download() {
21
18
  }
22
19
 
23
20
  WORKDIR="/tmp/lyp-release-installer"
24
- LYP_VERSION="0.2.0"
21
+ LYP_VERSION="0.2.2"
25
22
  URL_BASE="https://github.com/noteflakes/lyp/releases/download/v$LYP_VERSION"
26
23
 
27
24
  PLATFORM=`uname -sp`
@@ -3,20 +3,86 @@
3
3
  require 'lyp/version'
4
4
  require 'lyp'
5
5
 
6
- STDERR.puts "Lyp version #{Lyp::VERSION}"
6
+ def process_argv
7
+ options = {}
8
+ argv = ARGV.dup # copy for iterating
9
+ argv_clean = []
10
+ while arg = argv.shift
11
+ case arg
12
+ when '-r', '--raw'
13
+ options[:raw] = true
14
+ when '-E', '--env'
15
+ unless ENV['LILYPOND_VERSION']
16
+ STDERR.puts "$LILYPOND_VERSION not set"
17
+ exit 1
18
+ end
19
+ options[:use_version] = ENV['LILYPOND_VERSION']
20
+ when '-u', '--use'
21
+ options[:use_version] = argv.shift
22
+ when /^(?:\-u|\-\-use\=)"?([^\s]+)"?/
23
+ options[:use_version] = $1
24
+ when '-n', '--install'
25
+ options[:install] = true
26
+ else
27
+ argv_clean << arg
28
+ end
29
+ end
30
+
31
+ [options, argv_clean]
32
+ end
33
+ $options, $argv = process_argv
7
34
 
8
- Lyp::Lilypond.check_lilypond!
9
- lilypond_path = Lyp::Lilypond.current_lilypond
10
- unless lilypond_path && File.file?(lilypond_path)
11
- STDERR.puts "No version of lilypond found. To install lilypond run 'lyp install lilypond'."
35
+ def get_lilypond_path
36
+ if $options[:use_version]
37
+ if $options[:install]
38
+ Lyp::Lilypond.install_if_missing($options[:use_version])
39
+ end
40
+ Lyp::Lilypond.force_version!($options[:use_version])
41
+ end
42
+ Lyp::Lilypond.check_lilypond!
43
+ Lyp::Lilypond.current_lilypond.tap do |path|
44
+ unless path && File.file?(path)
45
+ STDERR.puts "No version of lilypond found. To install lilypond run 'lyp install lilypond'."
46
+ exit 1
47
+ end
48
+ end
49
+ rescue => e
50
+ STDERR.puts e.message
12
51
  exit 1
13
52
  end
53
+ $lilypond_path = get_lilypond_path
54
+
55
+ if $options[:raw]
56
+ exec("#{$lilypond_path} #{$argv[1..-1].join(' ')}")
57
+ end
58
+
59
+ OVERRIDING_LILYPOND_SWITCHES = %w{
60
+ -w --warranty
61
+ -v --version
62
+ scheme-sandbox
63
+ }
64
+ LILYPOND_HELP_SWITCHES = %w{
65
+ -h --help
66
+ }
67
+ LYP_LY_HELP = <<EOF
68
+ Lyp-provided options:
69
+ -r, --raw run raw lilypond (no pre-processing)
70
+ -E, --env use version specified in $LILYPOND_VERSION
71
+ -u, --use=VERSION use the given version of lilypond
72
+ -n, --install install the given version if not found
73
+ EOF
14
74
 
15
- case ARGV
16
- when [], ['-v'], ['--warranty'], ['scheme-sandbox']
17
- exec("#{lilypond_path} #{ARGV.join(' ')}")
75
+ case $argv.first
76
+ when nil, *OVERRIDING_LILYPOND_SWITCHES
77
+ STDERR.puts "Lyp version #{Lyp::VERSION}"
78
+ exec("#{$lilypond_path} #{$argv.join(' ')}")
79
+
80
+ when *LILYPOND_HELP_SWITCHES
81
+ STDERR.puts "Lyp version #{Lyp::VERSION}"
82
+ puts `#{$lilypond_path} #{$argv.join(' ')}`
83
+ puts LYP_LY_HELP
18
84
  else
19
85
  begin
20
- Lyp::Lilypond.compile(ARGV)
86
+ Lyp::Lilypond.compile($argv, $options)
21
87
  end
22
88
  end
@@ -25,6 +25,8 @@ module Lyp
25
25
  # etc/lyp.ly contains lyp:* procedure definitions for loading packages and
26
26
  # other support code.
27
27
  LYP_LY_LIB_PATH = File.expand_path('etc/lyp.ly', File.dirname(__FILE__))
28
+
29
+ LILYPOND_NOT_FOUND_MSG = "No version of lilypond found.\nTo install lilypond run 'lyp install lilypond'"
28
30
 
29
31
  SETTINGS_FILENAME = 'settings.yml'
30
32
 
@@ -39,10 +39,13 @@ LILYPOND_LEGEND = <<EOF
39
39
 
40
40
  EOF
41
41
 
42
+ $cmd_options = {}
43
+
42
44
  class Lyp::CLI < Thor
43
45
  package_name "lyp"
44
46
  map "-v" => :version
45
47
  check_unknown_options! :except => :compile
48
+ class_option :verbose, aliases: '-V', :type => :boolean
46
49
 
47
50
  desc "version", "show Lyp version"
48
51
  def version
@@ -51,7 +54,7 @@ class Lyp::CLI < Thor
51
54
 
52
55
  desc "search [PATTERN|lilypond]", "List available packages matching PATTERN or versions of lilypond"
53
56
  def search(pattern = '')
54
- # Lyp::System.test_installed_status!
57
+ $cmd_options = options
55
58
 
56
59
  pattern =~ Lyp::PACKAGE_RE
57
60
  package, version = $1, $2
@@ -68,9 +71,9 @@ class Lyp::CLI < Thor
68
71
  versions = Lyp::Lilypond.search(version)
69
72
 
70
73
  if versions.empty?
71
- puts "\nNo versions of lilypond are available for download\n\n"
74
+ puts "\nNo available versions of lilypond@#{version} found\n\n"
72
75
  else
73
- puts "\nAvailable versions of lilypond:\n\n"
76
+ puts "\nAvailable versions of lilypond@#{version}:\n\n"
74
77
  versions.each do |v|
75
78
  prefix = v[:installed] ? " * " : " "
76
79
  puts "#{prefix}#{v[:version]}"
@@ -94,42 +97,61 @@ class Lyp::CLI < Thor
94
97
  end
95
98
 
96
99
  desc "compile [<option>...] <FILE>", "Invokes lilypond with given file"
97
- method_option :install, aliases: '-i', type: :boolean, desc: 'Install the requested version of lilypond if not present'
98
- method_option :env, aliases: '-e', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
100
+ method_option :install, aliases: '-n', type: :boolean, desc: 'Install the requested version of lilypond if not present'
101
+ method_option :env, aliases: '-E', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
102
+ method_option :use, aliases: '-u', type: :string, desc: 'Use specified version'
99
103
  def compile(*args)
100
- $stderr.puts "Lyp #{Lyp::VERSION}"
101
- Lyp::System.test_installed_status!
104
+ $cmd_options = options
102
105
 
103
106
  if options[:env]
104
- Lyp::Lilypond.force_env_version!
105
- if options[:install] && !Lyp::Lilypond.forced_lilypond
106
- Lyp::Lilypond.install(Lyp::Lilypond.forced_version)
107
+ unless ENV['LILYPOND_VERSION']
108
+ STDERR.puts "$LILYPOND_VERSION not set"
109
+ exit 1
107
110
  end
108
- else
109
- # check lilypond default / current settings
110
- Lyp::Lilypond.check_lilypond!
111
+ options[:use] = ENV['LILYPOND_VERSION']
111
112
  end
112
113
 
114
+ if options[:use]
115
+ if options[:install]
116
+ Lyp::Lilypond.install_if_missing(options[:use], no_version_test: true)
117
+ end
118
+ Lyp::Lilypond.force_version!(options[:use])
119
+ end
120
+
121
+ # check lilypond default / current settings
122
+ Lyp::Lilypond.check_lilypond!
123
+
124
+ $stderr.puts "Lyp #{Lyp::VERSION}"
125
+ Lyp::System.test_installed_status!
113
126
  Lyp::Lilypond.compile(args)
114
127
  end
115
128
 
116
129
  desc "test [<option>...] [.|PATTERN]", "Runs package tests on installed packages or local directory"
117
- method_option :install, aliases: '-i', type: :boolean, desc: 'Install the requested version of lilypond if not present'
118
- method_option :env, aliases: '-e', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
119
- method_option :all, aliases: '-a', type: :boolean, desc: ''
130
+ method_option :install, aliases: '-n', type: :boolean, desc: 'Install the requested version of lilypond if not present'
131
+ method_option :env, aliases: '-E', type: :boolean, desc: 'Use version set by LILYPOND_VERSION environment variable'
132
+ method_option :use, aliases: '-u', type: :string, desc: 'Use specified version'
120
133
  def test(*args)
121
- $stderr.puts "Lyp #{Lyp::VERSION}"
134
+ $cmd_options = options
122
135
 
123
136
  if options[:env]
124
- Lyp::Lilypond.force_env_version!
125
- if options[:install] && !Lyp::Lilypond.forced_lilypond
126
- Lyp::Lilypond.install(Lyp::Lilypond.forced_version)
137
+ unless ENV['LILYPOND_VERSION']
138
+ STDERR.puts "$LILYPOND_VERSION not set"
139
+ exit 1
127
140
  end
128
- else
129
- # check lilypond default / current settings
130
- Lyp::Lilypond.check_lilypond!
141
+ options[:use] = ENV['LILYPOND_VERSION']
131
142
  end
132
143
 
144
+ if options[:use]
145
+ if options[:install]
146
+ Lyp::Lilypond.install_if_missing(options[:use], no_version_test: true)
147
+ end
148
+ Lyp::Lilypond.force_version!(options[:use])
149
+ end
150
+
151
+ # check lilypond default / current settings
152
+ Lyp::Lilypond.check_lilypond!
153
+
154
+ $stderr.puts "Lyp #{Lyp::VERSION}"
133
155
  case args
134
156
  when ['.']
135
157
  Lyp::Package.run_local_tests('.')
@@ -142,6 +164,8 @@ class Lyp::CLI < Thor
142
164
  method_option :default, aliases: '-d', type: :boolean, desc: 'Set default lilypond version'
143
165
  method_option :test, aliases: '-t', type: :boolean, desc: 'Run package tests after installation'
144
166
  def install(*args)
167
+ $cmd_options = options
168
+
145
169
  raise "No package specified" if args.empty?
146
170
 
147
171
  args.each do |package|
@@ -161,6 +185,8 @@ class Lyp::CLI < Thor
161
185
  desc "uninstall <PACKAGE|lilypond|self>...", "Uninstall a package or a version of lilypond. When 'uninstall self' is invoked, lyp uninstalls itself from ~/.lyp."
162
186
  method_option :all, aliases: '-a', type: :boolean, desc: 'Uninstall all versions'
163
187
  def uninstall(*args)
188
+ $cmd_options = options
189
+
164
190
  Lyp::System.test_installed_status!
165
191
 
166
192
  raise "No package specified" if args.empty?
@@ -170,7 +196,7 @@ class Lyp::CLI < Thor
170
196
  Lyp::System.uninstall!
171
197
  when Lyp::LILYPOND_RE
172
198
  Lyp::System.test_installed_status!
173
- Lyp::Lilypond.uninstall($1)
199
+ Lyp::Lilypond.uninstall($1, options)
174
200
  else
175
201
  Lyp::System.test_installed_status!
176
202
  Lyp::Package.uninstall(package, options)
@@ -181,6 +207,8 @@ class Lyp::CLI < Thor
181
207
  desc "use [lilypond@]<VERSION>", "Switch version of lilypond"
182
208
  method_option :default, aliases: '-d', type: :boolean, desc: 'Set default lilypond version'
183
209
  def use(version)
210
+ $cmd_options = options
211
+
184
212
  Lyp::System.test_installed_status!
185
213
 
186
214
  if version =~ Lyp::LILYPOND_RE
@@ -193,12 +221,19 @@ class Lyp::CLI < Thor
193
221
 
194
222
  desc "list [PATTERN|lilypond]", "List installed packages matching PATTERN or versions of lilypond"
195
223
  def list(pattern = nil)
224
+ $cmd_options = options
225
+
196
226
  Lyp::System.test_installed_status!
197
227
 
198
228
  if pattern == 'lilypond'
199
- STDOUT.puts LILYPOND_PREAMBLE
200
- Lyp::Lilypond.list.each {|info| puts format_lilypond_entry(info)}
201
- STDOUT.puts LILYPOND_LEGEND
229
+ list = Lyp::Lilypond.list
230
+ if list.empty?
231
+ puts LILYPOND_NOT_FOUND_MSG
232
+ else
233
+ puts LILYPOND_PREAMBLE
234
+ list.each {|info| puts format_lilypond_entry(info)}
235
+ puts LILYPOND_LEGEND
236
+ end
202
237
  else
203
238
  list = Lyp::Package.list(args.first)
204
239
  if list.empty?
@@ -223,10 +258,17 @@ class Lyp::CLI < Thor
223
258
 
224
259
  desc "which [PATTERN|lilypond]", "List locations of installed packages matching PATTERN or versions of lilypond"
225
260
  def which(pattern = nil)
261
+ $cmd_options = options
262
+
226
263
  Lyp::System.test_installed_status!
227
264
 
228
265
  if pattern == 'lilypond'
229
- puts Lyp::Lilypond.current_lilypond
266
+ current = Lyp::Lilypond.current_lilypond
267
+ if current
268
+ puts Lyp::Lilypond.current_lilypond
269
+ else
270
+ puts LILYPOND_NOT_FOUND_MSG
271
+ end
230
272
  else
231
273
  Lyp::Package.which(args.first).each {|p| puts p}
232
274
  end
@@ -234,6 +276,8 @@ class Lyp::CLI < Thor
234
276
 
235
277
  desc "deps FILE", "Lists dependencies found in user's files"
236
278
  def deps(fn)
279
+ $cmd_options = options
280
+
237
281
  resolver = Lyp::Resolver.new(fn)
238
282
  tree = resolver.get_dependency_tree(ignore_missing: true)
239
283
  tree[:dependencies].each do |package, leaf|
@@ -249,6 +293,8 @@ class Lyp::CLI < Thor
249
293
  desc "resolve FILE", "Resolves and installs missing dependencies found in user's files"
250
294
  method_option :all, aliases: '-a', type: :boolean, desc: 'Install all found dependencies'
251
295
  def resolve(fn)
296
+ $cmd_options = options
297
+
252
298
  resolver = Lyp::Resolver.new(fn)
253
299
  tree = resolver.get_dependency_tree(ignore_missing: true)
254
300
  tree[:dependencies].each do |package, leaf|
@@ -263,6 +309,6 @@ begin
263
309
  Lyp::CLI.start(ARGV)
264
310
  rescue => e
265
311
  puts e.message
266
- puts e.backtrace.join("\n")
312
+ puts e.backtrace.join("\n") if $cmd_options[:verbose]
267
313
  exit(1)
268
314
  end
@@ -1,5 +1,5 @@
1
- require 'httpclient'
2
1
  require 'uri'
2
+ require 'httpclient'
3
3
  require 'open3'
4
4
  require 'ruby-progressbar'
5
5
 
@@ -57,11 +57,12 @@ module Lyp::Lilypond
57
57
  end
58
58
 
59
59
  def forced_lilypond
60
- lilypond = lyp_lilyponds.find do |l|
61
- l[:version] == @forced_version
60
+ lilypond = filter_installed_list(@forced_version)[0]
61
+ if lilypond
62
+ lilypond[:path]
63
+ else
64
+ raise "No installed version found matching '#{@forced_version}'"
62
65
  end
63
-
64
- lilypond && lilypond[:path]
65
66
  end
66
67
 
67
68
  def force_env_version!
@@ -71,6 +72,10 @@ module Lyp::Lilypond
71
72
  end
72
73
  end
73
74
 
75
+ def force_version!(version)
76
+ @forced_version = version
77
+ end
78
+
74
79
  attr_reader :forced_version
75
80
 
76
81
  def check_lilypond!
@@ -81,7 +86,7 @@ module Lyp::Lilypond
81
86
  end
82
87
 
83
88
  def valid_lilypond?(path)
84
- File.file?(path) && (`#{path} -v` =~ /^GNU LilyPond/)
89
+ (File.file?(path) rescue nil) && (`#{path} -v` =~ /^GNU LilyPond/)
85
90
  end
86
91
 
87
92
  def select_default_lilypond!
@@ -89,6 +94,8 @@ module Lyp::Lilypond
89
94
  if latest
90
95
  default = latest[:path]
91
96
  set_default_lilypond(default)
97
+ else
98
+ raise LILYPOND_NOT_FOUND_MSG
92
99
  end
93
100
  end
94
101
 
@@ -110,9 +117,14 @@ module Lyp::Lilypond
110
117
  Gem::Version.new(x[:version]) <=> Gem::Version.new(y[:version])
111
118
  end
112
119
 
113
- def list
114
- system_list = system_lilyponds
115
- lyp_list = lyp_lilyponds
120
+ def filter_installed_list(version_specifier)
121
+ list = (system_lilyponds + lyp_lilyponds).sort!(&CMP_VERSION)
122
+ list.select {|l| version_match(l[:version], version_specifier, list)}
123
+ end
124
+
125
+ def list(opts = {})
126
+ system_list = opts[:lyp_only] ? [] : system_lilyponds
127
+ lyp_list = opts[:system_only] ? [] : lyp_lilyponds
116
128
 
117
129
  default = default_lilypond
118
130
  unless default
@@ -191,21 +203,19 @@ module Lyp::Lilypond
191
203
  # Returns a list of versions of lilyponds available for download
192
204
  def search(version_specifier = nil)
193
205
  require 'open-uri'
194
- require 'nokogiri'
195
206
 
196
207
  platform = detect_lilypond_platform
197
208
  url = "#{BASE_URL}/#{platform}/"
198
- doc = Nokogiri::HTML(open(url))
199
209
 
200
210
  versions = []
201
- doc.xpath("//td//a").each do |a|
202
- if a[:href] =~ /^lilypond-([0-9\.]+)/
203
- versions << $1
204
- end
211
+
212
+ open(url).read.scan(/a href=\"lilypond-([0-9\.]+)[^>]+\"/) do |m|
213
+ versions << $1
205
214
  end
206
-
215
+
207
216
  installed_versions = list.map {|l| l[:version]}
208
- versions.select {|v| version_match(v, version_specifier, versions)}.map do |v|
217
+ versions.select! {|v| version_match(v, version_specifier, versions)}
218
+ versions.map do |v|
209
219
  {
210
220
  version: v,
211
221
  installed: installed_versions.include?(v)
@@ -238,6 +248,12 @@ module Lyp::Lilypond
238
248
  search.last[:version]
239
249
  end
240
250
 
251
+ def install_if_missing(version_specifier, opts = {})
252
+ if filter_installed_list(version_specifier).empty?
253
+ install(version_specifier, opts)
254
+ end
255
+ end
256
+
241
257
  def install(version_specifier, opts = {})
242
258
  version = detect_version_from_specifier(version_specifier)
243
259
  raise "No version found matching specifier #{version_specifier}" unless version
@@ -394,7 +410,8 @@ module Lyp::Lilypond
394
410
  FileUtils.cp_r(dir, target_dir, remove_destination: true) if File.directory?(dir)
395
411
  end
396
412
 
397
- STDERR.puts exec "#{target_dir}/bin/lilypond -v" unless opts[:silent]
413
+ # Show lilypond versions
414
+ STDERR.puts `#{target_dir}/bin/lilypond -v` unless opts[:silent] || opts[:no_version_test]
398
415
  rescue => e
399
416
  puts e.message
400
417
  end
@@ -465,24 +482,29 @@ module Lyp::Lilypond
465
482
  lilypond
466
483
  end
467
484
 
468
- def uninstall(version)
469
- lilyponds = list.reverse
470
- lilypond = lilyponds.find {|l| l[:version] == version && !l[:system]}
471
- unless lilypond
472
- raise "Invalid version specified: #{version}"
485
+ def uninstall(version_specifier, opts = {})
486
+ list = list(lyp_only: true)
487
+ if version_specifier
488
+ list.select! {|l| version_match(l[:version], version_specifier, list)}
489
+ elsif !opts[:all]
490
+ # if no version is specified
491
+ raise "No version specifier given.\nTo uninstall all versions run 'lyp uninstall lilypond -a'.\n"
473
492
  end
474
- lilyponds.delete(lilypond)
475
- latest = lilyponds.first
476
493
 
477
- if lilypond[:default]
478
- set_default_lilypond(latest && latest[:path])
479
- end
480
- if lilypond[:current]
481
- set_current_lilypond(latest && latest[:path])
494
+ if list.empty?
495
+ if version_specifier
496
+ raise "No lilypond found matching #{version_specifier}"
497
+ else
498
+ raise "No lilypond found"
499
+ end
482
500
  end
483
501
 
484
- lilypond_dir = File.expand_path('../..', lilypond[:path])
485
- FileUtils.rm_rf(lilypond_dir)
502
+ list.each do |l|
503
+ puts "Uninstalling lilypond #{l[:version]}" unless opts[:silent]
504
+ set_current_lilypond(nil) if l[:current]
505
+ set_default_lilypond(nil) if l[:default]
506
+ FileUtils.rm_rf(l[:root_path])
507
+ end
486
508
  end
487
509
 
488
510
  def exec(cmd, raise_on_failure = true)
@@ -1,3 +1,3 @@
1
1
  module Lyp
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
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-28 00:00:00.000000000 Z
11
+ date: 2016-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: highline
14
+ name: httpclient
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2.7'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.7.8
22
+ version: 2.7.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '1.7'
29
+ version: '2.7'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.7.8
32
+ version: 2.7.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: ruby-progressbar
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -70,40 +70,6 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 0.19.1
73
- - !ruby/object:Gem::Dependency
74
- name: httpclient
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - "~>"
78
- - !ruby/object:Gem::Version
79
- version: '2.7'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 2.7.1
83
- type: :runtime
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.7'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 2.7.1
93
- - !ruby/object:Gem::Dependency
94
- name: nokogiri
95
- requirement: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - '='
98
- - !ruby/object:Gem::Version
99
- version: 1.6.6.2
100
- type: :runtime
101
- prerelease: false
102
- version_requirements: !ruby/object:Gem::Requirement
103
- requirements:
104
- - - '='
105
- - !ruby/object:Gem::Version
106
- version: 1.6.6.2
107
73
  - !ruby/object:Gem::Dependency
108
74
  name: rugged
109
75
  requirement: !ruby/object:Gem::Requirement