Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pep 517 #1668

Merged
merged 24 commits into from
Oct 8, 2022
Merged

Pep 517 #1668

Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

15 changes: 0 additions & 15 deletions .pylintrc

This file was deleted.

14 changes: 14 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ include LICENSE
include requirements.txt
include discord/bin/*.dll
include discord/py.typed

prune .github
prune docs
prune examples
prune tests
exclude discord/bin/COPYING
exclude .flake8
exclude .gitignore
exclude .pre-commit-config.yaml
exclude .prettierrc
exclude .readthedocs.yml
exclude CHANGELOG.md
exclude FUNDING.yml
exclude requirements-dev.txt
15 changes: 1 addition & 14 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)

import logging
from typing import Literal, NamedTuple

from . import abc, opus, sinks, ui, utils
from ._version import VersionInfo, __version__, version_info
from .activity import *
from .appinfo import *
from .asset import *
Expand Down Expand Up @@ -66,17 +66,4 @@
from .welcome_screen import *
from .widget import *


class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: Literal["alpha", "beta", "candidate", "final"]
serial: int


version_info: VersionInfo = VersionInfo(
major=2, minor=2, micro=0, releaselevel="final", serial=0
)

logging.getLogger(__name__).addHandler(logging.NullHandler())
89 changes: 89 additions & 0 deletions discord/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import re
import warnings
from datetime import date
from importlib.metadata import PackageNotFoundError, version

__all__ = ("__version__", "VersionInfo", "version_info")

from typing import Literal, NamedTuple, Optional

from discord.utils import deprecated

try:
__version__ = version("py-cord")
print("Set version")
except PackageNotFoundError:
# Package is not installed
try:
from setuptools_scm import get_version # type: ignore[import]

__version__ = get_version()
print("set version")
except ImportError:
# setuptools_scm is not installed
__version__ = "0.0.0"
warnings.warn(
"Package is not installed, and setuptools_scm is not installed. "
f"As a fallback, {__name__}.__version__ will be set to {__version__}",
RuntimeWarning,
stacklevel=2,
)


class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
release_level: Literal["alpha", "beta", "candidate", "final"]
serial: int
build: int | None = None
commit: str | None = None
date: Optional[date] = None

@property
@deprecated("release_level", "2.3")
def releaselevel(self) -> Literal["alpha", "beta", "candidate", "final"]:
return self.release_level


version_regex = re.compile(
r"^(?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<patch>\d+))?"
r"(?:(?P<level>rc|a|b)(?P<serial>\d+))?"
r"(?:\.dev(?P<build>\d+))?"
r"(?:\+(?:(?:g(?P<commit>[a-fA-F0-9]{8})\.d(?P<date>\d{4}\d{2}\d{2}))|d(?P<date1>\d{4}\d{2}\d{2})))?$"
)

raw_info = version_regex.match(__version__).groupdict()

level_info: Literal["alpha", "beta", "candidate", "final"]

if raw_info["level"] == "a":
level_info = "alpha"
elif raw_info["level"] == "b":
level_info = "beta"
elif raw_info["level"] == "rc":
level_info = "candidate"
elif raw_info["level"] is None:
level_info = "final"
else:
raise RuntimeError("Invalid release level")

if (raw_date := raw_info["date"] or raw_info["date1"]) is not None:
date_info = date(
int(raw_date[:4]),
int(raw_date[4:6]),
int(raw_date[6:]),
)
else:
date_info = None

version_info: VersionInfo = VersionInfo(
major=raw_info["major"],
minor=raw_info["minor"],
micro=raw_info["patch"],
release_level=level_info,
serial=raw_info["serial"],
build=raw_info["build"],
commit=raw_info["commit"],
date=date_info,
)
8 changes: 0 additions & 8 deletions mypy.ini

This file was deleted.

114 changes: 114 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,116 @@
[build-system]
requires = [
"setuptools==65.4.1",
"setuptools-scm==7.0.5"
]
build-backend = "setuptools.build_meta"

[project]
name = "py-cord"
authors = [
{name = "Pycord Development"}
]
description = "A Python wrapper for the Discord API"
readme = "README.rst"
requires-python = ">=3.8"
license = {text = "MIT"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Internet",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
"Typing :: Typed",
]
dynamic = ["version", "dependencies"]

[project.urls]
Homepage = "https://pycord.dev"
Changelog = "https://github.com/Pycord-Development/pycord/blob/master/CHANGELOG.md"
Source = "https://github.com/Pycord-Development/pycord"
Documentation = "https://docs.pycord.dev"
Tracker = "https://github.com/Pycord-Development/pycord/issues"
Funding = "https://patreon.com/pycord"

[project.optional-dependencies]
voice = [
"PyNaCl>=1.3.0,<1.6",
]
docs = [
"sphinx==4.5.0",
"sphinxcontrib_trio==1.1.2",
"sphinxcontrib-websupport",
"myst-parser",
]
speed = [
"orjson>=3.5.4",
"aiodns>=1.1",
"Brotlipy",
"cchardet",
]

[tool.setuptools]
packages = [
"discord",
"discord.types",
"discord.sinks",
"discord.ui",
"discord.webhook",
"discord.commands",
"discord.ext.commands",
"discord.ext.tasks",
"discord.ext.pages",
"discord.ext.bridge",
]

[tool.setuptools.dynamic]
dependencies = {file = "requirements.txt"}

[tool.setuptools_scm]

[tool.black]
target-version = ['py38', 'py39', 'py310', 'py311']

[tool.isort]
profile = "black"

[tool.mypy]
namespace_packages = true
install_types = true
strict = true
show_error_codes = true
#allow_untyped_decorators = true
#allow_untyped_calls = true
ignore_errors = true

[tool.pylint.main]
extension-pkg-whitelist = [
"pydantic",
"ujson"
]
py-version = 3.8

[tool.pylint.messages_control]
enable = [
"bad-indentation",
"line-too-long"
]
disable = [
"protected-access",
"fixme"
]

[tool.pylint.format]
indent-string = ' '
max-line-length = 120

[tool.pytest.ini_options]
asyncio_mode = "auto"
2 changes: 0 additions & 2 deletions pytest.ini

This file was deleted.