Skip to content

Commit afa695f

Browse files
committed
reformat project, use black, use isort, add action
1 parent 4d92a38 commit afa695f

File tree

15 files changed

+210
-153
lines changed

15 files changed

+210
-153
lines changed

.github/linters/.isort.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[settings]
2+
profile = black
3+
src_paths = hondana
4+
known_first_party = hondana
5+
lines_after_imports = 2

.github/linters/.python-black

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.black]
2+
line-length=125
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Type Coverage and Linting
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
job:
11+
name: Type Coverage and Linting
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Setup Python 3.9
16+
uses: actions/setup-python@v1
17+
with:
18+
python-version: 3.9
19+
20+
- name: Install Poetry
21+
uses: snok/[email protected]
22+
23+
- name: Setup node.js (pyright)
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: "14"
27+
28+
- name: Install Python deps
29+
run: |
30+
poetry install --no-dev
31+
32+
- name: Type Coverage
33+
run: |
34+
npm install -g pyright
35+
pyright --lib --ignoreexternal --verifytypes mystbin
36+
37+
- name: Lint
38+
uses: github/super-linter@v4
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
VALIDATE_PYTHON_BLACK: true
42+
VALIDATE_PYTHON_ISORT: true

.github/workflows/lint.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ __pycache__/
44
*.pyc
55
/dist/
66
/*.egg-info/
7-
.mypy_cache/

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Copyright 2020 AbstractUmbra
1+
Copyright 2020-Present AbstractUmbra
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

55
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66

7-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

mystbin/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
The MIT License (MIT)
33
4-
Copyright (c) 2020 AbstractUmbra
4+
Copyright (c) 2020-Present AbstractUmbra
55
66
Permission is hereby granted, free of charge, to any person obtaining a
77
copy of this software and associated documentation files (the "Software"),
@@ -22,11 +22,19 @@
2222
DEALINGS IN THE SOFTWARE.
2323
"""
2424

25-
from collections import namedtuple
25+
from typing import Literal, NamedTuple
2626

2727
from .client import HTTPClient as Client
2828
from .errors import *
2929

30-
__version__ = "1.0.1"
31-
VersionInfo = namedtuple("VersionInfo", "major minor micro releaselevel serial")
32-
version_info = VersionInfo(major=2, minor=1, micro=3, releaselevel="final", serial=0)
30+
31+
class VersionInfo(NamedTuple):
32+
major: int
33+
minor: int
34+
micro: int
35+
releaselevel: Literal["alpha", "beta", "candidate", "final"]
36+
serial: int
37+
38+
39+
__version__ = "2.1.3"
40+
version_info: VersionInfo = VersionInfo(major=2, minor=1, micro=3, releaselevel="final", serial=0)

mystbin/__main__.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
The MIT License (MIT)
33
4-
Copyright (c) 2020 AbstractUmbra
4+
Copyright (c) 2020-Present AbstractUmbra
55
66
Permission is hereby granted, free of charge, to any person obtaining a
77
copy of this software and associated documentation files (the "Software"),
@@ -29,6 +29,7 @@
2929
import aiohttp
3030
import pkg_resources
3131

32+
3233
try:
3334
import requests
3435
except ImportError:
@@ -40,17 +41,9 @@
4041
def show_version():
4142
entries = []
4243

43-
entries.append(
44-
"- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(
45-
sys.version_info
46-
)
47-
)
44+
entries.append("- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(sys.version_info))
4845
version_info = mystbin.version_info
49-
entries.append(
50-
"- mystbin.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(
51-
version_info
52-
)
53-
)
46+
entries.append("- mystbin.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(version_info))
5447
if version_info.releaselevel != "final":
5548
pkg = pkg_resources.get_distribution("mystbin.py")
5649
if pkg:
@@ -65,12 +58,8 @@ def show_version():
6558

6659

6760
def parse_args():
68-
parser = argparse.ArgumentParser(
69-
prog="mystbin", description="Tools for helping with mystbin.py"
70-
)
71-
parser.add_argument(
72-
"-v", "--version", action="store_true", help="shows the wrapper version"
73-
)
61+
parser = argparse.ArgumentParser(prog="mystbin", description="Tools for helping with mystbin.py")
62+
parser.add_argument("-v", "--version", action="store_true", help="shows the wrapper version")
7463
parser.set_defaults(func=core)
7564

7665
return parser, parser.parse_args()

mystbin/client.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
The MIT License (MIT)
33
4-
Copyright (c) 2020 AbstractUmbra
4+
Copyright (c) 2020-Present AbstractUmbra
55
66
Permission is hereby granted, free of charge, to any person obtaining a
77
copy of this software and associated documentation files (the "Software"),
@@ -32,6 +32,7 @@
3232
from .errors import APIError, BadPasteID
3333
from .objects import Paste, PasteData
3434

35+
3536
if TYPE_CHECKING:
3637
import requests
3738

@@ -60,9 +61,7 @@ def __init__(
6061
session: Optional[Union[aiohttp.ClientSession, requests.Session]] = None,
6162
) -> None:
6263
self.api_key = api_key
63-
self._are_we_async = session is None or isinstance(
64-
session, aiohttp.ClientSession
65-
)
64+
self._are_we_async = session is None or isinstance(session, aiohttp.ClientSession)
6665
self.session = session
6766

6867
async def _generate_async_session(self) -> aiohttp.ClientSession:
@@ -116,9 +115,7 @@ async def _perform_async_post(self, content: str, syntax: str = None) -> Paste:
116115
multi_part_write = aiohttp.MultipartWriter()
117116
paste_content = multi_part_write.append(content)
118117
paste_content.set_content_disposition("form-data", name="data")
119-
paste_content = multi_part_write.append_json(
120-
{"meta": [{"index": 0, "syntax": syntax}]}
121-
)
118+
paste_content = multi_part_write.append_json({"meta": [{"index": 0, "syntax": syntax}]})
122119
paste_content.set_content_disposition("form-data", name="meta")
123120

124121
async with self.session.post(
@@ -159,9 +156,7 @@ def get(self, paste_id: str) -> Union[PasteData, Awaitable]:
159156

160157
def _perform_sync_get(self, paste_id: str) -> PasteData:
161158
""" Sync get request. """
162-
response: requests.Response = self.session.get(
163-
f"{API_BASE_URL}/{paste_id}", timeout=CLIENT_TIMEOUT
164-
)
159+
response: requests.Response = self.session.get(f"{API_BASE_URL}/{paste_id}", timeout=CLIENT_TIMEOUT)
165160

166161
if response.status_code not in (200,):
167162
raise BadPasteID("This is an invalid Mystb.in paste ID.")
@@ -174,9 +169,7 @@ async def _perform_async_get(self, paste_id: str) -> PasteData:
174169
if not self.session:
175170
self.session: aiohttp.ClientSession = await self._generate_async_session()
176171

177-
async with self.session.get(
178-
f"{API_BASE_URL}/{paste_id}", timeout=aiohttp.ClientTimeout(CLIENT_TIMEOUT)
179-
) as response:
172+
async with self.session.get(f"{API_BASE_URL}/{paste_id}", timeout=aiohttp.ClientTimeout(CLIENT_TIMEOUT)) as response:
180173
if response.status not in (200,):
181174
raise BadPasteID("This is an invalid Mystb.in paste ID.")
182175
paste_data = await response.json()

mystbin/constants.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
The MIT License (MIT)
33
4-
Copyright (c) 2020 AbstractUmbra
4+
Copyright (c) 2020-Present AbstractUmbra
55
66
Permission is hereby granted, free of charge, to any person obtaining a
77
copy of this software and associated documentation files (the "Software"),
@@ -24,6 +24,7 @@
2424

2525
from re import compile
2626

27+
2728
__all__ = ("API_BASE_URL", "PASTE_BASE", "CLIENT_TIMEOUT", "MB_URL_RE")
2829

2930
API_BASE_URL = "https://mystb.in/api/pastes"
@@ -32,6 +33,4 @@
3233
CLIENT_TIMEOUT = 15
3334

3435
# grab the paste id: https://regex101.com/r/qkluDh/6
35-
MB_URL_RE = compile(
36-
r"(?:(?:https?://)?mystb\.in/)?(?P<ID>[a-zA-Z]+)(?:\.(?P<syntax>[a-zA-Z0-9]+))?"
37-
)
36+
MB_URL_RE = compile(r"(?:(?:https?://)?mystb\.in/)?(?P<ID>[a-zA-Z]+)(?:\.(?P<syntax>[a-zA-Z0-9]+))?")

0 commit comments

Comments
 (0)