Skip to content

Commit

Permalink
Merge pull request #647 from gauge-sh/fix-missing-project-name
Browse files Browse the repository at this point in the history
Allow missing name in packages
  • Loading branch information
emdoyle authored Feb 25, 2025
2 parents 92f6090 + 6e16117 commit 13195ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/external/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use super::error;
pub type Result<T> = std::result::Result<T, error::ParsingError>;

pub struct ProjectInfo {
pub name: String,
pub name: Option<String>,
pub dependencies: HashSet<String>,
pub source_paths: Vec<PathBuf>,
}

pub fn parse_pyproject_toml(pyproject_path: &Path) -> Result<ProjectInfo> {
let content = fs::read_to_string(pyproject_path)?;
let toml_value: Value = toml::from_str(&content)?;
let name = extract_project_name(&toml_value)?;
let name = extract_project_name(&toml_value);
let dependencies = extract_dependencies(&toml_value);
let source_paths = extract_source_paths(&toml_value, pyproject_path.parent().unwrap());
Ok(ProjectInfo {
Expand All @@ -26,14 +26,11 @@ pub fn parse_pyproject_toml(pyproject_path: &Path) -> Result<ProjectInfo> {
})
}

fn extract_project_name(toml_value: &Value) -> Result<String> {
fn extract_project_name(toml_value: &Value) -> Option<String> {
toml_value
.get("project")
.and_then(|p| p.get("name"))
.and_then(|n| n.as_str())
.ok_or(error::ParsingError::MissingField(
"project.name".to_string(),
))
.map(|s| s.to_string())
}

Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl TryFrom<PackageRoot> for Package {
let project_info = parsing::parse_pyproject_toml(&path.join("pyproject.toml"))?;

Ok(Self {
name: Some(project_info.name),
name: project_info.name,
root: path,
source_roots: vec![],
dependencies: project_info.dependencies,
Expand Down

0 comments on commit 13195ac

Please sign in to comment.