Skip to content

Commit

Permalink
enable pip/setuptools specific versions in project configration
Browse files Browse the repository at this point in the history
  • Loading branch information
sivanbecker committed Sep 3, 2019
1 parent 7896205 commit ec18e8e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
22 changes: 16 additions & 6 deletions cob/bootstrapping.py
Expand Up @@ -12,6 +12,7 @@
from .project import get_project

_logger = logbook.Logger(__name__)
config = get_project().config

_PREVENT_REENTRY_ENV_VAR = 'COB_NO_REENTRY'
_USE_PRE_ENV_VAR = 'COB_USE_PRE'
Expand All @@ -23,6 +24,7 @@
def ensure_project_bootstrapped(*, reenter=True):
if not os.path.isfile(COB_CONFIG_FILE_NAME):
raise RuntimeError('Project is not a cob project')

if _PREVENT_REENTRY_ENV_VAR in os.environ:
_logger.trace('{} found in environ. Not reentering.', _PREVENT_REENTRY_ENV_VAR)
return
Expand Down Expand Up @@ -68,14 +70,9 @@ def _ensure_virtualenv():
args[-1] += f'=={version}'
if os.environ.get(_USE_PRE_ENV_VAR):
args.append('--pre')
if PYPI_INDEX_ENV_VAR in os.environ:
args.extend(['-i', os.environ[PYPI_INDEX_ENV_VAR]])
_virtualenv_pip_install(args)

pypi_index_url = get_project().get_pypi_index_url()
deps = sorted(get_project().get_deps())
if pypi_index_url:
deps.extend(['-i', pypi_index_url])
_logger.trace('Installing dependencies: {}', deps)
if deps:
_virtualenv_pip_install(['-U', *deps])
Expand All @@ -91,6 +88,14 @@ def _create_virtualenv(path):
interpreter = sys.executable

_execute_long_command([interpreter, '-m', 'virtualenv', path], 'Creating virtualenv')
_alter_virtualenv_if_needed()


def _alter_virtualenv_if_needed():
'''In case a specific pip/setuptools or other basic virtualenv pkgs are needed inside the virtualenv '''
if config.get('specific_virtualenv_pkgs'):
click.echo("Altering Virtualenv")
_virtualenv_pip_install(['-U', *config['specific_virtualenv_pkgs'].split()])

def _locate_original_interpreter():
if not os.environ.get('COB_FORCE_CURRENT_INTERPRETER'):
Expand Down Expand Up @@ -150,7 +155,12 @@ def _execute_long_command(cmd, message):

def _virtualenv_pip_install(argv):
msg = 'Installing {} in virtualenv'.format(', '.join(arg for arg in argv if not arg.startswith('-')))
_execute_long_command([os.path.join(_VIRTUALENV_PATH, 'bin', 'python'), '-m', 'pip', 'install', *argv], msg)
_command_lst = [os.path.join(_VIRTUALENV_PATH, 'bin', 'python'), '-m', 'pip', 'install', *argv]
pypi_index_url = get_project().get_pypi_index_url()
if pypi_index_url:
msg += f' (Using PYPI INDEX {pypi_index_url})'
_command_lst.extend(['-i', pypi_index_url])
_execute_long_command(_command_lst, msg)

def _reenter():
if _is_in_project_virtualenv():
Expand Down
6 changes: 6 additions & 0 deletions cob/cli/docker_cli.py
Expand Up @@ -57,11 +57,17 @@ def generate_dockerfile():
else:
sdist_file_name = None

if proj.config.get('specific_virtualenv_pkgs'):
_specific_vers = proj.config['specific_virtualenv_pkgs']
else:
_specific_vers = "pip setuptools"

with open(".Dockerfile", "w") as f:
f.write(template.render(
project=proj,
deployment_base_image='python:3.6-jessie',
python_version='3.6',
specific_vers=_specific_vers,
is_develop=is_develop(),
cob_sdist_filename=os.path.basename(sdist_file_name) if sdist_file_name else None,
cob_root=cob_root() if is_develop() else None,
Expand Down
3 changes: 1 addition & 2 deletions cob/templates/Dockerfile.j2
Expand Up @@ -21,8 +21,7 @@ RUN echo "deb-src http://nginx.org/packages/mainline/debian/ jessie nginx" | tee
RUN apt-get update
RUN apt-get install -y nginx


RUN $PYTHON_EXECUTABLE -m pip install -U virtualenv pip setuptools
RUN $PYTHON_EXECUTABLE -m pip install -U virtualenv {{specific_vers}}

ADD . /app
RUN rm -rf /app/.cob
Expand Down

0 comments on commit ec18e8e

Please sign in to comment.