2018-11-05 21:09:54 +00:00
#!/usr/bin/env python
2019-02-14 11:17:52 +00:00
import os
import sys
2018-11-05 21:09:54 +00:00
import ci_lib
2018-11-06 13:47:09 +00:00
batches = [ ]
2019-02-14 11:17:52 +00:00
2019-05-27 21:27:50 +00:00
if 0 and os . uname ( ) [ 0 ] == ' Linux ' :
2019-05-26 11:14:31 +00:00
batches + = [
[
" sudo chown `whoami`: ~ " ,
" chmod u=rwx,g=rx,o= ~ " ,
2019-05-26 11:06:14 +00:00
2019-05-26 11:14:31 +00:00
" sudo mkdir /var/run/sshd " ,
" sudo /etc/init.d/ssh start " ,
2019-05-26 11:06:14 +00:00
2019-05-26 11:14:31 +00:00
" mkdir -p ~/.ssh " ,
" chmod u=rwx,go= ~/.ssh " ,
2019-05-26 11:06:14 +00:00
2019-05-26 11:14:31 +00:00
" ssh-keyscan -H localhost >> ~/.ssh/known_hosts " ,
" chmod u=rw,go= ~/.ssh/known_hosts " ,
2019-05-26 11:06:14 +00:00
2019-05-26 11:14:31 +00:00
" cat tests/data/docker/mitogen__has_sudo_pubkey.key > ~/.ssh/id_rsa " ,
" chmod u=rw,go= ~/.ssh/id_rsa " ,
2019-05-26 11:06:14 +00:00
2019-05-26 11:14:31 +00:00
" cat tests/data/docker/mitogen__has_sudo_pubkey.key.pub > ~/.ssh/authorized_keys " ,
" chmod u=rw,go=r ~/.ssh/authorized_keys " ,
]
2019-05-26 11:06:14 +00:00
]
2020-09-27 17:32:08 +00:00
# setup venv, need all python commands in 1 list to be subprocessed at the same time
venv_steps = [ ]
2020-09-27 17:52:28 +00:00
need_to_fix_psycopg2 = False
2020-09-27 18:10:35 +00:00
is_python3 = os . environ [ ' PYTHONVERSION ' ] . startswith ( ' 3 ' )
2020-09-23 03:44:46 +00:00
# @dw: The VSTS-shipped Pythons available via UsePythonVErsion are pure garbage,
# broken symlinks, incorrect permissions and missing codecs. So we use the
# deadsnakes PPA to get sane Pythons, and setup a virtualenv to install our
# stuff into. The virtualenv can probably be removed again, but this was a
# hard-fought battle and for now I am tired of this crap.
2019-02-14 11:17:52 +00:00
if ci_lib . have_apt ( ) :
2020-09-27 17:32:08 +00:00
venv_steps . extend ( [
2019-02-14 11:17:52 +00:00
' echo force-unsafe-io | sudo tee /etc/dpkg/dpkg.cfg.d/nosync ' ,
' sudo add-apt-repository ppa:deadsnakes/ppa ' ,
' sudo apt-get update ' ,
2019-05-26 11:06:14 +00:00
' sudo apt-get -y install '
' python {pv} '
' python {pv} -dev '
' libsasl2-dev '
' libldap2-dev '
2020-09-23 03:44:46 +00:00
. format ( pv = os . environ [ ' PYTHONVERSION ' ] ) ,
' sudo ln -fs /usr/bin/python {pv} /usr/local/bin/python {pv} '
. format ( pv = os . environ [ ' PYTHONVERSION ' ] )
2019-02-14 11:17:52 +00:00
] )
2020-09-27 18:10:35 +00:00
if is_python3 :
2020-10-03 22:39:53 +00:00
venv_steps . append ( ' sudo apt-get -y install python {pv} -venv ' . format ( pv = os . environ [ ' PYTHONVERSION ' ] ) )
2020-09-27 17:52:28 +00:00
# TODO: somehow `Mito36CentOS6_26` has both brew and apt installed https://dev.azure.com/dw-mitogen/Mitogen/_build/results?buildId=1031&view=logs&j=7bdbcdc6-3d3e-568d-ccf8-9ddca1a9623a&t=73d379b6-4eea-540f-c97e-046a2f620483
2020-09-27 18:10:35 +00:00
elif is_python3 and ci_lib . have_brew ( ) :
2020-09-27 17:52:28 +00:00
# Mac's System Integrity Protection prevents symlinking /usr/bin
# and Azure isn't allowing disabling it apparently: https://developercommunityapi.westus.cloudapp.azure.com/idea/558702/allow-disabling-sip-on-microsoft-hosted-macos-agen.html
# so we'll use /usr/local/bin/python for everything
# /usr/local/bin/python2.7 already exists!
2020-09-24 03:47:48 +00:00
need_to_fix_psycopg2 = True
2020-09-27 17:32:08 +00:00
venv_steps . append (
2020-09-24 03:27:41 +00:00
' brew install python@ {pv} postgresql '
2020-09-24 03:47:48 +00:00
. format ( pv = os . environ [ ' PYTHONVERSION ' ] )
2020-09-27 17:32:08 +00:00
)
2020-09-23 03:44:46 +00:00
# need wheel before building virtualenv because of bdist_wheel and setuptools deps
2020-09-27 17:32:08 +00:00
venv_steps . append ( ' /usr/local/bin/python {pv} -m pip install -U pip wheel setuptools ' . format ( pv = os . environ [ ' PYTHONVERSION ' ] ) )
2020-09-23 03:44:46 +00:00
if os . environ [ ' PYTHONVERSION ' ] . startswith ( ' 2 ' ) :
venv_steps . extend ( [
2020-09-23 04:34:35 +00:00
' /usr/local/bin/python {pv} -m pip install -U virtualenv ' . format ( pv = os . environ [ ' PYTHONVERSION ' ] ) ,
' /usr/local/bin/python {pv} -m virtualenv /tmp/venv -p /usr/local/bin/python {pv} ' . format ( pv = os . environ [ ' PYTHONVERSION ' ] )
2020-09-23 03:44:46 +00:00
] )
else :
2020-09-23 04:34:35 +00:00
venv_steps . append ( ' /usr/local/bin/python {pv} -m venv /tmp/venv ' . format ( pv = os . environ [ ' PYTHONVERSION ' ] ) )
2020-09-24 03:54:59 +00:00
# fixes https://stackoverflow.com/questions/59595649/can-not-install-psycopg2-on-macos-catalina https://github.com/Azure/azure-cli/issues/12854#issuecomment-619213863
2020-09-24 03:47:48 +00:00
if need_to_fix_psycopg2 :
2020-09-24 03:54:59 +00:00
venv_steps . append ( ' /tmp/venv/bin/pip3 install psycopg2==2.8.5 psycopg2-binary ' )
2020-09-24 03:47:48 +00:00
2020-09-23 03:44:46 +00:00
batches . append ( venv_steps )
2018-11-06 13:47:09 +00:00
ci_lib . run_batches ( batches )