Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling of dependency installation in setup.py #1135

Merged
merged 17 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ the `dist/` directory, so next step is installing it:

qiskit-aer/dist$ pip install -U dist/qiskit_aer*.whl

As we are using *scikit-build* and we need some *Python* dependencies to be present before compiling the C++ code,
we install those dependencies outside the regular setuptools *mechanism*. If you want to avoid automatic installation
of these packages set the environment variable DISABLE_DEPENDENCY_INSTALL (ON or 1).


**Standalone Executable**

If you want to build a standalone executable, you have to use *CMake* directly.
Expand Down Expand Up @@ -465,6 +470,10 @@ the `dist/` directory, so next step is installing it:

qiskit-aer/dist$ pip install -U dist/qiskit_aer*.whl

As we are using *scikit-build* and we need some *Python* dependencies to be present before compiling the C++ code,
we install those dependencies outside the regular setuptools *mechanism*. If you want to avoid automatic installation
of these packages set the environment variable DISABLE_DEPENDENCY_INSTALL (ON or 1).

**Standalone Executable**

If you want to build a standalone executable, you have to use **CMake** directly.
Expand Down Expand Up @@ -564,6 +573,10 @@ the `dist/` directory, so next step is installing it:

(QiskitDevEnv) qiskit-aer\dist$ pip install -U dist\qiskit_aer*.whl

As we are using *scikit-build* and we need some *Python* dependencies to be present before compiling the C++ code,
we install those dependencies outside the regular setuptools *mechanism*. If you want to avoid automatic installation
of these packages set the environment variable DISABLE_DEPENDENCY_INSTALL (ON or 1).

**Standalone Executable**

If you want to build a standalone executable, you have to use **CMake** directly.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
Some *Python* packages needed at C++ compilaton step were installed outside the regular *setuptools* circuit,
and it was not possible to avoid their installation by any option. Now it is possible to avoid automatic
installation of those packages by setting the environment variable *DISABLE_DEPENDENCY_INSTALL* to *1* or *ON*.
56 changes: 38 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,56 @@
"""
Main setup file for qiskit-aer
"""
import distutils.util
import importlib
import inspect
import os
import setuptools
import subprocess
import sys
from pkg_resources import parse_version
import platform


def strtobool(val):
val_lower = val.lower()
if val_lower in ('y', 'yes', 't', 'true', 'on', '1'): return True
vvilpas marked this conversation as resolved.
Show resolved Hide resolved
elif val_lower in ('n', 'no', 'f', 'false', 'off', '0'): return False
vvilpas marked this conversation as resolved.
Show resolved Hide resolved
else: raise ValueError('Value: "{}" not recognizes as True or False'.format(val))
vvilpas marked this conversation as resolved.
Show resolved Hide resolved


PACKAGE_NAME = os.getenv('QISKIT_AER_PACKAGE_NAME', 'qiskit-aer')
_DISABLE_CONAN = distutils.util.strtobool(os.getenv("DISABLE_CONAN", "OFF").lower())
_DISABLE_CONAN = strtobool(os.getenv("DISABLE_CONAN", "OFF").lower())
vvilpas marked this conversation as resolved.
Show resolved Hide resolved
_DISABLE_DEPENDENCY_INSTALL = strtobool(os.getenv("DISABLE_DEPENDENCY_INSTALL", "OFF").lower())
vvilpas marked this conversation as resolved.
Show resolved Hide resolved



def install_needed_req(to_import, to_install=None, min_version=None, max_version=None):
vvilpas marked this conversation as resolved.
Show resolved Hide resolved
to_install = to_install if to_install else to_import
to_install_ver = to_install
to_install_ver = to_install_ver + '>=' + min_version if min_version else to_install_ver
to_install_ver = to_install_ver + '<' + max_version if max_version else to_install_ver

if not _DISABLE_CONAN:
try:
from conans import client
except ImportError:
subprocess.call([sys.executable, '-m', 'pip', 'install', 'conan>=1.31.2'])
from conans import client

try:
from skbuild import setup
except ImportError:
subprocess.call([sys.executable, '-m', 'pip', 'install', 'scikit-build'])
from skbuild import setup

try:
import pybind11
except ImportError:
subprocess.call([sys.executable, '-m', 'pip', 'install', 'pybind11>=2.6'])
mod = importlib.import_module(to_import)
mod_ver = parse_version(mod.__version__)
if ((min_version and mod_ver < parse_version(min_version))
or (max_version and mod_ver >= parse_version(max_version))):
raise RuntimeError('{} {} is installed but required version is {}.'.
vvilpas marked this conversation as resolved.
Show resolved Hide resolved
format(to_install, mod_ver, to_install_ver))

except ImportError as err:
if _DISABLE_DEPENDENCY_INSTALL:
raise ImportError(str(err) +
"\n{} is a required dependency. Please provide it and repeat install"
vvilpas marked this conversation as resolved.
Show resolved Hide resolved
.format(to_install))

subprocess.call([sys.executable, '-m', 'pip', 'install', to_install_ver])

if not _DISABLE_CONAN:
install_needed_req('conans', to_install='conan', min_version='1.31.2')

install_needed_req('skbuild', to_install='scikit-build')
install_needed_req('pybind11', min_version='2.6')

from skbuild import setup

Expand Down