Files
typeshed/tests/check_consistent.py
Sebastian Rittau 5927e5ca30 Remove most consistency checks and split builtins.pyi into py2/3 files (#4686)
Split builtins.pyi in Python 2 and 3 versions

Partly addresses #4674
2020-10-22 13:39:06 -07:00

39 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
# For various reasons we need the contents of certain files to be
# duplicated in two places, for example stdlib/2/builtins.pyi and
# stdlib/2/__builtin__.pyi must be identical. In the past we used
# symlinks but that doesn't always work on Windows, so now you must
# manually update both files, and this test verifies that they are
# identical. The list below indicates which sets of files must match.
import os
import filecmp
consistent_files = [
{'stdlib/2/builtins.pyi', 'stdlib/2/__builtin__.pyi'},
{'stdlib/2and3/threading.pyi', 'stdlib/2and3/_dummy_threading.pyi'},
]
def main():
files = [os.path.join(root, file) for root, dir, files in os.walk('.') for file in files]
no_symlink = 'You cannot use symlinks in typeshed, please copy {} to its link.'
for file in files:
_, ext = os.path.splitext(file)
if ext == '.pyi' and os.path.islink(file):
raise ValueError(no_symlink.format(file))
for file1, *others in consistent_files:
f1 = os.path.join(os.getcwd(), file1)
for file2 in others:
f2 = os.path.join(os.getcwd(), file2)
if not filecmp.cmp(f1, f2):
raise ValueError(
"File {f1} does not match file {f2}. Please copy it to {f2}\n"
"Run either:\ncp {f1} {f2}\nOr:\ncp {f2} {f1}".format(f1=file1, f2=file2)
)
if __name__ == '__main__':
main()