1 Star 1 Fork 0

liq07lzucn/black-pre-commit-mirror

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mirror.py 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
Jelle Zijlstra 提交于 2023-12-12 08:41 . Exclude pre-releases (#5)
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qiangge_666/black-pre-commit-mirror.git
git@gitee.com:qiangge_666/black-pre-commit-mirror.git
qiangge_666
black-pre-commit-mirror
black-pre-commit-mirror
main

搜索帮助