Skip to content

Commit

Permalink
Merge branch 'V3/develop' into hyperlink-and-header
Browse files Browse the repository at this point in the history
  • Loading branch information
Kowlin authored Jul 18, 2024
2 parents d734230 + 601816a commit a80ccb5
Show file tree
Hide file tree
Showing 1,158 changed files with 230,097 additions and 143,125 deletions.
40 changes: 40 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Since version 2.23 (released in August 2019), git-blame has a feature
# to ignore or bypass certain commits.
#
# This file contains a list of commits that are not likely what you
# are looking for in a blame, such as mass reformatting or renaming.
# You can set this file as a default ignore file for blame by running
# the following command.
#
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs

# [V3] Update code standards (black code format pass) (#1650)
b88b5a2601f56bda985729352d24842f087a8ade

# Black tests and setup.py (#1657)
e01cdbb0912387749d9459e1d934f9ed393a9b51

# Black formatting for generate_strings.py and docs/conf.py (#1658)
1ecaf6f8d5f2af731bec3eb6ad3a9721ab7a2812

# [V3 Travis] Update travis to not skip pipfile lock... (#1678)
# additional black formatting pass to conform to black 18.5b
d3f406a34a5cae6ea63664e76e8e74be43f9949f

# [V3] Update black version and reformat (#1745)
14cc701b25cea385fd0d537cdb6475d341c017c5

# [V3] Clean up some ugly auto-formatted strings (#1753)
622382f42588ac1d8a52bd3e39bf171c89ff0224

# [CI] Improve automated checks (#2702)
16443c8cc0c24cbc5b3dc7de858edb71b9ca6cd3

# Bump black to 20.8b1 (and reformat) (#4371)
85afe19455f91af21a0f603705eeb5d9599b45cc

# Reformat with Black 22.1.0 (#5633)
c69e8d31fdadbe10230ec0ea2ef35402e5c4cf43

# Reformat with Black 2023 formatting changes
226d8d734de43e1d5ea96a528a8e480641604db1
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
5 changes: 5 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 Expand Up @@ -139,6 +141,8 @@
"Category: Core - API - App Commands Package":
# Source
- redbot/core/app_commands/*
# Docs
- docs/framework_app_commands.rst
# Tests
- tests/core/test_app_commands.py
"Category: Core - API - Commands Package":
Expand Down Expand Up @@ -252,6 +256,7 @@
"Category: Docs - Changelogs":
- CHANGES.rst
- docs/changelog.rst
- docs/incompatible_changes/**/*
"Category: Docs - For Developers":
- docs/framework_events.rst
- docs/guide_cog_creation.rst
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: 5 additions & 1 deletion .github/workflows/lint_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- run: "python -m pip install git+https://github.com/pycqa/pyflakes@1911c20#egg=pyflakes git+https://github.com/pycqa/pycodestyle@d219c68#egg=pycodestyle git+https://github.com/pycqa/[email protected]#egg=flake8"
- run: >
python -m pip install
'pyflakes @ https://github.com/pycqa/pyflakes/tarball/1911c20'
'pycodestyle @ https://github.com/pycqa/pycodestyle/tarball/d219c68'
'flake8 @ https://github.com/pycqa/flake8/tarball/3.7.9'
name: Install Flake8
- run: "python -m flake8 . --count --select=E9,F7,F82 --show-source"
name: Flake8 Linting
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 a80ccb5

Please sign in to comment.