Documentation
¶
Overview ¶
Package project turns the paths a user names — files, directories and glob patterns — into the model files to load, in a deterministic order.
Index ¶
- Constants
- func Dependencies(files []string, known func(name string) bool) []string
- func EnclosingProjects(path string) []string
- func EnvLibraryRoots() []string
- func Expand(inputs []string) ([]string, error)
- func IsArchive(path string) bool
- func IsArchiveFile(path string) bool
- func IsLoadable(path string) bool
- func IsModelFile(path string) bool
- func IsProjectDir(dir string) bool
- func IsStdin(path string) bool
- func MemberPath(archive, member string) string
- func ModelFiles(dir string) ([]string, error)
- func ReadFile(path string) (string, []byte, error)
- func SplitLibraryRoots(list string) []string
- func SplitMemberPath(p string) (archive, member string, ok bool)
- func Unbundle(a *Archive, dir string) error
- type Archive
- type ArchiveError
- type Checksum
- type Discovery
- func (d Discovery) ArchiveWarnings(paths []string) []string
- func (d Discovery) Around(paths []string) Projects
- func (d Discovery) Dependencies(files []string, known func(name string) bool) []string
- func (d Discovery) DependenciesOf(sources []Source, known func(name string) bool) []string
- func (d Discovery) Expand(inputs []string) ([]string, error)
- type Interchange
- type Meta
- type Projects
- type Source
- type Usage
Constants ¶
const ( MetamodelKerML = "https://www.omg.org/spec/KerML/20250201" MetamodelSysML = "https://www.omg.org/spec/SysML/20250201" )
Metamodel IRIs the metadata file names (§10.3, Table 13), the KerML one being what an archive without the field is read as.
const ArchiveExt = ".kpar"
ArchiveExt is the extension of a KerML project interchange file: a project directory archived with ZIP (KerML 1.0 §10.3).
const LibraryRootsEnvVar = "OPENSYSML_LIBRARY_ROOTS"
LibraryRootsEnvVar names the directories installed projects are looked for under, separated as PATH is, besides the well-known ones beneath each enclosing project.
const MetaFile = ".meta.json"
MetaFile is the metadata file an archive carries beside its interchange file.
const ProjectFile = ".project.json"
ProjectFile is the file every OMG project interchange directory holds beside its model files (KerML 1.0 §10.3): a directory holding one is a project.
const Stdin = "-"
Stdin is the path that names standard input, by the convention that a lone "-" is read from the stream rather than from a file of that name. A file really called "-" is named as "./-".
const StdinName = "<stdin>"
StdinName is what a model read from standard input is called in diagnostics.
Variables ¶
This section is empty.
Functions ¶
func Dependencies ¶
Dependencies returns the model files, beside or below the named ones, that declare a root namespace an import of the named files begins with and none of them declares, then the files those imports lead to in turn. known reports the names another source declares — the standard library's root packages — so an import of one is not searched for. A named file that cannot be read or is standard input contributes nothing; the loader reports the former. The result is ordered as it was found and holds no file already named.
func EnclosingProjects ¶ added in v0.11.0
EnclosingProjects lists the directories at or above path that are projects, the nearest first; path names a file or a directory, and need not exist.
func EnvLibraryRoots ¶ added in v0.11.0
func EnvLibraryRoots() []string
EnvLibraryRoots returns the library roots LibraryRootsEnvVar names, none when it is unset.
func Expand ¶
Expand turns the paths named on a command line (or at a %load prompt) into the sources to load: a directory contributes every model file and notebook under it, a pattern contributes the model files and notebooks among its matches, and any other path is taken as named. Files come back in a deterministic order — the inputs in the order given, each directory walk and each pattern match sorted by path — and duplicates are dropped, so naming a file twice loads it once.
func IsArchive ¶ added in v0.11.0
IsArchive reports whether path is named as a project interchange file.
func IsArchiveFile ¶ added in v0.11.0
IsArchiveFile reports whether path names an existing archive: a regular file with the archive extension.
func IsLoadable ¶ added in v0.10.0
IsLoadable reports whether path names a source a load reads: a model file or a notebook, whose code cells are the model.
func IsModelFile ¶
IsModelFile reports whether path names a SysML or KerML model file.
func IsProjectDir ¶ added in v0.11.0
IsProjectDir reports whether dir holds a project interchange file.
func MemberPath ¶ added in v0.11.0
MemberPath is the path a member of an archive is named by: the archive's path, then the member's path within it.
func ModelFiles ¶
ModelFiles walks dir and returns every .sysml/.kerml file and .ipynb notebook under it, sorted by path. Hidden directories are skipped, so a repository's .git or a build cache under a dot-directory contributes nothing. Symlinked directories are walked — a project may keep a shared library as a link — each at most once, so a cycle terminates.
func ReadFile ¶
ReadFile returns the contents of the model at path together with the name it is reported under, reading standard input when path names it.
func SplitLibraryRoots ¶ added in v0.11.0
SplitLibraryRoots splits a list of library roots written as PATH is, dropping empty entries.
func SplitMemberPath ¶ added in v0.11.0
SplitMemberPath splits a path naming a member of an archive into the archive and the member's path within it, reporting whether path is such a path: one whose leading directories include an existing .kpar file.
Types ¶
type Archive ¶ added in v0.11.0
type Archive struct {
// Path is the archive as it was named.
Path string
// Project is the interchange information of the archived project; its Dir
// is the archive's path.
Project *Interchange
// Meta is the archive's metadata.
Meta Meta
// Notes are findings about the archive that did not prevent reading it.
Notes []string
// contains filtered or unexported fields
}
Archive is a project interchange file read into memory: its project information, metadata and members, none of which touch the file system.
func OpenArchive ¶ added in v0.11.0
OpenArchive reads the archive at path into memory and validates it. A file that is not a ZIP archive, or one without the interchange and metadata files the specification requires at its top level, is an *ArchiveError.
func ParseArchive ¶ added in v0.11.0
ParseArchive reads an archive from its bytes, reported under path.
func (*Archive) Files ¶ added in v0.11.0
Files lists the model files of the archive as the paths they load under: the archive's path with the member's path appended.
type ArchiveError ¶ added in v0.11.0
ArchiveError is an archive that could not be read as a project interchange file, reported under the archive's path.
func (*ArchiveError) Error ¶ added in v0.11.0
func (e *ArchiveError) Error() string
func (*ArchiveError) Unwrap ¶ added in v0.11.0
func (e *ArchiveError) Unwrap() error
type Discovery ¶ added in v0.11.0
type Discovery struct {
// Roots are the directories installed projects are looked for under,
// besides the well-known ones beneath each enclosing project.
Roots []string
// Guard, when set, is asked before a file found by the dependency search is
// read; a file it refuses is left out as if it declared nothing.
Guard func(path string) error
}
Discovery locates the projects a project uses among the installed copies under its library roots. The zero value consults the well-known layouts only.
func (Discovery) ArchiveWarnings ¶ added in v0.11.0
ArchiveWarnings reports what the archives a load touched fell short of: an archive under a library root that is not a project interchange file, and a checksum of a loaded archive that could not be verified.
func (Discovery) Around ¶ added in v0.11.0
Around finds the project each path belongs to — the nearest directory at or above it holding a project interchange file — and the installed projects those use. Installed projects are looked for under the configured roots and under the well-known library directories of every project at or above the paths, so a file inside an installed project finds the projects installed beside it. A usage no installed project answers to, the standard library's archives among them, selects nothing.
func (Discovery) Dependencies ¶ added in v0.11.0
Dependencies is the package's Dependencies with the discovery's library roots: the files are also looked for in the project each named file belongs to and in the installed projects that project uses.
func (Discovery) DependenciesOf ¶ added in v0.11.0
DependenciesOf is Dependencies over sources already read, so a notebook's cells, or a file converted from another notation, are searched from as the model text they load as. Standard input contributes nothing.
type Interchange ¶ added in v0.11.0
type Interchange struct {
Dir string
Name string
Publisher string
Description string
Version string
License string
Usage []Usage
}
Interchange is the InterchangeProject information a project's .project.json carries (KerML 1.0 Table 12), with the directory it was read from — or, for an archived project, the archive's path.
func Bundle ¶ added in v0.11.0
func Bundle(dir string) ([]byte, *Interchange, error)
Bundle archives the project directory dir as a project interchange archive (KerML 1.0 §10.3) and returns its bytes with the project they hold. Every regular file under dir is a member except those in hidden directories and hidden files other than the two manifests; a .meta.json the directory has is kept and checked against the files, one it lacks is written from them. The archive is deterministic: members sorted, each with the same fixed time.
func ReadInterchange ¶ added in v0.11.0
func ReadInterchange(dir string) (*Interchange, error)
ReadInterchange reads the project interchange file in dir. A file that is missing, unreadable or not the JSON object the specification describes is an error; properties the specification does not name are passed over.
func (*Interchange) Files ¶ added in v0.11.0
func (p *Interchange) Files() []string
Files lists the model files the project contributes, sorted: the model members of an archive, or the loadable files under a directory, at most maxDependencyDirs directories deep.
func (*Interchange) IsArchived ¶ added in v0.11.0
func (p *Interchange) IsArchived() bool
IsArchived reports whether the project was read from an archive rather than a directory.
func (*Interchange) Uses ¶ added in v0.11.0
func (p *Interchange) Uses(u Usage) bool
Uses reports whether the usage's resource IRI names the project: its last two path segments are the project's publisher and name, or its last one the name of a project with no publisher, each compared as a slug (lower case, runs of anything but letters and digits as one hyphen), so the names a registry spells in a path match the ones the project spells for people. A version written after @ in the last segment, as package URLs do, and the extension of an archive are not part of the name.
type Meta ¶ added in v0.11.0
type Meta struct {
// Index maps the names and short names of the top-level elements of the
// project's root namespaces to the member file declaring them.
Index map[string]string `json:"index"`
// Created is when the archive was made, in ISO 8601 format.
Created string `json:"created"`
// Metamodel is the IRI of the language the members are written in; KerML
// when absent.
Metamodel string `json:"metamodel,omitempty"`
// IncludesDerived and IncludesImplied qualify XMI and JSON members.
IncludesDerived *bool `json:"includesDerived,omitempty"`
IncludesImplied *bool `json:"includesImplied,omitempty"`
// Checksum maps member paths to the checksums recorded for them.
Checksum map[string][]Checksum `json:"checksum,omitempty"`
}
Meta is the content of an archive's .meta.json (KerML 1.0 §10.3, Table 13).
type Projects ¶ added in v0.11.0
type Projects struct {
// Enclosing holds the nearest project at or above each path, each once.
Enclosing []*Interchange
// Used holds the installed projects the enclosing ones use, directly or
// through the projects those use in turn; with no enclosing project, every
// project installed under the configured roots.
Used []*Interchange
// Malformed holds the archives found under the roots that could not be
// read as project interchange files, each reported under its path.
Malformed []*ArchiveError
}
Projects is what a discovery found around a set of paths: the project each path belongs to and the installed projects those use.