Ejemplo n.º 1
0
 def _install_requirements(plugin_path):
     requirement_file = os.path.join(plugin_path, "plugin_requirements.txt")
     if os.path.isfile(requirement_file):
         LOG.info(
             "Installing requirements from: {}".format(requirement_file))
         pip_args = ['install', '-r', requirement_file]
         pip_main(args=pip_args)
Ejemplo n.º 2
0
    def _preinstall(package_list, options=[]):
        """ Pre-install PyPi packages before running cmake.
        """

        if not isinstance(package_list, list) or not isinstance(options, list):
            raise TypeError('preinstall inputs must be of type list.')

        pip_main(['install'] + options + package_list)
Ejemplo n.º 3
0
def pipinstall(package_list, options=[]):
    """ Pip install PyPi packages.
    """

    if not isinstance(package_list, list) or not isinstance(options, list):
        raise TypeError('preinstall inputs must be of type list.')

    pip_main(['install'] + options + package_list)
Ejemplo n.º 4
0
def marvcli_pip_uninstall(pipargs):
    """Uninstall python package (EE)."""
    assert within_pyinstaller_bundle()
    siteconf = get_site_config()
    sitepackages = make_config(siteconf).marv.sitepackages
    load_sitepackages(sitepackages)
    ensure_python(siteconf, sitepackages)
    from pip._internal.main import main as pip_main  # pylint: disable=import-outside-toplevel
    sys.argv = [sys.executable, 'uninstall', *pipargs]
    sys.exit(pip_main())
Ejemplo n.º 5
0
def marvcli_pip_install(pipargs):
    """Install python package (EE).

    Use -e like with plain pip to install in editable mode.
    """
    assert within_pyinstaller_bundle()
    siteconf = get_site_config()
    config = make_config(siteconf)
    sitepackages = config.marv.sitepackages
    load_sitepackages(sitepackages)
    ensure_python(siteconf, sitepackages)
    from pip._internal.main import main as pip_main  # pylint: disable=import-outside-toplevel
    sys.argv = [
        sys.executable, 'install', '--prefix',
        str(config.marv.venv), *pipargs
    ]
    sys.exit(pip_main())
Ejemplo n.º 6
0
def install():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="""
Install all requirements from specified file with pip. Optionally transform
git+git and git+ssh url to private repo's to use a given Personal Access Token for
github. That way installing them does not depend on a ssh-agent with suitable
keys. Which you don't have when installing requirements in a Docker.
These URLs will also be stripped of the -e flag, so they're installed globally.
Note the -e flag is optional for the git+git//github.com and git+ssh://github.com
urls.

This means that the following URL:
  -e [email protected]:MyOrg/my-project.git@my-tag#egg=my_project
would be transformed to:
  git+https://<token>:[email protected]/MyOrg/my-project.git@my-tag#egg=my_project

Non-private GitHub URL's (git+https) and non-GitHub URL's are kept as-is, but
are also stripped of the -e flag. If no token is given, private URLs will be
kept, including the -e flag (otherwise they can't be installed at all).
""")

    parser.add_argument(
        '--token',
        '-t',
        help='Your Personal Access Token for private GitHub repositories',
        default=os.environ.get('GITHUB_TOKEN'))
    parser.add_argument('req_file',
                        help='path to the requirements file to install')
    args = parser.parse_args()

    # TODO: rewrite to a clear collect and a clear transform phase. Or pass in a transform function
    pip_args = ['install'] + collect_requirements(
        args.req_file, transform_with_token=args.token)
    if pip_main(pip_args) != status_codes.SUCCESS:
        raise RuntimeError('Error installing requirements')
Ejemplo n.º 7
0
 def _pip_install_helper(package_names):
     for package in package_names:
         pip_main(["install", "-q", package])
     logger.reset()
