feat: add environment metadata file sysand_env/env.toml#175
feat: add environment metadata file sysand_env/env.toml#175victor-linroth-sensmetry wants to merge 13 commits intomainfrom
sysand_env/env.toml#175Conversation
f5eb786 to
2ff1dba
Compare
What about IRIs for non-PURL usages? Since names will likely not be unique (e.g. 10 projects named "Requirements"), how will they be disambiguated to the user? |
Well, our solution for name collisions is to use namespaces(/publishers). If you don't use them, then you don't get the solution. |
I highly suggest using paths relative to manifest/
Why would anyone care about collisions in what is effectively a display name? If a user has multiple projects named the same, they have bigger issues than some ambiguous name. |
|
Maybe also add |
sysand_envsysand_env/current.toml
sysand_env/current.tomlsysand_env/current.toml
sysand_env/current.tomlsysand_env/current.toml
2ff1dba to
dea655c
Compare
sysand_env/current.tomlsysand_env/env.toml
5f996f0 to
ec6f714
Compare
…t of the current project. Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
ec6f714 to
51e123f
Compare
| #[serde(deserialize_with = "deserialize_unix_path")] | ||
| pub path: Utf8UnixPathBuf, | ||
| /// List of identifiers (IRIs) used for the project. | ||
| /// The first identifier is to. be considered the canonical |
There was a problem hiding this comment.
| /// The first identifier is to. be considered the canonical | |
| /// The first identifier is considered the canonical |
| /// to the `path` of the project. | ||
| #[serde(deserialize_with = "deserialize_optional_unix_paths", default)] | ||
| pub files: Option<Vec<Utf8UnixPathBuf>>, | ||
| /// Indicator of wether the project is part of a workspace. |
There was a problem hiding this comment.
| /// Indicator of wether the project is part of a workspace. | |
| /// Indicator of whether the project is part of current workspace. |
Since editable projects are expected to change frequently, how will
Which workspace? Workspace that owns this env? Or another unrelated one? |
core/src/project/utils.rs
Outdated
| .as_os_str() | ||
| .to_str() | ||
| // This conversion should always be possible since everything is UTF8 encoded | ||
| .expect("component of `Utf8Path` no convertible to `str`"), |
There was a problem hiding this comment.
| .expect("component of `Utf8Path` no convertible to `str`"), | |
| .expect("component of `Utf8Path` not convertible to `str`"), |
There was a problem hiding this comment.
Nevermind, just use component.as_str() directly.
There was a problem hiding this comment.
Yes, looking at it the str conversion is probably leftover code from before camino. Will fix.
Hmm, good question. Could maybe be updated whenever the env is updated. Or simply simply drop
Yeah, I think the idea at least is to have common lockfile, env and build directory in a workspace. This is to indicate of that is the case and which projects are workspace memebers. |
Agree on dropping
Ok, so current workspace. Yeah, having common env/lockfile/build dir is a sensible thing to do. |
core/src/lock.rs
Outdated
| // Simple stopgap solution for now | ||
| pub fn get_package_url<'a>(&self) -> Option<PackageUrl<'a>> { | ||
| self.identifiers | ||
| .first() | ||
| .and_then(|id| PackageUrl::from_str(id.as_str()).ok()) | ||
| } |
There was a problem hiding this comment.
Shouldn't this use publisher and name (if both are present)?
There was a problem hiding this comment.
Especially with my upcoming changes to usage specification, not sure if identifiers will contain the PURL (haven't decided yet).
There was a problem hiding this comment.
Leftover from before publisher was added. Should probably remove.
| // TODO: Consider under which circumstances (if any) | ||
| // the workspace should carry over. |
There was a problem hiding this comment.
Workspace should not carry over by default, as that's unlikely to be the goal of the user when cloning a project. It would be sufficient to maybe expose command to add current project to workspace (out of scope of this PR), but not sure if it's worth it, workspace file can be easily edited manually.
| let root_path = if let Some(current_workspace) = &ctx.current_workspace { | ||
| wrapfs::canonicalize(current_workspace.root_path())? | ||
| } else if let Some(current_project) = &ctx.current_project { | ||
| wrapfs::canonicalize(current_project.root_path())? | ||
| } else { | ||
| wrapfs::canonicalize(&ctx.current_directory)? | ||
| }; |
There was a problem hiding this comment.
These should already be canonical and if not, should be made so elsewhere, as we need them to be canonical in most places. Regarding Windows, probably a good idea to use dunce crate to avoid UNC where possible.
There was a problem hiding this comment.
Yeah, this was due to Windows and UNC nonsense. canonicalize and current_dir gives different formats for some reason.
There was a problem hiding this comment.
From what I found, CWD is generally never UNC on Windows.
Add a TODO to this effect somewhere. Not sure what to do about this longer term, as |
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Put a TODO in |
| #[derive(Debug, Deserialize)] | ||
| pub struct EnvMetadata { | ||
| pub version: String, | ||
| #[serde(rename = "project", skip_serializing_if = "Vec::is_empty", default)] |
There was a problem hiding this comment.
No need for these here, as the serialization is implemented manually. Same applies to Lock (maybe there are others?).
| /// identifier, and if the project is not `editable` this | ||
| /// is the IRI it is installed as. The rest are considered | ||
| /// as aliases. Can only be empty for `editable` projects. | ||
| #[serde(skip_serializing_if = "Vec::is_empty", default)] |
There was a problem hiding this comment.
No need for this, see above.
(same applies to other fields here)
| pub fn to_toml(&self) -> Table { | ||
| let mut table = Table::new(); | ||
| if let Some(publisher) = &self.publisher { | ||
| table.insert("publisher", value(publisher)); | ||
| } | ||
| if let Some(name) = &self.name { | ||
| table.insert("name", value(name)); | ||
| } | ||
| table.insert("version", value(&self.version)); | ||
| table.insert("path", value(self.path.as_str())); | ||
| if !self.identifiers.is_empty() { | ||
| table.insert( | ||
| "identifiers", | ||
| value(multiline_array(self.identifiers.iter())), | ||
| ); | ||
| } | ||
| if !self.usages.is_empty() { | ||
| table.insert("usages", value(multiline_array(self.usages.iter()))); | ||
| } | ||
| if self.editable { | ||
| table.insert("editable", value(true)); | ||
| } | ||
|
|
||
| table | ||
| } |
There was a problem hiding this comment.
workspace is ignored
| /// Adds identifiers from other project. | ||
| /// Should only be done if the underlying projects are the same. | ||
| /// In particular they must have the same version. | ||
| pub fn merge(&mut self, other: &EnvProject) { |
There was a problem hiding this comment.
| pub fn merge(&mut self, other: &EnvProject) { | |
| pub fn merge_identifiers(&mut self, other: &EnvProject) { |
| dunce::canonicalize(path.as_ref()) | ||
| .map(|path| { | ||
| Utf8PathBuf::from_path_buf(path) | ||
| .expect("expected Dunce not to introduce non UTF8 characters") |
There was a problem hiding this comment.
This may not be the case with symlinks/relative path inputs. Do a manual match and return ErrorKind::InvalidData if conversion fails, like camino does.
| pub fn command_env<P: AsRef<Utf8Path>>(path: P) -> Result<LocalDirectoryEnvironment> { | ||
| Ok(do_env_local_dir(path)?) | ||
| } |
There was a problem hiding this comment.
This doesn't seem to create env.toml, which is later relied upon to exist in add_single_env_project. Am I missing something?
This PR adds a
env.tomlcontaining metadata for the projects installed in the local environment(inluding editable projects not present inside the
sysand_envfolder).Each project has the following fields:
publisher: String (optional).Publisher of the project. Intended for display purposes.
name: String (optional).Name of the project. Intended for display purposes.
version: String (required).Version of the project.
path: String (required).Path to the root directory of the project.
If the project is not
editablethis should be relativeto the env directory and otherwise it should be relative
to the workspace root.
identifiers: Array of strings (required for non-editable projects)List of identifiers (IRIs) used for the project.
The first identifier is to. be considered the canonical
identifier, and if the project is not
editablethisis the IRI it is installed as. The rest are considered
as aliases. Can only be empty for
editableprojects.usages: Array of strings.Usages of the project. Intended for tools needing to
track the interdependence of project in the environment.
editable: bool.Indicator of wether the project is fully installed in
the environment or located elsewhere.
files: Array of strings (only for editable projects).In case of an
editableproject these are the filesbelonging to the project. Intended for tools that
are not able to natively parse and understand the
projects
.meta.jsonfile. Paths should be relativeto the
pathof the project.workspace: Indicator of wether the project is part of a workspace.The current implementation doesn't change how
projects.txtworks and is intended to offer a transition step between env structures. Theenv.tomlisn't directly managed byLocalDirectoryEnvironmentsince such a thing will likely require a change in theWriteEnvironmenttrait. In particular it would have to offer the ability to give alias identifiers in addition to the main IRI used for installation (since we want to communicate the dependency structure between projects we need all aliases as well, at least if we want to incrementally add or remove from the environment).Also since the current implementation of workspaces only affects the
buildcommand, theworkspacefield isn't really effective at the moment, but should work as expected once the workspace feature catches up.Example: