Skip to content

Commit

Permalink
Merge branch 'V3/develop' into mutes-add-timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Flame442 authored Mar 26, 2024
2 parents baa74d6 + 0b390fe commit f610166
Show file tree
Hide file tree
Showing 692 changed files with 67,728 additions and 58,998 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@

# include commit/tag information in `.git_archive_info.txt` when packing with git-archive
.git_archive_info.txt export-subst

# hide diffs for .po files by default
# https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
*.po linguist-generated
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- "!redbot/cogs/audio/**/locales/*"
# Docs
- docs/cog_guides/audio.rst
# Tests
- tests/cogs/audio/**/*
"Category: Cogs - Bank": [] # historical label for a removed cog
"Category: Cogs - Cleanup":
# Source
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/crowdin_upload_strings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
curl https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | sudo apt-key add -
echo "deb https://artifacts.crowdin.com/repo/deb/ /" | sudo tee -a /etc/apt/sources.list
sudo apt-get update -qq
sudo apt-get install -y crowdin
sudo apt-get install -y crowdin3
pip install redgettext==3.4.2
- name: Generate source files
run: |
Expand All @@ -28,5 +28,5 @@ jobs:
run: |
make upload_translations
env:
CROWDIN_API_KEY: ${{ secrets.crowdin_token}}
CROWDIN_PROJECT_ID: ${{ secrets.crowdin_identifier }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_IDENTIFIER }}
6 changes: 3 additions & 3 deletions .github/workflows/prepare_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
curl https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | sudo apt-key add -
echo "deb https://artifacts.crowdin.com/repo/deb/ /" | sudo tee -a /etc/apt/sources.list
sudo apt-get update -qq
sudo apt-get install -y crowdin
sudo apt-get install -y crowdin3
pip install redgettext==3.4.2
- name: Generate source files
Expand All @@ -36,8 +36,8 @@ jobs:
run: |
make download_translations
env:
CROWDIN_API_KEY: ${{ secrets.crowdin_token}}
CROWDIN_PROJECT_ID: ${{ secrets.crowdin_identifier }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_IDENTIFIER }}

- name: Create Pull Request
id: cpr_crowdin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish Release
on:
push:
tags:
- "*"
- "3.[0-9]+.[0-9]+"

jobs:
release_information:
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/run_pip_compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,27 @@ jobs:
- name: Set up Python 3.8.
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: |
3.11
3.10
3.9
3.8
- name: Install dependencies
- name: Install dependencies on Linux/macOS
if: matrix.os != 'windows-latest'
run: |
python3.11 -m pip install -U pip pip-tools
python3.10 -m pip install -U pip pip-tools
python3.9 -m pip install -U pip pip-tools
python3.8 -m pip install -U pip pip-tools
- name: Install dependencies on Windows
if: matrix.os == 'windows-latest'
run: |
python -m pip install -U pip
python -m pip install -U pip-tools
py -3.11 -m pip install -U pip pip-tools
py -3.10 -m pip install -U pip pip-tools
py -3.9 -m pip install -U pip pip-tools
py -3.8 -m pip install -U pip pip-tools
- name: Generate requirements files.
id: compile_requirements
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/scripts/compile_requirements.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
import os
import re
import shutil
import subprocess
import sys
from pathlib import Path


EXCLUDE_STEM_RE = re.compile(r".*-3\.(?!8-)(\d+)-extra-(doc|style)")
GITHUB_OUTPUT = os.environ["GITHUB_OUTPUT"]
REQUIREMENTS_FOLDER = Path(__file__).parents[3].absolute() / "requirements"
os.chdir(REQUIREMENTS_FOLDER)


def pip_compile(name: str) -> None:
def pip_compile(version: str, name: str) -> None:
stem = f"{sys.platform}-{version}-{name}"
if EXCLUDE_STEM_RE.fullmatch(stem):
return

executable = ("py", f"-{version}") if sys.platform == "win32" else (f"python{version}",)
subprocess.check_call(
(
sys.executable,
*executable,
"-m",
"piptools",
"compile",
"--upgrade",
"--resolver=backtracking",
"--verbose",
f"{name}.in",
"--output-file",
f"{sys.platform}-{name}.txt",
f"{stem}.txt",
)
)


pip_compile("base")
shutil.copyfile(f"{sys.platform}-base.txt", "base.txt")
for file in REQUIREMENTS_FOLDER.glob("extra-*.in"):
pip_compile(file.stem)
for minor in range(8, 11 + 1):
version = f"3.{minor}"
pip_compile(version, "base")
shutil.copyfile(f"{sys.platform}-{version}-base.txt", "base.txt")
for file in REQUIREMENTS_FOLDER.glob("extra-*.in"):
pip_compile(version, file.stem)

with open(GITHUB_OUTPUT, "a", encoding="utf-8") as fp:
fp.write(f"sys_platform={sys.platform}\n")
117 changes: 93 additions & 24 deletions .github/workflows/scripts/merge_requirements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import os
from pathlib import Path
from typing import List, TextIO
from typing import Dict, Iterable, List, TextIO, Tuple

from packaging.markers import Marker
from packaging.requirements import Requirement
Expand All @@ -15,6 +17,12 @@ def __init__(self, requirement_string: str) -> None:
self.req = Requirement(requirement_string)
self.comments = set()

def __hash__(self) -> int:
return hash(self.req)

def __eq__(self, other: RequirementData) -> bool:
return self.req == other.req

