► |  | Package Management in Racket

1 | Getting Started with Packages
2 | Package Concepts
3 | Using raco pkg
4 | Package Metadata
5 | Source, Binary, and Built Packages
6 | Package APIs
7 | Package Catalog Protocol
8 | PLane T Compatibility
9 | FAQ
10 | Future Plans
11 | How Package Installation and Distribution Works

▼ | 6 | Package APIs

6.1 | Functions for raco pkg
6.2 | Package Management Functions
6.3 | Package Paths and Database
6.4 | Package Source Parsing
6.5 | Package Catalog Database

On this page:

package-source-format?
package-source->name
package-source->name+ type
package-source->path

6.1.1
top ← prev up next →

#### 6.4`` Package Source Parsing

(require pkg/name) | package: base

The pkg/name library provides functions for parsing and normalizing a package source, especially for extracting a package name.

> procedure (package-source-format? v) → boolean?
> v : any/c

Returns #t if v is 'name , 'file, 'dir, 'github, 'file-url, 'dir-url, 'link, or 'static-link, and returns #f otherwise.

The 'link and 'static-link formats are the same as 'dir in terms of parsing, but they are treated differently for tasks such as package installation.

> procedure (package-source->name source [type]) → (or/c #f string?)
> source : string?
> type : (or/c package-source-format? #f) = #f

Extracts the package name from a package source, where the package source type is inferred if type is #f. If a valid name cannot be inferred, the result is #f.

> > procedure
> > (package-source->name+type |
> > |  | source |
> > | [ | type |
> > |  | #:complain complain-proc |
> > |  | #:must-infer-name? must-infer-name?] |
> > |  | #:link-dirs? link-dir?) |
> | → |  |
> (or/c #f string?)
> (or/c package-source-format? #f)
> source : string?
> type : (or/c package-source-format? #f) = #f
> complain-proc : (string? string? . -> . any) = void
> must-infer-name? : boolean? = #f
> link-dir? : boolean?

Like package-source->name, but also returns the type of the source (which is useful when the type is inferred). If the source is not well-formed, the second result can be #f.

The complain-proc function is applied when source is ill-formed. The arguments to complain-proc are source and an error message.

If must-infer-name? is true, then complain-proc is called if a valid name cannot be inferred from source.

If link-dirs? is true, then a directory path is reported as type 'link instead of 'dir.

> procedure (package-source->path source [type]) → path?
> source : string?
> type : (or/c #f 'file 'dir 'link 'static-link) = #f

Converts a file or directory package source to a filesystem path.

The package-source->path function is different from string->path in the case that source starts with file://. Also, if type is 'dir, 'link, or 'static-link, then path->directory-path is used to ensure that the result path refers to a directory.

Added in version 10.0.1.11 of package base.

top ← prev up next →