From 1edeac3c2bed4ae182f3f8028f801e0b50cf718a Mon Sep 17 00:00:00 2001 From: Victor Kotlin Date: Fri, 24 Sep 2021 19:10:00 +0300 Subject: [PATCH] from CamelCase to snake_case, update versions info, update configs, reformat imports --- boticordpy/__init__.py | 14 +++++++++++ boticordpy/client.py | 5 ++-- boticordpy/config.py | 12 +++++++++ boticordpy/modules/bots.py | 20 ++++----------- boticordpy/modules/servers.py | 20 ++++----------- boticordpy/modules/users.py | 20 ++++----------- boticordpy/webhook.py | 4 +-- docs/conf.py | 12 +++++++-- setup.py | 47 +++++++++++++++++++++++++++++------ 9 files changed, 96 insertions(+), 58 deletions(-) diff --git a/boticordpy/__init__.py b/boticordpy/__init__.py index ffd543a..3862ac0 100644 --- a/boticordpy/__init__.py +++ b/boticordpy/__init__.py @@ -1,3 +1,17 @@ +""" +Boticord API Wrapper +~~~~~~~~~~~~~~~~~~~ +A basic wrapper for the Boticord API. +:copyright: (c) 2021 Grey Cat +:license: MIT, see LICENSE for more details. +""" + +__title__ = 'boticordpy' +__author__ = 'Grey Cat' +__license__ = 'MIT' +__copyright__ = 'Copyright 2021 Grey Cat' +__version__ = '2.0.0a' + from .client import BoticordClient from .webhook import BoticordWebhook from .types import * diff --git a/boticordpy/client.py b/boticordpy/client.py index efccd89..0642f9b 100644 --- a/boticordpy/client.py +++ b/boticordpy/client.py @@ -1,7 +1,8 @@ from discord.ext import commands +import aiohttp + from typing import Union import asyncio -import aiohttp from .modules import Bots, Servers, Users @@ -88,7 +89,7 @@ class BoticordClient: if isinstance(self.bot, commands.AutoShardedBot): data_to_send["shards"] = self.bot.shard_count - await self.Bots.postStats(data_to_send) + await self.Bots.post_stats(data_to_send) if sleep_time is None: sleep_time = 900 diff --git a/boticordpy/config.py b/boticordpy/config.py index 0f001dd..edd6fb0 100644 --- a/boticordpy/config.py +++ b/boticordpy/config.py @@ -1,3 +1,8 @@ +from aiohttp import ClientResponse + +from typing import Union +import json + from . import exceptions from . import types @@ -17,3 +22,10 @@ class Config: "delete_bot_comment": types.Comment, "new_bot_bump": types.BotVote } + + +async def _json_or_text(response: ClientResponse) -> Union[dict, str]: + text = await response.text() + if response.headers['Content-Type'] == 'application/json; charset=utf-8': + return json.loads(text) + return text diff --git a/boticordpy/modules/bots.py b/boticordpy/modules/bots.py index 8630bad..20eea4d 100644 --- a/boticordpy/modules/bots.py +++ b/boticordpy/modules/bots.py @@ -1,18 +1,8 @@ -import json - -from aiohttp import ClientResponse -from typing import Union import aiohttp + import asyncio -from ..config import Config - - -async def _json_or_text(response: ClientResponse) -> Union[dict, str]: - text = await response.text() - if response.headers['Content-Type'] == 'application/json; charset=utf-8': - return json.loads(text) - return text +from ..config import Config, _json_or_text class Bots: @@ -32,7 +22,7 @@ class Bots: self.loop = kwargs.get('loop') or asyncio.get_event_loop() self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop) - async def getBotInfo(self, botID: int): + async def get_bot_info(self, botID: int): """ Returns information about discord bot with the given ID. @@ -51,7 +41,7 @@ class Bots: raise status(resp) return data - async def getBotComments(self, botID: int): + async def get_bot_comments(self, botID: int): """ Returns comments of the discord bot with the given ID. @@ -69,7 +59,7 @@ class Bots: raise status(resp) return data - async def postStats(self, stats: dict): + async def post_stats(self, stats: dict): """ Post stats to Boticord API. diff --git a/boticordpy/modules/servers.py b/boticordpy/modules/servers.py index cc7900e..6cb184b 100644 --- a/boticordpy/modules/servers.py +++ b/boticordpy/modules/servers.py @@ -1,19 +1,9 @@ -import json - -from aiohttp import ClientResponse -from typing import Union import aiohttp -import asyncio import discord -from ..config import Config +import asyncio - -async def _json_or_text(response: ClientResponse) -> Union[dict, str]: - text = await response.text() - if response.headers['Content-Type'] == 'application/json; charset=utf-8': - return json.loads(text) - return text +from ..config import Config, _json_or_text class Servers: @@ -33,7 +23,7 @@ class Servers: self.loop = kwargs.get('loop') or asyncio.get_event_loop() self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop) - async def getServerInfo(self, serverID: int): + async def get_server_info(self, serverID: int): """ Returns information about discord server with the given ID. @@ -51,7 +41,7 @@ class Servers: raise status(resp) return data - async def getServerComments(self, serverID: int): + async def get_server_comments(self, serverID: int): """ Returns comments of the discord server with the given ID. @@ -69,7 +59,7 @@ class Servers: raise status(resp) return data - async def postServerStats(self, message: discord.Message, custom_stats: dict = None): + async def post_server_stats(self, message: discord.Message, custom_stats: dict = None): """ Post server stats to Boticord API. diff --git a/boticordpy/modules/users.py b/boticordpy/modules/users.py index 3ca9bc4..54f41d8 100644 --- a/boticordpy/modules/users.py +++ b/boticordpy/modules/users.py @@ -1,18 +1,8 @@ -import json - -from aiohttp import ClientResponse -from typing import Union import aiohttp + import asyncio -from ..config import Config - - -async def _json_or_text(response: ClientResponse) -> Union[dict, str]: - text = await response.text() - if response.headers['Content-Type'] == 'application/json; charset=utf-8': - return json.loads(text) - return text +from ..config import Config, _json_or_text class Users: @@ -26,7 +16,7 @@ class Users: self.loop = kwargs.get('loop') or asyncio.get_event_loop() self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop) - async def getUserInfo(self, userID: int): + async def get_user(self, userID: int): """ Returns information about discord user with the given ID. @@ -44,7 +34,7 @@ class Users: raise status(resp) return data - async def getUserComments(self, userID: int): + async def get_user_comments(self, userID: int): """ Returns comments of discord user with the given ID. @@ -62,7 +52,7 @@ class Users: raise status(resp) return data - async def getUserBots(self, userID: int): + async def get_user_bots(self, userID: int): """ Returns bots of discord user with the given ID. diff --git a/boticordpy/webhook.py b/boticordpy/webhook.py index ecd7123..80a5479 100644 --- a/boticordpy/webhook.py +++ b/boticordpy/webhook.py @@ -1,6 +1,7 @@ +from discord.ext.commands import Bot, AutoShardedBot +from aiohttp.web_urldispatcher import _WebHandler from aiohttp import web import aiohttp -from discord.ext.commands import Bot, AutoShardedBot import sys @@ -9,7 +10,6 @@ if sys.version_info >= (3, 8): else: from typing_extensions import TypedDict -from aiohttp.web_urldispatcher import _WebHandler from typing import Dict, Union from . import BoticordClient diff --git a/docs/conf.py b/docs/conf.py index 116d356..ac04efe 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,8 @@ # import os import sys +import re + sys.path.insert(0, os.path.abspath('..')) @@ -21,8 +23,14 @@ project = 'BoticordPY' copyright = '2021, Grey Cat' author = 'Grey Cat' -# The full version, including alpha/beta/rc tags -release = '1.5' +with open('../discord/__init__.py') as f: + version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1) + +# The full version, including alpha/beta/rc tags. +release = version + +# This assumes a tag is available for final releases +branch = 'master' if version.endswith('a') else 'v' + version # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 191da1f..0ba6d27 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,52 @@ import pathlib from setuptools import setup +import re -# The directory containing this file HERE = pathlib.Path(__file__).parent -# The text of the README file +requirements = [] +with open('requirements.txt') as f: + requirements = f.read().splitlines() + +version = '' +with open('boticordpy/__init__.py') as f: + version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1) + +if version.endswith(('a', 'b', 'rc')): + # append version identifier based on commit count + try: + import subprocess + + p = subprocess.Popen(['git', 'rev-list', '--count', 'HEAD'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + if out: + version += out.decode('utf-8').strip() + p = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + if out: + version += '+g' + out.decode('utf-8').strip() + except Exception: + pass + README = (HERE / "README.md").read_text(encoding="utf8") -# This call to setup() does all the work +packages = [ + 'boticordpy', + 'boticordpy.modules' +] + setup( name="boticordpy", - packages = ['boticordpy', 'boticordpy.modules'], - version="1.5", - description="Simple Python Module for boticord api", + project_urls={ + "Documentation": "https://py.boticord.top/en/latest/r", + "Issue tracker": "https://github.com/boticord/boticordpy/issues", + }, + packages=packages, + version=version, + description="A Python wrapper for Boticord api", long_description=README, long_description_content_type="text/markdown", url="https://github.com/grey-cat-1908/boticordpy", @@ -25,5 +58,5 @@ setup( "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", ], - install_requires=["discord.py", "aiohttp"], + install_requires=requirements, )