From afa46c4abfc73c8791742ed2ece886776823e8ab Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sat, 23 Jul 2022 14:47:06 +0200 Subject: Add Sample Project With Boilerplate Adds a bare-bones discord.py bot using features from bot-core, to be used for quickly prototyping and testing out bot-core features. Signed-off-by: Hassan Abouelela --- dev/README.rst | 45 +++++++++++++++++++++++++++++++++++++++++++++ dev/bot/__init__.py | 24 ++++++++++++++++++++++++ dev/bot/__main__.py | 34 ++++++++++++++++++++++++++++++++++ dev/bot/cog.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 dev/README.rst create mode 100644 dev/bot/__init__.py create mode 100644 dev/bot/__main__.py create mode 100644 dev/bot/cog.py (limited to 'dev') diff --git a/dev/README.rst b/dev/README.rst new file mode 100644 index 00000000..b1535962 --- /dev/null +++ b/dev/README.rst @@ -0,0 +1,45 @@ +Local Development & Testing +=========================== + +To test your features locally, there are a few possible approaches: + +1. Install your local copy of botcore into a pre-existing project such as bot +2. Use the provided template from the :repo-file:`dev/bot ` folder + +See below for more info on both approaches. + +What's going to be common between them is you'll need to write code to test your feature. +This might mean adding new commands, modifying existing ones, changing utilities, etc. +The steps below should provide most of the groundwork you need, but the exact requirements will +vary by the feature you're working on. + + +Option 1 +-------- +1. Navigate to the project you want to install bot-core in, such as bot or sir-lancebot +2. Run ``pip install /path/to/botcore`` in the project's environment + + - The path provided to install should be the root directory of this project on your maching. + That is, the folder which contains the ``pyproject.toml`` file. + - Make sure to install in the correct environment. Most Python Discord projects use + poetry, so you can run ``poetry run pip install /path/to/botcore``. + +3. You can now use features from your local bot-core changes. + To load new changes, run the install command again. + + +Option 2 +-------- +1. Copy the :repo-file:`bot template folder ` to the root of your project. + This copy is going to be git-ignored, so you're free to modify it however you like. +2. Run the project + + - Locally: You can run it on your system using ``python -m bot`` + - Docker: You can run on docker using ``docker compose up -d bot``. + +3. You can now test your changes. You do not need to do anything to reinstall the + library if you modify your code. + +.. tip:: + The docker-compose included contains services from our other applications + to help you test out certain features. Use them as needed. diff --git a/dev/bot/__init__.py b/dev/bot/__init__.py new file mode 100644 index 00000000..71871209 --- /dev/null +++ b/dev/bot/__init__.py @@ -0,0 +1,24 @@ +import asyncio +import logging +import os +import sys + +import botcore + +if os.name == "nt": + # Change the event loop policy on Windows to avoid exceptions on exit + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + +# Some basic logging to get existing loggers to show +logging.getLogger().addHandler(logging.StreamHandler()) +logging.getLogger().setLevel(logging.DEBUG) +logging.getLogger("discord").setLevel(logging.ERROR) + + +class Bot(botcore.BotBase): + """Sample Bot implementation.""" + + async def setup_hook(self) -> None: + """Load extensions on startup.""" + await super().setup_hook() + asyncio.create_task(self.load_extensions(sys.modules[__name__])) diff --git a/dev/bot/__main__.py b/dev/bot/__main__.py new file mode 100644 index 00000000..00ebdefc --- /dev/null +++ b/dev/bot/__main__.py @@ -0,0 +1,34 @@ +import asyncio +import os + +import aiohttp +import discord +import dotenv +from discord.ext import commands + +import botcore +from . import Bot + +dotenv.load_dotenv() +botcore.utils.apply_monkey_patches() + +roles = os.getenv("ALLOWED_ROLES") +roles = [int(role) for role in roles.split(",")] if roles else [] + +bot = Bot( + guild_id=int(os.getenv("GUILD_ID")), + http_session=None, # type: ignore # We need to instantiate the session in an async context + allowed_roles=roles, + command_prefix=commands.when_mentioned_or(os.getenv("PREFIX", "!")), + intents=discord.Intents.all(), + description="Bot-core test bot.", +) + + +async def main() -> None: + """Run the bot.""" + bot.http_session = aiohttp.ClientSession() + async with bot: + await bot.start(os.getenv("TOKEN")) + +asyncio.run(main()) diff --git a/dev/bot/cog.py b/dev/bot/cog.py new file mode 100644 index 00000000..7746c54e --- /dev/null +++ b/dev/bot/cog.py @@ -0,0 +1,33 @@ +from discord.ext import commands + +from . import Bot + + +class Cog(commands.Cog): + """A simple discord.py cog.""" + + def __init__(self, _bot: Bot): + self.bot = _bot + + @commands.Cog.listener() + async def on_ready(self) -> None: + """Print a message when the client (re)connects.""" + print("Client is ready.") + + @commands.command() + async def reload(self, ctx: commands.Context) -> None: + """Reload all available cogs.""" + message = await ctx.send(":hourglass_flowing_sand: Reloading") + for ext in list(self.bot.extensions): + await self.bot.reload_extension(ext) + await message.edit(content=":white_check_mark: Done") + + @commands.command() + async def ping(self, ctx: commands.Context) -> None: + """Test if the bot is online.""" + await ctx.send("We are live!") + + +async def setup(_bot: Bot) -> None: + """Install the cog.""" + await _bot.add_cog(Cog(_bot)) -- cgit v1.2.3 From 16804aab66588549da84ea503a7180fff2c54834 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sat, 23 Jul 2022 14:49:08 +0200 Subject: Clean Up Docker Configuration Rewrites the docker configuration to better work for this project. A docker compose containing the dependencies from our other projects is also included to help aid development. Signed-off-by: Hassan Abouelela --- .dockerignore | 9 ++++++++ dev/Dockerfile | 13 ++++++----- dev/docker-compose.yaml | 27 ---------------------- docker-compose.yaml | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 .dockerignore delete mode 100644 dev/docker-compose.yaml create mode 100644 docker-compose.yaml (limited to 'dev') diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..9fb3df72 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +* + +!botcore/ +!docs/ +!tests/ + +!pyproject.toml +!poetry.lock +!tox.ini diff --git a/dev/Dockerfile b/dev/Dockerfile index 738fc51a..e1d8eba3 100644 --- a/dev/Dockerfile +++ b/dev/Dockerfile @@ -4,18 +4,19 @@ FROM python:3.9-slim ENV PIP_NO_CACHE_DIR=false \ POETRY_VIRTUALENVS_CREATE=false -ENTRYPOINT ["/bin/bash"] -CMD ["./docker-entrypoint.sh"] - # Install poetry RUN pip install -U poetry -RUN mkdir bot -WORKDIR /bot +WORKDIR /app # Install project dependencies COPY pyproject.toml poetry.lock ./ -RUN poetry install --no-dev +RUN poetry install --no-root # Copy the source code in last to optimize rebuilding the image COPY . . +# Install again, this time with the root project +RUN poetry install + +ENTRYPOINT ["python"] +CMD ["-m", "bot"] diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml deleted file mode 100644 index e1dca5bb..00000000 --- a/dev/docker-compose.yaml +++ /dev/null @@ -1,27 +0,0 @@ -version: "3.9" - -x-logging: &logging - logging: - driver: "json-file" - options: - max-file: "5" - max-size: "10m" - -x-restart-policy: &restart_policy - restart: unless-stopped - -services: - botcore: - <<: *logging - <<: *restart_policy - build: - context: . - dockerfile: Dockerfile - container_name: botcore - - volumes: - - ./logs:/bot/logs - - .:/bot:ro - - env_file: - - .env diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..4b6468f1 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,61 @@ +# Modified version of python-discord/bot + +version: "3.8" + +x-restart-policy: &restart_policy + restart: unless-stopped + +services: + postgres: + << : *restart_policy + image: postgres:13-alpine + environment: + POSTGRES_DB: pysite + POSTGRES_PASSWORD: pysite + POSTGRES_USER: pysite + healthcheck: + test: ["CMD-SHELL", "pg_isready -U pysite"] + interval: 2s + timeout: 1s + retries: 5 + + redis: + << : *restart_policy + image: redis:5.0.9 + ports: + - "6379:6379" + + snekbox: + << : *restart_policy + image: ghcr.io/python-discord/snekbox:latest + init: true + ipc: none + ports: + - "8060:8060" + privileged: true + + web: + << : *restart_policy + image: ghcr.io/python-discord/site:latest + command: ["run", "--debug"] + ports: + - "8000:8000" + tty: true + environment: + DATABASE_URL: postgres://pysite:pysite@postgres:5432/pysite + METRICITY_DB_URL: postgres://pysite:pysite@postgres:5432/metricity + SECRET_KEY: suitable-for-development-only + STATIC_ROOT: /var/www/static + + bot: + << : *restart_policy + build: + context: . + dockerfile: dev/Dockerfile + volumes: + - .:/app:ro + tty: true + env_file: + - .env + environment: + BOT_API_KEY: badbot13m0n8f570f942013fc818f234916ca531 -- cgit v1.2.3 From 0e0b8933e4654bcfd80708c54a63c272bb5cbbd1 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sat, 23 Jul 2022 17:00:16 +0200 Subject: Document Sample Project Environment Variables Co-authored-by: Chris Lovering Signed-off-by: Hassan Abouelela --- dev/README.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'dev') diff --git a/dev/README.rst b/dev/README.rst index b1535962..afff6255 100644 --- a/dev/README.rst +++ b/dev/README.rst @@ -19,7 +19,7 @@ Option 1 1. Navigate to the project you want to install bot-core in, such as bot or sir-lancebot 2. Run ``pip install /path/to/botcore`` in the project's environment - - The path provided to install should be the root directory of this project on your maching. + - The path provided to install should be the root directory of this project on your machine. That is, the folder which contains the ``pyproject.toml`` file. - Make sure to install in the correct environment. Most Python Discord projects use poetry, so you can run ``poetry run pip install /path/to/botcore``. @@ -30,14 +30,22 @@ Option 1 Option 2 -------- -1. Copy the :repo-file:`bot template folder ` to the root of your project. +1. Copy the :repo-file:`bot template folder ` to the root of the bot-core project. This copy is going to be git-ignored, so you're free to modify it however you like. 2. Run the project - Locally: You can run it on your system using ``python -m bot`` - Docker: You can run on docker using ``docker compose up -d bot``. -3. You can now test your changes. You do not need to do anything to reinstall the +3. Configure the environment variables used by the program. + You can set them in an ``.env`` file in the project root directory. The variables are: + + - ``TOKEN`` (required): Discord bot token, with all intents enabled + - ``GUILD_ID`` (required): The guild the bot should monitor + - ``PREFIX``: The prefix to use for invoking bot commands. Defaults to mentions and ``!`` + - ``ALLOWED_ROLES``: A comma seperated list of role IDs which the bot is allowed to mention + +4. You can now test your changes. You do not need to do anything to reinstall the library if you modify your code. .. tip:: -- cgit v1.2.3 From a5e97cab08b31918a3d3865d9697b442c913261a Mon Sep 17 00:00:00 2001 From: ChrisJL Date: Mon, 25 Jul 2022 22:00:42 +0100 Subject: Bump Python To 3.10 (#108) --- .github/workflows/docs.yaml | 4 +- .github/workflows/lint-test.yaml | 2 +- dev/Dockerfile | 2 +- docs/changelog.rst | 1 + poetry.lock | 138 ++++++++++----------------------------- pyproject.toml | 4 +- 6 files changed, 42 insertions(+), 109 deletions(-) (limited to 'dev') diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 5254d524..fad707c0 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -25,7 +25,7 @@ jobs: uses: HassanAbouelela/actions/setup-python@setup-python_v1.1.0 with: dev: true - python_version: 3.9 + python_version: "3.10" install_args: "--extras async-rediscache" # Undeclared dependency for `releases`... whoops @@ -54,7 +54,7 @@ jobs: uses: HassanAbouelela/actions/setup-python@setup-python_v1.1.0 with: dev: true - python_version: 3.9 + python_version: "3.10" install_args: "--extras async-rediscache" # Undeclared dependency for `releases`... whoops diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index a51623cb..5b8bd5a4 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -21,7 +21,7 @@ jobs: with: # Set dev=true to run pre-commit which is a dev dependency dev: true - python_version: 3.9 + python_version: "3.10" install_args: "--extras async-rediscache" # We will not run `flake8` here, as we will use a separate flake8 diff --git a/dev/Dockerfile b/dev/Dockerfile index e1d8eba3..eaab04ba 100644 --- a/dev/Dockerfile +++ b/dev/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9-slim +FROM python:3.10-slim # Set pip to have no saved cache ENV PIP_NO_CACHE_DIR=false \ diff --git a/docs/changelog.rst b/docs/changelog.rst index b5d049d9..be4f7ee7 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,7 @@ Changelog ========= +- :support:`108` Bump Python version to 3.10.* - :bug:`107` Declare aiodns as a project dependency. - :support:`107` Add a sample project with boilerplate and documentation explaining how to develop for bot-core. diff --git a/poetry.lock b/poetry.lock index 20971c95..b7e8dc89 100644 --- a/poetry.lock +++ b/poetry.lock @@ -88,7 +88,7 @@ python-versions = ">=3.6" [[package]] name = "atomicwrites" -version = "1.4.0" +version = "1.4.1" description = "Atomic file writes." category = "dev" optional = false @@ -161,14 +161,6 @@ category = "dev" optional = false python-versions = ">=3.6.1" -[[package]] -name = "chardet" -version = "3.0.4" -description = "Universal encoding detector for Python 2 and 3" -category = "dev" -optional = false -python-versions = "*" - [[package]] name = "charset-normalizer" version = "2.1.0" @@ -236,10 +228,9 @@ voice = ["PyNaCl (>=1.3.0,<1.6)"] [package.source] type = "url" url = "https://github.com/Rapptz/discord.py/archive/0eb3d26343969a25ffc43ba72eca42538d2e7e7a.zip" - [[package]] name = "distlib" -version = "0.3.4" +version = "0.3.5" description = "Distribution utilities" category = "dev" optional = false @@ -436,7 +427,7 @@ gitdb = ">=4.0.1,<5" [[package]] name = "identify" -version = "2.5.1" +version = "2.5.2" description = "File identification library for Python" category = "dev" optional = false @@ -447,36 +438,20 @@ license = ["ukkonen"] [[package]] name = "idna" -version = "2.7" +version = "3.3" description = "Internationalized Domain Names in Applications (IDNA)" category = "main" optional = false -python-versions = "*" +python-versions = ">=3.5" [[package]] name = "imagesize" -version = "1.3.0" +version = "1.4.1" description = "Getting image size from png/jpeg/jpeg2000/gif file" category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -[[package]] -name = "importlib-metadata" -version = "4.12.0" -description = "Read metadata from Python packages" -category = "dev" -optional = false -python-versions = ">=3.7" - -[package.dependencies] -zipp = ">=0.5" - -[package.extras] -docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] -perf = ["ipython"] -testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.3)", "packaging", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)", "importlib-resources (>=1.3)"] - [[package]] name = "iniconfig" version = "1.1.1" @@ -823,21 +798,21 @@ sphinx = ">=1.3" [[package]] name = "requests" -version = "2.25.1" +version = "2.28.1" description = "Python HTTP for Humans." category = "dev" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.7, <4" [package.dependencies] certifi = ">=2017.4.17" -chardet = ">=3.0.2,<5" -idna = ">=2.5,<3" +charset-normalizer = ">=2,<3" +idna = ">=2.5,<4" urllib3 = ">=1.21.1,<1.27" [package.extras] -security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"] -socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] +socks = ["PySocks (>=1.5.6,!=1.5.7)"] +use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "semantic-version" @@ -901,7 +876,6 @@ babel = ">=1.3" colorama = {version = ">=0.3.5", markers = "sys_platform == \"win32\""} docutils = ">=0.14,<0.20" imagesize = "*" -importlib-metadata = {version = ">=4.4", markers = "python_version < \"3.10\""} Jinja2 = ">=2.3" packaging = "*" Pygments = ">=2.0" @@ -1070,7 +1044,7 @@ python-versions = ">=3.7" [[package]] name = "typing-extensions" -version = "4.2.0" +version = "4.3.0" description = "Backported and Experimental Type Hints for Python 3.7+" category = "main" optional = true @@ -1078,20 +1052,20 @@ python-versions = ">=3.7" [[package]] name = "urllib3" -version = "1.26.5" +version = "1.26.11" description = "HTTP library with thread-safe connection pooling, file post, and more." category = "dev" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4" [package.extras] -brotli = ["brotlipy (>=0.6.0)"] +brotli = ["brotlicffi (>=0.8.0)", "brotli (>=1.0.9)", "brotlipy (>=0.6.0)"] secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] name = "virtualenv" -version = "20.15.0" +version = "20.15.1" description = "Virtual Python Environment builder" category = "dev" optional = false @@ -1127,25 +1101,13 @@ python-versions = ">=3.6" idna = ">=2.0" multidict = ">=4.0" -[[package]] -name = "zipp" -version = "3.8.0" -description = "Backport of pathlib-compatible object wrapper for zip files" -category = "dev" -optional = false -python-versions = ">=3.7" - -[package.extras] -docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] -testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] - [extras] async-rediscache = ["async-rediscache"] [metadata] lock-version = "1.1" -python-versions = "3.9.*" -content-hash = "1863dfa1e1cc4608ae199608235e38b9d05d40b184f747b0f6471963de10101b" +python-versions = "3.10.*" +content-hash = "9aa6436d1097ec8507b51398b280f254ec38402f4948462349af00eeca207e59" [metadata.files] aiodns = [ @@ -1246,10 +1208,7 @@ async-timeout = [ {file = "async-timeout-4.0.2.tar.gz", hash = "sha256:2163e1640ddb52b7a8c80d0a67a08587e5d245cc9c553a74a847056bc2976b15"}, {file = "async_timeout-4.0.2-py3-none-any.whl", hash = "sha256:8ca1e4fcf50d07413d66d1a5e416e42cfdf5851c981d679a09851a6853383b3c"}, ] -atomicwrites = [ - {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, - {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, -] +atomicwrites = [] attrs = [ {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, @@ -1336,10 +1295,6 @@ cfgv = [ {file = "cfgv-3.3.1-py2.py3-none-any.whl", hash = "sha256:c6a0883f3917a037485059700b9e75da2464e6c27051014ad85ba6aaa5884426"}, {file = "cfgv-3.3.1.tar.gz", hash = "sha256:f5a830efb9ce7a445376bb66ec94c638a9787422f96264c98edc6bdeed8ab736"}, ] -chardet = [ - {file = "chardet-3.0.4-py2.py3-none-any.whl", hash = "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"}, - {file = "chardet-3.0.4.tar.gz", hash = "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"}, -] charset-normalizer = [ {file = "charset-normalizer-2.1.0.tar.gz", hash = "sha256:575e708016ff3a5e3681541cb9d79312c416835686d054a23accb873b254f413"}, {file = "charset_normalizer-2.1.0-py3-none-any.whl", hash = "sha256:5189b6f22b01957427f35b6a08d9a0bc45b46d3788ef5a92e978433c7a35f8a5"}, @@ -1396,10 +1351,7 @@ deprecated = [ {file = "Deprecated-1.2.13.tar.gz", hash = "sha256:43ac5335da90c31c24ba028af536a91d41d53f9e6901ddb021bcc572ce44e38d"}, ] "discord.py" = [] -distlib = [ - {file = "distlib-0.3.4-py2.py3-none-any.whl", hash = "sha256:6564fe0a8f51e734df6333d08b8b94d4ea8ee6b99b5ed50613f731fd4089f34b"}, - {file = "distlib-0.3.4.zip", hash = "sha256:e4b58818180336dc9c529bfb9a0b58728ffc09ad92027a3f30b7cd91e3458579"}, -] +distlib = [] docutils = [ {file = "docutils-0.18.1-py2.py3-none-any.whl", hash = "sha256:23010f129180089fbcd3bc08cfefccb3b890b0050e1ca00c867036e9d161b98c"}, {file = "docutils-0.18.1.tar.gz", hash = "sha256:679987caf361a7539d76e584cbeddc311e3aee937877c87346f31debc63e9d06"}, @@ -1408,10 +1360,7 @@ execnet = [ {file = "execnet-1.9.0-py2.py3-none-any.whl", hash = "sha256:a295f7cc774947aac58dde7fdc85f4aa00c42adf5d8f5468fc630c1acf30a142"}, {file = "execnet-1.9.0.tar.gz", hash = "sha256:8f694f3ba9cc92cab508b152dcfe322153975c29bda272e2fd7f3f00f36e47c5"}, ] -fakeredis = [ - {file = "fakeredis-1.8.2-py3-none-any.whl", hash = "sha256:5e85a480c41b2a46edd6ba67f44197acc6603c59427fdf4456ebb89e56e77fa5"}, - {file = "fakeredis-1.8.2.tar.gz", hash = "sha256:3564fbaed1eaec890eff96ee9088c1d30ee5fba2b81c97c72143f809d9c60c74"}, -] +fakeredis = [] filelock = [ {file = "filelock-3.7.1-py3-none-any.whl", hash = "sha256:37def7b658813cda163b56fc564cdc75e86d338246458c4c28ae84cabefa2404"}, {file = "filelock-3.7.1.tar.gz", hash = "sha256:3a0fd85166ad9dbab54c9aec96737b744106dc5f15c0b09a6744a445299fcf04"}, @@ -1520,22 +1469,12 @@ gitpython = [ {file = "GitPython-3.1.27-py3-none-any.whl", hash = "sha256:5b68b000463593e05ff2b261acff0ff0972df8ab1b70d3cdbd41b546c8b8fc3d"}, {file = "GitPython-3.1.27.tar.gz", hash = "sha256:1c885ce809e8ba2d88a29befeb385fcea06338d3640712b59ca623c220bb5704"}, ] -identify = [ - {file = "identify-2.5.1-py2.py3-none-any.whl", hash = "sha256:0dca2ea3e4381c435ef9c33ba100a78a9b40c0bab11189c7cf121f75815efeaa"}, - {file = "identify-2.5.1.tar.gz", hash = "sha256:3d11b16f3fe19f52039fb7e39c9c884b21cb1b586988114fbe42671f03de3e82"}, -] +identify = [] idna = [ - {file = "idna-2.7-py2.py3-none-any.whl", hash = "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e"}, - {file = "idna-2.7.tar.gz", hash = "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16"}, -] -imagesize = [ - {file = "imagesize-1.3.0-py2.py3-none-any.whl", hash = "sha256:1db2f82529e53c3e929e8926a1fa9235aa82d0bd0c580359c67ec31b2fddaa8c"}, - {file = "imagesize-1.3.0.tar.gz", hash = "sha256:cd1750d452385ca327479d45b64d9c7729ecf0b3969a58148298c77092261f9d"}, -] -importlib-metadata = [ - {file = "importlib_metadata-4.12.0-py3-none-any.whl", hash = "sha256:7401a975809ea1fdc658c3aa4f78cc2195a0e019c5cbc4c06122884e9ae80c23"}, - {file = "importlib_metadata-4.12.0.tar.gz", hash = "sha256:637245b8bab2b6502fcbc752cc4b7a6f6243bb02b31c5c26156ad103d3d45670"}, + {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"}, + {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"}, ] +imagesize = [] iniconfig = [ {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, @@ -1910,8 +1849,8 @@ releases = [ {file = "releases-1.6.3.tar.gz", hash = "sha256:555ae4c97a671a420281c1c782e9236be25157b449fdf20b4c4b293fe93db2f1"}, ] requests = [ - {file = "requests-2.25.1-py2.py3-none-any.whl", hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"}, - {file = "requests-2.25.1.tar.gz", hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"}, + {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, + {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, ] semantic-version = [ {file = "semantic_version-2.6.0-py3-none-any.whl", hash = "sha256:2d06ab7372034bcb8b54f2205370f4aa0643c133b7e6dbd129c5200b83ab394b"}, @@ -1938,8 +1877,8 @@ soupsieve = [ {file = "soupsieve-2.3.2.post1.tar.gz", hash = "sha256:fc53893b3da2c33de295667a0e19f078c14bf86544af307354de5fcf12a3f30d"}, ] sphinx = [ - {file = "Sphinx-5.1.0-py3-none-any.whl", hash = "sha256:50661b4dbe6a4a1ac15692a7b6db48671da6bae1d4d507e814f1b8525b6bba86"}, - {file = "Sphinx-5.1.0.tar.gz", hash = "sha256:7893d10d9d852c16673f9b1b7e9eda1606b420b7810270294d6e4b44c0accacc"}, + {file = "Sphinx-5.0.2-py3-none-any.whl", hash = "sha256:d3e57663eed1d7c5c50895d191fdeda0b54ded6f44d5621b50709466c338d1e8"}, + {file = "Sphinx-5.0.2.tar.gz", hash = "sha256:b18e978ea7565720f26019c702cd85c84376e948370f1cd43d60265010e1c7b0"}, ] sphinx-autodoc-typehints = [ {file = "sphinx_autodoc_typehints-1.18.3-py3-none-any.whl", hash = "sha256:20294de2a818bda04953c5cb302ec5af46138c81980ad9efa6d8fc1fc4242518"}, @@ -1994,16 +1933,13 @@ tomli = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] typing-extensions = [ - {file = "typing_extensions-4.2.0-py3-none-any.whl", hash = "sha256:6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708"}, - {file = "typing_extensions-4.2.0.tar.gz", hash = "sha256:f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376"}, -] -urllib3 = [ - {file = "urllib3-1.26.5-py2.py3-none-any.whl", hash = "sha256:753a0374df26658f99d826cfe40394a686d05985786d946fbe4165b5148f5a7c"}, - {file = "urllib3-1.26.5.tar.gz", hash = "sha256:a7acd0977125325f516bda9735fa7142b909a8d01e8b2e4c8108d0984e6e0098"}, + {file = "typing_extensions-4.3.0-py3-none-any.whl", hash = "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02"}, + {file = "typing_extensions-4.3.0.tar.gz", hash = "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6"}, ] +urllib3 = [] virtualenv = [ - {file = "virtualenv-20.15.0-py2.py3-none-any.whl", hash = "sha256:804cce4de5b8a322f099897e308eecc8f6e2951f1a8e7e2b3598dff865f01336"}, - {file = "virtualenv-20.15.0.tar.gz", hash = "sha256:4c44b1d77ca81f8368e2d7414f9b20c428ad16b343ac6d226206c5b84e2b4fcc"}, + {file = "virtualenv-20.15.1-py2.py3-none-any.whl", hash = "sha256:b30aefac647e86af6d82bfc944c556f8f1a9c90427b2fb4e3bfbf338cb82becf"}, + {file = "virtualenv-20.15.1.tar.gz", hash = "sha256:288171134a2ff3bfb1a2f54f119e77cd1b81c29fc1265a2356f3e8d14c7d58c4"}, ] wrapt = [ {file = "wrapt-1.14.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:1b376b3f4896e7930f1f772ac4b064ac12598d1c38d04907e696cc4d794b43d3"}, @@ -2145,7 +2081,3 @@ yarl = [ {file = "yarl-1.7.2-cp39-cp39-win_amd64.whl", hash = "sha256:797c2c412b04403d2da075fb93c123df35239cd7b4cc4e0cd9e5839b73f52c58"}, {file = "yarl-1.7.2.tar.gz", hash = "sha256:45399b46d60c253327a460e99856752009fcee5f5d3c80b2f7c0cae1c38d56dd"}, ] -zipp = [ - {file = "zipp-3.8.0-py3-none-any.whl", hash = "sha256:c4f6e5bbf48e74f7a38e7cc5b0480ff42b0ae5178957d564d18932525d5cf099"}, - {file = "zipp-3.8.0.tar.gz", hash = "sha256:56bf8aadb83c24db6c4b577e13de374ccfb67da2078beba1d037c17980bf43ad"}, -] diff --git a/pyproject.toml b/pyproject.toml index 557c6800..bc1ec458 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bot-core" -version = "7.5.0" +version = "8.0.0-beta.2" description = "Bot-Core provides the core functionality and utilities for the bots of the Python Discord community." authors = ["Python Discord "] license = "MIT" @@ -15,7 +15,7 @@ packages = [ exclude = ["tests", "tests.*"] [tool.poetry.dependencies] -python = "3.9.*" +python = "3.10.*" "discord.py" = {url = "https://github.com/Rapptz/discord.py/archive/0eb3d26343969a25ffc43ba72eca42538d2e7e7a.zip"} async-rediscache = { version = "0.2.0", extras = ["fakeredis"], optional = true } statsd = "3.3.0" -- cgit v1.2.3 From 0f12f00c8081462466e6d2d5c8a85945350a76c3 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 10 Sep 2022 20:44:17 +0100 Subject: Update poetry to use 1.2.0 This change requires the use of venvs, rather than pip user installs --- .github/workflows/docs.yaml | 5 ++--- .github/workflows/lint-test.yaml | 3 +-- dev/Dockerfile | 22 +++++++++++++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) (limited to 'dev') diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index fad707c0..001a498d 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -11,7 +11,6 @@ concurrency: group: docs-deployment-${{ github.ref }} cancel-in-progress: true - jobs: latest-build: # We only need to verify that the docs build with no warnings here @@ -22,7 +21,7 @@ jobs: - uses: actions/checkout@v2 - name: Install Python Dependencies - uses: HassanAbouelela/actions/setup-python@setup-python_v1.1.0 + uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1 with: dev: true python_version: "3.10" @@ -51,7 +50,7 @@ jobs: fetch-depth: 0 # We need to check out the entire repository to find all tags - name: Install Python Dependencies - uses: HassanAbouelela/actions/setup-python@setup-python_v1.1.0 + uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1 with: dev: true python_version: "3.10" diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index 5b8bd5a4..3a9c80a2 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -14,10 +14,9 @@ jobs: lint: name: Run Linting & Test Suites runs-on: ubuntu-latest - steps: - name: Install Python Dependencies - uses: HassanAbouelela/actions/setup-python@setup-python_v1.1.0 + uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.1 with: # Set dev=true to run pre-commit which is a dev dependency dev: true diff --git a/dev/Dockerfile b/dev/Dockerfile index eaab04ba..ccc653be 100644 --- a/dev/Dockerfile +++ b/dev/Dockerfile @@ -1,20 +1,32 @@ -FROM python:3.10-slim +FROM --platform=linux/amd64 python:3.10-slim # Set pip to have no saved cache -ENV PIP_NO_CACHE_DIR=false \ - POETRY_VIRTUALENVS_CREATE=false +ENV PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + POETRY_VERSION=1.2.0 \ + POETRY_HOME="/opt/poetry" \ + POETRY_VIRTUALENVS_IN_PROJECT=true \ + POETRY_NO_INTERACTION=1 \ + APP_DIR="/app" + +ENV PATH="$POETRY_HOME/bin:/$APP_DIR/.venv/bin:$PATH" # Install poetry -RUN pip install -U poetry +RUN apt-get update \ + && apt-get -y upgrade \ + && apt-get install --no-install-recommends -y curl \ + && apt-get clean && rm -rf /var/lib/apt/lists/* -WORKDIR /app +RUN curl -sSL https://install.python-poetry.org | python # Install project dependencies +WORKDIR $APP_DIR COPY pyproject.toml poetry.lock ./ RUN poetry install --no-root # Copy the source code in last to optimize rebuilding the image COPY . . + # Install again, this time with the root project RUN poetry install -- cgit v1.2.3 From ce894c0706d64756cdcd046f5729958425a803fc Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 10 Sep 2022 20:45:54 +0100 Subject: Use BOT_TOKEN in example project This is so that we use the same env var as metricity, remove the need for duplicate env vars. --- dev/README.rst | 2 +- dev/bot/__main__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'dev') diff --git a/dev/README.rst b/dev/README.rst index afff6255..ae4f3adc 100644 --- a/dev/README.rst +++ b/dev/README.rst @@ -40,7 +40,7 @@ Option 2 3. Configure the environment variables used by the program. You can set them in an ``.env`` file in the project root directory. The variables are: - - ``TOKEN`` (required): Discord bot token, with all intents enabled + - ``BOT_TOKEN`` (required): Discord bot token, with all intents enabled - ``GUILD_ID`` (required): The guild the bot should monitor - ``PREFIX``: The prefix to use for invoking bot commands. Defaults to mentions and ``!`` - ``ALLOWED_ROLES``: A comma seperated list of role IDs which the bot is allowed to mention diff --git a/dev/bot/__main__.py b/dev/bot/__main__.py index 00ebdefc..42d212c2 100644 --- a/dev/bot/__main__.py +++ b/dev/bot/__main__.py @@ -29,6 +29,6 @@ async def main() -> None: """Run the bot.""" bot.http_session = aiohttp.ClientSession() async with bot: - await bot.start(os.getenv("TOKEN")) + await bot.start(os.getenv("BOT_TOKEN")) asyncio.run(main()) -- cgit v1.2.3 From 6436908bb91205b8818909aae091ad704970de85 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sun, 18 Sep 2022 00:23:37 +0400 Subject: Use Poetry Base In Docker Image Use chrislovering/python-poetry-base as the base image for the Dockerfile. It manages everthing required to install and configure poetry. Signed-off-by: Hassan Abouelela --- dev/Dockerfile | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'dev') diff --git a/dev/Dockerfile b/dev/Dockerfile index ccc653be..0b35724a 100644 --- a/dev/Dockerfile +++ b/dev/Dockerfile @@ -1,26 +1,8 @@ -FROM --platform=linux/amd64 python:3.10-slim +FROM --platform=linux/amd64 ghcr.io/chrislovering/python-poetry-base:3.10-slim -# Set pip to have no saved cache -ENV PIP_NO_CACHE_DIR=1 \ - PIP_DISABLE_PIP_VERSION_CHECK=on \ - POETRY_VERSION=1.2.0 \ - POETRY_HOME="/opt/poetry" \ - POETRY_VIRTUALENVS_IN_PROJECT=true \ - POETRY_NO_INTERACTION=1 \ - APP_DIR="/app" - -ENV PATH="$POETRY_HOME/bin:/$APP_DIR/.venv/bin:$PATH" - -# Install poetry -RUN apt-get update \ - && apt-get -y upgrade \ - && apt-get install --no-install-recommends -y curl \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - -RUN curl -sSL https://install.python-poetry.org | python # Install project dependencies -WORKDIR $APP_DIR +WORKDIR /app COPY pyproject.toml poetry.lock ./ RUN poetry install --no-root -- cgit v1.2.3