From 85636b93a9bea558f1ac5d9644470551dbef5a5a Mon Sep 17 00:00:00 2001
From: Chris Pryer <14341145+cnpryer@users.noreply.github.com>
Date: Sun, 19 Nov 2023 11:19:55 -0500
Subject: [PATCH] Rename 'metadata file' to 'manifest file' (#859)
---
crates/huak-package-manager/src/error.rs | 8 +-
crates/huak-package-manager/src/lib.rs | 6 +-
.../src/{metadata.rs => manifest.rs} | 126 ++++++++++--------
crates/huak-package-manager/src/ops/add.rs | 57 ++++----
crates/huak-package-manager/src/ops/build.rs | 16 +--
crates/huak-package-manager/src/ops/format.rs | 14 +-
crates/huak-package-manager/src/ops/init.rs | 30 ++---
.../huak-package-manager/src/ops/install.rs | 22 +--
crates/huak-package-manager/src/ops/lint.rs | 16 +--
crates/huak-package-manager/src/ops/new.rs | 36 ++---
.../huak-package-manager/src/ops/publish.rs | 16 +--
crates/huak-package-manager/src/ops/remove.rs | 50 +++----
crates/huak-package-manager/src/ops/test.rs | 16 +--
crates/huak-package-manager/src/ops/update.rs | 52 +++++---
.../huak-package-manager/src/ops/version.rs | 2 +-
crates/huak-package-manager/src/package.rs | 26 ++--
crates/huak-package-manager/src/workspace.rs | 28 ++--
17 files changed, 276 insertions(+), 245 deletions(-)
rename crates/huak-package-manager/src/{metadata.rs => manifest.rs} (65%)
diff --git a/crates/huak-package-manager/src/error.rs b/crates/huak-package-manager/src/error.rs
index 7cff2198..aab42a26 100644
--- a/crates/huak-package-manager/src/error.rs
+++ b/crates/huak-package-manager/src/error.rs
@@ -44,10 +44,10 @@ pub enum Error {
PEP440Error(#[from] pep440_rs::Pep440Error),
#[error("a problem occurred with PEP508 parsing: {0}")]
PEP508Error(#[from] pep508_rs::Pep508Error),
- #[error("a metadata file already exists")]
- MetadataFileFound,
- #[error("a metadata file could not be found")]
- MetadataFileNotFound,
+ #[error("a manifest file already exists")]
+ ManifestFileFound,
+ #[error("a manifest file could not be found")]
+ ManifestFileNotFound,
#[error("a package version could not be found")]
PackageVersionNotFound,
#[error("a project already exists")]
diff --git a/crates/huak-package-manager/src/lib.rs b/crates/huak-package-manager/src/lib.rs
index 0b2d583f..3aeac597 100644
--- a/crates/huak-package-manager/src/lib.rs
+++ b/crates/huak-package-manager/src/lib.rs
@@ -52,7 +52,7 @@ mod environment;
mod error;
mod fs;
mod git;
-mod metadata;
+mod manifest;
pub mod ops;
mod package;
mod python_environment;
@@ -65,9 +65,9 @@ pub use environment::{env_path_string, env_path_values, Environment};
pub use error::{Error, HuakResult};
pub use fs::{copy_dir, last_path_component, CopyDirOptions};
pub use git::{default_python_gitignore, init as git_init};
-pub use metadata::{
+pub use manifest::{
default_package_entrypoint_string, default_package_test_file_contents,
- default_pyproject_toml_contents, LocalMetadata,
+ default_pyproject_toml_contents, LocalManifest,
};
pub use package::{importable_package_name, Package};
pub use python_environment::{
diff --git a/crates/huak-package-manager/src/metadata.rs b/crates/huak-package-manager/src/manifest.rs
similarity index 65%
rename from crates/huak-package-manager/src/metadata.rs
rename to crates/huak-package-manager/src/manifest.rs
index ac99317a..54c529c1 100644
--- a/crates/huak-package-manager/src/metadata.rs
+++ b/crates/huak-package-manager/src/manifest.rs
@@ -3,39 +3,38 @@ use huak_pyproject_toml::PyProjectToml;
use std::{ffi::OsStr, path::PathBuf, str::FromStr};
use toml_edit::Document;
-const DEFAULT_METADATA_FILE_NAME: &str = "pyproject.toml";
+const DEFAULT_MANIFEST_FILE_NAME: &str = "pyproject.toml";
-/// A `LocalMetadata` struct used to manage local `Metadata` files such as
-/// the pyproject.toml ().
-pub struct LocalMetadata {
- /// The core `Metadata`.
+/// A `LocalManifest` struct used to manage local manifest files such as the pyproject.toml ().
+pub struct LocalManifest {
+ /// The manifest's data including core metadata about the project.
/// See https://packaging.python.org/en/latest/specifications/core-metadata/.
- metadata: PyProjectToml, // TODO: https://github.com/cnpryer/huak/issues/574
- /// The path to the `LocalMetadata` file.
+ manifest_data: PyProjectToml, // TODO: https://github.com/cnpryer/huak/issues/574
+ /// The path to the `LocalManifest` file.
path: PathBuf,
}
-impl LocalMetadata {
- /// Initialize `LocalMetadata` from a path.
- pub fn new>(path: T) -> HuakResult {
+impl LocalManifest {
+ /// Initialize `LocalManifest` from a path.
+ pub fn new>(path: T) -> HuakResult {
let path = path.into();
// NOTE: Currently only pyproject.toml files are supported.
- if path.file_name() != Some(OsStr::new(DEFAULT_METADATA_FILE_NAME)) {
+ if path.file_name() != Some(OsStr::new(DEFAULT_MANIFEST_FILE_NAME)) {
return Err(Error::Unimplemented(format!(
"{} is not supported",
path.display()
)));
}
- let local_metadata = pyproject_toml_metadata(path)?;
+ let manifest = read_local_manifest(path)?;
- Ok(local_metadata)
+ Ok(manifest)
}
- /// Create a `LocalMetadata` template.
- pub fn template>(path: T) -> LocalMetadata {
- LocalMetadata {
- metadata: PyProjectToml {
+ /// Create a `LocalManifest` template.
+ pub fn template>(path: T) -> LocalManifest {
+ LocalManifest {
+ manifest_data: PyProjectToml {
doc: Document::from_str(&default_pyproject_toml_contents("project name"))
.expect("template pyproject.toml contents"),
},
@@ -43,33 +42,33 @@ impl LocalMetadata {
}
}
- /// Get a reference to the core `Metadata`.
+ /// Get a reference to the manifest data.
#[must_use]
- pub fn metadata(&self) -> &PyProjectToml {
- &self.metadata
+ pub fn manifest_data(&self) -> &PyProjectToml {
+ &self.manifest_data
}
- /// Get a mutable reference to the core `Metadata`.
- pub fn metadata_mut(&mut self) -> &mut PyProjectToml {
- &mut self.metadata
+ /// Get a mutable reference to the manifest data.
+ pub fn manifest_data_mut(&mut self) -> &mut PyProjectToml {
+ &mut self.manifest_data
}
- /// Write the `LocalMetadata` file to its path.
+ /// Write the `LocalManifest` file to its path.
pub fn write_file(&self) -> HuakResult<()> {
- Ok(self.metadata.write_toml(&self.path)?)
+ Ok(self.manifest_data.write_toml(&self.path)?)
}
}
-/// Create `LocalMetadata` from a pyproject.toml file.
-fn pyproject_toml_metadata>(path: T) -> HuakResult {
+/// Create `LocalManifest` from a pyproject.toml file.
+fn read_local_manifest>(path: T) -> HuakResult {
let path = path.into();
let pyproject_toml = PyProjectToml::read_toml(&path)?;
- let local_metadata = LocalMetadata {
- metadata: pyproject_toml,
+ let local_manifest = LocalManifest {
+ manifest_data: pyproject_toml,
path,
};
- Ok(local_metadata)
+ Ok(local_manifest)
}
#[must_use]
@@ -115,21 +114,28 @@ mod tests {
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let local_metadata = LocalMetadata::new(path).unwrap();
+ let local_manifest = LocalManifest::new(path).unwrap();
assert_eq!(
- local_metadata.metadata.project_name().unwrap().to_string(),
+ local_manifest
+ .manifest_data
+ .project_name()
+ .unwrap()
+ .to_string(),
"mock_project"
);
assert_eq!(
- *local_metadata
- .metadata
+ *local_manifest
+ .manifest_data
.project_version()
.unwrap()
.to_string(),
"0.0.1".to_string()
);
- assert!(local_metadata.metadata.project_dependencies().is_some());
+ assert!(local_manifest
+ .manifest_data
+ .project_dependencies()
+ .is_some());
}
#[ignore = "unsupported"]
@@ -138,10 +144,10 @@ mod tests {
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let local_metadata = LocalMetadata::new(path).unwrap();
+ let local_manifest = LocalManifest::new(path).unwrap();
assert_eq!(
- local_metadata.metadata.to_string(),
+ local_manifest.manifest_data.to_string(),
r#"[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
@@ -171,10 +177,10 @@ dev = [
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let local_metadata = LocalMetadata::new(path).unwrap();
+ let local_manifest = LocalManifest::new(path).unwrap();
assert_eq!(
- local_metadata.metadata.project_dependencies().unwrap(),
+ local_manifest.manifest_data.project_dependencies().unwrap(),
vec!["click == 8.1.7".to_string()]
);
}
@@ -184,11 +190,11 @@ dev = [
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let local_metadata = LocalMetadata::new(path).unwrap();
+ let local_manifest = LocalManifest::new(path).unwrap();
assert_eq!(
- local_metadata
- .metadata
+ local_manifest
+ .manifest_data
.project_optional_dependencies()
.unwrap()
.get("dev")
@@ -202,14 +208,14 @@ dev = [
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let mut local_metadata = LocalMetadata::new(path).unwrap();
- local_metadata
- .metadata
+ let mut local_manifest = LocalManifest::new(path).unwrap();
+ local_manifest
+ .manifest_data
.add_project_dependency("test")
.formatted();
assert_eq!(
- local_metadata.metadata.to_string(),
+ local_manifest.manifest_data.to_string(),
r#"[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
@@ -241,16 +247,16 @@ dev = [
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let mut local_metadata = LocalMetadata::new(path).unwrap();
+ let mut local_manifest = LocalManifest::new(path).unwrap();
- local_metadata
- .metadata
+ local_manifest
+ .manifest_data
.add_project_optional_dependency("test1", "dev");
- local_metadata
- .metadata
+ local_manifest
+ .manifest_data
.add_project_optional_dependency("test2", "new-group");
assert_eq!(
- local_metadata.metadata.formatted().to_string(),
+ local_manifest.manifest_data.formatted().to_string(),
r#"[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
@@ -285,11 +291,13 @@ new-group = [
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let mut local_metadata = LocalMetadata::new(path).unwrap();
- local_metadata.metadata.remove_project_dependency("click");
+ let mut local_manifest = LocalManifest::new(path).unwrap();
+ local_manifest
+ .manifest_data
+ .remove_project_dependency("click");
assert_eq!(
- local_metadata.metadata.formatted().to_string(),
+ local_manifest.manifest_data.formatted().to_string(),
r#"[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
@@ -318,13 +326,13 @@ dev = [
let path = dev_resources_dir()
.join("mock-project")
.join("pyproject.toml");
- let mut local_metadata = LocalMetadata::new(path).unwrap();
+ let mut local_manifest = LocalManifest::new(path).unwrap();
- local_metadata
- .metadata
+ local_manifest
+ .manifest_data
.remove_project_optional_dependency("ruff", "dev");
assert_eq!(
- local_metadata.metadata.formatted().to_string(),
+ local_manifest.manifest_data.formatted().to_string(),
r#"[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
diff --git a/crates/huak-package-manager/src/ops/add.rs b/crates/huak-package-manager/src/ops/add.rs
index 5b201320..d954e8a7 100644
--- a/crates/huak-package-manager/src/ops/add.rs
+++ b/crates/huak-package-manager/src/ops/add.rs
@@ -13,11 +13,15 @@ pub fn add_project_dependencies(
options: &AddOptions,
) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
- // Collect all dependencies that need to be added to the metadata file.
+ // Collect all dependencies that need to be added to the manifest file.
let mut deps = dependency_iter(dependencies)
- .filter(|dep| !metadata.metadata().contains_project_dependency(dep.name()))
+ .filter(|dep| {
+ !manifest
+ .manifest_data()
+ .contains_project_dependency(dep.name())
+ })
.collect::>();
if deps.is_empty() {
@@ -27,7 +31,7 @@ pub fn add_project_dependencies(
let python_env = workspace.resolve_python_environment()?;
python_env.install_packages(&deps, &options.install_options, config)?;
- // If there's no version data then get the installed version and add to metadata file.
+ // If there's no version data then get the installed version and add to manifest file.
let packages = python_env.installed_packages()?; // TODO: Only run if versions weren't provided.
for dep in &mut deps {
if dep.requirement().version_or_url.is_none() {
@@ -40,15 +44,18 @@ pub fn add_project_dependencies(
}
}
- if !metadata.metadata().contains_project_dependency(dep.name()) {
- metadata
- .metadata_mut()
+ if !manifest
+ .manifest_data()
+ .contains_project_dependency(dep.name())
+ {
+ manifest
+ .manifest_data_mut()
.add_project_dependency(&dep.to_string());
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
Ok(())
}
@@ -60,14 +67,14 @@ pub fn add_project_optional_dependencies(
options: &AddOptions,
) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
// Collect all dependencies that need to be added.
// TODO(cnpryer): Allow
let mut deps = dependency_iter(dependencies)
.filter(|dep| {
- !metadata
- .metadata()
+ !manifest
+ .manifest_data()
.contains_project_optional_dependency(dep.name(), group)
})
.collect::>();
@@ -79,7 +86,7 @@ pub fn add_project_optional_dependencies(
let python_env = workspace.resolve_python_environment()?;
python_env.install_packages(&deps, &options.install_options, config)?;
- // If there's no version data then get the installed version and add to metadata file.
+ // If there's no version data then get the installed version and add to manifest file.
let packages = python_env.installed_packages()?; // TODO: Only run if versions weren't provided.
for dep in &mut deps {
if dep.requirement().version_or_url.is_none() {
@@ -92,18 +99,18 @@ pub fn add_project_optional_dependencies(
}
}
- if !metadata
- .metadata()
+ if !manifest
+ .manifest_data()
.contains_project_optional_dependency(dep.name(), group)
{
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_optional_dependency(&dep.to_string(), group);
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
Ok(())
}
@@ -145,10 +152,12 @@ mod tests {
add_project_dependencies(&[String::from("ruff")], &config, &options).unwrap();
let dep = Dependency::from_str("ruff").unwrap();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
assert!(venv.contains_module("ruff").unwrap());
- assert!(metadata.metadata().contains_project_dependency(dep.name()));
+ assert!(manifest
+ .manifest_data()
+ .contains_project_dependency(dep.name()));
}
#[test]
@@ -184,11 +193,11 @@ mod tests {
.unwrap();
let dep = Dependency::from_str("isort").unwrap();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
assert!(venv.contains_module("isort").unwrap());
- assert!(metadata
- .metadata()
+ assert!(manifest
+ .manifest_data()
.contains_project_optional_dependency(dep.name(), "dev"));
}
}
diff --git a/crates/huak-package-manager/src/ops/build.rs b/crates/huak-package-manager/src/ops/build.rs
index cfca5508..c285ff7d 100644
--- a/crates/huak-package-manager/src/ops/build.rs
+++ b/crates/huak-package-manager/src/ops/build.rs
@@ -10,7 +10,7 @@ pub struct BuildOptions {
pub fn build_project(config: &Config, options: &BuildOptions) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
let python_env = workspace.resolve_python_environment()?;
// Install the `build` package if it isn't already installed.
@@ -19,9 +19,9 @@ pub fn build_project(config: &Config, options: &BuildOptions) -> HuakResult<()>
python_env.install_packages(&[&build_dep], &options.install_options, config)?;
}
- // Add the installed `build` package to the metadata file.
- if !metadata
- .metadata()
+ // Add the installed `build` package to the manifest file.
+ if !manifest
+ .manifest_data()
.contains_project_dependency_any(build_dep.name())
{
for pkg in python_env
@@ -29,14 +29,14 @@ pub fn build_project(config: &Config, options: &BuildOptions) -> HuakResult<()>
.iter()
.filter(|pkg| pkg.name() == build_dep.name())
{
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_optional_dependency(&pkg.to_string(), "dev");
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
// Run `build`.
let mut cmd = Command::new(python_env.python_path());
diff --git a/crates/huak-package-manager/src/ops/format.rs b/crates/huak-package-manager/src/ops/format.rs
index 206e6ad8..1306bb65 100644
--- a/crates/huak-package-manager/src/ops/format.rs
+++ b/crates/huak-package-manager/src/ops/format.rs
@@ -10,7 +10,7 @@ pub struct FormatOptions {
pub fn format_project(config: &Config, options: &FormatOptions) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
let python_env = workspace.resolve_python_environment()?;
// Install `ruff` it isn't already installed.
@@ -25,12 +25,12 @@ pub fn format_project(config: &Config, options: &FormatOptions) -> HuakResult<()
python_env.install_packages(&new_format_deps, &options.install_options, config)?;
}
- // Add the installed `ruff` package to the metadata file if not already there.
+ // Add the installed `ruff` package to the manifest file if not already there.
let new_format_deps = format_deps
.iter()
.filter(|dep| {
- !metadata
- .metadata()
+ !manifest
+ .manifest_data()
.contains_project_dependency_any(dep.name())
})
.map(Dependency::name)
@@ -42,13 +42,13 @@ pub fn format_project(config: &Config, options: &FormatOptions) -> HuakResult<()
.iter()
.filter(|pkg| new_format_deps.contains(&pkg.name()))
{
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_optional_dependency(&pkg.to_string(), "dev");
}
}
- metadata.write_file()?;
+ manifest.write_file()?;
// Run `ruff` for formatting imports and the rest of the Python code in the workspace.
// NOTE: This needs to be refactored https://github.com/cnpryer/huak/issues/784, https://github.com/cnpryer/huak/issues/718
diff --git a/crates/huak-package-manager/src/ops/init.rs b/crates/huak-package-manager/src/ops/init.rs
index bbf8c72b..2a15f02c 100644
--- a/crates/huak-package-manager/src/ops/init.rs
+++ b/crates/huak-package-manager/src/ops/init.rs
@@ -3,7 +3,7 @@ use toml_edit::{Item, Table};
use super::init_git;
use crate::{
default_package_entrypoint_string, importable_package_name, last_path_component, Config,
- Dependency, Error, HuakResult, LocalMetadata, WorkspaceOptions,
+ Dependency, Error, HuakResult, LocalManifest, WorkspaceOptions,
};
use std::str::FromStr;
@@ -11,15 +11,15 @@ pub fn init_app_project(config: &Config, options: &WorkspaceOptions) -> HuakResu
init_lib_project(config, options)?;
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
- let Some(name) = metadata.metadata().project_name() else {
+ let Some(name) = manifest.manifest_data().project_name() else {
return Err(Error::InternalError("missing project name".to_string()));
};
let as_dep = Dependency::from_str(&name)?;
let _entry_point = default_package_entrypoint_string(&importable_package_name(as_dep.name())?);
- if let Some(table) = metadata.metadata_mut().project_table_mut() {
+ if let Some(table) = manifest.manifest_data_mut().project_table_mut() {
let scripts = &mut table["scripts"];
if scripts.is_none() {
@@ -30,16 +30,16 @@ pub fn init_app_project(config: &Config, options: &WorkspaceOptions) -> HuakResu
scripts[name] = toml_edit::value(format!("{importable}.main:main"));
}
- metadata.write_file()
+ manifest.write_file()
}
pub fn init_lib_project(config: &Config, options: &WorkspaceOptions) -> HuakResult<()> {
let workspace = config.workspace();
- // Create a metadata file or error if one already exists.
- let mut metadata = match workspace.current_local_metadata() {
- Ok(_) => return Err(Error::MetadataFileFound),
- Err(_) => LocalMetadata::template(workspace.root().join("pyproject.toml")),
+ // Create a manifest file or error if one already exists.
+ let mut manifest = match workspace.current_local_manifest() {
+ Ok(_) => return Err(Error::ManifestFileFound),
+ Err(_) => LocalManifest::template(workspace.root().join("pyproject.toml")),
};
if options.uses_git {
@@ -47,8 +47,8 @@ pub fn init_lib_project(config: &Config, options: &WorkspaceOptions) -> HuakResu
}
let name = last_path_component(&config.workspace_root)?;
- metadata.metadata_mut().set_project_name(&name);
- metadata.write_file()
+ manifest.manifest_data_mut().set_project_name(&name);
+ manifest.write_file()
}
#[cfg(test)]
@@ -77,10 +77,10 @@ mod tests {
init_lib_project(&config, &options).unwrap();
let ws = config.workspace();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
assert_eq!(
- metadata.metadata().to_string(),
+ manifest.manifest_data().to_string(),
default_pyproject_toml_contents("mock-project")
);
}
@@ -106,10 +106,10 @@ mod tests {
init_app_project(&config, &options).unwrap();
let ws = config.workspace();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
assert_eq!(
- metadata.metadata().to_string(),
+ manifest.manifest_data().to_string(),
r#"[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
diff --git a/crates/huak-package-manager/src/ops/install.rs b/crates/huak-package-manager/src/ops/install.rs
index ad5f13db..445301ce 100644
--- a/crates/huak-package-manager/src/ops/install.rs
+++ b/crates/huak-package-manager/src/ops/install.rs
@@ -6,7 +6,7 @@ pub fn install_project_dependencies(
options: &InstallOptions,
) -> HuakResult<()> {
let workspace = config.workspace();
- let metadata = workspace.current_local_metadata()?;
+ let manifest = workspace.current_local_manifest()?;
let mut dependencies = Vec::new();
@@ -14,15 +14,16 @@ pub fn install_project_dependencies(
// If the group "required" is passed and isn't a valid optional dependency group
// then install just the required dependencies.
// TODO(cnpryer): Refactor/move
- if metadata
- .metadata()
+ if manifest
+ .manifest_data()
.project_optional_dependency_groups()
.map_or(false, |it| it.iter().any(|s| s == "required"))
{
- if let Some(reqs) = metadata.metadata().project_dependencies() {
+ if let Some(reqs) = manifest.manifest_data().project_dependencies() {
dependencies.extend(reqs);
}
- } else if let Some(optional_deps) = metadata.metadata().project_optional_dependencies() {
+ } else if let Some(optional_deps) = manifest.manifest_data().project_optional_dependencies()
+ {
for g in gs {
// TODO(cnpryer): Perf
if let Some(deps) = optional_deps.get(&g.to_string()) {
@@ -31,16 +32,19 @@ pub fn install_project_dependencies(
}
}
} else {
- // If no groups are passed then install all dependencies listed in the metadata file
+ // If no groups are passed then install all dependencies listed in the manifest file
// including the optional dependencies.
- if let Some(reqs) = metadata.metadata().project_dependencies() {
+ if let Some(reqs) = manifest.manifest_data().project_dependencies() {
dependencies.extend(reqs);
}
// TODO(cnpryer): Install optional as opt-in
- if let Some(groups) = metadata.metadata().project_optional_dependency_groups() {
+ if let Some(groups) = manifest
+ .manifest_data()
+ .project_optional_dependency_groups()
+ {
for key in groups {
- if let Some(g) = metadata.metadata().project_optional_dependencies() {
+ if let Some(g) = manifest.manifest_data().project_optional_dependencies() {
if let Some(it) = g.get(&key) {
dependencies.extend(it.iter().cloned());
}
diff --git a/crates/huak-package-manager/src/ops/lint.rs b/crates/huak-package-manager/src/ops/lint.rs
index 423f28f9..283c22cd 100644
--- a/crates/huak-package-manager/src/ops/lint.rs
+++ b/crates/huak-package-manager/src/ops/lint.rs
@@ -11,7 +11,7 @@ pub struct LintOptions {
pub fn lint_project(config: &Config, options: &LintOptions) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
let python_env = workspace.resolve_python_environment()?;
// Install `ruff` if it isn't already installed.
@@ -52,12 +52,12 @@ pub fn lint_project(config: &Config, options: &LintOptions) -> HuakResult<()> {
cmd.args(args).current_dir(workspace.root());
terminal.run_command(&mut cmd)?;
- // Add installed lint deps (potentially both `mypy` and `ruff`) to metadata file if not already there.
+ // Add installed lint deps (potentially both `mypy` and `ruff`) to manifest file if not already there.
let new_lint_deps = lint_deps
.iter()
.filter(|dep| {
- !metadata
- .metadata()
+ !manifest
+ .manifest_data()
.contains_project_dependency_any(dep.name())
})
.map(Dependency::name)
@@ -69,14 +69,14 @@ pub fn lint_project(config: &Config, options: &LintOptions) -> HuakResult<()> {
.iter()
.filter(|pkg| new_lint_deps.contains(&pkg.name()))
{
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_optional_dependency(&pkg.to_string(), "dev");
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
Ok(())
}
diff --git a/crates/huak-package-manager/src/ops/new.rs b/crates/huak-package-manager/src/ops/new.rs
index a14585b8..20e3bdd7 100644
--- a/crates/huak-package-manager/src/ops/new.rs
+++ b/crates/huak-package-manager/src/ops/new.rs
@@ -3,7 +3,7 @@ use toml_edit::{Item, Table};
use super::{create_workspace, init_git};
use crate::{
default_package_test_file_contents, importable_package_name, last_path_component, Config,
- Dependency, Error, HuakResult, LocalMetadata, WorkspaceOptions,
+ Dependency, Error, HuakResult, LocalManifest, WorkspaceOptions,
};
use std::str::FromStr;
@@ -11,11 +11,11 @@ pub fn new_app_project(config: &Config, options: &WorkspaceOptions) -> HuakResul
new_lib_project(config, options)?;
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
let name = last_path_component(workspace.root().as_path())?;
let as_dep = Dependency::from_str(&name)?;
- metadata.metadata_mut().set_project_name(&name);
+ manifest.manifest_data_mut().set_project_name(&name);
let src_path = workspace.root().join("src");
let importable_name = importable_package_name(as_dep.name())?;
@@ -24,7 +24,7 @@ pub fn new_app_project(config: &Config, options: &WorkspaceOptions) -> HuakResul
super::DEFAULT_PYTHON_MAIN_FILE_CONTENTS,
)?;
- if let Some(table) = metadata.metadata_mut().project_table_mut() {
+ if let Some(table) = manifest.manifest_data_mut().project_table_mut() {
let scripts = &mut table["scripts"];
if scripts.is_none() {
@@ -35,16 +35,16 @@ pub fn new_app_project(config: &Config, options: &WorkspaceOptions) -> HuakResul
scripts[name] = toml_edit::value(format!("{importable}.main:main"));
}
- metadata.write_file()
+ manifest.write_file()
}
pub fn new_lib_project(config: &Config, options: &WorkspaceOptions) -> HuakResult<()> {
let workspace = config.workspace();
- // Create a new metadata file or error if one exists.
- let mut metadata = match workspace.current_local_metadata() {
+ // Create a new manifest file or error if one exists.
+ let mut manifest = match workspace.current_local_manifest() {
Ok(_) => return Err(Error::ProjectFound),
- Err(_) => LocalMetadata::template(workspace.root().join("pyproject.toml")),
+ Err(_) => LocalManifest::template(workspace.root().join("pyproject.toml")),
};
create_workspace(workspace.root())?;
@@ -54,11 +54,11 @@ pub fn new_lib_project(config: &Config, options: &WorkspaceOptions) -> HuakResul
}
let name = &last_path_component(&config.workspace_root)?;
- metadata.metadata_mut().set_project_name(name);
+ manifest.manifest_data_mut().set_project_name(name);
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
+ manifest.write_file()?;
let as_dep = Dependency::from_str(name)?;
let src_path = config.workspace_root.join("src");
@@ -103,7 +103,7 @@ mod tests {
new_lib_project(&config, &options).unwrap();
let ws = config.workspace();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
let test_file_filepath = ws.root().join("tests").join("test_version.py");
let test_file = std::fs::read_to_string(test_file_filepath).unwrap();
let expected_test_file = r"from mock_project import __version__
@@ -121,8 +121,8 @@ def test_version():
let expected_init_file = "__version__ = \"0.0.1\"
";
- assert!(metadata
- .metadata()
+ assert!(manifest
+ .manifest_data()
.project_table()
.and_then(|it| it.get("scripts"))
.is_none());
@@ -150,7 +150,7 @@ def test_version():
new_app_project(&config, &options).unwrap();
let ws = config.workspace();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
let main_file_filepath = ws.root().join("src").join("mock_project").join("main.py");
let main_file = std::fs::read_to_string(main_file_filepath).unwrap();
let expected_main_file = r#"def main():
@@ -163,8 +163,8 @@ if __name__ == "__main__":
assert_eq!(
value_to_sanitized_string(
- metadata
- .metadata()
+ manifest
+ .manifest_data()
.project_table()
.unwrap()
.get("scripts")
diff --git a/crates/huak-package-manager/src/ops/publish.rs b/crates/huak-package-manager/src/ops/publish.rs
index 13a23364..69c76078 100644
--- a/crates/huak-package-manager/src/ops/publish.rs
+++ b/crates/huak-package-manager/src/ops/publish.rs
@@ -10,7 +10,7 @@ pub struct PublishOptions {
pub fn publish_project(config: &Config, options: &PublishOptions) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
let python_env = workspace.resolve_python_environment()?;
// Install `twine` if it isn't already installed.
@@ -19,9 +19,9 @@ pub fn publish_project(config: &Config, options: &PublishOptions) -> HuakResult<
python_env.install_packages(&[&pub_dep], &options.install_options, config)?;
}
- // Add the installed `twine` package to the metadata file if it isn't already there.
- if !metadata
- .metadata()
+ // Add the installed `twine` package to the manifest file if it isn't already there.
+ if !manifest
+ .manifest_data()
.contains_project_dependency_any(pub_dep.name())
{
for pkg in python_env
@@ -29,14 +29,14 @@ pub fn publish_project(config: &Config, options: &PublishOptions) -> HuakResult<
.iter()
.filter(|pkg| pkg.name() == pub_dep.name())
{
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_optional_dependency(&pkg.to_string(), "dev");
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
// Run `twine`.
let mut cmd = Command::new(python_env.python_path());
diff --git a/crates/huak-package-manager/src/ops/remove.rs b/crates/huak-package-manager/src/ops/remove.rs
index ba22cd93..48c27227 100644
--- a/crates/huak-package-manager/src/ops/remove.rs
+++ b/crates/huak-package-manager/src/ops/remove.rs
@@ -10,13 +10,13 @@ pub fn remove_project_dependencies(
options: &RemoveOptions,
) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
- // Collect any dependencies to remove from the metadata file.
+ // Collect any dependencies to remove from the manifest file.
let deps = dependency_iter(dependencies)
.filter(|dep| {
- metadata
- .metadata()
+ manifest
+ .manifest_data()
.contains_project_dependency_any(dep.name())
})
.collect::>();
@@ -25,24 +25,26 @@ pub fn remove_project_dependencies(
return Ok(());
}
- let optional_groups = metadata.metadata().project_optional_dependency_groups();
+ let optional_groups = manifest
+ .manifest_data()
+ .project_optional_dependency_groups();
for dep in &deps {
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.remove_project_dependency(dep.name());
if let Some(groups) = optional_groups.as_ref() {
for g in groups {
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.remove_project_optional_dependency(dep.name(), g);
}
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
// Uninstall the dependencies from the Python environment if an environment is found.
match workspace.current_python_environment() {
@@ -93,19 +95,19 @@ mod tests {
let test_dep = Dependency::from_str("click==8.1.3").unwrap();
venv.install_packages(&[&test_dep], &options.install_options, &config)
.unwrap();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
let venv_had_package = venv.contains_package(&test_package);
- let toml_had_package = metadata
- .metadata()
+ let toml_had_package = manifest
+ .manifest_data()
.contains_project_dependency(test_dep.name());
remove_project_dependencies(&["click".to_string()], &config, &options).unwrap();
let ws = config.workspace();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
let venv_contains_package = venv.contains_package(&test_package);
- let toml_contains_package = metadata
- .metadata()
+ let toml_contains_package = manifest
+ .manifest_data()
.contains_project_dependency(test_dep.name());
assert!(venv_had_package);
@@ -140,25 +142,25 @@ mod tests {
};
let ws = config.workspace();
initialize_venv(ws.root().join(".venv"), &ws.environment()).unwrap();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
let venv = ws.resolve_python_environment().unwrap();
let test_dep = Dependency::from_str("ruff").unwrap();
venv.install_packages(&[&test_dep], &options.install_options, &config)
.unwrap();
let venv_had_package = venv.contains_module(test_dep.name()).unwrap();
- let toml_had_package = metadata
- .metadata()
+ let toml_had_package = manifest
+ .manifest_data()
.contains_project_optional_dependency(test_dep.name(), "dev");
remove_project_dependencies(&["ruff".to_string()], &config, &options).unwrap();
let ws = config.workspace();
- let metadata = ws.current_local_metadata().unwrap();
+ let manifest = ws.current_local_manifest().unwrap();
let venv_contains_package = venv
- .contains_module(&metadata.metadata().project_name().unwrap().to_string())
+ .contains_module(&manifest.manifest_data().project_name().unwrap().to_string())
.unwrap();
- let toml_contains_package = metadata
- .metadata()
+ let toml_contains_package = manifest
+ .manifest_data()
.contains_project_dependency(test_dep.name());
assert!(venv_had_package);
diff --git a/crates/huak-package-manager/src/ops/test.rs b/crates/huak-package-manager/src/ops/test.rs
index 951757f1..67016a3d 100644
--- a/crates/huak-package-manager/src/ops/test.rs
+++ b/crates/huak-package-manager/src/ops/test.rs
@@ -10,7 +10,7 @@ pub struct TestOptions {
pub fn test_project(config: &Config, options: &TestOptions) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
let python_env = workspace.resolve_python_environment()?;
// Install `pytest` if it isn't already installed.
@@ -19,9 +19,9 @@ pub fn test_project(config: &Config, options: &TestOptions) -> HuakResult<()> {
python_env.install_packages(&[&test_dep], &options.install_options, config)?;
}
- // Add the installed `pytest` package to the metadata file if it isn't already there.
- if !metadata
- .metadata()
+ // Add the installed `pytest` package to the manifest file if it isn't already there.
+ if !manifest
+ .manifest_data()
.contains_project_dependency_any(test_dep.name())
{
for pkg in python_env
@@ -29,14 +29,14 @@ pub fn test_project(config: &Config, options: &TestOptions) -> HuakResult<()> {
.iter()
.filter(|pkg| pkg.name() == test_dep.name())
{
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_optional_dependency(&pkg.to_string(), "dev");
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
// Run `pytest` with the package directory added to the command's `PYTHONPATH`.
let mut cmd = Command::new(python_env.python_path());
diff --git a/crates/huak-package-manager/src/ops/update.rs b/crates/huak-package-manager/src/ops/update.rs
index fe454d03..735b8461 100644
--- a/crates/huak-package-manager/src/ops/update.rs
+++ b/crates/huak-package-manager/src/ops/update.rs
@@ -13,15 +13,15 @@ pub fn update_project_dependencies(
options: &UpdateOptions,
) -> HuakResult<()> {
let workspace = config.workspace();
- let mut metadata = workspace.current_local_metadata()?;
+ let mut manifest = workspace.current_local_manifest()?;
let python_env = workspace.resolve_python_environment()?;
- // Collect dependencies to update if they are listed in the metadata file.
+ // Collect dependencies to update if they are listed in the manifest file.
if let Some(it) = dependencies.as_ref() {
let deps = dependency_iter(it)
.filter_map(|dep| {
- if metadata
- .metadata()
+ if manifest
+ .manifest_data()
.contains_project_dependency_any(dep.name())
{
Some(dep)
@@ -37,13 +37,16 @@ pub fn update_project_dependencies(
python_env.update_packages(&deps, &options.install_options, config)?;
} else {
- let mut deps = metadata
- .metadata()
+ let mut deps = manifest
+ .manifest_data()
.project_dependencies()
.map_or(Vec::new(), |reqs| reqs.into_iter().collect::>());
- if let Some(gs) = metadata.metadata().project_optional_dependency_groups() {
- if let Some(optional_deps) = metadata.metadata().project_optional_dependencies() {
+ if let Some(gs) = manifest
+ .manifest_data()
+ .project_optional_dependency_groups()
+ {
+ if let Some(optional_deps) = manifest.manifest_data().project_optional_dependencies() {
for g in gs {
// TODO(cnpryer): Perf
if let Some(it) = optional_deps.get(&g.to_string()) {
@@ -58,38 +61,43 @@ pub fn update_project_dependencies(
python_env.update_packages(&deps, &options.install_options, config)?;
}
- let groups = metadata.metadata().project_optional_dependency_groups();
+ let groups = manifest
+ .manifest_data()
+ .project_optional_dependency_groups();
for pkg in python_env.installed_packages()? {
let dep = &Dependency::from_str(&pkg.to_string())?;
- if metadata.metadata().contains_project_dependency(dep.name()) {
- metadata
- .metadata_mut()
+ if manifest
+ .manifest_data()
+ .contains_project_dependency(dep.name())
+ {
+ manifest
+ .manifest_data_mut()
.remove_project_dependency(dep.name());
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_dependency(&dep.to_string());
}
if let Some(gs) = groups.as_ref() {
for g in gs {
- if metadata
- .metadata()
+ if manifest
+ .manifest_data()
.contains_project_optional_dependency(dep.name(), g)
{
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.remove_project_optional_dependency(dep.name(), g);
- metadata
- .metadata_mut()
+ manifest
+ .manifest_data_mut()
.add_project_optional_dependency(&dep.to_string(), g);
}
}
}
}
- metadata.metadata_mut().formatted();
- metadata.write_file()?;
+ manifest.manifest_data_mut().formatted();
+ manifest.write_file()?;
Ok(())
}
diff --git a/crates/huak-package-manager/src/ops/version.rs b/crates/huak-package-manager/src/ops/version.rs
index 77c6920e..f1ada95a 100644
--- a/crates/huak-package-manager/src/ops/version.rs
+++ b/crates/huak-package-manager/src/ops/version.rs
@@ -6,7 +6,7 @@ pub fn display_project_version(config: &Config) -> HuakResult<()> {
let workspace = config.workspace();
let package = workspace.current_package()?;
- let Some(version) = package.metadata().project_version() else {
+ let Some(version) = package.manifest_data().project_version() else {
return Err(Error::PackageVersionNotFound);
};
diff --git a/crates/huak-package-manager/src/package.rs b/crates/huak-package-manager/src/package.rs
index ffe647bc..f4c7856f 100644
--- a/crates/huak-package-manager/src/package.rs
+++ b/crates/huak-package-manager/src/package.rs
@@ -1,4 +1,4 @@
-use crate::{Error, HuakResult};
+use crate::{Error, HuakResult, LocalManifest};
use huak_pyproject_toml::PyProjectToml;
use lazy_static::lazy_static;
use pep440_rs::{Operator, Version, VersionSpecifiers};
@@ -27,8 +27,8 @@ lazy_static! {
pub struct Package {
/// Information used to identify the `Package`.
id: PackageId,
- /// The `Package`'s core `PyProjectToml` metadata.
- metadata: PyProjectToml,
+ /// The `Package`'s manifest data (TODO(cnpryer): Make just core)
+ manifest_data: PyProjectToml,
}
impl Package {
@@ -44,18 +44,18 @@ impl Package {
&self.id.version
}
- /// Get a reference to the `Package`'s core `PyProjectToml` metadata.
+ /// Get a reference to the `Package`'s manifest data.
#[must_use]
- pub fn metadata(&self) -> &PyProjectToml {
- &self.metadata
+ pub fn manifest_data(&self) -> &PyProjectToml {
+ &self.manifest_data
}
- pub fn try_from_metadata(metadata: &PyProjectToml) -> HuakResult {
- let Some(name) = metadata.project_name() else {
+ pub fn try_from_manifest(manifest: &LocalManifest) -> HuakResult {
+ let Some(name) = manifest.manifest_data().project_name() else {
return Err(Error::InternalError("missing project name".to_string()));
};
- let Some(version) = metadata.project_version() else {
+ let Some(version) = manifest.manifest_data().project_version() else {
return Err(Error::InternalError("missing project version".to_string()));
};
@@ -65,7 +65,7 @@ impl Package {
version: Version::from_str(&version)
.map_err(|e| Error::InvalidVersionString(e.to_string()))?,
},
- metadata: metadata.clone(),
+ manifest_data: manifest.manifest_data().clone(),
})
}
@@ -108,10 +108,10 @@ impl Package {
version: version_specifer.version().to_owned(),
};
- let mut metadata = PyProjectToml::default();
- metadata.set_project_name(&name);
+ let mut manifest_data = PyProjectToml::default();
+ manifest_data.set_project_name(&name);
- let package = Package { id, metadata };
+ let package = Package { id, manifest_data };
Ok(package)
}
diff --git a/crates/huak-package-manager/src/workspace.rs b/crates/huak-package-manager/src/workspace.rs
index 80a19348..29b289dd 100644
--- a/crates/huak-package-manager/src/workspace.rs
+++ b/crates/huak-package-manager/src/workspace.rs
@@ -2,7 +2,7 @@ use crate::package::Package;
use crate::{
environment::Environment,
fs,
- metadata::LocalMetadata,
+ manifest::LocalManifest,
python_environment::{default_venv_name, venv_config_file_name},
Config, Error, HuakResult, PythonEnvironment,
};
@@ -48,29 +48,29 @@ impl Workspace {
Environment::new()
}
- /// Get the current `Package`. The current `Package` is one found by its metadata file nearest based
+ /// Get the current `Package`. The current `Package` is one found by its manifest file nearest based
/// on the `Workspace`'s `Config` data.
pub fn current_package(&self) -> HuakResult {
- // Currently only pyproject.toml `LocalMetadata` file is supported.
- let metadata = self.current_local_metadata()?;
+ // Currently only pyproject.toml `LocalManifest` file is supported.
+ let manifest = self.current_local_manifest()?;
- let package = Package::try_from_metadata(metadata.metadata())?;
+ let package = Package::try_from_manifest(&manifest)?;
Ok(package)
}
- /// Get the current `LocalMetadata` based on the `Config` data.
- pub fn current_local_metadata(&self) -> HuakResult {
- // The current metadata file is the first found in a search.
+ /// Get the current `LocalManifest` based on the `Config` data.
+ pub fn current_local_manifest(&self) -> HuakResult {
+ // The current manifest file is the first found in a search.
let ws = resolve_first(&self.config.cwd, PathMarker::file("pyproject.toml"));
// Currently only pyproject.toml is supported.
let path = ws.root().join("pyproject.toml");
if path.exists() {
- LocalMetadata::new(path)
+ LocalManifest::new(path)
} else {
- Err(Error::MetadataFileNotFound)
+ Err(Error::ManifestFileFound)
}
}
@@ -216,10 +216,10 @@ fn resolve_local_toolchain(
return resolver.from_dir(channel, toolchains);
}
- // Use workspace project metadata and return if a toolchain is listed.
- if let Ok(metadata) = workspace.current_local_metadata() {
- if let Some(table) = metadata
- .metadata()
+ // Use workspace project manifest and return if a toolchain is listed.
+ if let Ok(manifest) = workspace.current_local_manifest() {
+ if let Some(table) = manifest
+ .manifest_data()
.tool_table()
.and_then(|it| it.get("huak"))
{