-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Validate user input against project-schema.json #10433
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
Closed
rbogart1990
wants to merge
16
commits into
python-poetry:main
from
rbogart1990:feature/invalid-project-name
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
32228a6
refactor(init): make name assignment more Pythonic
e647315
feat(init): validate pyproject data before creating pyproject.toml file
ac37d72
test(init): add parametric tests for project name validation with det…
19260a2
Merge branch 'main' of https://github.com/python-poetry/poetry into f…
de85d79
Revert "refactor(init): make name assignment more Pythonic"
4744ec6
chore: add type annotations and fix mypy errors across init and tests
4b146b2
add toml package for TOML parsing and manipulation
f558d4b
fix(init): convert TOMLDocument to dictionary for validation
7fc3293
chore: add types-toml for mypy type checking
8850d66
fix: use tomlkit.parse() instead of toml.loads() to avoid adding new …
dc17053
fix: remove toml and types-toml now that tomlkit.parse is used
7167171
Merge branch 'main' of https://github.com/python-poetry/poetry into f…
5623e28
remove validation in order to test ci/cd build
71b4152
Revert "remove validation in order to test ci/cd build"
fd5a8ca
fix(init): instantiate factory instance to avoid altering shared state
07bd96a
refactor(init): improve _validate() clarity with comment and variable…
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,9 +13,11 @@ | |||||||||||||||||||||||||||
| from cleo.helpers import option | ||||||||||||||||||||||||||||
| from packaging.utils import canonicalize_name | ||||||||||||||||||||||||||||
| from tomlkit import inline_table | ||||||||||||||||||||||||||||
| from tomlkit import parse | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from poetry.console.commands.command import Command | ||||||||||||||||||||||||||||
| from poetry.console.commands.env_command import EnvCommand | ||||||||||||||||||||||||||||
| from poetry.factory import Factory | ||||||||||||||||||||||||||||
| from poetry.utils.dependency_specification import RequirementsParser | ||||||||||||||||||||||||||||
| from poetry.utils.env.python import Python | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -265,6 +267,14 @@ def _init_pyproject( | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Validate fields before creating pyproject.toml file. If any validations fail, throw an error. | ||||||||||||||||||||||||||||
| # Convert TOML string to a TOMLDocument (a dict-like object) for validation. | ||||||||||||||||||||||||||||
| pyproject_dict = parse(pyproject.data.as_string()) | ||||||||||||||||||||||||||||
| validation_results = self._validate(pyproject_dict) | ||||||||||||||||||||||||||||
| if validation_results.get("errors"): | ||||||||||||||||||||||||||||
| self.line_error(f"<error>Validation failed: {validation_results}</error>") | ||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||
|
Comment on lines
+274
to
+276
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. 🚨 suggestion (security): Printing the full Extract and display only the relevant error messages to prevent leaking internal or sensitive information.
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| pyproject.save() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if create_layout: | ||||||||||||||||||||||||||||
|
|
@@ -533,3 +543,13 @@ def _get_pool(self) -> RepositoryPool: | |||||||||||||||||||||||||||
| self._pool.add_repository(PyPiRepository(pool_size=pool_size)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return self._pool | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||
| def _validate(pyproject_data: dict[str, Any]) -> dict[str, Any]: | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| Validates the given pyproject data and returns the validation results. | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| # Instantiate a new Factory to avoid relying on shared/global state, | ||||||||||||||||||||||||||||
| # which can cause unexpected behavior in other parts of the codebase or test suite. | ||||||||||||||||||||||||||||
| factory = Factory() | ||||||||||||||||||||||||||||
| return factory.validate(pyproject_data) | ||||||||||||||||||||||||||||
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
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.
suggestion: Consider formatting validation errors for readability
Displaying only relevant error messages or a summary instead of the full dictionary will make the output clearer for users.