Example #1
0
def downgrade_files(files):
    # Check and prepare 3to2 module.
    try:
        from lib3to2.main import main as lib3to2_main
    except ImportError:
        try:
            from pip import main as pipmain
        except:
            from pip._internal import main as pipmain

        pipmain(['install', '3to2'])

        from lib3to2.main import main as lib3to2_main

    if len(files) > 0:
        options = [
            "-f",
            "all",
            # FIXME: It will trigger AssertionError: Sanity check failed: 0xFFFFFFFF
            # "-f", "int",
            "-f",
            "collections",
            "-f",
            "memoryview",
            "-f",
            "printfunction",
            "-f",
            "unittest",
            "-w",
            "-n",
            "--no-diffs",
        ]
        options += files

        lib3to2_main("lib3to2.fixes", options)
Example #2
0
def upgrade():
    package = 'rlbot'

    import importlib
    import os
    folder = os.path.dirname(os.path.realpath(__file__))

    try:
        # https://stackoverflow.com/a/24773951
        importlib.import_module(package)

        from rlbot.utils import public_utils, logging_utils

        logger = logging_utils.get_logger(DEFAULT_LOGGER)
        if not public_utils.have_internet():
            logger.log(logging_utils.logging_level,
                       'Skipping upgrade check for now since it looks like you have no internet')
        elif public_utils.is_safe_to_upgrade():
            # Upgrade only the rlbot-related stuff.
            rlbot_requirements = os.path.join(folder, 'rlbot-requirements.txt')
            pipmain(['install', '-r', rlbot_requirements, '--upgrade'])

    except (ImportError, ModuleNotFoundError):
        # First time installation, install lots of stuff
        all_requirements = os.path.join(folder, 'requirements.txt')
        pipmain(['install', '-r', all_requirements])
Example #3
0
def cp_cmd(project_name, example, no_dependencies, with_docs, quiet):
    '''
    Create an algorithm project.
    '''

    if example:
        exmpl_path = os.path.join(this_path, 'examples', 'project')
        shutil.copytree(exmpl_path, project_name)
        path = os.path.abspath(project_name)
        generate_settings(this_path, path)
        if no_dependencies:
            click.echo('Skipping dependencies...')
        else:
            try:
                from pip import main as pipmain
            except ImportError:
                from pip._internal import main as pipmain

            reqs = os.path.join(exmpl_path, 'requirements.txt')
            pip_options = ['install', '-r', reqs]
            if quiet:
                pip_options += ['-q']
            pipmain(pip_options)
    else:
        os.mkdir(project_name)
        path = os.path.abspath(project_name)

        create_file(project_name, this_path, path, 'licenses', '.json')
        create_file(project_name, this_path, path, 'config')
        create_file(project_name, this_path, path, '__init__')
        create_file(project_name, this_path, path, 'run')
        create_file('', this_path, path, 'gitignore', '.')

        generate_settings(this_path, path)

        os.mkdir(os.path.join(path, 'algorithms'))
        create_file(project_name, this_path, os.path.join(path, 'algorithms'),
                    '__init__')

        os.mkdir(os.path.join(path, 'chains'))

        os.mkdir(os.path.join(path, 'logs'))
        logpath = os.path.join(path, 'logs')
        filename = os.path.join(logpath, 'app.log')
        with open(filename, 'a'):
            os.utime(filename, None)

    if with_docs:
        docs_path = os.path.join(
            os.path.abspath(os.path.join(this_path, os.pardir)), 'docs')
        dest_path = os.path.join(path, 'docs')
        if not os.path.exists(dest_path):
            os.mkdir(dest_path)
        cmd = 'sphinx-build ' + docs_path + ' ' + dest_path
        if quiet:
            cmd += ' -q'
        subprocess.call(cmd, shell=True)

    if not quiet:
        click.echo('Project created!')
Example #4
0
def install_requirements():
    """
    Install non-colliding dependencies from a "requirements.txt" file found at
    the content root.
    """

    reqfile = None
    if os.path.exists('deconst-requirements.txt'):
        reqfile = 'deconst-requirements.txt'
    elif os.path.exists('requirements.txt'):
        reqfile = 'requirements.txt'
    else:
        return

    dependencies = []

    with open(reqfile, 'r', encoding='utf-8') as rf:
        for line in rf:
            if line.startswith('#'):
                continue

            stripped = line.strip()
            if not stripped:
                continue

            dependencies.append(stripped)

    print("Installing dependencies from {}: {}.".format(
        reqfile, ', '.join(dependencies)))
    pipmain(['install'] + dependencies)
