drop all external python dependencies (re: #16)

This commit is contained in:
riscy 2022-04-03 14:24:28 -07:00
parent 36a9eb9855
commit e5fca66b6a
3 changed files with 49 additions and 40 deletions

View file

@ -12,8 +12,10 @@ optional arguments:
""" """
import argparse import argparse
import configparser import configparser
import contextlib
import functools import functools
import glob import glob
import json
import operator import operator
import os import os
import re import re
@ -23,10 +25,10 @@ import subprocess
import sys import sys
import tempfile import tempfile
import time import time
import urllib.error
import urllib.request
from typing import Any, Dict, Iterator, List, Optional, Set, TextIO, Tuple from typing import Any, Dict, Iterator, List, Optional, Set, TextIO, Tuple
import requests
_RETURN_CODE = 0 # eventual return code when run as script _RETURN_CODE = 0 # eventual return code when run as script
_MELPAZOID_ROOT = os.path.join(os.path.dirname(__file__), '..') _MELPAZOID_ROOT = os.path.join(os.path.dirname(__file__), '..')
_PKG_TMPDIR = os.path.join(_MELPAZOID_ROOT, 'pkg') _PKG_TMPDIR = os.path.join(_MELPAZOID_ROOT, 'pkg')
@ -368,17 +370,15 @@ def _check_license_github(clone_address: str) -> bool:
@functools.lru_cache() @functools.lru_cache()
def repo_info_github(clone_address: str) -> Dict[str, Any]: def repo_info_github(clone_address: str) -> Dict[str, Any]:
"""What does the GitHub API say about the repo? """What does the GitHub API say about the repo?
Raise ConnectionError if API request fails. Raise urllib.error.URLError if API request fails.
""" """
if clone_address.endswith('.git'): if clone_address.endswith('.git'):
clone_address = clone_address[:-4] clone_address = clone_address[:-4]
match = re.search(r'github.com/([^"]*)', clone_address, flags=re.I) match = re.search(r'github.com/([^"]*)', clone_address, flags=re.I)
if not match: if not match:
return {} return {}
response = requests.get(f"{GITHUB_API}/{match.groups()[0].rstrip('/')}") with urllib.request.urlopen(f"{GITHUB_API}/{match.groups()[0].rstrip('/')}") as r:
if not response.ok: return dict(json.load(r))
raise ConnectionError(f"GitHub API error on {clone_address}")
return dict(response.json())
def _check_license_file(elisp_dir: str) -> bool: def _check_license_file(elisp_dir: str) -> bool:
@ -527,8 +527,13 @@ def emacsattic_packages(*keywords: str) -> Dict[str, str]:
>>> emacsattic_packages('sos') >>> emacsattic_packages('sos')
{'sos': 'https://github.com/emacsattic/sos'} {'sos': 'https://github.com/emacsattic/sos'}
""" """
packages = {kw: f"https://github.com/emacsattic/{kw}" for kw in keywords} packages = {}
return {kw: url for kw, url in packages.items() if requests.head(url).ok} for keyword in set(keywords):
url = f"https://github.com/emacsattic/{keyword}"
with contextlib.suppress(urllib.error.HTTPError):
with urllib.request.urlopen(urllib.request.Request(url, method='HEAD')):
packages[keyword] = url
return packages
@functools.lru_cache() @functools.lru_cache()
@ -540,9 +545,10 @@ def emacswiki_packages(*keywords: str) -> Dict[str, str]:
packages = {} packages = {}
for keyword in set(keywords): for keyword in set(keywords):
el_file = keyword if keyword.endswith('.el') else (keyword + '.el') el_file = keyword if keyword.endswith('.el') else (keyword + '.el')
pkg = f"https://github.com/emacsmirror/emacswiki.org/blob/master/{el_file}" url = f"https://github.com/emacsmirror/emacswiki.org/blob/master/{el_file}"
if requests.head(pkg).ok: with contextlib.suppress(urllib.error.HTTPError):
packages[keyword] = pkg with urllib.request.urlopen(urllib.request.Request(url, method='HEAD')):
packages[keyword] = url
return packages return packages
@ -551,7 +557,8 @@ def emacsmirror_packages() -> Dict[str, str]:
"""All mirrored packages.""" """All mirrored packages."""
epkgs = 'https://raw.githubusercontent.com/emacsmirror/epkgs/master/.gitmodules' epkgs = 'https://raw.githubusercontent.com/emacsmirror/epkgs/master/.gitmodules'
epkgs_parser = configparser.ConfigParser() epkgs_parser = configparser.ConfigParser()
epkgs_parser.read_string(requests.get(epkgs).text) with urllib.request.urlopen(epkgs) as r:
epkgs_parser.read_string(r.read().decode())
return { return {
epkg.split('"')[1]: 'https://' epkg.split('"')[1]: 'https://'
+ data['url'].replace(':', '/')[4:] + data['url'].replace(':', '/')[4:]
@ -572,12 +579,17 @@ def elpa_packages(*keywords: str) -> Dict[str, str]:
# q.v. http://elpa.gnu.org/packages/archive-contents # q.v. http://elpa.gnu.org/packages/archive-contents
elpa = 'https://elpa.gnu.org' elpa = 'https://elpa.gnu.org'
nongnu_elpa = 'https://elpa.nongnu.org' nongnu_elpa = 'https://elpa.nongnu.org'
packages = { sources = {
**{kw: f"{elpa}/devel/{kw}.html" for kw in keywords}, **{kw: f"{elpa}/devel/{kw}.html" for kw in keywords},
**{kw: f"{elpa}/packages/{kw}.html" for kw in keywords}, **{kw: f"{elpa}/packages/{kw}.html" for kw in keywords},
**{f"{kw} (nongnu)": f"{nongnu_elpa}/nongnu/{kw}.html" for kw in keywords}, **{f"{kw} (nongnu)": f"{nongnu_elpa}/nongnu/{kw}.html" for kw in keywords},
} }
return {kw: url for kw, url in packages.items() if requests.head(url).ok} packages = {}
for kw, url in sources.items():
with contextlib.suppress(urllib.error.HTTPError):
with urllib.request.urlopen(urllib.request.Request(url, method='HEAD')):
packages[kw] = url
return packages
@functools.lru_cache() @functools.lru_cache()
@ -591,11 +603,12 @@ def melpa_packages(*keywords: str) -> Dict[str, str]:
kw: f"https://github.com/melpa/melpa/blob/master/recipes/{kw}" kw: f"https://github.com/melpa/melpa/blob/master/recipes/{kw}"
for kw in keywords for kw in keywords
} }
return { packages = {}
kw: f"https://melpa.org/#/{kw}" for kw, url in sources.items():
for kw, url in sources.items() with contextlib.suppress(urllib.error.HTTPError):
if requests.head(url).ok with urllib.request.urlopen(urllib.request.Request(url, method='HEAD')):
} packages[kw] = f"https://melpa.org/#/{kw}"
return packages
def check_melpa_recipe(recipe: str): def check_melpa_recipe(recipe: str):
@ -745,14 +758,16 @@ def check_melpa_pr(pr_url: str):
@functools.lru_cache() @functools.lru_cache()
def _pr_data(pr_number: str) -> Dict[str, Any]: def _pr_data(pr_number: str) -> Dict[str, Any]:
"""Get data from GitHub API -- cached to avoid rate limiting.""" """Get data from GitHub API -- cached to avoid rate limiting."""
return dict(requests.get(f"{MELPA_PULL_API}/{pr_number}").json()) with urllib.request.urlopen(f"{MELPA_PULL_API}/{pr_number}") as r:
return dict(json.load(r))
@functools.lru_cache() @functools.lru_cache()
def _filename_and_recipe(pr_data_diff_url: str) -> Tuple[str, str]: def _filename_and_recipe(pr_data_diff_url: str) -> Tuple[str, str]:
"""Determine the filename and the contents of the user's recipe.""" """Determine the filename and the contents of the user's recipe."""
# TODO: use https://developer.github.com/v3/repos/contents/ instead of 'patch' # TODO: use https://developer.github.com/v3/repos/contents/ instead of 'patch'
diff_text = requests.get(pr_data_diff_url).text with urllib.request.urlopen(pr_data_diff_url) as r:
diff_text = r.read().decode()
if 'a/recipes' not in diff_text or 'b/recipes' not in diff_text: if 'a/recipes' not in diff_text or 'b/recipes' not in diff_text:
_fail('New recipes should be added to the `recipes` subdirectory') _fail('New recipes should be added to the `recipes` subdirectory')
return '', '' return '', ''
@ -832,18 +847,19 @@ def run_build_script(script: str) -> str:
@functools.lru_cache() @functools.lru_cache()
def _package_build_files() -> Dict[str, str]: def _package_build_files() -> Dict[str, str]:
"""Grab the required package-build files from the MELPA repo.""" """Grab the required package-build files from the MELPA repo."""
return { files = {}
filename: requests.get( for filename in [
'package-build-badges.el',
'package-build.el',
'package-recipe-mode.el',
'package-recipe.el',
]:
with urllib.request.urlopen(
'https://raw.githubusercontent.com/melpa/melpa/master/' 'https://raw.githubusercontent.com/melpa/melpa/master/'
f'package-build/{filename}' f"package-build/{filename}"
).text ) as r:
for filename in [ files[filename] = r.read().decode()
'package-build-badges.el', return files
'package-build.el',
'package-recipe-mode.el',
'package-recipe.el',
]
}
def _check_loop() -> None: def _check_loop() -> None:

View file

@ -1,6 +0,0 @@
requests==2.24
certifi==2020.6.20
chardet==3.0.4
urllib3==1.26.5
idna==2.10

View file

@ -7,7 +7,6 @@ setup(
author='D. Chris Rayner', author='D. Chris Rayner',
author_email='dchrisrayner@gmail.com', author_email='dchrisrayner@gmail.com',
packages=['melpazoid'], packages=['melpazoid'],
install_requires=['requests>=2.0'],
license='GPL-3.0-or-later', license='GPL-3.0-or-later',
url='https://github.com/riscy/melpazoid', url='https://github.com/riscy/melpazoid',
) )