代码拉取完成,页面将自动刷新
import subprocess
from pathlib import Path
import tomli
import tomli_w
import urllib3
from packaging.requirements import Requirement
from packaging.version import Version
def main():
with open(Path(__file__).parent / "pyproject.toml", "rb") as f:
pyproject = tomli.load(f)
# get current version of black
deps = pyproject["project"]["dependencies"]
assert len(deps) == 1
black_dep = Requirement(deps[0])
assert black_dep.name == "black"
black_specs = list(black_dep.specifier)
assert len(black_specs) == 1
assert black_specs[0].operator == "=="
current_version = Version(black_specs[0].version)
# get all versions of black from PyPI
resp = urllib3.request("GET", "https://pypi.org/pypi/black/json")
if resp.status != 200:
raise RuntimeError
versions = [Version(release) for release in resp.json()["releases"]]
versions = [v for v in versions if v > current_version and not v.is_prerelease]
versions.sort()
for version in versions:
pyproject["project"]["dependencies"] = [f"black=={version}"]
with open(Path(__file__).parent / "pyproject.toml", "wb") as f:
tomli_w.dump(pyproject, f)
subprocess.run(["git", "add", "pyproject.toml"])
subprocess.run(["git", "commit", "-m", f"black {version}"])
subprocess.run(["git", "tag", f"{version}"])
if __name__ == "__main__":
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。