-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
48 lines (37 loc) · 1.29 KB
/
utils.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
48
# -*- coding: utf-8 -*-
# Copyright © 2022-present Worldr Technologies Limited. All Rights Reserved.
"""Utilities."""
import enum
from typing import Any, Sequence
import requests
from setupr import __version__
GITHUB_URL = "https://api.github.com/repos/worldr/setupr/releases/latest"
class VersionCheck(enum.Enum):
"""Version check ENUM."""
LATEST = enum.auto()
LAGGING = enum.auto()
UNKNOWN = enum.auto()
def join_with_oxford_commas(obj_list: Sequence[Any]) -> str:
"""Oxford commas for lists.
Takes a list of objects and returns their string representations,
separated by commas and with 'and' between the penultimate and final
items
"""
if not obj_list:
return ""
size = len(obj_list)
if size == 1:
return f"{str(obj_list[0])}"
return (
", ".join(str(obj) for obj in obj_list[: size - 1])
+ f", and {str(obj_list[size - 1])}"
)
def check_if_latest_version() -> VersionCheck:
"""Check if there is a new version published on GitHub."""
response = requests.get(GITHUB_URL)
if response.status_code == 200:
latest_version = response.json()["tag_name"]
if latest_version == f"v{__version__}":
return VersionCheck.LATEST
return VersionCheck.LAGGING
return VersionCheck.UNKNOWN