Skip to content

Commit 43ee782

Browse files
authored
chore: Start migration to uv & ruff & hatch (#4)
* Start migration to uv * Setup ruff and hatch * Change pre-commit to use ruff * Format with ruff * Fix mistake * Add dev deps * Change workflows to use uv and ruff * ➕ Add colorlog and remove requirements folder and fix build * 💚 Fix sphinx build ? * 🐛 Add __version.py for version management and update import in __init__.py * ✏️ Update lib-checks.yml to run ruff on ubuntu-latest * 🐛 Update lib-checks.yml to run mypy with uv * 🔥 Delete MANIFEST.in * ✨ Enhance lib-checks.yml to include ruff formatter check * ♻️ Refactor pyproject.toml and uv.lock to use optional-dependencies for voice and speed
1 parent 32ef1c8 commit 43ee782

File tree

151 files changed

+4017
-4728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+4017
-4728
lines changed

.github/workflows/docs-checks.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ jobs:
4141
uses: actions/setup-python@v5
4242
with:
4343
python-version: "3.13"
44-
cache: "pip"
45-
cache-dependency-path: "requirements/docs.txt"
46-
check-latest: true
47-
- name: Install dependencies
48-
run: |
49-
python -m pip install -U pip
50-
pip install ".[docs]"
44+
- name: "Install uv"
45+
uses: astral-sh/setup-uv@v6
46+
with:
47+
enable-cache: true
48+
- name: Sync dependencies
49+
run: uv sync --no-python-downloads --group dev --group docs
5150
- name: "Check Links"
51+
env:
52+
SPHINXBUILD: ${{ github.workspace }}/.venv/bin/sphinx-build
5253
if: ${{ github.event_name == 'schedule' || inputs.with_linkcheck }}
5354
run: |
5455
cd docs
5556
make linkcheck
5657
- name: "Compile to html"
58+
env:
59+
SPHINXBUILD: ${{ github.workspace }}/.venv/bin/sphinx-build
5760
run: |
5861
cd docs
5962
make -e SPHINXOPTS="-D language='en'" html

.github/workflows/lib-checks.yml

Lines changed: 24 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@ jobs:
3737
uses: actions/setup-python@v5
3838
with:
3939
python-version: "3.13"
40-
cache: "pip"
41-
cache-dependency-path: "requirements/dev.txt"
42-
- name: "Install dependencies"
43-
run: |
44-
python -m pip install --upgrade pip
45-
pip install -r requirements/dev.txt
40+
- name: "Install uv"
41+
uses: astral-sh/setup-uv@v6
42+
with:
43+
enable-cache: true
44+
- name: Sync dependencies
45+
run: uv sync --no-python-downloads --group dev
4646
- name: "Run codespell"
4747
run:
48-
codespell --ignore-words-list="groupt,nd,ot,ro,falsy,BU" \
48+
uv run codespell --ignore-words-list="groupt,nd,ot,ro,falsy,BU" \
4949
--exclude-file=".github/workflows/codespell.yml"
50-
bandit:
51-
if: ${{ github.event_name != 'schedule' }}
50+
ruff:
5251
runs-on: ubuntu-latest
5352
steps:
5453
- name: "Checkout Repository"
@@ -57,38 +56,16 @@ jobs:
5756
uses: actions/setup-python@v5
5857
with:
5958
python-version: "3.13"
60-
cache: "pip"
61-
cache-dependency-path: "requirements/dev.txt"
62-
- name: "Install dependencies"
63-
run: |
64-
python -m pip install --upgrade pip
65-
pip install -r requirements/dev.txt
66-
- name: "Run bandit"
67-
run: bandit --recursive --skip B101,B104,B105,B110,B307,B311,B404,B603,B607 .
68-
pylint:
69-
if: ${{ github.event_name != 'schedule' }}
70-
runs-on: ubuntu-latest
71-
steps:
72-
- name: "Checkout Repository"
73-
uses: actions/checkout@v4
74-
- name: "Setup Python"
75-
uses: actions/setup-python@v5
59+
- name: "Install uv"
60+
uses: astral-sh/setup-uv@v6
7661
with:
77-
python-version: "3.13"
78-
cache: "pip"
79-
cache-dependency-path: "requirements/dev.txt"
80-
- name: "Install dependencies"
81-
run: |
82-
python -m pip install --upgrade pip
83-
pip install -r requirements/dev.txt
84-
- name: "Setup cache"
85-
id: cache-pylint
86-
uses: actions/cache@v4
87-
with:
88-
path: .pylint.d
89-
key: pylint
90-
- name: "Run pylint"
91-
run: pylint discord/ --exit-zero
62+
enable-cache: true
63+
- name: Sync dependencies
64+
run: uv sync --no-python-downloads --group dev
65+
- name: "Run ruff linter check"
66+
run: uv run ruff check discord/
67+
- name: "Run ruff formatter check"
68+
run: uv run ruff format --check discord/
9269
mypy:
9370
if: ${{ github.event_name != 'schedule' }}
9471
runs-on: ubuntu-latest
@@ -99,12 +76,12 @@ jobs:
9976
uses: actions/setup-python@v5
10077
with:
10178
python-version: "3.13"
102-
cache: "pip"
103-
cache-dependency-path: "requirements/dev.txt"
104-
- name: "Install dependencies"
105-
run: |
106-
python -m pip install --upgrade pip
107-
pip install -r requirements/dev.txt
79+
- name: "Install uv"
80+
uses: astral-sh/setup-uv@v6
81+
with:
82+
enable-cache: true
83+
- name: Sync dependencies
84+
run: uv sync --no-python-downloads --group dev
10885
- name: "Setup cache"
10986
id: cache-mypy
11087
uses: actions/cache@v4
@@ -115,44 +92,4 @@ jobs:
11592
id: cache-dir-mypy
11693
run: mkdir -p -v .mypy_cache
11794
- name: "Run mypy"
118-
run: mypy --non-interactive discord/
119-
pytest:
120-
strategy:
121-
matrix:
122-
os: [ubuntu-latest, macos-latest, windows-latest]
123-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
124-
exclude:
125-
- { python-version: "3.9", os: "macos-latest" }
126-
include:
127-
- { python-version: "3.9", os: "macos-13" }
128-
runs-on: ${{ matrix.os }}
129-
env:
130-
OS: ${{ matrix.os }}
131-
PYTHON: ${{ matrix.python-version }}
132-
steps:
133-
- name: "Checkout Repository"
134-
uses: actions/checkout@v4
135-
- name: "Setup Python"
136-
uses: actions/setup-python@v5
137-
with:
138-
python-version: ${{ matrix.python-version }}
139-
cache: "pip"
140-
cache-dependency-path: "requirements/dev.txt"
141-
check-latest: true
142-
- name: "Install dependencies"
143-
run: |
144-
python -m pip install --upgrade pip
145-
pip install flake8
146-
pip install -r requirements/dev.txt
147-
- name: "Setup cache"
148-
id: cache-pytest
149-
uses: actions/cache@v4
150-
with:
151-
path: .pytest_cache
152-
key: ${{ matrix.os }}-${{ matrix.python-version }}-pytest
153-
- name: "Lint with flake8"
154-
run: |
155-
# stop the build if there are Python syntax errors or undefined names
156-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
157-
# exit-zero treats all errors as warnings.
158-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
95+
run: uv run mypy --non-interactive discord/

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ docs/_build
177177
__pycache__
178178
.vs/*
179179
.vscode/*
180-
test.py
181180
node_modules/*
182181

183182
# changelog is autogenerated from CHANGELOG.md
@@ -192,3 +191,5 @@ docs/build/linkcheck
192191
!docs/locales/*
193192
/build/
194193
/vscode/
194+
195+
/discord/_version.py

.pre-commit-config.yaml

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,12 @@ repos:
1010
exclude: \.(po|pot|yml|yaml)$
1111
- id: end-of-file-fixer
1212
exclude: \.(po|pot|yml|yaml)$
13-
- repo: https://github.com/PyCQA/autoflake
14-
rev: v2.3.1
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.11.9
1515
hooks:
16-
- id: autoflake
17-
# args:
18-
# - --in-place
19-
# - --remove-all-unused-imports
20-
# - --expand-star-imports
21-
# - --remove-duplicate-keys
22-
# - --remove-unused-variables
23-
- repo: https://github.com/asottile/pyupgrade
24-
rev: v3.19.1
25-
hooks:
26-
- id: pyupgrade
27-
exclude: \.(po|pot|yml|yaml)$
28-
- repo: https://github.com/PyCQA/isort
29-
rev: 6.0.1
30-
hooks:
31-
- id: isort
32-
exclude: \.(po|pot|yml|yaml)$
33-
- repo: https://github.com/psf/black
34-
rev: 25.1.0
35-
hooks:
36-
- id: black
37-
args: [--safe, --quiet]
38-
exclude: \.(po|pot|yml|yaml)$
39-
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker
40-
rev: v1.1.3
41-
hooks:
42-
- id: black-disable-checker
43-
# - repo: https://github.com/PyCQA/flake8
44-
# rev: 4.0.1
45-
# hooks:
46-
# - id: flake8
47-
# additional_dependencies: [flake8-typing-imports==1.12.0]
48-
# - repo: local
49-
# hooks:
50-
# - id: pylint
51-
# name: pylint
52-
# entry: pylint
53-
# language: system
54-
# types: [python]
55-
# args: ["-rn", "-sn", "--rcfile=.pylintrc", "--fail-on=I"]
56-
# # We define an additional manual step to allow running pylint with a spelling
57-
# # checker in CI.
58-
# - id: pylint
59-
# alias: pylint-with-spelling
60-
# name: pylint
61-
# entry: pylint
62-
# language: system
63-
# types: [python]
64-
# args: ["-rn", "-sn", "--rcfile=.pylintrc", "--fail-on=I", "--spelling-dict=en"]
65-
# stages: [manual]
66-
# - id: mypy
67-
# name: mypy
68-
# entry: mypy
69-
# language: system
70-
# types: [python]
71-
# args: ["--non-interactive"]
16+
- id: ruff
17+
args: [ --fix ]
18+
- id: ruff-format
7219
# - repo: https://github.com/myint/rstcheck
7320
# rev: "v5.0.0"
7421
# hooks:
@@ -86,15 +33,3 @@ repos:
8633
- id: prettier
8734
args: [--prose-wrap=always, --print-width=88]
8835
exclude: \.(po|pot|yml|yaml)$
89-
- repo: https://github.com/DanielNoord/pydocstringformatter
90-
rev: v0.7.3
91-
hooks:
92-
- id: pydocstringformatter
93-
exclude: \.(po|pot|yml|yaml)$
94-
args:
95-
[
96-
--style=numpydoc,
97-
--no-numpydoc-name-type-spacing,
98-
--no-final-period,
99-
--no-capitalize-first-letter,
100-
]

MANIFEST.in

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

discord/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# We need __version__ to be imported first
2121
# isort: off
22-
from ._version import *
22+
from .__version import *
2323

2424
# isort: on
2525

discord/__main__.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,10 @@
3636

3737

3838
def show_version() -> None:
39-
entries = [
40-
"- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(
41-
sys.version_info
42-
)
43-
]
39+
entries = ["- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(sys.version_info)]
4440

4541
version_info = discord.version_info
46-
entries.append(
47-
"- py-cord v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(version_info)
48-
)
42+
entries.append("- py-cord v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(version_info))
4943
if version_info.releaselevel != "final":
5044
version = importlib.metadata.version("py-cord")
5145
if version:
@@ -299,9 +293,7 @@ def newcog(parser, args) -> None:
299293

300294

301295
def add_newbot_args(subparser: argparse._SubParsersAction) -> None:
302-
parser = subparser.add_parser(
303-
"newbot", help="creates a command bot project quickly"
304-
)
296+
parser = subparser.add_parser("newbot", help="creates a command bot project quickly")
305297
parser.set_defaults(func=newbot)
306298

307299
parser.add_argument("name", help="the bot project name")
@@ -311,12 +303,8 @@ def add_newbot_args(subparser: argparse._SubParsersAction) -> None:
311303
nargs="?",
312304
default=Path.cwd(),
313305
)
314-
parser.add_argument(
315-
"--prefix", help="the bot prefix (default: $)", default="$", metavar="<prefix>"
316-
)
317-
parser.add_argument(
318-
"--sharded", help="whether to use AutoShardedBot", action="store_true"
319-
)
306+
parser.add_argument("--prefix", help="the bot prefix (default: $)", default="$", metavar="<prefix>")
307+
parser.add_argument("--sharded", help="whether to use AutoShardedBot", action="store_true")
320308
parser.add_argument(
321309
"--no-git",
322310
help="do not create a .gitignore file",
@@ -347,18 +335,12 @@ def add_newcog_args(subparser: argparse._SubParsersAction) -> None:
347335
help="whether to hide all commands in the cog",
348336
action="store_true",
349337
)
350-
parser.add_argument(
351-
"--full", help="add all special methods as well", action="store_true"
352-
)
338+
parser.add_argument("--full", help="add all special methods as well", action="store_true")
353339

354340

355341
def parse_args() -> Tuple[argparse.ArgumentParser, argparse.Namespace]:
356-
parser = argparse.ArgumentParser(
357-
prog="discord", description="Tools for helping with Pycord"
358-
)
359-
parser.add_argument(
360-
"-v", "--version", action="store_true", help="shows the library version"
361-
)
342+
parser = argparse.ArgumentParser(prog="discord", description="Tools for helping with Pycord")
343+
parser.add_argument("-v", "--version", action="store_true", help="shows the library version")
362344
parser.set_defaults(func=core)
363345

364346
subparser = parser.add_subparsers(dest="subcommand", title="subcommands")

0 commit comments

Comments
 (0)