# Path: venv_update.py
# def colorize(cmd):
#     from os import isatty
# 
#     if isatty(1):
#         template = '\033[36m>\033[m \033[32m{0}\033[m'
#     else:
#         template = '> {0}'
# 
#     return template.format(shellescape(cmd))


import os
import socket
import subprocess
import sys
import time
import pytest
import six
from contextlib import contextmanager
from errno import ECONNREFUSED
from ephemeral_port_reserve import reserve
from testing import run
from testing import TOP
from venv_update import colorize
    from sys import executable
    from os import defpath
    from os.path import dirname
        from _pytest.assertion.util import assertrepr_compare
            sys.executable,
            'tests/testing/make_sdists.py',
            'tests/testing/packages',
            '.',  # we need venv-update to be installable too
            str(package_temp),
        )

    yield package_temp


@pytest.fixture(scope='session')
def pypi_port():
    yield reserve()


@contextmanager
def start_pypi_server(packages, port, pypi_fallback):
    port = str(port)
    cmd = (
        'pypi-server', '-v',
        '-i', '127.0.0.1',
        '-p', port,
        # Default fallback is HTTP, which is no longer supported.
        # TODO: revert after a new pypiserver is released with this patch:
        # https://github.com/pypiserver/pypiserver/pull/182
        '--fallback-url', 'https://pypi.python.org/simple',
    )
    if not pypi_fallback:
        cmd += ('--disable-fallback',)
    cmd += (str(packages),)

# Path: venv_update.py
# def colorize(cmd):
#     from os import isatty
# 
#     if isatty(1):
#         template = '\033[36m>\033[m \033[32m{0}\033[m'
#     else:
#         template = '> {0}'
# 
#     return template.format(shellescape(cmd))


# Path: tests/conftest.py
import os
import socket
import subprocess
import sys
import time
import pytest
import six
from contextlib import contextmanager
from errno import ECONNREFUSED
from ephemeral_port_reserve import reserve
from testing import run
from testing import TOP
from venv_update import colorize
    from sys import executable
    from os import defpath
    from os.path import dirname
        from _pytest.assertion.util import assertrepr_compare

            sys.executable,
            'tests/testing/make_sdists.py',
            'tests/testing/packages',
            '.',  # we need venv-update to be installable too
            str(package_temp),
        )

    yield package_temp


@pytest.fixture(scope='session')
def pypi_port():
    yield reserve()


@contextmanager
def start_pypi_server(packages, port, pypi_fallback):
    port = str(port)
    cmd = (
        'pypi-server', '-v',
        '-i', '127.0.0.1',
        '-p', port,
        # Default fallback is HTTP, which is no longer supported.
        # TODO: revert after a new pypiserver is released with this patch:
        # https://github.com/pypiserver/pypiserver/pull/182
        '--fallback-url', 'https://pypi.python.org/simple',
    )
    if not pypi_fallback:
        cmd += ('--disable-fallback',)
    cmd += (str(packages),)

    print(colorize(cmd))