project

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const ArchiveExt = ".kpar"

ArchiveExt is the extension of a KerML project interchange file: a project directory archived with ZIP (KerML 1.0 §10.3).

View Source
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.

View Source
const MetaFile = ".meta.json"

MetaFile is the metadata file an archive carries beside its interchange file.

View Source
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.

View Source
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 "./-".

View Source
const StdinName = "<stdin>"

StdinName is what a model read from standard input is called in diagnostics.

Variables

This section is empty.

Functions

func Dependencies

func Dependencies(files []string, known func(name string) bool) []string

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

func EnclosingProjects(path string) []string

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

func Expand(inputs []string) ([]string, error)

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

func IsArchive(path string) bool

IsArchive reports whether path is named as a project interchange file.

func IsArchiveFile added in v0.11.0

func IsArchiveFile(path string) bool

IsArchiveFile reports whether path names an existing archive: a regular file with the archive extension.

func IsLibraryDir added in v0.12.0

func IsLibraryDir(dir, name string) bool

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

func IsLoadable(path string) bool

IsLoadable reports whether path names a source a load reads: a model file or a notebook, whose code cells are the model.

func IsModelFile

func IsModelFile(path string) bool

IsModelFile reports whether path names a SysML or KerML model file.

func IsProjectDir added in v0.11.0

func IsProjectDir(dir string) bool

IsProjectDir reports whether dir holds a project interchange file.

func IsStdin

func IsStdin(path string) bool

IsStdin reports whether path names standard input.

func MemberPath added in v0.11.0

func MemberPath(archive, member string) string

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

func ModelFiles(dir string) ([]string, error)

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

func ReadFile(path string) (string, []byte, error)

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

func Relative(root, path string) string

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

func SplitLibraryRoots(list string) []string

SplitLibraryRoots splits a list of library roots written as PATH is, dropping empty entries.

func SplitMemberPath added in v0.11.0

func SplitMemberPath(p string) (archive, member string, ok bool)

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.

func Unbundle added in v0.11.0

func Unbundle(a *Archive, dir string) error

Unbundle materializes the archive as a project directory at dir, which must not exist or be empty, so an archive never overwrites a file that was there. Members are written under their archive paths, which OpenArchive has already confined to the directory.

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

func OpenArchive(path string) (*Archive, error)

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

func ParseArchive(path string, data []byte) (*Archive, error)

ParseArchive reads an archive from its bytes, reported under path.

func (*Archive) Files added in v0.11.0

func (a *Archive) Files() []string

Files lists the model files of the archive as the paths they load under: the archive's path with the member's path appended.

func (*Archive) Names added in v0.11.0

func (a *Archive) Names() []string

Names lists every member of the archive, sorted.

func (*Archive) Read added in v0.11.0

func (a *Archive) Read(member string) ([]byte, error)

Read returns the bytes of a member.

type ArchiveError added in v0.11.0

type ArchiveError struct {
	Path string
	Err  error
}

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

type Checksum struct {
	Value     string `json:"value"`
	Algorithm string `json:"algorithm"`
}

Checksum is one recorded digest of a member file.

func (Checksum) Unrecorded added in v0.12.0

func (c Checksum) Unrecorded() bool

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

func (c Checksums) MarshalJSON() ([]byte, error)

MarshalJSON writes one checksum as the schema's object, several as a list.

func (*Checksums) UnmarshalJSON added in v0.12.0

func (c *Checksums) UnmarshalJSON(data []byte) error

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

func (d Discovery) Around(paths []string) Projects

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

func (d Discovery) Dependencies(files []string, known func(name string) bool) []string

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

func (d Discovery) DependenciesOf(sources []Source, known func(name string) bool) []string

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

func (d Discovery) Expand(inputs []string) ([]string, error)

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

func (d Discovery) Warnings(paths []string) []Warning

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).

func ParseMeta added in v0.11.0

func ParseMeta(content []byte) (Meta, error)

ParseMeta reads the metadata of Table 13 from the bytes of a .meta.json. A checksum may be recorded as one object, as the schema has it, or as a list of them, as the table's text has it.

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.

func (Projects) Dirs added in v0.11.0

func (p Projects) Dirs() []string

Dirs lists the directories of the enclosing and the used projects, in that order.

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.

func NewScan added in v0.13.0

func NewScan() *Scan

NewScan returns an empty Scan.

type Source added in v0.10.0

type Source struct {
	Path    string
	Content []byte
}

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

type Warning struct {
	Path    string
	Message string
}

Warning is what a load fell short of about the project or archive at Path.

func (Warning) String added in v0.12.0

func (w Warning) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL