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 Aug 28, 2019
1 parent 7896205 commit 9c389c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions cob/bootstrapping.py
Expand Up @@ -72,6 +72,7 @@ def _ensure_virtualenv():
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:
Expand All @@ -91,6 +92,19 @@ 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 are needed inside the virtualenv '''
click.echo("Altering Virtualenv")
_deps = []
if get_project().config.get('pip_version'):
_deps.extend([f"pip=={get_project().config.get('pip_version')}"])

if get_project().config.get('setuptools_version'):
_deps.extend([f"setuptools=={get_project().config.get('setuptools_version')}"])
if _deps:
_virtualenv_pip_install(_deps)

def _locate_original_interpreter():
if not os.environ.get('COB_FORCE_CURRENT_INTERPRETER'):
Expand Down
13 changes: 13 additions & 0 deletions cob/cli/docker_cli.py
Expand Up @@ -57,11 +57,24 @@ def generate_dockerfile():
else:
sdist_file_name = None

_pip = 'pip'
_setuptools = 'setuptools'

pip_ver = proj.config.get('pip_version')
if pip_ver:
_pip += f'=={pip_ver}'

setuptools_ver = proj.config.get('setuptools_version')
if setuptools_ver:
_setuptools += f'=={setuptools_ver}'

with open(".Dockerfile", "w") as f:
f.write(template.render(
project=proj,
deployment_base_image='python:3.6-jessie',
python_version='3.6',
pip=_pip,
setuptools=_setuptools,
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 {{pip}} {{setuptools}}

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

0 comments on commit 9c389c3

Please sign in to comment.