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 ImportedRoots(root *ast.RootNamespace) []string
- func IsArchive(path string) bool
- func IsArchiveFile(path string) bool
- func IsLibraryDir(dir, name 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 ReferencedRoots(root *ast.RootNamespace) []string
- func Relative(root, path string) string
- 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 Checksums
- type Discovery
- func (d Discovery) Around(paths []string) Projects
- func (d Discovery) Declaring(paths []string, names []string, exclude func(path string) bool) map[string][]string
- 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)
- func (d Discovery) NewWorkspaceIndex(root string) *WorkspaceIndex
- func (d Discovery) Warnings(paths []string) []Warning
- type Interchange
- type Meta
- type Projects
- type Scan
- type Source
- type Usage
- type Warning
- type WorkspaceIndex
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 the named files reference — by an import or by a qualified name — and none of them declares, then the files those references lead to in turn. known reports the names another source declares — the standard library's root packages — so a reference to 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 ImportedRoots ¶ added in v0.12.0
func ImportedRoots(root *ast.RootNamespace) []string
ImportedRoots is ReferencedRoots over the imports alone: the root namespaces the text's imports expect to find outside itself. An import is resolved before the names it makes visible, so these are looked for first.
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 IsLibraryDir ¶ added in v0.12.0
IsLibraryDir reports whether name, under dir, starts a well-known library layout of the project in dir (one holding .project.json): installed, not own, files.
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, as are the well-known library directories of a project directory, whose contents its usages select. 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 ReferencedRoots ¶ added in v0.12.0
func ReferencedRoots(root *ast.RootNamespace) []string
ReferencedRoots lists the first segment of every import and every qualified name written in root that no enclosing namespace declares — the root namespaces the text expects to find outside itself — each once, in the order first written.
func Relative ¶ added in v0.12.0
Relative spells path as a reader beside root would: relative to it when it lies under it, else as given.
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 Checksum ¶ added in v0.11.0
Checksum is one recorded digest of a member file.
func (Checksum) Unrecorded ¶ added in v0.12.0
Unrecorded reports a checksum that records no digest, by the algorithm NONE (sysand's placeholder for a member it did not digest) or an empty value.
type Checksums ¶ added in v0.12.0
type Checksums []Checksum
Checksums are the checksums recorded for one member: one object per path in the normative schema (KerML-Model-Interchange.json), a list in Table 13's text.
func (Checksums) MarshalJSON ¶ added in v0.12.0
MarshalJSON writes one checksum as the schema's object, several as a list.
func (*Checksums) UnmarshalJSON ¶ added in v0.12.0
UnmarshalJSON reads one checksum object or a non-empty list of them.
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
// Scan, when set, keeps what each library root was found to hold, so the
// discoveries of one load walk a root once. Nil walks afresh every time.
Scan *Scan
}
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) 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) Declaring ¶ added in v0.12.0
func (d Discovery) Declaring(paths []string, names []string, exclude func(path string) bool) map[string][]string
Declaring returns, for each name, the model files beside and below paths and in the projects around them that declare it at their root namespace, sorted by path and leaving out paths themselves and the files exclude admits — those a session already holds. A name no file declares is absent from the result; a file the guard refuses declares 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, searched from the directories their paths lie in — an archive member's, the archive — for the model text they load as. Standard input contributes nothing.
func (Discovery) Expand ¶ added in v0.11.0
Expand is the package's Expand with the discovery's library roots: a named directory holding a project interchange file contributes, after its own files, those of the installed projects the project uses.
func (Discovery) NewWorkspaceIndex ¶ added in v0.12.0
func (d Discovery) NewWorkspaceIndex(root string) *WorkspaceIndex
NewWorkspaceIndex is an index over the model files under root, found as the discovery finds the dependencies of a loaded file.
func (Discovery) Warnings ¶ added in v0.12.0
Warnings reports what the projects and archives a load touched fell short of: a usage left unlinked between several unclaimed installed projects, 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.
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. A .meta.json the directory has is kept and decides the members: the two manifests and exactly the files it records (checksum keys and index targets), each of which must exist. Without one, the members are what §10.3 says an archive holds — the model files under dir, outside hidden entries, library directories and nested projects — and a .meta.json 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. A directory below it that holds a project interchange file of its own is a project of its own, read through its own installation, and contributes nothing here; nor do its members in an archive.
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. The path read is the one of the resource's location (Usage.location): for a pkg:generic package URL, the repository its vcs_url qualifier names.
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]Checksums `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
// Linking describes the usages that name no installed project by publisher and name —
// linked by elimination, or answerable by several unclaimed projects — one warning per usage.
Linking []Warning
// contains filtered or unexported fields
}
Projects is what a discovery found around a set of paths: the project each path belongs to and the installed projects those use.
type Scan ¶ added in v0.13.0
type Scan struct {
// contains filtered or unexported fields
}
Scan remembers the projects and archives found under library roots. It reflects the disk as of each root's first walk, so it serves one operation.
type Source ¶ added in v0.10.0
Source is a loaded source as the dependency search sees it: the path it was read from, which locates the directories searched, and its model text. The cells of a notebook are Sources sharing the notebook's path.
type Usage ¶ added in v0.11.0
type Usage struct {
Resource string `json:"resource"`
VersionConstraint string `json:"versionConstraint"`
}
Usage is one InterchangeProjectUsage: the IRI of a project the project uses and, optionally, a constraint on the versions of it that may be used.
type Warning ¶ added in v0.12.0
Warning is what a load fell short of about the project or archive at Path.
type WorkspaceIndex ¶ added in v0.12.0
type WorkspaceIndex struct {
// contains filtered or unexported fields
}
WorkspaceIndex maps the names declared at the root namespace of the model files under a directory — and of the installed projects the project interchange file there, or above it, uses — to the files declaring them. A file is parsed once and again only when its size or modification time changed, so asking the index after every submission costs a directory walk and a stat per file, not a parse.
func (*WorkspaceIndex) Declaring ¶ added in v0.12.0
func (ix *WorkspaceIndex) Declaring(names []string, exclude func(path string) bool) map[string][]string
Declaring returns, for each name, the model files under the root declaring it at their root namespace, sorted by path and leaving out those exclude admits — the files a session already holds. A name no file declares is absent from the result. Hidden directories are not searched, and a file the discovery's guard refuses declares nothing.
func (*WorkspaceIndex) Root ¶ added in v0.12.0
func (ix *WorkspaceIndex) Root() string
Root is the directory the index is over.