Ejemplo n.º 8
0
# Global parameters
CLASSIFIERS = [
    "Development Status :: 1 - Planning", "Environment :: Console",
    "Operating System :: OS Independent", "Programming Language :: Python",
    "Topic :: Scientific/Engineering"
]
AUTHOR = """
Antoine Grigis <*****@*****.**>
Samuel Farrens <*****@*****.**>
Jean-Luc Starck <*****@*****.**>
Philippe Ciuciu <*****@*****.**>
"""
# Write setup
setup_requires = ["numpy>=1.16.4", "cython>=0.27.3", "pytest-runner"]

pip_main(['install'] + setup_requires)

setup(
    name="pysap-mri",
    description="Python Sparse data Analysis Package external MRI plugin.",
    long_description="Python Sparse data Analysis Package external MRI plugin.",
    license="CeCILL-B",
    classifiers="CLASSIFIERS",
    author=AUTHOR,
    author_email="XXX",
    version="0.4.0",
    url="https://github.com/CEA-COSMIC/pysap-mri",
    packages=find_packages(),
    setup_requires=setup_requires,
    install_requires=[
        "scikit-learn>=0.19.1",
Ejemplo n.º 9
0
    def update_plugin(self,
                      plugin_name,
                      revision=None,
                      skip_reqs=False,
                      hard_reset=False):
        """Updates a Git-based plugin

        Pulls changes from the remote, and checkout a specific revision.
        (will point to the tip of the branch if revision isn't given)
        :param plugin_name: Name of plugin to update.
        :param revision: Revision to checkout.
        :param skip_reqs: If True, will skip plugin requirements installation.
        :param hard_reset: Whether to drop all changes using git hard reset
        """
        if plugin_name not in self.PLUGINS_DICT:
            raise IRFailedToUpdatePlugin(
                "Plugin '{}' isn't installed".format(plugin_name))

        plugin = self.get_plugin(plugin_name)

        try:
            repo = git.Repo(plugin.path, search_parent_directories=True)
        except git.InvalidGitRepositoryError:
            raise IRFailedToUpdatePlugin(
                "Plugin '{}' isn't a Git-based plugin".format(plugin_name))

        # microseconds ('%f') required for unit testing
        timestamp = \
            datetime.datetime.fromtimestamp(
                time.time()).strftime('%B-%d-%Y_%H-%M-%S-%f')
        update_string = \
            'IR_Plugin_update_{plugin_name}_{timestamp}' \
            ''.format(plugin_name=plugin_name, timestamp=timestamp)

        LOG.debug("Checking for changes of tracked files "
                  "in {}".format(plugin.path))
        changed_tracked_files = \
            repo.git.status('--porcelain', '--untracked-files=no')
        all_changed_files = repo.git.status('--porcelain')

        if changed_tracked_files and not hard_reset:
            raise IRFailedToUpdatePlugin("Failed to update plugin {}\n"
                                         "Found changes in tracked files, "
                                         "please go to {}, and manually save "
                                         "your changes!".format(
                                             plugin_name, plugin.path))

        if hard_reset:
            if all_changed_files:
                repo.git.stash('save', '-u', update_string)
                LOG.warning("All changes have been "
                            "stashed - '{}'".format(update_string))
            repo.git.reset('--hard', 'HEAD')

        # checkout revision
        self._checkout_git_plugin_revision(repo, revision, update_string)

        if not hard_reset:
            # pull changes
            self._pull_git_plugin_changes(repo)

        if repo.git.status('--porcelain', '--untracked-files=no'):
            LOG.warning("Changes in tracked files have been found")

        if not skip_reqs:
            reqs_file = os.path.join(plugin.path, 'requirements.txt')
            if os.path.isfile(reqs_file):
                pip_main(['install', '-r', reqs_file])
Ejemplo n.º 10
0
def import_requirements(req_file):
    with open(req_file, "r") as requirements:
        for req in requirements:
            if pip_main(["install", req]) == 1:
                raise Exception("Package {} not installed".format(req))