Skip to content

Commit b92af86

Browse files
committed
Merge remote-tracking branch 'upstream/main' into cleanup
2 parents b69875c + 63ac305 commit b92af86

36 files changed

+626
-343
lines changed

.github/workflows/main.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize]
9+
10+
jobs:
11+
tests:
12+
runs-on: ubuntu-20.04
13+
strategy:
14+
matrix:
15+
python-version: ["3.7", "3.8", "3.9", "3.10"]
16+
include:
17+
- python-version: "3.7"
18+
toxenv: py37
19+
- python-version: "3.8"
20+
toxenv: py38
21+
- python-version: "3.9"
22+
toxenv: py39
23+
- python-version: "3.10"
24+
toxenv: py310-flake8
25+
env:
26+
PYTHON: ${{ matrix.python-version }}
27+
steps:
28+
- name: examine environment
29+
run: env
30+
- uses: actions/checkout@v1
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v1
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
python -m pip install tox
39+
- name: Test with tox
40+
run: python -m tox
41+
env:
42+
TOXENV: ${{ matrix.toxenv }}
43+
- uses: codecov/codecov-action@v1
44+
with:
45+
env_vars: PYTHON
46+
47+
docker:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Build Docker image
51+
uses: docker/build-push-action@v2
52+
with:
53+
load: true
54+
push: false
55+
tags: csbot:latest
56+
- name: Run tests inside Docker
57+
run: docker run --rm csbot:latest pytest
58+
- name: Login to GitHub Container Registry
59+
if: github.event_name == 'push' && github.repository == 'HackSoc/csbot' && github.ref == 'refs/heads/main'
60+
uses: docker/login-action@v1
61+
with:
62+
registry: ghcr.io
63+
username: ${{ github.actor }}
64+
password: ${{ secrets.GITHUB_TOKEN }}
65+
- name: Publish Docker image
66+
if: github.event_name == 'push' && github.repository == 'HackSoc/csbot' && github.ref == 'refs/heads/main'
67+
uses: docker/build-push-action@v2
68+
with:
69+
push: true
70+
tags: |
71+
ghcr.io/hacksoc/csbot/csbot:latest

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pip-log.txt
4242

4343
# Unit test / coverage reports
4444
.coverage
45+
coverage*.xml
4546
.tox
4647
nosetests.xml
4748
_trial_temp/

.travis.yml

-25
This file was deleted.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.7
1+
FROM python:3.10
22

33
ARG UID=9000
44
ARG GID=9000

README.rst

