parent
c6ee451377
commit
b0baec99c9
@ -0,0 +1,40 @@
|
||||
import toml
|
||||
import pkg_resources
|
||||
|
||||
|
||||
def update_pyproject_versions(pyproject_path):
|
||||
try:
|
||||
with open(pyproject_path, "r") as file:
|
||||
data = toml.load(file)
|
||||
except FileNotFoundError:
|
||||
print(f"Error: The file '{pyproject_path}' was not found.")
|
||||
return
|
||||
except toml.TomlDecodeError:
|
||||
print(
|
||||
f"Error: The file '{pyproject_path}' is not a valid TOML"
|
||||
" file."
|
||||
)
|
||||
return
|
||||
|
||||
dependencies = (
|
||||
data.get("tool", {}).get("poetry", {}).get("dependencies", {})
|
||||
)
|
||||
|
||||
for package in dependencies:
|
||||
if package.lower() == "python":
|
||||
continue # Skip the Python version dependency
|
||||
|
||||
try:
|
||||
version = pkg_resources.get_distribution(package).version
|
||||
dependencies[package] = version
|
||||
except pkg_resources.DistributionNotFound:
|
||||
print(f"Warning: Package '{package}' not installed.")
|
||||
|
||||
with open(pyproject_path, "w") as file:
|
||||
toml.dump(data, file)
|
||||
|
||||
print(f"Updated versions written to {pyproject_path}")
|
||||
|
||||
|
||||
# Usage
|
||||
update_pyproject_versions("pyproject.toml")
|
Loading…
Reference in new issue