# Path: pyp2rpm/name_convertor.py
# class NameConvertor(object):
#     distro = settings.DEFAULT_TEMPLATE
# 
#     def __init__(self, distro):
#         self.distro = distro
#         self.reg_start = re.compile(r'^[Pp]ython(\d*|)-(.*)')
#         self.reg_end = re.compile(r'(.*)-(python)(\d*|)$')
# 
#     @classmethod
#     def get_default_py_version(cls):
#         try:
#             return settings.DEFAULT_PYTHON_VERSIONS[cls.distro][0]
#         except KeyError:
#             logger.error('Default python versions for template {0} are '
#                          'missing in settings, using versions of template '
#                          '{1}.'.format(cls.distro,
#                                        settings.DEFAULT_TEMPLATE))
#             return settings.DEFAULT_PYTHON_VERSIONS[
#                 settings.DEFAULT_TEMPLATE][0]
# 
#     @classmethod
#     def rpm_versioned_name(cls, name, version, default_number=False,
#                            use_macros=False):
#         """Properly versions the name.
#         For example:
#         rpm_versioned_name('python-foo', '26') will return python26-foo
#         rpm_versioned_name('pyfoo, '3') will return python3-pyfoo
# 
#         If version is same as settings.DEFAULT_PYTHON_VERSION, no change
#         is done.
# 
#         Args:
#             name: name to version
#             version: version or None
#         Returns:
#             Versioned name or the original name if given version is None.
#         """
#         regexp = re.compile(r'^python(\d*|)-(.*)')
#         auto_provides_regexp = re.compile(r'^python(\d*|)dist(.*)')
# 
#         if (not version or version == cls.get_default_py_version() and
#                 not default_number):
#             found = regexp.search(name)
#             # second check is to avoid renaming of python2-devel to
#             # python-devel
#             if found and found.group(2) != 'devel':
#                 if 'epel' not in cls.distro:
#                     return 'python-{0}'.format(regexp.search(name).group(2))
#             return name
# 
#         versioned_name = name
#         if version:
# 
#             if regexp.search(name):
#                 versioned_name = re.sub(r'^python(\d*|)-', 'python{0}-'.format(
#                     version), name)
#             elif auto_provides_regexp.search(name):
#                 versioned_name = re.sub(
#                     r'^python(\d*|)dist', 'python{0}dist'.format(
#                         version), name)
# 
#             else:
#                 versioned_name = 'python{0}-{1}'.format(version, name)
#             if (use_macros and 'epel' in cls.distro and version !=
#                     cls.get_default_py_version()):
#                 versioned_name = versioned_name.replace('python{0}-'.format(
#                     version), 'python%{{python{0}_pkgversion}}-'.format(version))
#         return versioned_name
# 
#     def rpm_name(self, name, python_version=None, pkg_name=False):
#         """Returns name of the package converted to (possibly) correct package
#            name according to Packaging Guidelines.
#         Args:
#             name: name to convert
#             python_version: python version for which to retrieve the name of
#                             the package
#             pkg_name: flag to perform conversion of rpm package name,
#                       present in this class just for API compatibility reason
#         Returns:
#             Converted name of the package, that should be in line with
#             Fedora Packaging Guidelines. If for_python is not None,
#             the returned name is in form python%(version)s-%(name)s
#         """
#         logger.debug("Converting name: {0} to rpm name, version: {1}.".format(
#             name, python_version))
#         rpmized_name = self.base_name(name)
# 
#         rpmized_name = 'python-{0}'.format(rpmized_name)
# 
#         if self.distro == 'mageia':
#             rpmized_name = rpmized_name.lower()
#         logger.debug('Rpmized name of {0}: {1}.'.format(name, rpmized_name))
#         return NameConvertor.rpm_versioned_name(rpmized_name, python_version)
# 
#     def base_name(self, name):
#         """Removes any python prefixes of suffixes from name if present."""
#         base_name = name.replace('.', "-")
#         # remove python prefix if present
#         found_prefix = self.reg_start.search(name)
#         if found_prefix:
#             base_name = found_prefix.group(2)
# 
#         # remove -pythonXY like suffix if present
#         found_end = self.reg_end.search(name.lower())
#         if found_end:
#             base_name = found_end.group(1)
# 
#         return base_name
# 
# Path: pyp2rpm/settings.py
# DEFAULT_DISTRO = 'fedora'
# 
# DEFAULT_PYTHON_VERSION = DEFAULT_PYTHON_VERSIONS[DEFAULT_TEMPLATE][0]


import os
import pytest
import shutil
import sys
import tempfile
from flexmock import flexmock
    from pyp2rpm.virtualenv import (DirsContent,
                                    VirtualEnv,
                                    site_packages_filter,
                                    scripts_filter)
from pyp2rpm.name_convertor import NameConvertor
from pyp2rpm.settings import DEFAULT_DISTRO, DEFAULT_PYTHON_VERSION
try:
except ImportError:
    VirtualEnv = None

pytestmark = pytest.mark.skipif(VirtualEnv is None,
                                reason="virtualenv-api not installed")


