Пример #1
0
def lint():
    pip_tool(
        'flake8',
        *[f for f in tools.all_files() if f.endswith('.py')],
        '--config',
        os.path.join(tools.ROOT, '.flake8'),
    )
Пример #2
0
def documentation():
    try:
        if hp.has_release():
            hp.update_changelog_and_version()
        pip_tool(
            # See https://www.sphinx-doc.org/en/stable/man/sphinx-build.html
            "sphinx-build",
            "-n",
            "-W",
            "--keep-going",
            "-T",
            "-E",
            "-b",
            "html",
            "docs",
            "docs/_build/html",
            cwd=hp.HYPOTHESIS_PYTHON,
        )
    finally:
        subprocess.check_call(
            [
                "git", "checkout", "docs/changes.rst",
                "src/hypothesis/version.py"
            ],
            cwd=hp.HYPOTHESIS_PYTHON,
        )
Пример #3
0
def lint():
    pip_tool(
        "flake8",
        *[f for f in tools.all_files() if f.endswith(".py")],
        "--config",
        os.path.join(tools.ROOT, ".flake8"),
    )
Пример #4
0
def lint():
    pip_tool(
        "flake8",
        *(f for f in tools.all_files() if f.endswith(".py")),
        "--config",
        os.path.join(tools.ROOT, ".flake8"),
    )
    codespell(*(f for f in tools.all_files() if not f.endswith("by-domain.txt")))
Пример #5
0
def test_doctests():
    env = dict(os.environ)
    env['PYTHONPATH'] = 'src'

    pip_tool(
        'sphinx-build', '-W', '-b', 'doctest', '-d', 'docs/_build/doctrees',
        'docs', 'docs/_build/html', env=env, cwd=BASE_DIR,
    )
Пример #6
0
def codespell(*files):
    pip_tool(
        "codespell",
        "--check-hidden",
        "--check-filenames",
        "--ignore-words=./tooling/ignore-list.txt",
        "--skip=__pycache__,.mypy_cache,.venv,.git,tlds-alpha-by-domain.txt",
        *files,
    )
Пример #7
0
def doctest():
    os.chdir(hp.HYPOTHESIS_PYTHON)
    env = dict(os.environ)
    env['PYTHONPATH'] = 'src'

    pip_tool(
        'sphinx-build', '-W', '-b', 'doctest', '-d', 'docs/_build/doctrees',
        'docs', 'docs/_build/html', env=env,
    )
Пример #8
0
def compile_requirements(upgrade=False):
    if upgrade:
        extra = ['--upgrade']
    else:
        extra = []

    for f in glob(os.path.join('requirements', '*.in')):
        base, _ = os.path.splitext(f)
        pip_tool('pip-compile', *extra, f, '--output-file', base + '.txt',
                 cwd=tools.ROOT)
Пример #9
0
def documentation():
    os.chdir(tools.HYPOTHESIS_PYTHON)
    try:
        update_changelog_for_docs()
        pip_tool('sphinx-build', '-W', '-b', 'html', '-d',
                 'docs/_build/doctrees', 'docs', 'docs/_build/html')
    finally:
        subprocess.check_call([
            'git', 'checkout', 'docs/changes.rst', 'src/hypothesis/version.py'
        ])
Пример #10
0
def compile_requirements(upgrade=False):
    if upgrade:
        extra = ["--upgrade"]
    else:
        extra = []

    for f in glob(os.path.join("requirements", "*.in")):
        base, _ = os.path.splitext(f)
        pip_tool(
            "pip-compile", *extra, f, "--output-file", base + ".txt", cwd=tools.ROOT
        )
Пример #11
0
def compile_requirements(upgrade=False):
    if upgrade:
        extra = ['--upgrade']
    else:
        extra = []

    os.chdir(tools.ROOT)

    for f in glob(os.path.join('requirements', '*.in')):
        base, _ = os.path.splitext(f)
        pip_tool('pip-compile', *extra, f, '--output-file', base + '.txt')
