Skip to content

Conversation

@StellaHuang95
Copy link
Contributor

This PR implements validation for pyproject.toml when installing dependencies, addressing issue #411. It's an initial implementation that covers some most common formatting errors, we can definitely expand coverage as we receive user feedback.

This PR

  1. Ensured pyproject.toml adheres to relevant PEP standards (PEP 508, PEP 440, PEP 621, PEP 518) before attempting to install packages from it and provides feedback when validation fails, allowing the user to fix the file or proceed if they choose.

It added validatePyprojectToml in pipUtils.ts which checks:

  • Package Name (PEP 508): Validates name format (alphanumeric, dots, hyphens, underscores).
image
  • Version Format (PEP 440): Validates version strings against the standard (including pre/post/dev/local releases).
image
  • Required Fields (PEP 621): Checks for the presence of the required name field in the [project] section.
image
  • Build System (PEP 518): Checks for the presence of the required requires field in the [build-system] section.
image
  1. Implemented shouldProceedAfterPyprojectValidation to display an error message with options to "Open pyproject.toml", "Continue Anyway", or "Cancel", only when user selects dependencies from incorrectly formatted pypyroject.toml file to install when creating environment.

Example user flow:

Recording.2025-12-15.115457.mp4
  1. Added a new test file helpers.validatePyproject.unit.test.ts with comprehensive unit tests.

export function validatePyprojectToml(toml: tomljs.JsonMap): string | undefined {
// 1. Validate package name (PEP 508)
if (toml.project && (toml.project as tomljs.JsonMap).name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified if you check toml.project and exit out early.
You can additionally have const project = toml.project as tomljs.JsonMap, you could even create a interface for the version and name fields that you need and avoid tomljs.JsonMap entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, made some changes to address your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request no-changelog

2 participants