Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Exclude everything by default
*

# Whitelist specific files
!src/**/*
!tests/**/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought we didn't want tests in the docker?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want tests in a Python package (e.g. bdist_wheel), but they are deliberately in the Docker image so that tests get run inside the image as part of the Docker Hub build process. That way we have confidence that the produced image will run the bot correctly.

(There may be better ways to run tests without leaving them in the image, but I couldn't figure out a better one yet.)

!setup.py
!requirements.txt
!pytest.ini
!csbot.*.cfg

# Exclude Python temp files
**/__pycache__
**/*.pyc
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
sudo: false
dist: xenial
language: python
python:
- 3.6
- 3.7

install:
- pip install -r requirements.txt
- pip install tox

script:
- pytest -v --cov
matrix:
include:
- python: '3.6'
env: TOXENV=py36-coveralls
- python: '3.7'
env: TOXENV=py37-coveralls

after_success:
- coveralls
script: tox

cache:
directories:
Expand Down
17 changes: 9 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
FROM python:3.7

VOLUME /app
WORKDIR /app
COPY csbot ./csbot
COPY csbot.*.cfg requirements.txt run_csbot.py docker-entrypoint.sh ./
RUN find . -name '*.pyc' -delete
ARG UID=9000
ARG GID=9000

RUN groupadd -g $GID app \
&& useradd -u $UID -g $GID --no-create-home app

COPY --chown=app:app . /app
WORKDIR /app
RUN pip install -r requirements.txt

ARG SOURCE_COMMIT
ENV SOURCE_COMMIT $SOURCE_COMMIT

ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["./csbot.cfg"]
USER app:app
CMD ["csbot", "csbot.cfg"]
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and running [1]_::
$ python3 -m venv venv3
$ source venv3/bin/activate
$ pip install -r requirements.txt
$ ./run_csbot.py --help
$ csbot --help

Look at ``csbot.deploy.cfg`` for an example of a bot configuration.

Expand Down
5 changes: 2 additions & 3 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ version: "3"

services:
sut:
build: .
entrypoint: pytest
command: []
image: "${IMAGE_NAME}"
command: pytest
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- ./deploy.env
environment:
MONGODB_URI: mongodb://mongodb:27017/csbot
command: ${CSBOT_CONFIG:-csbot.cfg}
command: csbot ${CSBOT_CONFIG:-csbot.cfg}
ports:
- "127.0.0.1:8180:80"
labels:
Expand Down
3 changes: 0 additions & 3 deletions docker-entrypoint.sh

This file was deleted.

2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[pytest]
testpaths = tests/
addopts = --cov=src/
markers =
bot: mark a test as Bot-based rather than IRCClient-based
17 changes: 3 additions & 14 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
# Requirements for deployment
click>=6.2,<7.0
straight.plugin==1.4.0-post-1
pymongo>=3.6.0
requests>=2.9.1,<3.0.0
lxml>=2.3.5
aiogoogle==0.1.13
isodate>=0.5.1
aiohttp>=3.5.1,<4.0
async_generator>=1.10,<2.0
rollbar

# Requirements for unit testing
pytest==4.2.0
pytest-asyncio==0.10.0
pytest-aiohttp==0.3.0
#aioresponses==0.6.0
git+https://github.com/alanbriolat/aioresponses.git@callback-coroutines#egg=aioresponses
pytest-cov==2.6.1
pytest-cov
asynctest==0.12.2
aiofastforward==0.0.17
responses
python-coveralls>=2.6.0,<2.7.0
mongomock

# Requirements for documentation
# (commented out to save build time)
#sphinx

-e .
3 changes: 0 additions & 3 deletions run_csbot.py

This file was deleted.

38 changes: 33 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
from distutils.core import setup
setup(name='csbot',
version='0.1',
packages=['csbot', 'csbot.plugins'],
)
import setuptools


setuptools.setup(
name='csbot',
version='0.3.0',
author='Alan Briolat',
author_email='alan@briol.at',
url='https://github.com/HackSoc/csbot',
packages=['csbot', 'csbot.plugins'],
package_dir={'': 'src'},
classifiers=[
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
install_requires=[
'click>=6.2,<7.0',
'straight.plugin==1.4.0-post-1',
'pymongo>=3.6.0',
'requests>=2.9.1,<3.0.0',
'lxml>=2.3.5',
'aiogoogle>=0.1.13',
'isodate>=0.5.1',
'aiohttp>=3.5.1,<4.0',
'async_generator',
'rollbar',
],
entry_points={
'console_scripts': [
'csbot = csbot:main',
],
},
)
14 changes: 13 additions & 1 deletion csbot/__init__.py → src/csbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@
from .core import Bot


__version__ = None
try:
import pkg_resources
__version__ = pkg_resources.get_distribution('csbot').version
except (pkg_resources.DistributionNotFound, ImportError):
pass


LOG = logging.getLogger(__name__)


@click.command(context_settings={'help_option_names': ['-h', '--help']})
@click.command(context_settings={
'help_option_names': ['-h', '--help'],
'auto_envvar_prefix': 'CSBOT',
})
@click.version_option(version=__version__)
@click.option('--debug', '-d', is_flag=True, default=False,
help='Turn on debug logging for the bot.')
@click.option('--debug-irc', is_flag=True, default=False,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions csbot/test/conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import responses as responses_
from aioresponses import aioresponses as aioresponses_

from csbot import test
from csbot.irc import IRCClient
from csbot.core import Bot
from . import mock_open_connection


@pytest.fixture
Expand Down Expand Up @@ -55,7 +55,7 @@ async def irc_client(request, event_loop, irc_client_class, pre_irc_client, irc_
else:
client = irc_client_class(loop=event_loop, **irc_client_config)
# Connect fake stream reader/writer (for tests that don't need the read loop)
with test.mock_open_connection():
with mock_open_connection():
await client.connect()

# Mock all the things!
Expand Down Expand Up @@ -138,7 +138,7 @@ async def run_client(event_loop, irc_client_helper):
... await irc_client_helper.receive_bytes(b":nick!user@host PRIVMSG #channel :hello\r\n")
... irc_client_helper.assert_sent('PRIVMSG #channel :what do you mean, hello?')
"""
with test.mock_open_connection():
with mock_open_connection():
# Start the client
run_fut = event_loop.create_task(irc_client_helper.client.run())
await irc_client_helper.client.connected.wait()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion csbot/test/test_config.py → tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from csbot.test import TempEnvVars
from . import TempEnvVars
import csbot.plugin


Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion csbot/test/test_irc.py → tests/test_irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from csbot.test import mock_open_connection, mock_open_connection_paused
from . import mock_open_connection, mock_open_connection_paused
from csbot.irc import IRCMessage, IRCParseError, IRCUser


Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import asynctest

from csbot import core
from csbot.test import read_fixture_file
from csbot.test.test_plugin_webserver import WebServer
from . import read_fixture_file
from .test_plugin_webserver import WebServer


class Bot(core.Bot):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from csbot.test import read_fixture_file
from . import read_fixture_file


test_cases = [
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from csbot import core
from csbot.plugin import Plugin
from csbot.test.test_plugin_webserver import WebServer
from .test_plugin_webserver import WebServer


class WebhookTest(Plugin):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from csbot.test import read_fixture_file
from . import read_fixture_file


#: Tests are (number, url, content-type, fixture, expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import urllib.parse as urlparse

from csbot.test import read_fixture_file
from . import read_fixture_file
from csbot.plugins.youtube import YoutubeError


Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[tox]
envlist = py36,py37
skipsdist = True

[testenv]
passenv = TRAVIS TRAVIS_*
deps =
-r requirements.txt
coveralls: coveralls
commands =
python -m pytest {posargs}
# Try to run coveralls, but don't fail if coveralls fails
coveralls: - coveralls