Пример #12
0
def compile_requirements(upgrade=False):
    if upgrade:
        extra = ["--upgrade"]
    else:
        extra = []

    for f in glob(os.path.join("requirements", "*.in")):
        base, _ = os.path.splitext(f)
        pip_tool(
            "pip-compile", *extra, f, "--output-file", base + ".txt", cwd=tools.ROOT
        )
Пример #13
0
def format():
    def should_format_file(path):
        if "vendor" in path.split(os.path.sep):
            return False
        return path.endswith(".py")

    changed = tools.modified_files()

    format_all = os.environ.get("FORMAT_ALL", "").lower() == "true"
    if "requirements/tools.txt" in changed:
        # We've changed the tools, which includes a lot of our formatting
        # logic, so we need to rerun formatters.
        format_all = True

    files = tools.all_files() if format_all else changed

    files_to_format = [f for f in sorted(files) if should_format_file(f)]

    if not files_to_format:
        return

    for f in files_to_format:
        lines = []
        with open(f, encoding="utf-8") as o:
            shebang = None
            first = True
            header_done = False
            for l in o.readlines():
                if first:
                    first = False
                    if l[:2] == "#!":
                        shebang = l
                        continue
                if "END HEADER" in l and not header_done:
                    lines = []
                    header_done = True
                else:
                    lines.append(l)
        source = "".join(lines).strip()
        with open(f, "w", encoding="utf-8") as o:
            if shebang is not None:
                o.write(shebang)
                o.write("\n")
            o.write(HEADER)
            if source:
                o.write("\n\n")
                o.write(source)
            o.write("\n")
    pip_tool("isort", *files_to_format)

    pip_tool("black", *files_to_format)
Пример #14
0
def documentation():
    os.chdir(hp.HYPOTHESIS_PYTHON)
    try:
        if hp.has_release():
            hp.update_changelog_and_version()
        pip_tool(
            # See http://www.sphinx-doc.org/en/stable/man/sphinx-build.html
            'sphinx-build', '-n', '-W', '--keep-going', '-T', '-E',
            '-b', 'html', 'docs', 'docs/_build/html'
        )
    finally:
        subprocess.check_call([
            'git', 'checkout', 'docs/changes.rst', 'src/hypothesis/version.py'
        ])
Пример #15
0
def lint():
    pip_tool(
        "flake8",
        *[f for f in tools.all_files() if f.endswith(".py")],
        "--config",
        os.path.join(tools.ROOT, ".flake8"),
    )
    # Check for redefined test functions, where e.g. a copy-pasted definition
    # will shadow the earlier test and Pytest never sees or executes it.
    pip_tool(
        "pylint",
        "--score=n",
        "--jobs=0",
        "--disable=all",
        "--enable=function-redefined",
        "hypothesis-python/tests/",
    )
Пример #16
0
def lint():
    pip_tool(
        "flake8",
        *[f for f in tools.all_files() if f.endswith(".py")],
        "--config",
        os.path.join(tools.ROOT, ".flake8"),
    )
    # Check for redefined test functions, where e.g. a copy-pasted definition
    # will shadow the earlier test and Pytest never sees or executes it.
    pip_tool(
        "pylint",
        "--score=n",
        "--jobs=0",
        "--disable=all",
        "--enable=function-redefined",
        "hypothesis-python/tests/",
    )
Пример #17
0
def run_tox(task, version):
    python = install.python_executable(version)

    # Create a version of the name that tox will pick up for the correct
    # interpreter alias.
    linked_version = os.path.basename(python) + ALIASES[version]
    try:
        os.symlink(python, linked_version)
    except FileExistsError:
        pass

    env = dict(os.environ)
    python = install.python_executable(version)

    env["PATH"] = os.path.dirname(python) + ":" + env["PATH"]
    print(env["PATH"])

    pip_tool("tox", "-e", task, env=env, cwd=hp.HYPOTHESIS_PYTHON)
Пример #18
0
def run_tox(task, version):
    python = install.python_executable(version)

    # Create a version of the name that tox will pick up for the correct
    # interpreter alias.
    linked_version = os.path.basename(python) + ALIASES[version]
    try:
        os.symlink(python, linked_version)
    except FileExistsError:
        pass

    env = dict(os.environ)
    python = install.python_executable(version)

    env['PATH'] = os.path.dirname(python) + ':' + env['PATH']
    print(env['PATH'])

    pip_tool('tox', '-e', task, env=env, cwd=hp.HYPOTHESIS_PYTHON)
