-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Warn when trying to uv sync a package without build configuration
#7420
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
Changes from 1 commit
4cf007d
2e976e7
9e410d7
ad900be
5161c52
76b2956
591e4a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ pub struct PyProjectToml { | |
| #[serde(skip)] | ||
| pub raw: String, | ||
|
|
||
| /// Used to determine whether a `build-system` is present. | ||
| /// Used to determine whether a `build-system` section is present. | ||
| #[serde(default, skip_serializing)] | ||
| build_system: Option<serde::de::IgnoredAny>, | ||
| } | ||
|
|
@@ -70,18 +70,43 @@ impl PyProjectToml { | |
| /// non-package ("virtual") project. | ||
| pub fn is_package(&self) -> bool { | ||
| // If `tool.uv.package` is set, defer to that explicit setting. | ||
| if let Some(is_package) = self | ||
| .tool | ||
| .as_ref() | ||
| .and_then(|tool| tool.uv.as_ref()) | ||
| .and_then(|uv| uv.package) | ||
| { | ||
| if let Some(is_package) = self.is_uv_package() { | ||
| return is_package; | ||
| } | ||
|
|
||
| // Otherwise, a project is assumed to be a package if `build-system` is present. | ||
| self.build_system.is_some() | ||
| } | ||
|
|
||
| /// Returns whether the project should be considered a packaged script. | ||
lucab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// This detects if a project is declared as a uv package, or if it has | ||
| /// a scripts-related section defined. | ||
| pub fn is_packaged_script(&self) -> bool { | ||
|
||
| if let Some(is_package) = self.is_uv_package() { | ||
| return is_package; | ||
| }; | ||
|
|
||
| if let Some(ref project) = self.project { | ||
| let is_script = project.gui_scripts.is_some() || project.scripts.is_some(); | ||
| return is_script; | ||
| }; | ||
|
|
||
| false | ||
| } | ||
|
|
||
| /// Returns whether the project has a `build-system` section. | ||
| pub fn has_build_system(&self) -> bool { | ||
| self.build_system.is_some() | ||
| } | ||
|
|
||
| /// Returns the value of `tool.uv.package`, if explicitly set. | ||
| fn is_uv_package(&self) -> Option<bool> { | ||
lucab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.tool | ||
| .as_ref() | ||
| .and_then(|tool| tool.uv.as_ref()) | ||
| .and_then(|uv| uv.package) | ||
| } | ||
| } | ||
|
|
||
| // Ignore raw document in comparison. | ||
|
|
@@ -102,7 +127,7 @@ impl AsRef<[u8]> for PyProjectToml { | |
| /// PEP 621 project metadata (`project`). | ||
| /// | ||
| /// See <https://packaging.python.org/en/latest/specifications/pyproject-toml>. | ||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] | ||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: |
||
| #[serde(rename_all = "kebab-case")] | ||
| pub struct Project { | ||
| /// The name of the project | ||
|
|
@@ -113,6 +138,13 @@ pub struct Project { | |
| pub requires_python: Option<VersionSpecifiers>, | ||
| /// The optional dependencies of the project. | ||
| pub optional_dependencies: Option<BTreeMap<ExtraName, Vec<String>>>, | ||
|
|
||
| /// Used to determine whether a `gui-scripts` section is present. | ||
| #[serde(default, skip_serializing)] | ||
| pub(crate) gui_scripts: Option<serde::de::IgnoredAny>, | ||
| /// Used to determine whether a `scripts` section is present. | ||
| #[serde(default, skip_serializing)] | ||
| pub(crate) scripts: Option<serde::de::IgnoredAny>, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -451,6 +451,12 @@ pub(crate) async fn run( | |
| .await? | ||
| }; | ||
|
|
||
| if project.workspace().pyproject_toml().is_packaged_script() | ||
|
||
| && !project.workspace().pyproject_toml().has_build_system() | ||
| { | ||
| warn_user!("No `build-system` section found for the package; consider adding one to correctly build the project"); | ||
| } | ||
|
|
||
| if no_sync { | ||
| debug!("Skipping environment synchronization due to `--no-sync`"); | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.