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 all 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*.
62 changes: 44 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,62 @@
"""
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
elif val_lower in ('n', 'no', 'f', 'false', 'off', '0'):
return False
else:
raise ValueError(f'Value: "{val}" not recognizes as True or False')


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"))
_DISABLE_DEPENDENCY_INSTALL = strtobool(os.getenv("DISABLE_DEPENDENCY_INSTALL", "OFF"))



def install_needed_req(import_name, package_name=None, min_version=None, max_version=None):
if package_name is None:
package_name = import_name
install_ver = package_name
if min_version:
install_ver += '>=' + min_version
if max_version:
install_ver += '<' + max_version

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>=0.11.0'])
from skbuild import setup

try:
import pybind11
except ImportError:
subprocess.call([sys.executable, '-m', 'pip', 'install', 'pybind11>=2.6'])
mod = importlib.import_module(import_name)
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(f'{package_name} {mod_ver} is installed '
f'but required version is {install_ver}.')

except ImportError as err:
if _DISABLE_DEPENDENCY_INSTALL:
raise ImportError(str(err) +
f"\n{package_name} is a required dependency. "
f"Please provide it and repeat install")

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

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

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

from skbuild import setup

Expand Down