Пример #19
0
def test_doctests():
    env = dict(os.environ)
    env["PYTHONPATH"] = "src"

    pip_tool(
        "sphinx-build",
        "-n",
        "-W",
        "--keep-going",
        "-T",
        "-b",
        "doctest",
        "-d",
        "docs/_build/doctrees",
        "docs",
        "docs/_build/html",
        env=env,
        cwd=BASE_DIR,
    )
Пример #20
0
def run_tox(task, version):
    python = install.python_executable(version)

    # Create a version of the name that tox will pick up for the correct
    # interpreter alias.
    linked_version = os.path.basename(python) + ALIASES[version]
    try:
        os.symlink(python, linked_version)
    except FileExistsError:
        pass

    os.chdir(hp.HYPOTHESIS_PYTHON)
    env = dict(os.environ)
    python = install.python_executable(version)

    env['PATH'] = os.path.dirname(python) + ':' + env['PATH']
    print(env['PATH'])

    pip_tool('tox', '-e', task, env=env)
Пример #21
0
def documentation():
    try:
        if hp.has_release():
            hp.update_changelog_and_version()
        pip_tool(
            # See https://www.sphinx-doc.org/en/stable/man/sphinx-build.html
            "sphinx-build",
            "-n",
            "-W",
            "--keep-going",
            "-T",
            "-E",
            "-b",
            "html",
            "docs",
            "docs/_build/html",
            cwd=hp.HYPOTHESIS_PYTHON,
        )
    finally:
        subprocess.check_call(
            ["git", "checkout", "docs/changes.rst", "src/hypothesis/version.py"],
            cwd=hp.HYPOTHESIS_PYTHON,
        )
Пример #22
0
def test_bandit_passes_on_hypothesis():
    # pypi.org/project/bandit has the table of error codes, or `bandit --help`
    pip_tool('bandit', '--skip', 'B101,B102,B110,B303,B311', '--recursive',
             PYTHON_SRC)
Пример #23
0
def test_bandit_passes_on_hypothesis():
    # pypi.org/project/bandit has the table of error codes, or `bandit --help`
    # Note that e.g. the hash type is important for users subject to FIPS-140.
    pip_tool("bandit", "--skip=B101,B102,B110,B311", "--recursive", PYTHON_SRC)
Пример #24
0
def test_mypy_passes_on_hypothesis():
    pip_tool("mypy", PYTHON_SRC)
Пример #25
0
def test_pyright_passes_on_hypothesis():
    pip_tool("pyright", "--project", HYPOTHESIS_PYTHON)
Пример #26
0
def test_passes_flake8():
    pip_tool('flake8', '--select=W191,W291,W292,W293,W391', *ALL_RST)
Пример #27
0
def test_bandit_passes_on_hypothesis():
    # pypi.org/project/bandit has the table of error codes, or `bandit --help`
    pip_tool('bandit', '--skip', 'B101,B102,B110,B303,B311',
             '--recursive', PYTHON_SRC)
Пример #28
0
def format():
    def should_format_file(path):
        if os.path.basename(path) in ('header.py',
                                      'test_lambda_formatting.py'):
            return False
        if 'vendor' in path.split(os.path.sep):
            return False
        return path.endswith('.py')

    changed = tools.modified_files()

    format_all = os.environ.get('FORMAT_ALL', '').lower() == 'true'
    if 'scripts/header.py' in changed:
        # We've changed the header, so everything needs its header updated.
        format_all = True
    if 'requirements/tools.txt' in changed:
        # We've changed the tools, which includes a lot of our formatting
        # logic, so we need to rerun formatters.
        format_all = True

    files = tools.all_files() if format_all else changed

    files_to_format = [f for f in sorted(files) if should_format_file(f)]

    if not files_to_format:
        return

    for f in files_to_format:
        print(f)
        lines = []
        with open(f, encoding='utf-8') as o:
            shebang = None
            first = True
            header_done = False
            for l in o.readlines():
                if first:
                    first = False
                    if l[:2] == '#!':
                        shebang = l
                        continue
                if 'END HEADER' in l and not header_done:
                    lines = []
                    header_done = True
                else:
                    lines.append(l)
        source = ''.join(lines).strip()
        with open(f, 'w', encoding='utf-8') as o:
            if shebang is not None:
                o.write(shebang)
                o.write('\n')
            o.write(HEADER)
            if source:
                o.write('\n\n')
                o.write(source)
            o.write('\n')
    pip_tool(
        'isort',
        '-p',
        'hypothesis',
        '-ls',
        '-m',
        '2',
        '-w',
        '75',
        '-a',
        'from __future__ import absolute_import, print_function, division',
        *files_to_format,
    )

    pip_tool('pyformat', '-i', *files_to_format)
