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 9 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 we want to build a standalone executable, we 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 we want to build a standalone executable, we 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 we want to build a standalone executable, we 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*.
44 changes: 28 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,41 @@
import setuptools
import subprocess
import sys
from pkg_resources import parse_version
import platform


PACKAGE_NAME = os.getenv('QISKIT_AER_PACKAGE_NAME', 'qiskit-aer')
_DISABLE_CONAN = distutils.util.strtobool(os.getenv("DISABLE_CONAN", "OFF").lower())
_DISABLE_DEPENDENCY_INSTALL = distutils.util.strtobool(os.getenv("DISABLE_DEPENDENCY_INSTALL", "OFF").lower())

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