Example #5
0
def install_package(package_name):
    try:
        from pip import main as pipmain
    except ImportError:
        from pip._internal import main as pipmain

    pipmain(['install', package_name])
Example #6
0
def main():
    install_and_import('rlbot')
    from rlbot.utils import public_utils, logging_utils
    logger = logging_utils.get_logger(DEFAULT_LOGGER)
    if not public_utils.have_internet():
        logger.log(logging_utils.logging_level, 'Skipping upgrade check for now since it looks like you have no internet')
    elif public_utils.is_safe_to_upgrade():
        pipmain(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager'])

    try:
        import sys
        import os

        path = os.path.dirname(os.path.abspath(__file__))
        sys.path.insert(0, path)  # this is for first process imports

        if len(sys.argv) > 1 and sys.argv[1] == 'gui':
            from rlbot.gui.qt_root import RLBotQTGui
            RLBotQTGui.main()
        else:
            from rlbot import runner
            runner.main()
    except Exception as e:
        print("Encountered exception: ", e)
        print("Press enter to close.")
        input()
Example #7
0
 def install(self):
     """
     Install this package in the current env.
     We always specify the version, we cant be sure we are the latest one
     or that the user wants to install any other available.
     """
     pkg_string = "%s==%s" % (self.name, self.version)
     pipmain(["install", "-q", pkg_string])
Example #8
0
def installer(program):
    try:
        from pip import main as pipmain
    except:
        print("[*]Pip not installed")
        exit()
    pipmain(['install', program])
    exit()
Example #9
0
    def install_package(package: str):
        """Installs a package that is normally only used
        by a test configuration.

        Arguments:
            package {str} -- Name of the PIP package.
        """
        pipmain(["install", package])
Example #10
0
 def install(self):
     """
     Install this package in the current env.
     We always specify the version, we cant be sure we are the latest one
     or that the user wants to install any other available.
     """
     pkg_string = "%s==%s" % (self.name, self.version)
     pipmain(["install", "-q", pkg_string])
Example #11
0
def install_and_import(package):
    import importlib

    try:
        importlib.import_module(package)
    except ImportError:
        pipmain(['install', package])
    finally:
        globals()[package] = importlib.import_module(package)
Example #12
0
    def install(self, package):
        # Debugging
        # pip.main(["install", "--pre", "--upgrade", "--no-index",
        #         "--find-links=.", package, "--log-file", "log.txt", "-vv"])

        pipmain([
            "install", "--upgrade", "--no-index",
            "--find-links={}".format(self.package_repos), package
        ])
        pass
Example #13
0
def _pre_install(dir):
    from subprocess import check_call
    check_call(['./setup.sh'], shell=True, cwd=os.getcwd())

    # Install local version of Jericho
    try:
        from pip import main as pipmain
    except:
        from pip._internal import main as pipmain
    pipmain(['install', os.path.join(os.getcwd(), "jericho")])
Example #14
0
def install(module_name):
    from logging import warning
    try:
        try:
            from pip import main as pipmain
        except ImportError:
            from pip._internal.main import main as pipmain
        pipmain(['install', module_name])
    except Exception as x:
        warning("caproto: %s" % x)
Example #15
0
def checkPackages():
    # If Windows NT
    extra_packages = {
        "nt" : ['pywin32', 'pywin32-ctypes', 'opencv-python', 'cmake', 'PyInstaller'],
        "linux" : ['opencv-python'],
    }
    for system in extra_packages:
        if system in os.name:
            for package in extra_packages[system]:
                if not package in sys.modules:
                    pipmain(['install', package])
def use_pydgutils():
    try:
        import pydgutils
    except:
        use_pip()
        try:
            from pip import main as pipmain
        except:
            from pip._internal import main as pipmain

        pipmain(["install", "pydgutils"])
Example #17
0
def installer(program):
  print("Unable to import module %s. Would you like to install it?" % program)
  resp = input("(y/n) ")
  try:
    if str(resp.lower()) == 'y':
      from pip import main as pipmain
      pipmain(['install', program])
      print("Install successful. Exiting")
      exit()
  except:
    print("Unable to install %s with pip3" % program)
    exit()
Example #18
0
def install_and_import(package):
    import importlib
    try:
        importlib.import_module(package)
    except ImportError:
        try:
            from pip import main as pipmain
        except:
            from pip._internal import main as pipmain
        pipmain(['install', '--proxy=' + HTTPS_PROXY, package])
    finally:
        globals()[package] = importlib.import_module(package)
Example #19
0
def import_try_install(package, extern_url=None):
    """Try import the specified package.
    If the package not installed, try use pip to install and import if success.

    Parameters
    ----------
    package : str
        The name of the package trying to import.
    extern_url : str or None, optional
        The external url if package is not hosted on PyPI.
        For example, you can install a package using:
         "pip install git+http://github.com/user/repo/tarball/master/egginfo=xxx".
        In this case, you can pass the url to the extern_url.

    Returns
    -------
    <class 'Module'>
        The imported python module.

    """
    import tempfile
    import portalocker
    lockfile = os.path.join(tempfile.gettempdir(), package + '_install.lck')
    with portalocker.Lock(lockfile):
        try:
            return __import__(package)
        except ImportError:
            try:
                from pip import main as pipmain
            except ImportError:
                from pip._internal import main as pipmain
                from types import ModuleType
                # fix for pip 19.3
                if isinstance(pipmain, ModuleType):
                    from pip._internal.main import main as pipmain

            # trying to install package
            url = package if extern_url is None else extern_url
            pipmain(['install', '--user',
                     url])  # will raise SystemExit Error if fails

            # trying to load again
            try:
                return __import__(package)
            except ImportError:
                import sys
                import site
                user_site = site.getusersitepackages()
                if user_site not in sys.path:
                    sys.path.append(user_site)
                return __import__(package)
    return __import__(package)
Example #20
0
def install_package(package_name):
    '''
    Installs package with pip
    Params:
        package_name - name of package which needs to be installed
    '''
    #old versions of python compatibility
    try:
        from pip import main as pipmain
    except ImportError:
        from pip._internal import main as pipmain

    pipmain(['install', package_name])
Example #21
0
def maybe_update(module_, required_version):
    def outdated(expected, actual):
        for num1, num2 in zip(
                *map(lambda v: v.split('.'), (expected, actual))):
            if int(num1) > int(num2):
                return True
        else:
            return False

    if outdated(required_version, module_.__version__):
        pipmain(
            ['install', '--upgrade', '--target', 'lib', module_.__package__])
        importlib.reload(module_)
Example #22
0
 def local_install(package_name):
     Helpers.prepare_folders()
     pipmain(['install', 'setuptools'])
     pipmain(['install', 'wget'])
     tmp_folder_4_downloads = tempfile.mkdtemp()
     tmp_folder_4_extracted = tempfile.mkdtemp()
     apt_output = subprocess.check_output('apt-get --print-uris --yes -d --reinstall --no-install-recommends install '+package_name, shell=True)
     package_links = re.findall(r'http:\/\/[\w\d\.\-\/]+\.deb', str(apt_output))
     for link in package_links:
         print(f"Getting {link}...")
         package_filename = os.path.basename(urlparse(link).path)
         target_path = os.path.join(tmp_folder_4_downloads, package_filename)
         wget.download(link, target_path)
         apt_inst.deb_extract_archive(target_path, tmp_folder_4_extracted)
Example #23
0
def intellImport(package):
    if hasattr(package, "__len__") and (not isinstance(package, str)):
        package = list(package)
        for each in package:
            try:
                __import__(each)
            except ImportError:
                pipmain(['install', each])
                __import__(each)
    else:
        try:
            __import__(package)
        except ImportError:
            pipmain(['install', package])
            __import__(package)
Example #24
0
def checkPackages():
    # If Linux
    extra_packages = {
        "linux-apt": ['build-essential', 'cmake', 'libopenblas-dev', 'liblapack-dev', 'libx11-dev', 'libgtk-3-dev'],
        "linux": ['dlib'],
    }
    for system in extra_packages:
        if os.name in system:
            if '-apt' in system:
                for package in extra_packages[system]:
                    if not package in sys.modules:
                        subprocess.run('apt install {p}'.format(p=package))
            else:
                for package in extra_packages[system]:
                    if not package in sys.modules:
                        pipmain(['install', package])
Example #25
0
def update_reqs():
    print(
        "Updating requirements. This may take a while on first-time installs.."
    )
    try:
        try:
            from pip import main as pipmain
        except ImportError:
            from pip._internal import main as pipmain
        pipmain(
            ['install', '--upgrade', '-r',
             path.join(dr, 'requirements.txt')])
        print('\n' * 10)
        os.system('cls' if os.name == 'nt' else 'clear')
    except Exception as ex:
        print(ex)
Example #26
0
def downloadModules (localFolder):
    reqFile = getPropertiesFile()

    if not reqFile:
        return

    if not os.path.isdir(localFolder):
        print ("path %s is not local folder to download PIP packages.. " %localFolder)
        return

    if not internet_on():
        print ("MUST HAVE INTERENET CONNECTION TO START DOWNLOAD ! ")
        return

    print ("DOWNLOADING ....")
    pipmain(['download', '-r', reqFile, '-d', localFolder])
Example #27
0
    def __install_plugin_deps(self):
        ret = pipmain(["install"] + self.__plugin_deps)

        if ret is not 0:
            self.__error_exit("Unable to install plugin dependencies.")
            return False

        return True
Example #28
0
def install_pip():
    retries = RETRIES
    while retries > 0:
        ret = pipmain(['install', 'dvc'])
        if ret == 0:
            break
        retries -= 1
    assert ret == 0
Example #29
0
def installModule (localFolder=None):
    reqFile = getPropertiesFile ()

    if not reqFile:
        return

    if not localFolder and internet_on():
        print ("Dowloading PIP packages from the web")
        pipmain(['install', '-r', reqFile])

    elif localFolder:
        if os.path.isdir(localFolder):
            pipmain(['install', '-r', reqFile, '--no-index', '--find-links', 'file:'+localFolder])
        else:
            print ('%s IS NOT FOLDER !!', localFolder)
    else:
        print ("NO INTERNET CONNECTION OR NO VALID LOCAL FOLDER ")
def install_and_import(package):
    """Import a given package after installing it when needed.

    Args:
        package (str): The name of the package to be imported."""
    import importlib
    try:
        importlib.import_module(package)
    except ImportError:
        checkPipInstalled()
        try:
            from pip import main as pipmain
        except:
            from pip._internal import main as pipmain
        pipmain(['install', package])
    finally:
        globals()[package] = importlib.import_module(package)
Example #31
0
def call_pip(packageName, target, packageVersion=None):
    package = packageName if not packageVersion else "{}=={}".format(
        packageName, packageVersion)
    rc = pipmain([
        "install", package, '--no-cache-dir', '--disable-pip-version-check',
        '--upgrade', '--quiet', '--target', target
    ])
    if rc != 0:
        raise Exception('pip.main returned ' + str(rc))
Example #32
0
 def run(self):
     install.run(self)
     if sys.platform == 'darwin':
         pipmain(['install', mac_url])
     elif sys.platform.startswith('linux'):
         if sys.version_info.minor == 4:
             pipmain(['install', linux_py4_url])
         elif sys.version_info.minor == 5:
             pipmain(['install', linux_py5_url])
         elif sys.version_info.minor == 6:
             pipmain(['install', linux_py6_url])
Example #33
0
def install_reqs(only_verbose=False):
    import pip
    try:
        from pip import main as pipmain
    except:
        from pip._internal import main as pipmain
    # if utils.is_windows() and not utils.is_admin():
    #     utils.set_admin()
    pipmain(['install', '--upgrade', 'pip'])
    retcode = 0
    reqs_fname = op.join(utils.get_parent_fol(levels=2), 'requirements.txt')
    with open(reqs_fname, 'r') as f:
        for line in f:
            if only_verbose:
                print('Trying to install {}'.format(line.strip()))
            else:
                pipcode = pipmain(['install', '--upgrade', line.strip()])
                retcode = retcode or pipcode
    return retcode
Example #34
0
def import_try_install(package, extern_url=None):
    """Try import the specified package.
    If the package not installed, try use pip to install and import if success.

    Parameters
    ----------
    package : str
        The name of the package trying to import.
    extern_url : str or None, optional
        The external url if package is not hosted on PyPI.
        For example, you can install a package using:
         "pip install git+http://github.com/user/repo/tarball/master/egginfo=xxx".
        In this case, you can pass the url to the extern_url.

    Returns
    -------
    <class 'Module'>
        The imported python module.

    """
    try:
        return __import__(package)
    except ImportError:
        try:
            from pip import main as pipmain
        except ImportError:
            from pip._internal import main as pipmain

        # trying to install package
        url = package if extern_url is None else extern_url
        pipmain(['install', '--user', url])  # will raise SystemExit Error if fails

        # trying to load again
        try:
            return __import__(package)
        except ImportError:
            import sys
            import site
            user_site = site.getusersitepackages()
            if user_site not in sys.path:
                sys.path.append(user_site)
            return __import__(package)
    return __import__(package)
Example #35
0
def update():
    logging.debug('def restart')
    del sys.argv[1:]
    time.sleep(2)
    logging.info('Git pull nzbtomedia & premiumizer')
    subprocess.call(['git', '-C', os.path.join(rootdir, 'nzbtomedia'), 'pull'])
    subprocess.call(['git', '-C', rootdir, 'pull'])
    prem_config = configparser.ConfigParser()
    default_config = configparser.ConfigParser()
    prem_config.read(os.path.join(ConfDir, 'settings.cfg'))
    default_config.read(os.path.join(runningdir, 'settings.cfg.tpl'))
    prem_config.set('update', 'updated', '1')
    with open(os.path.join(ConfDir, 'settings.cfg'), 'w') as configfile:
        prem_config.write(configfile)
    if prem_config.getfloat('update', 'req_version') < default_config.getfloat('update', 'req_version'):
        logging.info('updating pip requirements')
        pipmain(['install', '-r', os.path.join(rootdir, 'requirements.txt')])
        prem_config.set('update', 'req_version', str(default_config.getfloat('update', 'req_version')))
        with open(os.path.join(ConfDir, 'settings.cfg'), 'w') as configfile:
            prem_config.write(configfile)
    if prem_config.getfloat('update', 'config_version') < default_config.getfloat('update', 'config_version'):
        logging.info('updating config file')
        import shutil
        shutil.copy(os.path.join(ConfDir, 'settings.cfg'), os.path.join(ConfDir, 'settings.cfg.old'))
        shutil.copy(os.path.join(runningdir, 'settings.cfg.tpl'), os.path.join(ConfDir, 'settings.cfg'))
        prem_config.read(os.path.join(ConfDir, 'settings.cfg.old'))
        default_config.read(os.path.join(ConfDir, 'settings.cfg'))
        for section in prem_config.sections():
            if section in default_config.sections() and section != 'update':
                for key in prem_config.options(section):
                    if key in default_config.options(section):
                        default_config.set(section, key, (prem_config.get(section, key)))
        with open(os.path.join(ConfDir, 'settings.cfg'), 'w') as configfile:
            default_config.write(configfile)

    if os_arg == '--windows':
        pass
    else:
        time.sleep(3)
        exec(compile(open(os.path.join(runningdir, 'premiumizer.py'), "rb").read(),
                     os.path.join(runningdir, 'premiumizer.py'), 'exec'), globals(), globals())
Example #36
0
 def reinstall(self):
     pipmain(["install", "-q", "--force-reinstall", self.name])
     self.emit(SIGNAL("pluginInstalled(PyQt_PyObject)"), self)
Example #37
0
except ImportError:
    from pip._internal import main as pipmain

DEFAULT_LOGGER = 'rlbot'

if __name__ == '__main__':

    try:
        from rlbot.utils import public_utils, logging_utils

        logger = logging_utils.get_logger(DEFAULT_LOGGER)
        if not public_utils.have_internet():
            logger.log(logging_utils.logging_level,
                       'Skipping upgrade check for now since it looks like you have no internet')
        elif public_utils.is_safe_to_upgrade():
            pipmain(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager'])

            # https://stackoverflow.com/a/44401013
            rlbots = [module for module in sys.modules if module.startswith('rlbot')]
            for rlbot_module in rlbots:
                sys.modules.pop(rlbot_module)

    except ImportError:
        pipmain(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager'])

    try:
        if len(sys.argv) > 1 and sys.argv[1] == 'gui':
            from rlbot.gui.qt_root import RLBotQTGui

            RLBotQTGui.main()
        else:
 def reinstall(self):
     pipmain(["install", "-q", "--force-reinstall", self.name])
     self.pluginInstalled.emit(self)
 def upgrade(self):
     pipmain(["install", "-q", "--ugprade", self.name])
     self.pluginInstalled.emit(self)
Example #40
0
 def upgrade(self):
     pipmain(["install", "-q", "--ugprade", self.name])
     self.emit(SIGNAL("pluginInstalled(PyQt_PyObject)"), self)
Example #41
0
def uninstall(package: str) -> int:
    """Uninstall a PIP package"""
    return pipmain([r'uninstall', package])
Example #42
0
"""

import sys
import os
import unittest
import qgis  # NOQA  For SIP API to V2 if run outside of QGIS

try:
    from pip import main as pipmain
except:
    from pip._internal import main as pipmain

try:
    import coverage
except ImportError:
    pipmain(['install', 'coverage'])
    import coverage
import tempfile
from osgeo import gdal
from qgis.PyQt import Qt
from safe.utilities.gis import qgis_version

__author__ = 'etiennetrimaille'
__revision__ = 'bd00bfeac510722b427544b186bfa10861749e51'
__date__ = '14/06/2016'
__copyright__ = (
    'Copyright 2012, Australia Indonesia Facility for Disaster Reduction')


def _run_tests(test_suite, package_name, with_coverage=False):
    """Core function to test a test suite."""
Example #43
0
 def remove(self):
     pipmain(["uninstall", "-q", "-y", self.name])
Example #44
0
def install(package: str) -> int:
    """Install PIP package"""
    return pipmain([r'install', package])