Improve distutils (#418)

* remove old distutils

* core done

* ccompiler done

* compilers done

* archive_util done

* dep_util done

* dir_util done

* file_util done

* util done

* dist done

* debug, error, extension done

* fancy_getopt done

* filelist, log, spawn done

* sysconfig done

* text_file done

* version done

* cmd done

* add command

* add emxccompiler which is py2 only

* command.build_py have spec only in py3

* make pytype happy by resolving relative import
This commit is contained in:
Valérian Rousset
2016-08-04 00:38:15 +02:00
committed by Matthias Kramm
parent 2c21f27310
commit 2e560d38dc
51 changed files with 407 additions and 40 deletions

View File

@@ -1,7 +0,0 @@
# Stubs for distutils (Python 2)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from typing import Any
__revision__ = ... # type: Any

View File

@@ -0,0 +1,5 @@
# Stubs for emxccompiler
from distutils.unixccompiler import UnixCCompiler
class EMXCCompiler(UnixCCompiler): ...

View File

@@ -1,23 +0,0 @@
# Stubs for distutils.version (Python 2)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.
from typing import Any
class Version:
def __init__(self, vstring=...) -> None: ...
class StrictVersion(Version):
version_re = ... # type: Any
version = ... # type: Any
prerelease = ... # type: Any
def parse(self, vstring): ...
def __cmp__(self, other): ...
class LooseVersion(Version):
component_re = ... # type: Any
def __init__(self, vstring=...) -> None: ...
vstring = ... # type: Any
version = ... # type: Any
def parse(self, vstring): ...
def __cmp__(self, other): ...

View File

@@ -0,0 +1,12 @@
# Stubs for distutils.archive_util
from typing import Optional
def make_archive(base_name: str, format: str, root_dir: Optional[str] = ...,
base_dir: Optional[str] = ..., verbose: int = ...,
dry_run: int = ...) -> str: ...
def make_tarball(base_name: str, base_dir: str, compress: Optional[str] = ...,
verbose: int = ..., dry_run: int = ...) -> str: ...
def make_zipfile(base_name: str, base_dir: str, verbose: int = ...,
dry_run: int = ...) -> str: ...

View File

@@ -0,0 +1,6 @@
# Stubs for distutils.bcppcompiler
from distutils.ccompiler import CCompiler
class BCPPCompiler(CCompiler): ...

View File

@@ -0,0 +1,119 @@
# Stubs for distutils.ccompiler
from typing import Any, Callable, List, Optional, Tuple, Union
_Macro = Union[Tuple[str], Tuple[str, str]]
def gen_lib_options(compiler: CCompiler, library_dirs: List[str],
runtime_library_dirs: List[str],
libraries: List[str]) -> List[str]: ...
def gen_preprocess_options(macros: List[_Macro],
include_dirs: List[str]) -> List[str]: ...
def get_default_compiler(osname: Optional[str] = ...,
platform: Optional[str] = ...) -> str: ...
def new_compiler(plat: Optional[str] = ..., compiler: Optional[str] = ...,
verbose: int = ..., dry_run: int = ...,
force: int = ...) -> CCompiler: ...
def show_compilers() -> None: ...
class CCompiler:
def __init__(self, verbose: int = ..., dry_run: int = ...,
force: int = ...) -> None: ...
def add_include_dir(self, dir: str) -> None: ...
def set_include_dirs(self, dirs: List[str]) -> None: ...
def add_library(self, libname: str) -> None: ...
def set_libraries(self, libnames: List[str]) -> None: ...
def add_library_dir(self, dir: str) -> None: ...
def set_library_dirs(self, dirs: List[str]) -> None: ...
def add_runtime_library_dir(self, dir: str) -> None: ...
def set_runtime_library_dirs(self, dirs: List[str]) -> None: ...
def define_macro(self, name: str, value: Optional[str] = ...) -> None: ...
def undefine_macro(self, name: str) -> None: ...
def add_link_object(self, object: str) -> None: ...
def set_link_objects(self, objects: List[str]) -> None: ...
def detect_language(self, sources: Union[str, List[str]]) -> Optional[str]: ...
def find_library_file(self, dirs: List[str], lib: str,
debug: bool = ...) -> Optional[str]: ...
def has_function(self, funcname: str, includes: Optional[List[str]] = ...,
include_dirs: Optional[List[str]] = ...,
libraries: Optional[List[str]] = ...,
library_dirs: Optional[List[str]] = ...) -> bool: ...
def library_dir_option(self, dir: str) -> str: ...
def library_option(self, lib: str) -> str: ...
def runtime_library_dir_option(self, dir: str) -> str: ...
def set_executables(self, **args: str) -> None: ...
def compile(self, sources: List[str], output_dir: Optional[str] = ...,
macros: Optional[_Macro] = ...,
include_dirs: Optional[List[str]] = ..., debug: bool = ...,
extra_preargs: Optional[List[str]] = ...,
extra_postargs: Optional[List[str]] = ...,
depends: Optional[List[str]] = ...) -> List[str]: ...
def create_static_lib(self, objects: List[str], output_libname: str,
output_dir: Optional[str] = ..., debug: bool = ...,
target_lang: Optional[str] = ...) -> None: ...
def link(self, target_desc: str, objects: List[str], output_filename: str,
output_dir: Optional[str] = ...,
libraries: Optional[List[str]] = ...,
library_dirs: Optional[List[str]] = ...,
runtime_library_dirs: Optional[List[str]] = ...,
export_symbols: Optional[List[str]] = ..., debug: bool = ...,
extra_preargs: Optional[List[str]] = ...,
extra_postargs: Optional[List[str]] = ...,
build_temp: Optional[str] = ...,
target_lang: Optional[str] = ...) -> None: ...
def link_executable(self, objects: List[str], output_progname: str,
output_dir: Optional[str] = ...,
libraries: Optional[List[str]] = ...,
library_dirs: Optional[List[str]] = ...,
runtime_library_dirs: Optional[List[str]] = ...,
debug: bool = ...,
extra_preargs: Optional[List[str]] = ...,
extra_postargs: Optional[List[str]] = ...,
target_lang: Optional[str] = ...) -> None: ...
def link_shared_lib(self, objects: List[str], output_libname: str,
output_dir: Optional[str] = ...,
libraries: Optional[List[str]] = ...,
library_dirs: Optional[List[str]] = ...,
runtime_library_dirs: Optional[List[str]] = ...,
export_symbols: Optional[List[str]] = ...,
debug: bool = ...,
extra_preargs: Optional[List[str]] = ...,
extra_postargs: Optional[List[str]] = ...,
build_temp: Optional[str] = ...,
target_lang: Optional[str] = ...) -> None: ...
def link_shared_object(self, objects: List[str], output_filename: str,
output_dir: Optional[str] = ...,
libraries: Optional[List[str]] = ...,
library_dirs: Optional[List[str]] = ...,
runtime_library_dirs: Optional[List[str]] = ...,
export_symbols: Optional[List[str]] = ...,
debug: bool = ...,
extra_preargs: Optional[List[str]] = ...,
extra_postargs: Optional[List[str]] = ...,
build_temp: Optional[str] = ...,
target_lang: Optional[str] = ...) -> None: ...
def preprocess(self, source: str, output_file: Optional[str] = ...,
macros: Optional[List[_Macro]] = ...,
include_dirs: Optional[List[str]] = ...,
extra_preargs: Optional[List[str]] = ...,
extra_postargs: Optional[List[str]] = ...) -> None: ...
def executable_filename(self, basename: str, strip_dir: int = ...,
output_dir: str = ...) -> str: ...
def library_filename(self, libname: str, lib_type: str = ...,
strip_dir: int = ...,
output_dir: str = ...) -> str: ...
def object_filenames(self, source_filenames: List[str],
strip_dir: int = ...,
output_dir: str = ...) -> List[str]: ...
def shared_object_filename(self, basename: str, strip_dir: int = ...,
output_dir: str = ...) -> str: ...
def execute(self, func: Callable[..., None], args: Tuple[Any, ...],
msg: Optional[str] = ..., level: int = ...) -> None: ...
def spawn(self, cmd: List[str]) -> None: ...
def mkpath(self, name: str, mode: int = ...) -> None: ...
def move_file(self, src: str, dst: str) -> str: ...
def announce(self, msg: str, level: int = ...) -> None: ...
def warn(self, msg: str) -> None: ...
def debug_print(self, msg: str) -> None: ...

View File

@@ -0,0 +1,15 @@
# Stubs for distutils.cmd
from typing import Callable, List, Tuple, Union
from abc import abstractmethod
from distutils.dist import Distribution
class Command:
sub_commands = ... # type: List[Tuple[str, Union[Callable[[], bool], str, None]]]
def __init__(self, dist: Distribution) -> None: ...
@abstractmethod
def initialize_options(self) -> None: ...
@abstractmethod
def finalize_options(self) -> None: ...
@abstractmethod
def run(self) -> None: ...

View File

View File

@@ -0,0 +1,5 @@
# Stubs for distutils.command.bdist_msi
from distutils.cmd import Command
class bdist_msi(Command): ...

View File

View File

@@ -0,0 +1,8 @@
# Stubs for distutils.command.bdist_msi
from distutils.cmd import Command
import sys
if sys.version_info >= (3,):
class build_py(Command): ...
class build_py_2to3(Command): ...

View File

View File

View File

View File

@@ -0,0 +1,35 @@
# Stubs for distutils.core
from typing import Any, List, Mapping, Optional, Tuple, Type, Union
from distutils.cmd import Command as Command
from distutils.dist import Distribution as Distribution
from distutils.extension import Extension as Extension
def setup(name: str = ...,
version: str = ...,
description: str = ...,
long_description: str = ...,
author: str = ...,
author_email: str = ...,
maintainer: str = ...,
maintainer_email: str = ...,
url: str = ...,
download_url: str = ...,
packages: List[str] = ...,
py_modules: List[str] = ...,
scripts: List[str] = ...,
ext_modules: List[Extension] = ...,
classifiers: List[str] = ...,
distclass: Type[Distribution] = ...,
script_name: str = ...,
script_args: List[str] = ...,
options: Mapping[str, Any] = ...,
license: str = ...,
keywords: Union[List[str], str] = ...,
platforms: Union[List[str], str] = ...,
cmdclass: Mapping[str, Command] = ...,
data_files: List[Tuple[str, List[str]]] = ...,
package_dir: Mapping[str, str] = ...) -> None: ...
def run_setup(script_name: str,
script_args: Optional[List[str]] = ...,
stop_after: str = ...) -> Distribution: ...

View File

@@ -0,0 +1,7 @@
# Stubs for distutils.cygwinccompiler
from distutils.unixccompiler import UnixCCompiler
class CygwinCCompiler(UnixCCompiler): ...
class Mingw32CCompiler(CygwinCCompiler): ...

View File

@@ -0,0 +1,3 @@
# Stubs for distutils.debug
DEBUG = ... # type: bool

View File

@@ -0,0 +1,8 @@
# Stubs for distutils.dep_util
from typing import List, Tuple
def newer(source: str, target: str) -> bool: ...
def newer_pairwise(sources: List[str],
targets: List[str]) -> List[Tuple[str, str]]: ...
def newer_group(sources: List[str], target: str, missing: str = ...) -> bool: ...

View File

@@ -0,0 +1,15 @@
# Stubs for distutils.dir_util
from typing import List
def mkpath(name: str, mode: int = ..., verbose: int = ...,
dry_run: int = ...) -> List[str]: ...
def create_tree(base_dir: str, files: List[str], mode: int = ...,
verbose: int = ..., dry_run: int = ...) -> None: ...
def copy_tree(src: str, dst: str, preserve_mode: int = ...,
preserve_times: int = ..., preserve_symlinks: int = ...,
update: int = ..., verbose: int = ...,
dry_run: int = ...) -> List[str]: ...
def remove_tree(directory: str, verbose: int = ...,
dry_run: int = ...) -> None: ...

View File

@@ -0,0 +1,7 @@
# Stubs for distutils.dist
from typing import Any, Mapping, Optional
class Distribution:
def __init__(self, attrs: Optional[Mapping[str, Any]] = ...) -> None: ...

View File

@@ -0,0 +1,4 @@
# Stubs for distutils.errors
class DistutilsExecError(Exception): ...
class DistutilsFileError(Exception): ...

View File

@@ -0,0 +1,39 @@
# Stubs for distutils.extension
from typing import List, Optional, Tuple
import sys
class Extension:
if sys.version_info >= (3,):
def __init__(self,
*, name: str = ...,
sources: List[str] = ...,
include_dirs: List[str] = ...,
define_macros: List[Tuple[str, Optional[str]]] = ...,
undef_macros: List[str] = ...,
library_dirs: List[str] = ...,
libraries: List[str] = ...,
runtime_library_dirs: List[str] = ...,
extra_objects: List[str] = ...,
extra_compile_args: List[str] = ...,
extra_link_args: List[str] = ...,
export_symbols: List[str] = ...,
depends: List[str] = ...,
language: str = ...,
optional: bool = ...) -> None: ...
else:
def __init__(self,
*, name: str = ...,
sources: List[str] = ...,
include_dirs: List[str] = ...,
define_macros: List[Tuple[str, Optional[str]]] = ...,
undef_macros: List[str] = ...,
library_dirs: List[str] = ...,
libraries: List[str] = ...,
runtime_library_dirs: List[str] = ...,
extra_objects: List[str] = ...,
extra_compile_args: List[str] = ...,
extra_link_args: List[str] = ...,
export_symbols: List[str] = ...,
depends: List[str] = ...,
language: str = ...) -> None: ...

View File

@@ -0,0 +1,27 @@
# Stubs for distutils.fancy_getopt
from typing import (
Any, List, Mapping, Optional, Tuple, Union,
TypeVar, overload,
)
_Option = Tuple[str, str, str]
_GR = Tuple[List[str], OptionDummy]
def fancy_getopt(options: List[_Option],
negative_opt: Mapping[_Option, _Option],
object: Any,
args: Optional[List[str]]) -> Union[List[str], _GR]: ...
def wrap_text(text: str, width: int) -> List[str]: ...
class FancyGetopt:
def __init__(self, option_table: Optional[List[_Option]] = ...) -> None: ...
# TODO kinda wrong, `getopt(object=object())` is invalid
@overload
def getopt(self, args: Optional[List[str]] = ...) -> _GR: ...
@overload
def getopt(self, args: Optional[List[str]], object: Any) -> List[str]: ...
def get_option_order(self) -> List[Tuple[str, str]]: ...
def generate_help(self, header: Optional[str] = ...) -> List[str]: ...
class OptionDummy: ...

View File

@@ -0,0 +1,12 @@
# Stubs for distutils.file_util
from typing import Optional, Sequence, Tuple
def copy_file(src: str, dst: str, preserve_mode: bool = ...,
preserve_times: bool = ..., update: bool = ...,
link: Optional[str] = ..., verbose: bool = ...,
dry_run: bool = ...) -> Tuple[str, str]: ...
def move_file(src: str, dst: str, verbose: bool = ...,
dry_run: bool = ...) -> str: ...
def write_file(filename: str, contents: Sequence[str]) -> None: ...

View File

@@ -0,0 +1,3 @@
# Stubs for distutils.filelist
class FileList: ...

View File

View File

@@ -0,0 +1,6 @@
# Stubs for distutils.msvccompiler
from distutils.ccompiler import CCompiler
class MSVCCompiler(CCompiler): ...

View File

@@ -0,0 +1,8 @@
# Stubs for distutils.spawn
from typing import Optional
def spawn(cmd: List[str], search_path: bool = ...,
verbose: bool = ..., dry_run: bool = ...) -> None: ...
def find_executable(executable: str,
path: Optional[str] = ...) -> Optional[str]: ...

View File

@@ -0,0 +1,19 @@
# Stubs for distutils.sysconfig
from typing import Mapping, Optional, Union
from distutils.ccompiler import CCompiler
PREFIX = ... # type: str
EXEC_PREFIX = ... # type: str
def get_config_var(name: str) -> Union[int, str, None]: ...
def get_config_vars(*args: str) -> Mapping[str, Union[int, str]]: ...
def get_config_h_filename() -> str: ...
def get_makefile_filename() -> str: ...
def get_python_inc(plat_specific: bool = ...,
prefix: Optional[str] = ...) -> str: ...
def get_python_lib(plat_specific: bool = ..., standard_lib: bool = ...,
prefix: Optional[str] = ...) -> str: ...
def customize_compiler(compiler: CCompiler) -> None: ...
def set_python_build() -> None: ...

View File

@@ -0,0 +1,18 @@
# Stubs for distutils.text_file
from typing import IO, Optional, Tuple, Union
class TextFile:
def __init__(self, filename: Optional[str] = ...,
file: Optional[IO[str]] = ...,
*, strip_comments: bool = ...,
lstrip_ws: bool = ..., rstrip_ws: bool = ...,
skip_blanks: bool = ..., join_lines: bool = ...,
collapse_join: bool = ...) -> None: ...
def open(self, filename: str) -> None: ...
def close(self) -> None: ...
def warn(self, msg: str,
line: Union[List[int], Tuple[int, int], int] = ...) -> None: ...
def readline(self) -> Optional[str]: ...
def readlines(self) -> List[str]: ...
def unreadline(self, line: str) -> str: ...

View File

@@ -0,0 +1,6 @@
# Stubs for distutils.unixccompiler
from distutils.ccompiler import CCompiler
class UnixCCompiler(CCompiler): ...

View File

@@ -0,0 +1,20 @@
# Stubs for distutils.util
from typing import Any, Callable, Mapping, Optional, Tuple
def get_platform() -> str: ...
def convert_path(pathname: str) -> str: ...
def change_root(new_root: str, pathname: str) -> str: ...
def check_environ() -> None: ...
def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ...
def split_quoted(s: str) -> List[str]: ...
def execute(func: Callable[..., None], args: Tuple[Any, ...],
msg: Optional[str] = ..., verbose: bool = ...,
dry_run: bool = ...) -> None: ...
def strtobool(val: str) -> bool: ...
def byte_compile(py_files: List[str], optimize: int = ..., force: bool = ...,
prefix: Optional[str] = ..., base_dir: Optional[str] = ...,
verbose: bool = ..., dry_run: bool = ...,
direct: Optional[bool] = ...) -> None: ...
def rfc822_escape(header: str) -> str: ...

View File

View File

@@ -1,4 +0,0 @@
import typing
class DistutilsError(Exception): ...
class DistutilsExecError(DistutilsError): ...

View File

@@ -1,6 +0,0 @@
from typing import List
# In Python, arguments have integer default values
def spawn(cmd: List[str], search_path: bool = ..., verbose: bool = ...,
dry_run: bool = ...) -> None: ...
def find_executable(executable: str, path: str = ...) -> str: ...