project

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 30 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 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

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

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

func (d Discovery) ArchiveWarnings(paths []string) []string

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

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

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.

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

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 or, as the table's text has it, as a list of them.

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.

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

Jump to

Keyboard shortcuts

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