Use custom build backend for the client package

This commit is contained in:
Lonami Exo 2023-10-16 18:32:12 +02:00
parent 957a66f797
commit 2f6ea3497a
4 changed files with 79 additions and 1 deletions

View File

@ -0,0 +1,62 @@
import sys
from pathlib import Path
from typing import Any, Dict, Optional
from setuptools import build_meta as _orig
from setuptools.build_meta import * # noqa: F403
def gen_types_if_needed() -> None:
tl_root = Path("src/telethon/_impl/tl")
layer_py = tl_root / "layer.py"
mtproto_root = tl_root / "mtproto"
generator_path = "../generator/src"
api_tl = Path("../generator/tl/api.tl")
mtproto_tl = Path("../generator/tl/mtproto.tl")
if not layer_py.exists():
print(layer_py, "is missing; attempting to generate types", file=sys.stderr)
# Import generator and clean-up path
sys.path.append(generator_path)
import telethon_generator as gen
sys.path.remove(generator_path)
# api.tl
fs = gen.codegen.FakeFs()
gen.codegen.generate(fs, gen.tl_parser.load_tl_file(api_tl))
fs.materialize(tl_root)
print("written api.tl files:", tl_root, file=sys.stderr)
# mtproto.tl
fs = gen.codegen.FakeFs()
gen.codegen.generate(fs, gen.tl_parser.load_tl_file(mtproto_tl))
fs.materialize(mtproto_root)
print("written mtproto.tl files:", mtproto_root, file=sys.stderr)
def build_wheel( # type: ignore [no-redef]
wheel_directory: str,
config_settings: Optional[Dict[Any, Any]] = None,
metadata_directory: Optional[str] = None,
) -> str:
gen_types_if_needed()
return _orig.build_wheel(wheel_directory, config_settings, metadata_directory)
def build_sdist( # type: ignore [no-redef]
sdist_directory: str, config_settings: Optional[Dict[Any, Any]] = None
) -> str:
gen_types_if_needed()
return _orig.build_sdist(sdist_directory, config_settings)
def build_editable( # type: ignore [no-redef]
wheel_directory: str,
config_settings: Optional[Dict[Any, Any]] = None,
metadata_directory: Optional[str] = None,
) -> str:
gen_types_if_needed()
return _orig.build_editable(wheel_directory, config_settings, metadata_directory)

View File

@ -48,7 +48,8 @@ doc = [
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
build-backend = "backend"
backend-path = ["build_backend"]
[tool.setuptools.dynamic]
version = {attr = "telethon.version.__version__"}

View File

@ -0,0 +1,15 @@
from typing import Any, Dict, Optional
def build_wheel(
wheel_directory: str,
config_settings: Optional[Dict[Any, Any]] = None,
metadata_directory: Optional[str] = None,
) -> str: ...
def build_sdist(
sdist_directory: str, config_settings: Optional[Dict[Any, Any]] = None
) -> str: ...
def build_editable(
wheel_directory: str,
config_settings: Optional[Dict[Any, Any]] = None,
metadata_directory: Optional[str] = None,
) -> str: ...

0
stubs/setuptools.pyi Normal file
View File