utils

Utilities to be used by the other modules.

Byte utilities.

class byte_bot.byte.lib.utils.PEP[source]

Bases: TypedDict

PEP data.

Based off of the PEPS API.

class byte_bot.byte.lib.utils.FormattedRuffRule[source]

Bases: BaseRuffRule

Formatted Ruff rule data.

class byte_bot.byte.lib.utils.PEPStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

Status of a PEP.

Note

Active and Accepted both traditionally use A, but are differentiated here for clarity.

Based off of PEP Status in PEP1.

class byte_bot.byte.lib.utils.PEPType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

Type of PEP.

Based off of PEP Types in PEP1.

class byte_bot.byte.lib.utils.RuffRule[source]

Bases: BaseRuffRule

Ruff rule data.

byte_bot.byte.lib.utils.chunk_sequence(sequence: Iterable[_T], size: int) Iterable[tuple[_T, ...]][source]

Naïve chunking of an iterable.

Parameters:
  • sequence (Iterable[_T]) – Iterable to chunk

  • size (int) – Size of chunk

Yields:

Iterable[tuple[_T, …]] – An n-tuple that contains chunked data

Formats the resolution URL into a markdown link.

Parameters:

resolution (str) – The resolution URL.

Returns:

The formatted markdown link.

Return type:

str

byte_bot.byte.lib.utils.format_ruff_rule(rule_data: RuffRule) FormattedRuffRule[source]

Format ruff rule data for embed-friendly output and append rule link.

Parameters:

rule_data – The ruff rule data.

Returns:

The formatted rule data.

Return type:

FormattedRuffRule

byte_bot.byte.lib.utils.get_next_friday(now: datetime, delay: int | None = None) tuple[datetime, datetime][source]

Calculate the next Friday from now.

If delay, calculate the Friday for delay weeks from now.

Parameters:
  • now – The current date and time.

  • delay – The number of weeks to delay the calculation.

Returns:

The next Friday, optionally for the week after next.

Return type:

datetime

byte_bot.byte.lib.utils.linker(title: str, link: str, show_embed: bool = False) str[source]

Create a Markdown link, optionally with an embed.

Parameters:
  • title – The title of the link.

  • link – The URL of the link.

  • show_embed – Whether to show the embed or not.

Returns:

A Markdown link.

async byte_bot.byte.lib.utils.paste(code: str) str[source]

Uploads the given code to paste.pythondiscord.com.

Parameters:

code – The formatted code to upload.

Returns:

The URL of the uploaded paste.

Return type:

str

async byte_bot.byte.lib.utils.query_all_peps() list[PEP][source]

Query all PEPs from the PEPs Python.org API.

Returns:

All PEPs

Return type:

list[PEP]

async byte_bot.byte.lib.utils.query_all_ruff_rules() list[RuffRule][source]

Query all Ruff linting rules.

Returns:

All ruff rules

Return type:

list[RuffRule]

byte_bot.byte.lib.utils.run_ruff_format(code: str) str[source]

Formats code using Ruff.

Parameters:

code – The code to format.

Returns:

The formatted code.

Return type:

str