Skip to content

Commit

Permalink
[internal] use xml-rpc api to get owners (pantsbuild#11901)
Browse files Browse the repository at this point in the history
Calling an API is better than scraping a web site, and the results are the same.
This also allows the removal of bs4 dependency in pants.

https://warehouse.pypa.io/api-reference/xml-rpc.html?highlight=maintainer#package-querying


<img width="670" alt="Screen Shot 2021-04-12 at 9 28 24 PM" src="https://user-images.githubusercontent.com/1268088/114497470-13f48d00-9bd7-11eb-9580-d3776c2215f7.png">
<img width="1284" alt="Screen Shot 2021-04-12 at 9 29 23 PM" src="https://user-images.githubusercontent.com/1268088/114497472-1525ba00-9bd7-11eb-88ff-4f4bdce6518c.png">
  • Loading branch information
asherf authored Apr 13, 2021
1 parent 3667fc0 commit b488cef
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
1 change: 0 additions & 1 deletion 3rdparty/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
python_requirements(
module_mapping={
"ansicolors": ["colors"],
"beautifulsoup4": ["bs4"],
"PyYAML": ["yaml"],
"setuptools": ["pkg_resources"],
}
Expand Down
4 changes: 1 addition & 3 deletions 3rdparty/python/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by build-support/bin/generate_lockfile.sh on Mon Apr 12 19:49:47 MST 2021
# Generated by build-support/bin/generate_lockfile.sh on Tue Apr 13 10:17:21 PDT 2021
ansicolors==1.1.8
attrs==20.3.0
beautifulsoup4==4.9.3
bugout==0.1.11
certifi==2020.12.5
cffi==1.14.5
Expand Down Expand Up @@ -32,7 +31,6 @@ requests==2.25.1
setproctitle==1.2.2
setuptools==53.1.0
six==1.15.0
soupsieve==2.2.1
toml==0.10.2
typed-ast==1.4.3
typing-extensions==3.7.4.3
Expand Down
1 change: 0 additions & 1 deletion 3rdparty/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ansicolors==1.1.8
beautifulsoup4>=4.9,<4.10
fasteners==0.16
freezegun==1.1.0

Expand Down
14 changes: 4 additions & 10 deletions build-support/bin/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import subprocess
import sys
import xmlrpc.client
from configparser import ConfigParser
from contextlib import contextmanager
from functools import total_ordering
Expand All @@ -19,7 +20,6 @@
from xml.etree import ElementTree

import requests
from bs4 import BeautifulSoup
from common import banner, die, green, travis_section
from reversion import reversion

Expand Down Expand Up @@ -69,15 +69,9 @@ def latest_published_version(self) -> str:
return cast(str, json_data["info"]["version"])

def owners(self) -> set[str]:
url_content = requests.get(
f"https://pypi.org/project/{self.name}/{self.latest_published_version()}/"
).text
parser = BeautifulSoup(url_content, "html.parser")
owners = {
span.find("a", recursive=False).get_text().strip().lower()
for span in parser.find_all("span", class_="sidebar-section__maintainer")
}
return owners
client = xmlrpc.client.ServerProxy("https://pypi.org/pypi")
roles = client.package_roles(self.name)
return {row[1] for row in roles if row[0] == "Owner"} # type: ignore[union-attr,index]


PACKAGES = sorted(
Expand Down

0 comments on commit b488cef

Please sign in to comment.