Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import os
import re
import sys
from typing import TypeVar, overload
from collections.abc import Callable
from typing import Any, ClassVar, TypeVar, overload

from . import _modified, archive_util, dir_util, file_util, util
from ._log import log
Expand Down Expand Up @@ -49,7 +50,14 @@ class Command:
# 'sub_commands' is usually defined at the *end* of a class, because
# predicates can be unbound methods, so they must already have been
# defined. The canonical example is the "install" command.
sub_commands = []
sub_commands: ClassVar[ # Any to work around variance issues
list[tuple[str, Callable[[Any], bool] | None]]
] = []

user_options: ClassVar[
# Specifying both because list is invariant. Avoids mypy override assignment issues
list[tuple[str, str, str]] | list[tuple[str, str | None, str]]
] = []

# -- Creation/initialization methods -------------------------------

Expand Down
5 changes: 3 additions & 2 deletions distutils/command/bdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import warnings
from typing import ClassVar

from ..core import Command
from ..errors import DistutilsOptionError, DistutilsPlatformError
Expand All @@ -23,7 +24,7 @@ def show_formats():
pretty_printer.print_help("List of available distribution formats:")


class ListCompat(dict):
class ListCompat(dict[str, tuple[str, str]]):
# adapter to allow for Setuptools compatibility in format_commands
def append(self, item):
warnings.warn(
Expand Down Expand Up @@ -70,7 +71,7 @@ class bdist(Command):
]

# The following commands do not take a format option from bdist
no_format_option = ('bdist_rpm',)
no_format_option: ClassVar[tuple[str, ...]] = ('bdist_rpm',)

# This won't do in reality: will need to distinguish RPM-ish Linux,
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
Expand Down
3 changes: 2 additions & 1 deletion distutils/command/build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import os
from distutils._log import log
from typing import ClassVar

from ..core import Command
from ..errors import DistutilsSetupError
Expand All @@ -31,7 +32,7 @@ def show_compilers():
class build_clib(Command):
description = "build C/C++ libraries used by Python extensions"

user_options = [
user_options: ClassVar[list[tuple[str, str, str]]] = [
('build-clib=', 'b', "directory to build C/C++ libraries to"),
('build-temp=', 't', "directory to put temporary build by-products"),
('debug', 'g', "compile with debugging information"),
Expand Down
3 changes: 2 additions & 1 deletion distutils/command/build_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from distutils import sysconfig
from distutils._log import log
from stat import ST_MODE
from typing import ClassVar

from .._modified import newer
from ..core import Command
Expand All @@ -25,7 +26,7 @@
class build_scripts(Command):
description = "\"build\" scripts (copy and fixup #! line)"

user_options = [
user_options: ClassVar[list[tuple[str, str, str]]] = [
('build-dir=', 'd', "directory to \"build\" (copy) to"),
('force', 'f', "forcibly build everything (ignore file timestamps"),
('executable=', 'e', "specify final destination interpreter path"),
Expand Down
3 changes: 2 additions & 1 deletion distutils/command/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import contextlib
from typing import ClassVar

from ..core import Command
from ..errors import DistutilsSetupError
Expand Down Expand Up @@ -41,7 +42,7 @@ class check(Command):
"""This command checks the meta-data of the package."""

description = "perform some checks on the package"
user_options = [
user_options: ClassVar[list[tuple[str, str, str]]] = [
('metadata', 'm', 'Verify meta-data'),
(
'restructuredtext',
Expand Down
8 changes: 4 additions & 4 deletions distutils/command/command_template
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ Implements the Distutils 'x' command.
__revision__ = "$Id$"

from distutils.core import Command
from typing import ClassVar


class x(Command):

# Brief (40-50 characters) description of the command
description = ""

# List of option tuples: long name, short name (None if no short
# name), and help string.
user_options = [('', '',
""),
]
user_options: ClassVar[list[tuple[str, str, str]]] = [
('', '', ""),
]

def initialize_options(self):
self. = None
Expand Down
3 changes: 2 additions & 1 deletion distutils/command/install_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import re
import sys
from typing import ClassVar

from .. import dir_util
from .._log import log
Expand All @@ -18,7 +19,7 @@ class install_egg_info(Command):
"""Install an .egg-info file for the package"""

description = "Install package's PKG-INFO metadata as an .egg-info file"
user_options = [
user_options: ClassVar[list[tuple[str, str, str]]] = [
('install-dir=', 'd', "directory to install to"),
]

Expand Down
4 changes: 3 additions & 1 deletion distutils/command/install_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
Implements the Distutils 'install_headers' command, to install C/C++ header
files to the Python include directory."""

from typing import ClassVar

from ..core import Command


# XXX force is never used
class install_headers(Command):
description = "install C/C++ header files"

user_options = [
user_options: ClassVar[list[tuple[str, str, str]]] = [
('install-dir=', 'd', "directory to install header files to"),
('force', 'f', "force installation (overwrite existing files)"),
]
Expand Down
3 changes: 2 additions & 1 deletion distutils/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from distutils._log import log
from glob import glob
from itertools import filterfalse
from typing import ClassVar

from ..core import Command
from ..errors import DistutilsOptionError, DistutilsTemplateError
Expand Down Expand Up @@ -114,7 +115,7 @@ def checking_metadata(self):

sub_commands = [('check', checking_metadata)]

READMES = ('README', 'README.txt', 'README.rst')
READMES: ClassVar[tuple[str, ...]] = ('README', 'README.txt', 'README.rst')

def initialize_options(self):
# 'template' and 'manifest' are, respectively, the names of
Expand Down
3 changes: 2 additions & 1 deletion distutils/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from distutils.cmd import Command
from distutils.dist import Distribution, fix_help_options
from distutils.tests import support
from typing import ClassVar

import jaraco.path
import pytest
Expand All @@ -23,7 +24,7 @@
class test_dist(Command):
"""Sample distutils extension command."""

user_options = [
user_options: ClassVar[list[tuple[str, str, str]]] = [
("sample-option=", "S", "help text"),
]

Expand Down
Loading