+6-7
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ Testing
6969
-------
7070
csbot has some unit tests. (It'd be nice to have more.) To run them::
7171

72-
$ pytest
72+
$ tox
7373

74-
We're also using Travis-CI for continuous integration and continuous deployment.
74+
We're also using GitHub Actions for continuous integration and continuous deployment.
7575

76-
.. image:: https://travis-ci.org/HackSoc/csbot.svg?branch=master
77-
:target: https://travis-ci.org/HackSoc/csbot
76+
.. image:: https://github.com/HackSoc/csbot/actions/workflows/main.yml/badge.svg
7877

79-
.. image:: https://coveralls.io/repos/HackSoc/csbot/badge.png
80-
:target: https://coveralls.io/r/HackSoc/csbot
78+
.. image:: https://codecov.io/gh/HackSoc/csbot/branch/main/graph/badge.svg?token=oMJcY9E9lj
79+
:target: https://codecov.io/gh/HackSoc/csbot
8180

8281

8382
.. [1] csbot depends on lxml_, which is a compiled extension module based on
@@ -90,4 +89,4 @@ We're also using Travis-CI for continuous integration and continuous deployment.
9089
.. _lxml: http://lxml.de/
9190
.. _Docker Compose: https://docs.docker.com/compose/
9291
.. _published image: https://hub.docker.com/r/alanbriolat/csbot
93-
.. _Watchtower: https://containrrr.github.io/watchtower/
92+
.. _Watchtower: https://containrrr.github.io/watchtower/

csbot.deploy.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ircv3 = true
33
nickname = "Mathison"
44
auth_method = "sasl_plain"
5-
irc_host = "irc.freenode.net"
5+
irc_host = "irc.libera.chat"
66
channels = [
77
"#cs-york",
88
"#cs-york-dev",
@@ -39,15 +39,15 @@ scan_limit = 2
3939
[auth]
4040
"@everything" = "* *:*"
4141
Alan = "@everything"
42-
hjmills = "@everything"
42+
#hjmills = "@everything"
4343
barrucadu = "#cs-york:topic"
4444
Helzibah = "#cs-york:topic"
45-
DinCahill = "#cs-york:topic"
46-
jalada = "#cs-york:topic"
47-
kyubiko = "#cs-york:topic #hacksoc:*"
48-
eep = "#cs-york:topic #hacksoc:*"
45+
#DinCahill = "#cs-york:topic"
46+
#jalada = "#cs-york:topic"
47+
#kyubiko = "#cs-york:topic #hacksoc:*"
48+
#eep = "#cs-york:topic #hacksoc:*"
4949
fromankyra = "#hacksoc-bottest:*"
50-
ldm = "#hacksoc:* #hacksoc-bottest:*"
50+
luke = "#hacksoc:* #hacksoc-bottest:*"
5151

5252
"*" = "#compsoc-uk:topic"
5353

docker-compose.test.yml

-6
This file was deleted.

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3"
22

33
services:
44
bot:
5-
image: alanbriolat/csbot:latest
5+
image: ghcr.io/hacksoc/csbot/csbot:latest
66
volumes:
77
- ${CSBOT_CONFIG_LOCAL:-./csbot.toml}:/app/csbot.toml
88
links:

pytest.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[pytest]
22
testpaths = tests/
3-
addopts = --cov=src/ -W ignore::schematics.deprecated.SchematicsDeprecationWarning
3+
addopts = --cov=src/ --cov-report=xml -W ignore::schematics.deprecated.SchematicsDeprecationWarning
44
markers =
55
bot: mark a test as Bot-based rather than IRCClient-based
6+
asyncio_mode = auto

requirements.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Requirements for unit testing
2-
pytest>=5.2.2,<6.0
3-
pytest-asyncio==0.10.0
4-
pytest-aiohttp==0.3.0
5-
aioresponses==0.6.1
2+
pytest>=7.0.1,<8
3+
pytest-asyncio==0.18.1
4+
pytest-aiohttp==1.0.4
5+
aioresponses==0.7.3
66
pytest-cov
77
asynctest==0.13.0
88
aiofastforward==0.0.24
9+
time-machine==2.6.0
910
mongomock
1011

1112
# Requirements for documentation

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
install_requires=[
1717
'click>=6.2,<7.0',
18-
'pymongo>=3.6.0',
18+
'pymongo>=4.0.1',
1919
'requests>=2.9.1,<3.0.0',
2020
'lxml>=2.3.5',
2121
'aiogoogle>=0.1.13',

src/csbot/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ def _write(self, s, raw=False):
350350
"""Write *s* to the current stream; if *raw* is True, don't apply comment filter."""
351351
if not raw and self._commented:
352352
lines = s.split("\n")
353-
modified = [f"# {l}" if l and not l.startswith("#") else l
354-
for l in lines]
353+
modified = [f"# {line}" if line and not line.startswith("#") else line
354+
for line in lines]
355355
s = "\n".join(modified)
356356
self._stream.write(s)
357357
self._at_start = False

src/csbot/events.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, get_handlers, loop=None):
3333
self.loop = loop
3434

3535
self.events = deque()
36-
self.new_events = asyncio.Event(loop=self.loop)
36+
self.new_events = asyncio.Event()
3737
self.futures = set()
3838
self.future = None
3939

@@ -91,11 +91,7 @@ def _run_handler(self, handler, event):
9191
result = handler(event)
9292
except Exception as e:
9393
self._handle_exception(exception=e, csbot_event=event)
94-
future = maybe_future(
95-
result,
96-
log=LOG,
97-
loop=self.loop,
98-
)
94+
future = maybe_future(result, log=LOG)
9995
if future:
10096
future = asyncio.ensure_future(self._finish_async_handler(future, event), loop=self.loop)
10197
return future
@@ -129,9 +125,7 @@ async def _run(self):
129125
# Run until one or more futures complete (or new events are added)
130126
new_events = self.loop.create_task(self.new_events.wait())
131127
LOG.debug('waiting on %s futures', len(self.futures))
132-
done, pending = await asyncio.wait(self.futures | {new_events},
133-
loop=self.loop,
134-
return_when=asyncio.FIRST_COMPLETED)
128+
done, pending = await asyncio.wait(self.futures | {new_events}, return_when=asyncio.FIRST_COMPLETED)
135129
# Remove done futures from the set of futures being waited on
136130
done_futures = done - {new_events}
137131
LOG.debug('%s of %s futures done', len(done_futures), len(self.futures))

src/csbot/irc.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ def __init__(self, *, loop=None, **kwargs):
276276

277277
self.reader, self.writer = None, None
278278
self._exiting = False
279-
self.connected = asyncio.Event(loop=self.loop)
279+
self.connected = asyncio.Event()
280280
self.connected.clear()
281-
self.disconnected = asyncio.Event(loop=self.loop)
281+
self.disconnected = asyncio.Event()
282282
self.disconnected.set()
283283
self._last_message_received = self.loop.time()
284284
self._client_ping = None
@@ -325,7 +325,6 @@ async def connect(self):
325325

326326
self.reader, self.writer = await asyncio.open_connection(self.__config['host'],
327327
self.__config['port'],
328-
loop=self.loop,
329328
local_addr=local_addr)
330329

331330
def disconnect(self):

src/csbot/plugins/last.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def last(self, nick, channel=None, msgtype=None):
2424
if msgtype is not None:
2525
search['type'] = msgtype
2626

27-
return self.db.find_one(search, sort=[('when', pymongo.DESCENDING)])
27+
# Additional sorting by _id to make sort order stable for messages that arrive in the same millisecond
28+
# (which sometimes happens during tests).
29+
return self.db.find_one(search, sort=[('when', pymongo.DESCENDING), ('_id', pymongo.DESCENDING)])
2830

2931
def last_message(self, nick, channel=None):
3032
"""Get the last message sent by a nick, optionally filtering
@@ -104,8 +106,7 @@ def _schedule_update(self, e, query, update):
104106

105107
@Plugin.hook('last.update')
106108
def _apply_update(self, e):
107-
self.db.remove(e['query'])
108-
self.db.insert(e['update'])
109+
self.db.replace_one(e['query'], e['update'], upsert=True)
109110

110111
@Plugin.command('seen', help=('seen nick [type]: show the last thing'
111112
' said by a nick in this channel, optionally'

0 commit comments

Comments
 (0)