@property
def name(self) -> str:
return self.req.name
Expand Down Expand Up @@ -49,30 +57,47 @@ def get_requirements(fp: TextIO) -> List[RequirementData]:
return requirements


def iter_envs(envs: Iterable[str]) -> Iterable[Tuple[str, str]]:
for env_name in envs:
platform, python_version = env_name.split("-", maxsplit=1)
yield (platform, python_version)


names = ["base"]
names.extend(file.stem for file in REQUIREMENTS_FOLDER.glob("extra-*.in"))
base_requirements = []
base_requirements: List[RequirementData] = []

for name in names:
# {req_name: {sys_platform: RequirementData}
input_data = {}
# {req_data: {sys_platform: RequirementData}
input_data: Dict[RequirementData, Dict[str, RequirementData]] = {}
all_envs = set()
all_platforms = set()
all_python_versions = set()
for file in REQUIREMENTS_FOLDER.glob(f"*-{name}.txt"):
platform_name = file.stem.split("-", maxsplit=1)[0]
platform_name, python_version, _ = file.stem.split("-", maxsplit=2)
env_name = f"{platform_name}-{python_version}"
all_envs.add(env_name)
all_platforms.add(platform_name)
all_python_versions.add(python_version)
with file.open(encoding="utf-8") as fp:
requirements = get_requirements(fp)

for req in requirements:
platforms = input_data.setdefault(req.name, {})
platforms[platform_name] = req
envs = input_data.setdefault(req, {})
envs[env_name] = req

output = base_requirements if name == "base" else []
for req_name, platforms in input_data.items():
req = next(iter(platforms.values()))
for other_req in platforms.values():
if req.req != other_req.req:
raise RuntimeError(f"Incompatible requirements for {req_name}.")
for req, envs in input_data.items():
# {platform: [python_versions...]}
python_versions_per_platform: Dict[str, List[str]] = {}
# {python_version: [platforms...]}
platforms_per_python_version: Dict[str, List[str]] = {}
platforms = python_versions_per_platform.keys()
python_versions = platforms_per_python_version.keys()
for env_name, other_req in envs.items():
platform_name, python_version = env_name.split("-", maxsplit=1)
python_versions_per_platform.setdefault(platform_name, []).append(python_version)
platforms_per_python_version.setdefault(python_version, []).append(platform_name)

req.comments.update(other_req.comments)

Expand All @@ -84,30 +109,74 @@ def get_requirements(fp: TextIO) -> List[RequirementData]:
old_req_marker = req.marker
req.marker = base_req.marker = None
if base_req.req != req.req:
raise RuntimeError(f"Incompatible requirements for {req_name}.")
raise RuntimeError(f"Incompatible requirements for {req.name}.")

base_req.marker = old_base_marker
req.marker = old_req_marker
if base_req.marker is None or base_req.marker == req.marker:
continue

if len(platforms) == len(all_platforms):
if len(envs) == len(all_envs):
output.append(req)
continue
elif len(platforms) < len(all_platforms - platforms.keys()):
platform_marker = " or ".join(
f"sys_platform == '{platform}'" for platform in platforms

# At this point I'm wondering why I didn't just go for
# a more generic boolean algebra simplification (sympy.simplify_logic())...
if (
len(set(map(frozenset, python_versions_per_platform.values()))) == 1
or len(set(map(frozenset, platforms_per_python_version.values()))) == 1
):
# Either all platforms have the same Python version set
# or all Python versions have the same platform set.
# We can generate markers for platform (platform_marker) and Python
# (python_version_marker) version sets separately and then simply require
# that both markers are fulfilled at the same time (env_marker).

python_version_marker = (
# Requirement present on less Python versions than not.
" or ".join(
f"python_version == '{python_version}'" for python_version in python_versions
)
if len(python_versions) < len(all_python_versions - python_versions)
# Requirement present on more Python versions than not
# This may generate an empty string when Python version is irrelevant.
else " and ".join(
f"python_version != '{python_version}'"
for python_version in all_python_versions - python_versions
)
)

platform_marker = (
# Requirement present on less platforms than not.
" or ".join(f"sys_platform == '{platform}'" for platform in platforms)
if len(platforms) < len(all_platforms - platforms)
# Requirement present on more platforms than not
# This may generate an empty string when platform is irrelevant.
else " and ".join(
f"sys_platform != '{platform}'" for platform in all_platforms - platforms
)
)

if python_version_marker and platform_marker:
env_marker = f"({python_version_marker}) and ({platform_marker})"
else:
env_marker = python_version_marker or platform_marker
else:
platform_marker = " and ".join(
f"sys_platform != '{platform}'" for platform in all_platforms - platforms.keys()
# Fallback to generic case.
env_marker = (
# Requirement present on less envs than not.
" or ".join(
f"(sys_platform == '{platform}' and python_version == '{python_version}')"
for platform, python_version in iter_envs(envs)
)
if len(envs) < len(all_envs - envs.keys())
else " and ".join(
f"(sys_platform != '{platform}' and python_version != '{python_version}')"
for platform, python_version in iter_envs(all_envs - envs.keys())
)
)

new_marker = (
f"({req.marker}) and ({platform_marker})"
if req.marker is not None
else platform_marker
)
new_marker = f"({req.marker}) and ({env_marker})" if req.marker is not None else env_marker
req.marker = Marker(new_marker)
if base_req is not None and base_req.marker == req.marker:
continue
Expand Down
Loading

0 comments on commit f610166

Please sign in to comment.