Skip to content

Commit 8f85b64

Browse files
committed
chore: add linting & release actions
1 parent b72cefb commit 8f85b64

File tree

15 files changed

+661
-507
lines changed

15 files changed

+661
-507
lines changed

.github/workflows/lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
on:
3+
push:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
lint:
9+
name: Run Flake8
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Initialize Python 3.7
16+
uses: actions/setup-python@v1
17+
with:
18+
python-version: 3.7
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install flake8
24+
25+
- name: Lint with flake8
26+
run: flake8 .
27+

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
tag:
8+
name: Add/update 'latest' tag
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v2
14+
15+
- name: Run latest-tag
16+
uses: EndBug/latest-tag@v1
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
20+
publish:
21+
name: Publish on PyPI
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- name: Initialize Python 3.7
28+
uses: actions/setup-python@v1
29+
with:
30+
python-version: 3.7
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install twine
36+
37+
- name: Build
38+
run: python setup.py sdist bdist_wheel
39+
40+
- name: Publish
41+
uses: pypa/gh-action-pypi-publish@release/v1
42+
with:
43+
user: __token__
44+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
test.py
2-
upload.sh
1+
etc
32
dbots/__pycache__/**
43
dist
54
build

dbots/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
from .service import *
1414
from .poster import Poster, ClientPoster, AsyncLoop
1515

16-
VersionInfo = namedtuple('VersionInfo', 'major minor micro releaselevel serial')
16+
VersionInfo = namedtuple(
17+
'VersionInfo', 'major minor micro releaselevel serial')
1718
version_info = VersionInfo(
18-
major = 3, minor = 0, micro = 0,
19-
releaselevel = 'final', serial = 0
19+
major=3, minor=0, micro=0,
20+
releaselevel='final', serial=0
2021
)
2122

2223
try:
@@ -26,4 +27,4 @@ class NullHandler(logging.Handler):
2627
def emit(self, record):
2728
pass
2829

29-
logging.getLogger(__name__).addHandler(NullHandler())
30+
logging.getLogger(__name__).addHandler(NullHandler())

dbots/client_filler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .errors import ClientException
22

3+
34
class ClientFiller:
45
"""A class that gets certain values from a client."""
56

@@ -54,6 +55,7 @@ def shard_count(self) -> int or None:
5455
"""
5556
return None
5657

58+
5759
class DiscordPy(ClientFiller):
5860
"""Represents the client filler for discord.py clients."""
5961

@@ -85,9 +87,10 @@ def shard_count(self):
8587
else:
8688
return self.client.shard_count
8789

90+
8891
ClientFiller.CLIENT_KEYMAP = {
8992
'discord.py': DiscordPy,
9093
'discordpy': DiscordPy,
9194
'd.py': DiscordPy,
9295
'dpy': DiscordPy,
93-
}
96+
}

dbots/errors.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@ class DBotsException(Exception):
55
"""
66
pass
77

8+
89
class PosterException(DBotsException):
910
"""Exception that is thrown when the poster encounters an error."""
1011
pass
1112

13+
1214
class ClientException(PosterException):
1315
"""Exception that is thrown when the options for a client is invalid."""
1416
pass
1517

18+
1619
class ServiceException(PosterException):
1720
"""Exception that is thrown when the options for a service is invalid."""
1821
pass
1922

23+
2024
class APIKeyException(PosterException):
2125
"""Exception that is thrown when an API key is invalid."""
2226
pass
2327

28+
2429
class HTTPException(DBotsException):
2530
"""Exception that is thrown when an HTTP request has an error."""
2631
def __init__(self, response):
@@ -34,30 +39,35 @@ def __init__(self, response):
3439

3540
super().__init__(fmt.format(self.response, self.body))
3641

42+
3743
class HTTPForbidden(HTTPException):
3844
"""Exception that's thrown for when status code 403 occurs.
3945
Subclass of :exc:`HTTPException`
4046
"""
4147
pass
4248

49+
4350
class HTTPUnauthorized(HTTPException):
4451
"""Exception that's thrown for when status code 403 occurs.
4552
Subclass of :exc:`HTTPException`
4653
"""
4754
pass
4855

56+
4957
class HTTPNotFound(HTTPException):
5058
"""Exception that's thrown for when status code 404 occurs.
5159
Subclass of :exc:`HTTPException`
5260
"""
5361
pass
5462

63+
5564
class EndpointRequiresToken(DBotsException):
56-
"""Exception that's thrown for when an endpoint is being used without a token."""
65+
"""Exception that's thrown for when an endpoint is used without a token."""
5766
def __init__(self):
5867
super().__init__('This endpoint requires a token.')
5968

69+
6070
class PostingUnsupported(ServiceException):
6171
"""Exception that's thrown for services that cannot be posted to."""
6272
def __init__(self):
63-
super().__init__('This service does not support posting.')
73+
super().__init__('This service does not support posting.')

dbots/eventhandler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
log = logging.getLogger(__name__)
88

9+
910
class _ClientEventTask(asyncio.Task):
1011
def __init__(self, original_coro, event_name, coro, *, loop):
1112
super().__init__(coro, loop=loop)
@@ -22,8 +23,9 @@ def __repr__(self):
2223
info.append(('exception', repr(self._exception)))
2324
return '<ClientEventTask {}>'.format(' '.join('%s=%s' % t for t in info))
2425

26+
2527
class EventHandler:
26-
def __init__(self, loop = None):
28+
def __init__(self, loop=None):
2729
self.loop = asyncio.get_event_loop() if loop is None else loop
2830
self._listeners = {}
2931

@@ -41,7 +43,7 @@ def event(self, name_or_coro):
4143
log.debug('%s has successfully been registered as an event', event_name)
4244
return name_or_coro
4345
else:
44-
def inner(coro):
46+
def inner(coro):
4547
if not asyncio.iscoroutinefunction(coro):
4648
raise TypeError('event registered must be a coroutine function')
4749
if name_or_coro in self._listeners:
@@ -50,7 +52,7 @@ def inner(coro):
5052
self._listeners[name_or_coro] = [coro]
5153
log.debug('%s has successfully been registered as an event using named decorator', name_or_coro)
5254
return coro
53-
return inner
55+
return inner
5456
return
5557

5658
async def _run_event(self, coro, event_name, *args, **kwargs):
@@ -83,4 +85,4 @@ def dispatch(self, event, *args, **kwargs):
8385
except AttributeError:
8486
pass
8587
else:
86-
self._schedule_event(coro, event, *args, **kwargs)
88+
self._schedule_event(coro, event, *args, **kwargs)

dbots/http.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
log = logging.getLogger(__name__)
1111

12+
1213
class HTTPClient:
1314
"""Represents an HTTP client that can send requests."""
1415

@@ -35,7 +36,7 @@ def recreate_session(self):
3536
async def request(self, method, path, **kwargs):
3637
# Evaluate kwargs
3738

38-
if not 'headers' in kwargs:
39+
if 'headers' not in kwargs:
3940
kwargs['headers'] = {
4041
'User-Agent': self.user_agent,
4142
}
@@ -45,7 +46,7 @@ async def request(self, method, path, **kwargs):
4546
if 'json' in kwargs:
4647
kwargs['headers']['Content-Type'] = 'application/json'
4748
kwargs['data'] = HTTPClient.to_json(kwargs.pop('json'))
48-
49+
4950
if self.proxy is not None:
5051
kwargs['proxy'] = self.proxy
5152
if self.proxy_auth is not None:
@@ -54,7 +55,7 @@ async def request(self, method, path, **kwargs):
5455
url = path
5556
if self.base_url:
5657
url = self.base_url + path
57-
58+
5859
if 'query' in kwargs:
5960
url = url + '?' + _encode_query(kwargs['query'])
6061
del kwargs['query']
@@ -63,7 +64,7 @@ async def request(self, method, path, **kwargs):
6364
log.debug('%s %s with %s has returned %s', method, url, kwargs.get('data'), r.status)
6465

6566
response = HTTPResponse(r, await r.text(encoding='utf-8'))
66-
67+
6768
if 300 > r.status >= 200:
6869
log.debug('%s %s has received %s', method, url, response.body)
6970
return response
@@ -124,4 +125,4 @@ def __repr__(self):
124125
('method', self.method),
125126
('url', self.url)
126127
]
127-
return '<%s %s>' % (self.__class__.__name__, ' '.join('%s=%r' % t for t in attrs))
128+
return '<%s %s>' % (self.__class__.__name__, ' '.join('%s=%r' % t for t in attrs))

0 commit comments

Comments
 (0)