Пример #29
0
def check_rst():
    rst = glob('*.rst') + glob('guides/*.rst')
    docs = glob('hypothesis-python/docs/*.rst')

    pip_tool('rst-lint', *rst)
    pip_tool('flake8', '--select=W191,W291,W292,W293,W391', *(rst + docs))
Пример #30
0
def check_type_hints():
    pip_tool('mypy', hp.PYTHON_SRC)
Пример #31
0
def test_passes_rst_lint():
    pip_tool("rst-lint", *[f for f in ALL_RST if not is_sphinx(f)])
Пример #32
0
def lint():
    pip_tool(
        'flake8',
        *[f for f in tools.all_files() if f.endswith('.py')],
        '--config', os.path.join(tools.ROOT, '.flake8'),
    )
Пример #33
0
def format():
    def should_format_file(path):
        if os.path.basename(path) in (
            'header.py', 'test_lambda_formatting.py'
        ):
            return False
        if 'vendor' in path.split(os.path.sep):
            return False
        return path.endswith('.py')

    changed = tools.modified_files()

    format_all = os.environ.get('FORMAT_ALL', '').lower() == 'true'
    if 'scripts/header.py' in changed:
        # We've changed the header, so everything needs its header updated.
        format_all = True
    if 'requirements/tools.txt' in changed:
        # We've changed the tools, which includes a lot of our formatting
        # logic, so we need to rerun formatters.
        format_all = True

    files = tools.all_files() if format_all else changed

    files_to_format = [f for f in sorted(files) if should_format_file(f)]

    if not files_to_format:
        return

    for f in files_to_format:
        print(f)
        lines = []
        with open(f, encoding='utf-8') as o:
            shebang = None
            first = True
            header_done = False
            for l in o.readlines():
                if first:
                    first = False
                    if l[:2] == '#!':
                        shebang = l
                        continue
                if 'END HEADER' in l and not header_done:
                    lines = []
                    header_done = True
                else:
                    lines.append(l)
        source = ''.join(lines).strip()
        with open(f, 'w', encoding='utf-8') as o:
            if shebang is not None:
                o.write(shebang)
                o.write('\n')
            o.write(HEADER)
            if source:
                o.write('\n\n')
                o.write(source)
            o.write('\n')
    pip_tool(
        'isort', '-p', 'hypothesis', '-ls', '-m', '2', '-w', '75', '-a',
        'from __future__ import absolute_import, print_function, division',
        *files_to_format,
    )

    pip_tool('pyformat', '-i', *files_to_format)
def test_passes_flake8():
    pip_tool("flake8", "--select=W191,W291,W292,W293,W391", *ALL_RST)
Пример #35
0
def test_passes_flake8():
    pip_tool("flake8", "--select=W191,W291,W292,W293,W391", *ALL_RST)
Пример #36
0
def test_mypy_passes_on_hypothesis_strict():
    pip_tool("mypy", "--strict", PYTHON_SRC)
