Skip to content

Commit

Permalink
Check Python 3.10 (#315)
Browse files Browse the repository at this point in the history
* Adding Python 3.10 Support
* Use Ubuntu 22.04 instead of 20.04 for Testing

Co-authored-by: Renato Alves <alves.rjc@gmail.com>
  • Loading branch information
attzonko and unode authored Aug 21, 2022
1 parent 30ec64e commit 8c66ab8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ on:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Cancel Outdated Runs
uses: styfle/cancel-workflow-action@0.10.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.10'
- uses: actions/cache@v3
with:
path: ~/.cache/pip
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:

jobs:
unit_test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, '3.10']

steps:
- name: Cancel Outdated Runs
Expand All @@ -35,10 +35,10 @@ jobs:
run: pytest -vv tests/unit_tests -n auto

integration_test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, '3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ coverage.xml
**/*.log
**/*.lock
test.py
.venv
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ flake8==5.0.4
isort==5.10.1
pytest==7.1.2
pytest-xdist==2.5.0
pytype==2021.10.18
pytype==2022.8.3
snapshottest==0.6.0
23 changes: 16 additions & 7 deletions mmpy_bot/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import re
from abc import ABC, abstractmethod
from typing import Callable, Optional, Sequence
from typing import Callable, Optional, Sequence, Union

import click

Expand All @@ -19,24 +19,32 @@
class Function(ABC):
def __init__(
self,
function: Callable,
function: Union[Function, click.command],
matcher: re.Pattern,
**metadata,
):
# If another Function was passed, keep track of all these siblings.
# We later use them to register not only the outermost Function, but also any
# stacked ones.
self.siblings = []

while isinstance(function, Function):
self.siblings.append(function)
function = function.function

# FIXME: After this while loop it is possible that function is not a Function, do we really want to assign self.function to something which is not a Function? Check if this is needed for the click.Command case
self.function = function
self.is_coroutine = asyncio.iscoroutinefunction(function)
self.is_click_function: bool = False
self.matcher = matcher
self.metadata = metadata

if not isinstance(function, click.Command):
self.function.callback = None
self.function.get_help = None
self.function.make_context = None
self.function.invoke = None

# To be set in the child class or from the parent plugin
self.plugin = None
self.name: Optional[str] = None
Expand Down Expand Up @@ -85,6 +93,10 @@ def __init__(
else:
self.allowed_channels = [channel.lower() for channel in allowed_channels]

# Default for non-click functions
_function: Union[Callable, click.Command] = self.function
self.docstring = self.function.__doc__

if self.is_click_function:
_function = self.function.callback
if asyncio.iscoroutinefunction(_function):
Expand All @@ -100,11 +112,8 @@ def __init__(
self.docstring = self.function.get_help(ctx).replace(
"\n", f"\n{spaces(8)}"
)
else:
_function = self.function
self.docstring = self.function.__doc__

self.name = _function.__qualname__
if _function is not None:
self.name = _function.__qualname__

argspec = list(inspect.signature(_function).parameters.keys())
if not argspec[:2] == ["self", "message"]:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ exclude =
ignored
# Keep going past errors to analyse as many files as possible.
keep_going = True
python_version = 3.8
python_version = 3.10
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def requires(filename: str):
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",
],
Expand Down

0 comments on commit 8c66ab8

Please sign in to comment.