# Path: pyp2rpm/name_convertor.py
# class NameConvertor(object):
#     distro = settings.DEFAULT_TEMPLATE
# 
#     def __init__(self, distro):
#         self.distro = distro
#         self.reg_start = re.compile(r'^[Pp]ython(\d*|)-(.*)')
#         self.reg_end = re.compile(r'(.*)-(python)(\d*|)$')
# 
#     @classmethod
#     def get_default_py_version(cls):
#         try:
#             return settings.DEFAULT_PYTHON_VERSIONS[cls.distro][0]
#         except KeyError:
#             logger.error('Default python versions for template {0} are '
#                          'missing in settings, using versions of template '
#                          '{1}.'.format(cls.distro,
#                                        settings.DEFAULT_TEMPLATE))
#             return settings.DEFAULT_PYTHON_VERSIONS[
#                 settings.DEFAULT_TEMPLATE][0]
# 
#     @classmethod
#     def rpm_versioned_name(cls, name, version, default_number=False,
#                            use_macros=False):
#         """Properly versions the name.
#         For example:
#         rpm_versioned_name('python-foo', '26') will return python26-foo
#         rpm_versioned_name('pyfoo, '3') will return python3-pyfoo
# 
#         If version is same as settings.DEFAULT_PYTHON_VERSION, no change
#         is done.
# 
#         Args:
#             name: name to version
#             version: version or None
#         Returns:
#             Versioned name or the original name if given version is None.
#         """
#         regexp = re.compile(r'^python(\d*|)-(.*)')
#         auto_provides_regexp = re.compile(r'^python(\d*|)dist(.*)')
# 
#         if (not version or version == cls.get_default_py_version() and
#                 not default_number):
#             found = regexp.search(name)
#             # second check is to avoid renaming of python2-devel to
#             # python-devel
#             if found and found.group(2) != 'devel':
#                 if 'epel' not in cls.distro:
#                     return 'python-{0}'.format(regexp.search(name).group(2))
#             return name
# 
#         versioned_name = name
#         if version:
# 
#             if regexp.search(name):
#                 versioned_name = re.sub(r'^python(\d*|)-', 'python{0}-'.format(
#                     version), name)
#             elif auto_provides_regexp.search(name):
#                 versioned_name = re.sub(
#                     r'^python(\d*|)dist', 'python{0}dist'.format(
#                         version), name)
# 
#             else:
#                 versioned_name = 'python{0}-{1}'.format(version, name)
#             if (use_macros and 'epel' in cls.distro and version !=
#                     cls.get_default_py_version()):
#                 versioned_name = versioned_name.replace('python{0}-'.format(
#                     version), 'python%{{python{0}_pkgversion}}-'.format(version))
#         return versioned_name
# 
#     def rpm_name(self, name, python_version=None, pkg_name=False):
#         """Returns name of the package converted to (possibly) correct package
#            name according to Packaging Guidelines.
#         Args:
#             name: name to convert
#             python_version: python version for which to retrieve the name of
#                             the package
#             pkg_name: flag to perform conversion of rpm package name,
#                       present in this class just for API compatibility reason
#         Returns:
#             Converted name of the package, that should be in line with
#             Fedora Packaging Guidelines. If for_python is not None,
#             the returned name is in form python%(version)s-%(name)s
#         """
#         logger.debug("Converting name: {0} to rpm name, version: {1}.".format(
#             name, python_version))
#         rpmized_name = self.base_name(name)
# 
#         rpmized_name = 'python-{0}'.format(rpmized_name)
# 
#         if self.distro == 'mageia':
#             rpmized_name = rpmized_name.lower()
#         logger.debug('Rpmized name of {0}: {1}.'.format(name, rpmized_name))
#         return NameConvertor.rpm_versioned_name(rpmized_name, python_version)
# 
#     def base_name(self, name):
#         """Removes any python prefixes of suffixes from name if present."""
#         base_name = name.replace('.', "-")
#         # remove python prefix if present
#         found_prefix = self.reg_start.search(name)
#         if found_prefix:
#             base_name = found_prefix.group(2)
# 
#         # remove -pythonXY like suffix if present
#         found_end = self.reg_end.search(name.lower())
#         if found_end:
#             base_name = found_end.group(1)
# 
#         return base_name
# 
# Path: pyp2rpm/settings.py
# DEFAULT_DISTRO = 'fedora'
# 
# DEFAULT_PYTHON_VERSION = DEFAULT_PYTHON_VERSIONS[DEFAULT_TEMPLATE][0]


# Path: tests/test_virtualenv.py
import os
import pytest
import shutil
import sys
import tempfile
from flexmock import flexmock
    from pyp2rpm.virtualenv import (DirsContent,
                                    VirtualEnv,
                                    site_packages_filter,
                                    scripts_filter)
from pyp2rpm.name_convertor import NameConvertor
from pyp2rpm.settings import DEFAULT_DISTRO, DEFAULT_PYTHON_VERSION

try:
except ImportError:
    VirtualEnv = None

pytestmark = pytest.mark.skipif(VirtualEnv is None,
                                reason="virtualenv-api not installed")


tests_dir = os.path.split(os.path.abspath(__file__))[0]