-
Notifications
You must be signed in to change notification settings - Fork 493
fix(pixi-build-python): clarify missing pyproject error #5922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lawrence3699
wants to merge
1
commit into
prefix-dev:main
Choose a base branch
from
lawrence3699:fix/missing-pyproject-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+39
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,11 @@ pub enum MetadataError { | |||||
| PyProjectToml(#[from] toml::de::Error), | ||||||
| #[error("failed to parse version from pyproject.toml, {0}")] | ||||||
| ParseVersion(ParseVersionError), | ||||||
| #[error("`pixi-build-python` requires a `pyproject.toml` in {0}")] | ||||||
| #[diagnostic(help( | ||||||
| "Add a PEP 517/518 `pyproject.toml` to the package source directory, or use a different build backend." | ||||||
| ))] | ||||||
| MissingPyProjectToml(PathBuf), | ||||||
| #[error(transparent)] | ||||||
| Io(#[from] std::io::Error), | ||||||
| } | ||||||
|
|
@@ -72,8 +77,15 @@ impl PyprojectMetadataProvider { | |||||
| /// Ensures that the manifest is loaded | ||||||
| fn ensure_manifest(&self) -> Result<&PyProjectToml, MetadataError> { | ||||||
| self.pyproject_manifest.get_or_try_init(move || { | ||||||
| let pyproject_toml_path = self.manifest_root.join("pyproject.toml"); | ||||||
| let pyproject_toml_content = | ||||||
| fs_err::read_to_string(self.manifest_root.join("pyproject.toml"))?; | ||||||
| fs_err::read_to_string(&pyproject_toml_path).map_err(|err| { | ||||||
| if err.kind() == std::io::ErrorKind::NotFound { | ||||||
| MetadataError::MissingPyProjectToml(pyproject_toml_path.clone()) | ||||||
| } else { | ||||||
| MetadataError::Io(err) | ||||||
| } | ||||||
| })?; | ||||||
| toml::from_str(&pyproject_toml_content).map_err(MetadataError::PyProjectToml) | ||||||
| }) | ||||||
| } | ||||||
|
|
@@ -750,6 +762,32 @@ version = "1.0.0" | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn test_missing_pyproject_toml_errors_clearly() { | ||||||
| let temp_dir = TempDir::new().expect("Failed to create temp directory"); | ||||||
| let mut provider = create_metadata_provider(temp_dir.path()); | ||||||
|
|
||||||
| let err = provider | ||||||
| .name() | ||||||
| .expect_err("missing pyproject.toml should return an error"); | ||||||
| let message = err.to_string(); | ||||||
| let expected_path = temp_dir.path().join("pyproject.toml"); | ||||||
|
|
||||||
| match &err { | ||||||
| MetadataError::MissingPyProjectToml(path) => assert_eq!(path, &expected_path), | ||||||
| other => panic!("Expected MissingPyProjectToml, got: {other:?}"), | ||||||
| } | ||||||
|
|
||||||
| assert!( | ||||||
| message.contains("requires a `pyproject.toml`"), | ||||||
| "unexpected error message: {message}" | ||||||
| ); | ||||||
| assert!( | ||||||
| message.contains(&expected_path.display().to_string()), | ||||||
| "error should mention the manifest root: {message}" | ||||||
|
||||||
| "error should mention the manifest root: {message}" | |
| "error should mention the `pyproject.toml` path: {message}" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message says "requires a
pyproject.tomlin {0}", but{0}is a full file path (…/pyproject.toml). Using "at {0}" (or changing{0}to be the directory) would read more clearly and avoid implying{0}is a directory.