-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdelete_remote_packages.py
47 lines (43 loc) · 1.71 KB
/
delete_remote_packages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
"""
Helper script for working around a "feature" in Gitlab's pypi package
repositories.
Pypi does not support uploading packages of the same version,
they believe the version should be bumped for any change.
We're going to delete packages instead.
Call this script with positional args.
The first is the token with read and write access to the pypi repository.
This can be your personal access token or $CI_DEPLOY_PASSWORD.
$CI_JOB_TOKEN does not work, it doesn't have write access.
The remainder is an unlimited list of wheels to be uploaded.
If any local wheels find a match in name and version in the remote pypi
repository, the remote will be deleted.
"""
import sys
import pkginfo
import requests
TOKEN = sys.argv[1]
for wheel_loc in sys.argv[2:]:
wheel = pkginfo.Wheel(wheel_loc)
response = requests.get(
f"https://git.grammatech.com/api/v4/projects/1587/"
f"packages?package_name={wheel.name}",
headers={"PRIVATE-TOKEN": TOKEN},
)
if response.status_code != 200:
raise Exception(
f"{response.status_code} status code while requesting package "
f"listings filtered by local name: {wheel.name}"
)
for package in response.json():
if wheel.version == package["version"]:
response = requests.delete(
f"https://git.grammatech.com/api/v4/projects/1587/packages/"
f'{package["id"]}',
headers={"PRIVATE-TOKEN": TOKEN},
)
if response.status_code != 204:
raise Exception(
f"{response.status_code} status code while deleting this "
f'package: {package["name"]} {package["version"]}'
)