Пример #37
0
def format():
    def should_format_file(path):
        return path.endswith(".py")

    def should_format_doc_file(path):
        return path.endswith((".rst", ".md"))

    changed = tools.modified_files()

    format_all = os.environ.get("FORMAT_ALL", "").lower() == "true"
    if "requirements/tools.txt" in changed:
        # We've changed the tools, which includes a lot of our formatting
        # logic, so we need to rerun formatters.
        format_all = True

    files = tools.all_files() if format_all else changed

    doc_files_to_format = [f for f in sorted(files) if should_format_doc_file(f)]
    pip_tool("blacken-docs", *doc_files_to_format)

    files_to_format = [f for f in sorted(files) if should_format_file(f)]

    if not files_to_format:
        return

    # .coveragerc lists several regex patterns to treat as nocover pragmas, and
    # we want to find (and delete) cases where # pragma: no cover is redundant.
    def warn(msg):
        raise Exception(msg)

    config = CoverageConfig()
    config.from_file(os.path.join(hp.BASE_DIR, ".coveragerc"), warn=warn, our_file=True)
    pattern = "|".join(l for l in config.exclude_list if "pragma" not in l)
    unused_pragma_pattern = re.compile(f"(({pattern}).*)  # pragma: no (branch|cover)")

    for f in files_to_format:
        lines = []
        with open(f, encoding="utf-8") as o:
            shebang = None
            first = True
            header_done = False
            for l in o.readlines():
                if first:
                    first = False
                    if l[:2] == "#!":
                        shebang = l
                        continue
                if "END HEADER" in l and not header_done:
                    lines = []
                    header_done = True
                else:
                    lines.append(unused_pragma_pattern.sub(r"\1", l))
        source = "".join(lines).strip()
        with open(f, "w", encoding="utf-8") as o:
            if shebang is not None:
                o.write(shebang)
                o.write("\n")
            o.write(HEADER)
            if source:
                o.write("\n\n")
                o.write(source)
            o.write("\n")

    codespell("--write-changes", *files_to_format, *doc_files_to_format)
    pip_tool("shed", *files_to_format, *doc_files_to_format)
Пример #38
0
def format():
    def should_format_file(path):
        if "vendor" in path.split(os.path.sep):
            return False
        return path.endswith(".py")

    changed = tools.modified_files()

    format_all = os.environ.get("FORMAT_ALL", "").lower() == "true"
    if "requirements/tools.txt" in changed:
        # We've changed the tools, which includes a lot of our formatting
        # logic, so we need to rerun formatters.
        format_all = True

    files = tools.all_files() if format_all else changed

    files_to_format = [f for f in sorted(files) if should_format_file(f)]

    if not files_to_format:
        return

    for f in files_to_format:
        lines = []
        with open(f, encoding="utf-8") as o:
            shebang = None
            first = True
            header_done = False
            for l in o.readlines():
                if first:
                    first = False
                    if l[:2] == "#!":
                        shebang = l
                        continue
                if "END HEADER" in l and not header_done:
                    lines = []
                    header_done = True
                else:
                    lines.append(l)
        source = "".join(lines).strip()
        with open(f, "w", encoding="utf-8") as o:
            if shebang is not None:
                o.write(shebang)
                o.write("\n")
            o.write(HEADER)
            if source:
                o.write("\n\n")
                o.write(source)
            o.write("\n")

    pip_tool(
        "autoflake",
        "--recursive",
        "--in-place",
        "--exclude=compat.py",
        "--remove-all-unused-imports",
        "--remove-duplicate-keys",
        "--remove-unused-variables",
        *files_to_format,
    )
    pip_tool("pyupgrade", "--keep-percent-format", *files_to_format)
    pip_tool("isort", *files_to_format)
    pip_tool("black", *files_to_format)
