Skip to content
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

feat: preserve existing data in [project] #84

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

mkniewallner
Copy link
Owner

Closes #52.

Preserve existing data in [project] section of pyproject.toml when performing the migration. This can be opted out by setting --replace-project-section flag.

This should also enable support for projects using PEP 621 with Poetry, but official support and tests will be added in another PR.

There are some edge cases that are not handled, but that are I believe not worth handling.

For instance, if a project using Pipenv has the following Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[[source]]
url = "https://example.com/simple"
verify_ssl = true
name = "other-index"

[packages]
dep = "==1.2.3"
private-dep = { version = "==1.2.3", index = "other-index" }
local-package = { path = "package/" }
git-dep = { git = "https://example.com/foo/bar.git", ref = "v1.2.3" }

and the following pyproject.toml:

[project]
name = "for"
version = "1.0.0"
requires-python = ">=3.13"
dependencies = ["bar==1.2.3"]

The project would get migrated to:

[project]
name = "foo"
version = "1.0.0"
requires-python = ">=3.13"
dependencies = ["bar==1.2.3"]

[tool.uv]
package = false

[[tool.uv.index]]
name = "pypi"
url = "https://pypi.org/simple"

[[tool.uv.index]]
name = "other-index"
url = "https://example.com/simple"
explicit = true

[tool.uv.sources]
private-dep = { index = "other-index" }
local-package = { path = "package/" }
git-dep = { git = "https://example.com/foo/bar.git", rev = "v1.2.3" }

where [tool.uv.sources] would reference dependencies that do not exist, since we keep the existing dependencies key.

We could conditionally add sources only if dependencies is replaced, or consider an option to merge some sections, but I feel like this would make things way more complex, for something that I believe is not really a use case to begin with.

@mkniewallner mkniewallner marked this pull request as ready for review January 20, 2025 14:46
@mkniewallner mkniewallner merged commit bbd7f3c into main Jan 20, 2025
5 checks passed
@mkniewallner mkniewallner deleted the feat/preserve-existing-project-data branch January 20, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect/keep [project] values in pyproject.toml
1 participant