Пример #39
0
def format():
    def should_format_file(path):
        if "vendor" in path.split(os.path.sep):
            return False
        return path.endswith(".py")

    def should_format_doc_file(path):
        return path.endswith((".rst", ".md"))

    changed = tools.modified_files()

    format_all = os.environ.get("FORMAT_ALL", "").lower() == "true"
    if "requirements/tools.txt" in changed:
        # We've changed the tools, which includes a lot of our formatting
        # logic, so we need to rerun formatters.
        format_all = True

    files = tools.all_files() if format_all else changed

    doc_files_to_format = [
        f for f in sorted(files) if should_format_doc_file(f)
    ]
    pip_tool("blacken-docs", *doc_files_to_format)

    files_to_format = [f for f in sorted(files) if should_format_file(f)]

    if not files_to_format:
        return

    for f in files_to_format:
        lines = []
        with open(f, encoding="utf-8") as o:
            shebang = None
            first = True
            header_done = False
            for l in o.readlines():
                if first:
                    first = False
                    if l[:2] == "#!":
                        shebang = l
                        continue
                if "END HEADER" in l and not header_done:
                    lines = []
                    header_done = True
                else:
                    lines.append(l)
        source = "".join(lines).strip()
        with open(f, "w", encoding="utf-8") as o:
            if shebang is not None:
                o.write(shebang)
                o.write("\n")
            o.write(HEADER)
            if source:
                o.write("\n\n")
                o.write(source)
            o.write("\n")

    pip_tool(
        "autoflake",
        "--recursive",
        "--in-place",
        "--exclude=compat.py",
        "--remove-all-unused-imports",
        "--remove-duplicate-keys",
        "--remove-unused-variables",
        *files_to_format,
    )
    pip_tool("pyupgrade", "--keep-percent-format", *files_to_format)
    pip_tool("isort", *files_to_format)
    pip_tool("black", *files_to_format)
Пример #40
0
def format():
    def should_format_file(path):
        return path.endswith(".py")

    def should_format_doc_file(path):
        return path.endswith((".rst", ".md"))

    changed = tools.modified_files()

    format_all = os.environ.get("FORMAT_ALL", "").lower() == "true"
    if "requirements/tools.txt" in changed:
        # We've changed the tools, which includes a lot of our formatting
        # logic, so we need to rerun formatters.
        format_all = True

    files = tools.all_files() if format_all else changed

    doc_files_to_format = [
        f for f in sorted(files) if should_format_doc_file(f)
    ]
    pip_tool("blacken-docs", *doc_files_to_format)

    files_to_format = [f for f in sorted(files) if should_format_file(f)]

    if not files_to_format:
        return

    # .coveragerc lists several regex patterns to treat as nocover pragmas, and
    # we want to find (and delete) cases where # pragma: no cover is redundant.
    config = CoverageConfig()
    config.from_file(os.path.join(hp.BASE_DIR, ".coveragerc"), our_file=True)
    pattern = "|".join(l for l in config.exclude_list if "pragma" not in l)
    unused_pragma_pattern = re.compile(f"({pattern}).*# pragma: no cover")

    for f in files_to_format:
        lines = []
        with open(f, encoding="utf-8") as o:
            shebang = None
            first = True
            header_done = False
            for l in o.readlines():
                if first:
                    first = False
                    if l[:2] == "#!":
                        shebang = l
                        continue
                if "END HEADER" in l and not header_done:
                    lines = []
                    header_done = True
                elif unused_pragma_pattern.search(l) is not None:
                    lines.append(l.replace("# pragma: no cover", ""))
                else:
                    lines.append(l)
        source = "".join(lines).strip()
        with open(f, "w", encoding="utf-8") as o:
            if shebang is not None:
                o.write(shebang)
                o.write("\n")
            o.write(HEADER)
            if source:
                o.write("\n\n")
                o.write(source)
            o.write("\n")

    pip_tool(
        "autoflake",
        "--recursive",
        "--in-place",
        "--exclude=compat.py",
        "--remove-all-unused-imports",
        "--remove-duplicate-keys",
        "--remove-unused-variables",
        *files_to_format,
    )
    pip_tool("pyupgrade", "--keep-percent-format", "--py36-plus",
             *files_to_format)
    pip_tool("isort", *files_to_format)
    pip_tool("black", "--target-version=py36", *files_to_format)
Пример #41
0
def test_mypy_passes_on_hypothesis():
    pip_tool('mypy', PYTHON_SRC)
Пример #42
0
def test_passes_flake8():
    pip_tool('flake8', '--select=W191,W291,W292,W293,W391', *ALL_RST)
def test_passes_rst_lint():
    pip_tool("rst-lint", *[f for f in ALL_RST if not is_sphinx(f)])