diff --git a/.coveragerc b/.coveragerc index 04204bd1..f3737016 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,6 +5,10 @@ omit = */python?.?/* */site-packages/nose/* */test/* + */pygobject-3.20.1/* + */site-packages/* + scarlett_os/__main__.py + scarlett_os/scripts/*.py [report] # Regexes for lines to exclude from consideration @@ -22,4 +26,5 @@ exclude_lines = # From old Scarlett repo assert False raise NotImplementedError + raise AssertionError if __name__ == .__main__.: diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..1e12ab75 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,39 @@ +.git/* +vendor/* +node_modules/* + +*.git +*.pyc +*.vagrant +*.vendor +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +.tox/ +.bundle/ +.cache/ +__pycache__/ + +.git +*.gitignore + +*.mo +*.pyc +*.swp +*.swo +*.~ + +Procfile* diff --git a/.travis.yml b/.travis.yml index d90ab58f..e13bc9d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ matrix: fast_finish: true include: + # - python: '3.5' + # env: TOXENV=typing PYTHON="python3" PACKAGES="python3-gi python3-gi-cairo" DOCKER_COMPOSE_VERSION=1.8.0 TEST_TARGET=typing DOCKER_DATA="$HOME/docker_data" DOCKER_VERSION=1.12.0-0~trusty DOCKER_COMPOSE_VERSION=1.8.0 + # sudo: required + # dist: trusty + # language: python + # group: edge - python: '3.5' - env: TOXENV=typing PYTHON="python3" PACKAGES="python3-gi python3-gi-cairo" - sudo: required - dist: trusty - language: python - group: edge - - python: '3.5' - env: TOXENV=py35 PYTHON="python3" PACKAGES="python3-gi python3-gi-cairo" + env: TOXENV=py35 PYTHON="python3" PACKAGES="python3-gi python3-gi-cairo" DOCKER_COMPOSE_VERSION=1.8.0 TEST_TARGET=default DOCKER_DATA="$HOME/docker_data" DOCKER_VERSION=1.12.0-0~trusty DOCKER_COMPOSE_VERSION=1.8.0 sudo: required dist: trusty language: python @@ -17,115 +17,50 @@ matrix: - python: '3.5' env: TOXENV=typing +services: + - docker + +before_install: + - travis_retry pip install coveralls + # List available docker versions. + - apt-cache madison docker-engine + # Update Docker. See: https://graysonkoonce.com/managing-docker-and-docker-compose-versions-on-travis-ci/. + - sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION} + # Add docker-compose at the version specified in ENV. + - sudo rm -f /usr/local/bin/docker-compose + - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose + - chmod +x docker-compose + - sudo mv docker-compose /usr/local/bin + - docker-compose --version + cache: apt: true directories: - "$HOME/.cache/pip" - "$HOME/virtualenv/python3.5.2/lib/python3.5/site-packages" - -before_install: -- export SKIP_ON_TRAVIS=yes -- export CURRENT_DIR=$(pwd) -- export GSTREAMER=1.0 -- export ENABLE_PYTHON2=yes -- export ENABLE_PYTHON3=yes -- export ENABLE_GTK=yes -- export PYTHON_VERSION_MAJOR=3 -- export PYTHON_VERSION=3.5 -- export CFLAGS="-fPIC -O0 -ggdb -fno-inline -fno-omit-frame-pointer" -- export MAKEFLAGS="-j4" -- export PREFIX="${HOME}/jhbuild" -- export JHBUILD="${HOME}/gnome" -- export PATH=${PREFIX}/bin:${PREFIX}/sbin:${PATH} -- export LD_LIBRARY_PATH=${PREFIX}/lib:${LD_LIBRARY_PATH} -- export PYTHONPATH=${PREFIX}/lib/python${PYTHON_VERSION}/site-packages:/usr/lib/python${PYTHON_VERSION}/site-packages -- export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig:/usr/lib/pkgconfig -- export XDG_DATA_DIRS=${PREFIX}/share:/usr/share -- export XDG_CONFIG_DIRS=${PREFIX}/etc/xdg -- export PYTHON="python3" -- export PACKAGES="python3-gi python3-gi-cairo" -- export CC=gcc -- if [ '$GSTREAMER' = '1.0' ]; then sudo add-apt-repository -y ppa:ricotz/testing; - fi -- if [ '$GSTREAMER' = '1.0' ]; then sudo add-apt-repository -y ppa:gnome3-team/gnome3; - fi -- if [ '$GSTREAMER' = '1.0' ]; then sudo add-apt-repository -y ppa:gnome3-team/gnome3-staging; - fi -- sudo add-apt-repository -y ppa:pitti/systemd-semaphore -- sudo apt-get update -qq -- sudo apt-get update -qq -- sudo apt-get install -y libz-dev libbz2-dev gstreamer$GSTREAMER-tools libgstreamer$GSTREAMER-dev - libgstreamer-plugins-base$GSTREAMER-dev libgstreamer-plugins-bad$GSTREAMER-dev -- if [ '$GSTREAMER' = '1.0' ]; then sudo apt-get install -y libgstreamer-plugins-good$GSTREAMER-dev; - fi -- sudo apt-get update -qq -- sudo apt-get install -y gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 graphviz-dev - gstreamer1.0-plugins-good gstreamer1.0-plugins-bad python-gst-1.0 -- sudo apt-get install -qq python3-gi -- sudo apt-get install -qq python-gst-1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-bad - gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-libav libsndfile1-dev - libasound2-dev libgstreamer-plugins-base1.0-dev python-numpy python-scipy -- sudo apt-get -y install automake gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 - gstreamer1.0-libav gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good - gstreamer1.0-plugins-ugly gstreamer1.0-tools libasound2-dev libgstreamer-plugins-base1.0-dev - libsndfile1-dev python python-dev python-gi python-gst-1.0 python-gst-1.0 python-imaging - python-lxml python-numpy python-scipy python-virtualenv python3-gi -- sudo apt-get -y install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev - gnome-common; -- sudo apt-get -y install libgstreamer1.0-dev gstreamer1.0-alsa gstreamer1.0-plugins-base; -- sudo apt-get -y install python-dev libsmpeg-dev libswscale-dev libavformat-dev libavcodec-dev - libjpeg-dev libtiff4-dev libX11-dev libmtdev-dev; -- sudo apt-get -y install python-setuptools build-essential libgl1-mesa-dev libgles2-mesa-dev; -- sudo apt-get -y install xvfb pulseaudio; -- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo add-apt-repository 'deb http://us.archive.ubuntu.com/ubuntu/ - trusty main restricted universe multiverse'; fi -- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo add-apt-repository 'deb http://us.archive.ubuntu.com/ubuntu/ - trusty-updates main restricted universe multiverse'; fi -- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install - -qq pkg-config; fi -- sudo apt-get -y update -- sudo apt-get -y install ubuntu-restricted-extras -- sudo apt-get -y install libfftw3-dev -- sudo apt-get install -qq python3-dev python3-cairo-dev python3-gi gnome-common gtk-doc-tools - libgtk-3-dev libgirepository1.0-dev libmount-dev cvs; -- sudo apt-get update -q -- sudo apt-get install --no-install-recommends -y xvfb gir1.2-gtk-3.0 $(echo $PACKAGES) -- sudo apt-get install -qq build-essential git -- sudo apt-get install -qq gettext xsltproc docbook-xml docbook-xsl -- sudo apt-get install -qq bison docbook-xsl build-essential git-core python-libxml2 - byacc flex apt-file autopoint -- sudo apt-get install -qq apt-file -- sudo apt-file update -- sudo apt-get install wget -qq -- pip install virtualenv virtualenvwrapper -- sudo pip install --upgrade virtualenvwrapper -- export VIRTUALENV_WRAPPER_SH=`which virtualenvwrapper.sh` -- export VIRTUALENVWRAPPER_PYTHON=`which python3` -- export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv` -- pip install -I path.py==7.7.1 -- export WORKON_HOME=${HOME}/.virtualenvs -- export PROJECT_HOME=${HOME}/dev -- export VIRTUALENVWRAPPER_PYTHON=`which python3` -- export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv` -- env -- travis_retry source $VIRTUALENV_WRAPPER_SH -- export PYTHONSTARTUP=$HOME/.pythonrc -- export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache -- mkdir -p $WORKON_HOME -- mkvirtualenv scarlett_os -- bash ./ci/set_postactivate.sh -- workon scarlett_os -- pip install -U coveralls sphinx numpy ipython -- bash ./ci/travis.sh -- jhbuild run python3 setup.py install + - "$HOME/.ccache" + - "$HOME/jhbuild" + - "$HOME/gnome" install: -- sudo apt-get update -q -- sudo apt-get install --no-install-recommends -y xvfb gir1.2-gtk-3.0 $(echo $PACKAGES) + - travis_retry docker-compose pull + # set containers as privileged to bypass Travis environment limitations + - 'sed -i "/build: ./a \ \ privileged: true" docker-compose.yml' + - travis_retry docker-compose -f docker-compose.yml -f ci/build.yml build -script: jhbuild run python3 setup.py test +script: + #- "docker-compose -f docker-compose.test.yml run --rm ${TEST_TARGET}" + - docker run --privileged -v `pwd`:/home/pi/dev/bossjones-github/scarlett_os -i -t --rm scarlettos_scarlett_master make test -after_success: coveralls +after_success: + - _USER=$(ls -lta | awk '{print $3}') + - _GROUP=$(ls -lta | awk '{print $4}') + - sudo chown $_USER:$_GROUP -R . + - mv .coverage .coverage.tests + - coverage combine + # Coverage report contains Docker paths. We replace them, so that we can run Coveralls. + - sed -i 's@\"/home/pi/dev/bossjones-github/scarlett_os/@'"\"$(pwd)/"'@g' .coverage + - coveralls deploy: distributions: sdist bdist_wheel diff --git a/.travis_non_docker.yml b/.travis_non_docker.yml new file mode 100644 index 00000000..d064d16f --- /dev/null +++ b/.travis_non_docker.yml @@ -0,0 +1,161 @@ +matrix: + fast_finish: true + include: + - python: '3.5' + env: TOXENV=typing PYTHON="python3" PACKAGES="python3-gi python3-gi-cairo" + sudo: required + dist: trusty + language: python + group: edge + - python: '3.5' + env: TOXENV=py35 PYTHON="python3" PACKAGES="python3-gi python3-gi-cairo" + sudo: required + dist: trusty + language: python + group: edge + allow_failures: + - python: '3.5' + env: TOXENV=typing + +cache: + apt: true + directories: + - "$HOME/.cache/pip" + - "$HOME/virtualenv/python3.5.2/lib/python3.5/site-packages" + - "$HOME/.ccache" + - "$HOME/jhbuild" + - "$HOME/gnome" + + +before_install: +- export SKIP_ON_TRAVIS=yes +- export CURRENT_DIR=$(pwd) +- export GSTREAMER=1.0 +# - export ENABLE_PYTHON2=yes +- export ENABLE_PYTHON3=yes +- export ENABLE_GTK=yes +- export PYTHON_VERSION_MAJOR=3 +- export PYTHON_VERSION=3.5 +- export CFLAGS="-fPIC -O0 -ggdb -fno-inline -fno-omit-frame-pointer" +- export MAKEFLAGS="-j4" +- export PREFIX="${HOME}/jhbuild" +- export JHBUILD="${HOME}/gnome" +- export PATH=${PREFIX}/bin:${PREFIX}/sbin:${PATH} +- export LD_LIBRARY_PATH=${PREFIX}/lib:${LD_LIBRARY_PATH} +- export PYTHONPATH=${PREFIX}/lib/python${PYTHON_VERSION}/site-packages:/usr/lib/python${PYTHON_VERSION}/site-packages +- export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig:/usr/lib/pkgconfig +- export XDG_DATA_DIRS=${PREFIX}/share:/usr/share +- export XDG_CONFIG_DIRS=${PREFIX}/etc/xdg +- export PYTHON="python3" +- export PACKAGES="python3-gi python3-gi-cairo" +- export CC=gcc +- if [ '$GSTREAMER' = '1.0' ]; then sudo add-apt-repository -y ppa:ricotz/testing; + fi +- if [ '$GSTREAMER' = '1.0' ]; then sudo add-apt-repository -y ppa:gnome3-team/gnome3; + fi +- if [ '$GSTREAMER' = '1.0' ]; then sudo add-apt-repository -y ppa:gnome3-team/gnome3-staging; + fi +- sudo add-apt-repository -y ppa:pitti/systemd-semaphore +- travis_retry sudo apt-get update -qq +- travis_retry sudo apt-get update -qq +- travis_retry sudo apt-get install -y libz-dev libbz2-dev gstreamer$GSTREAMER-tools libgstreamer$GSTREAMER-dev + libgstreamer-plugins-base$GSTREAMER-dev libgstreamer-plugins-bad$GSTREAMER-dev +- if [ '$GSTREAMER' = '1.0' ]; then travis_retry sudo apt-get install -y libgstreamer-plugins-good$GSTREAMER-dev; + fi +- travis_retry sudo apt-get update -qq +- travis_retry sudo apt-get install -y gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 graphviz-dev + gstreamer1.0-plugins-good gstreamer1.0-plugins-bad python-gst-1.0 +- travis_retry sudo apt-get install -qq python3-gi +- travis_retry sudo apt-get install -qq python-gst-1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-bad + gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-libav libsndfile1-dev + libasound2-dev libgstreamer-plugins-base1.0-dev python-numpy python-scipy +- travis_retry sudo apt-get -y install automake gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 + gstreamer1.0-libav gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good + gstreamer1.0-plugins-ugly gstreamer1.0-tools libasound2-dev libgstreamer-plugins-base1.0-dev + libsndfile1-dev python python-dev python-gi python-gst-1.0 python-gst-1.0 python-imaging + python-lxml python-numpy python-scipy python-virtualenv python3-gi +- travis_retry sudo apt-get -y install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev + gnome-common; +- travis_retry sudo apt-get -y install libgstreamer1.0-dev gstreamer1.0-alsa gstreamer1.0-plugins-base; +- travis_retry sudo apt-get -y install python-dev libsmpeg-dev libswscale-dev libavformat-dev libavcodec-dev + libjpeg-dev libtiff4-dev libX11-dev libmtdev-dev; +- travis_retry sudo apt-get -y install python-setuptools build-essential libgl1-mesa-dev libgles2-mesa-dev; +- travis_retry sudo apt-get -y install xvfb pulseaudio; +- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo add-apt-repository 'deb http://us.archive.ubuntu.com/ubuntu/ + trusty main restricted universe multiverse'; fi +- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo add-apt-repository 'deb http://us.archive.ubuntu.com/ubuntu/ + trusty-updates main restricted universe multiverse'; fi +- if [ "$TRAVIS_OS_NAME" = "linux" ]; then travis_retry sudo apt-get update -qq; travis_retry sudo apt-get install + -qq pkg-config; fi +- travis_retry sudo apt-get -y update +- travis_retry sudo apt-get -y install ubuntu-restricted-extras +- travis_retry sudo apt-get -y install libfftw3-dev +- travis_retry sudo apt-get install -qq python3-dev python3-cairo-dev python3-gi gnome-common gtk-doc-tools + libgtk-3-dev libgirepository1.0-dev libmount-dev cvs; +- travis_retry sudo apt-get update -q +- travis_retry sudo apt-get install --no-install-recommends -y xvfb gir1.2-gtk-3.0 $(echo $PACKAGES) +- travis_retry sudo apt-get install -qq build-essential git +- travis_retry sudo apt-get install -qq gettext xsltproc docbook-xml docbook-xsl +- travis_retry sudo apt-get install -qq bison docbook-xsl build-essential git-core python-libxml2 + byacc flex apt-file autopoint +- travis_retry sudo apt-get install gcc automake autoconf libtool bison swig python-dev libpulse-dev -y +# NOTE: We only need this for sysdeps +# - travis_retry sudo apt-get install -qq apt-file +# - sudo apt-file update +# ubuntu 16.04 says: +# ['Linux', '4.4.0', '38', 'generic', 'x86_64', 'with', 'Ubuntu', '16.04', 'xenial'] +# travis says +# ['Linux', '4.4.0', '38', 'generic', 'x86_64', 'with', 'debian', 'jessie', 'sid'] +- python -c "import platform;print(platform.platform().split('-'))" +- travis_retry sudo apt-get install wget -qq +- pip install virtualenv virtualenvwrapper +- sudo pip install --upgrade virtualenvwrapper +- export VIRTUALENV_WRAPPER_SH=`which virtualenvwrapper.sh` +- export VIRTUALENVWRAPPER_PYTHON=`which python3` +- export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv` +- pip install -I path.py==7.7.1 +- export WORKON_HOME=${HOME}/.virtualenvs +- export PROJECT_HOME=${HOME}/dev +- export VIRTUALENVWRAPPER_PYTHON=`which python3` +- export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv` +- env +- travis_retry source $VIRTUALENV_WRAPPER_SH +- export PYTHONSTARTUP=$HOME/.pythonrc +- export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache +- mkdir -p $WORKON_HOME +- travis_retry mkvirtualenv scarlett_os +- travis_retry bash ./ci/set_postactivate.sh +- workon scarlett_os +- travis_retry pip install -U coveralls sphinx numpy ipython pytest-cov +- travis_retry bash ./ci/travis.sh +# - travis_retry jhbuild run -- pip install -e .[test] +- travis_retry jhbuild run python3 setup.py install + +install: +- travis_retry pip install -U coveralls sphinx numpy ipython +- travis_retry sudo apt-get update -q +- travis_retry sudo apt-get install --no-install-recommends -y xvfb gir1.2-gtk-3.0 $(echo $PACKAGES) + +script: +- jhbuild run -- coverage run -- setup.py test + +after_success: +- coveralls + +deploy: + distributions: sdist bdist_wheel + provider: pypi + user: bossjones + password: + secure: RTwOAJzBeEXy1as+a3sutcSjNTfoSg15ep8tHIjOqK0etkThWXNFs0FvWNuChV3zsFhA40sMpAamHvcGXJ717GAYIPstIrgAusLKM7OIUXpUF6kqvZsRQw9RPS4vBmueBoBo+pLY6q9gIP+Bav+fFwWocSyjwHLGcaOVdOF/m2VbWEg3p+SGwVolguSpWBNobLDmwj8yd/qiZ6b2LvTrOVkUENfa8Zk8BSXerZiTe98I2c/KuGqkVird+3LulK0kDU1FENO9v5eh+wZzElgbVSGfy87gkdc5whYIz4oA794Gc0jt+YiP2k0pNPRGAcrAn5MRjCdvWQtmkbxdns/JZOeK59SrhcQ6BRfDNQC97MPEZAz/E3qhiDPxwbhuK+LsdIiRHnazwv4MuUU27TcqwtTWcYijzT0aifiQUW6hLwpmVMx6GJy8dvhh+Ursr52jaAaFVx31NUB96+Wa204LCZV1CFo8vKgqDxTjZBfEK0zepQUh06dRdMJaeAN/dhsupMjnEfVY5GSv+ySKkJJ2r77mngyVO3snMs6x2sdH+PjfMnOEmQUcpnaNCQF01RxxfUz+7TY0JonM4yb7dnc+T402G+PhEDKGi5/O1YCIHwWQcMxhv2rMiYSlUt3ikcxkW8YGhhRvEUX1rGyAtPWBanyJ+KMb3QWv7huKE7Ezc/E= + on: + condition: "$TOXENV == py27" + repo: bossjones/scarlett_os + tags: true + +notifications: + slack: + on_success: change + on_failure: always + rooms: + secure: arS7e7IDG80ukrrjy4fVfNDh5Yqrz4mxmduWqJU2zHzwxL0QkJWnhncWBpTgXr06MVgWYwq/YnoCGZ+wcWHkYzsqDHWtFI0JguZuJcFAWV5l7PWOxcUUh731hipRcgkZIH03pqnfZTbN3kkNTvFcTL9NG92ZOYd/ZSQeCnNPF9T2PUjn5LnPNwOxJSVAdmvz7CoLJWIR6vF9ojoxZdMj1RhV4b1C9orP3pBh3V3sVc5ExX6cUePXJtkvb51fXwdCsGNA22xZrDfbxCoOXfMmgDuN/7W/DVPPyaZCInYQl2B/oLF+3TOqUZ8STM3BPDIBjxgPRBdULIqeaQJNNJ9rfQ6h+YhvCWDmZD5ugdTQkGCSX2hR4TGMnS9v/nu5KKSalQEkNOfcqZUSTRVHKL800arEwja2avRGu9KBlijg79r/k2EILb7sPfleeS0+eLKIYTBVyQvuiqo31NcZ4Yun9ykQlTJW0n1NiVrLRVHbCIScrHwyH8pI4ts6PbwtUO8HWWDXEUSZRipc14ckZBzqB6ozAAwtF4fStnHC5rkd1sRreZalLKsZxaVpsX0mspZfSLfz6eV34vnDs9Xv0+tPuW0X0P1/FZIykvjDrmoM8s5TD1xzES9zRslhWxK2yv0a5OaryWvicQKcCwg8zwdiCTAwq1wBNkYzrtTnTN9QnRA= diff --git a/Dockerfile b/Dockerfile index 049058ff..ff3bcb77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,257 +1,16 @@ -FROM behance/docker-base:latest +FROM bossjones/boss-docker-jhbuild-pygobject3:v1 MAINTAINER Malcolm Jones -# Prepare packaging environment -ENV DEBIAN_FRONTEND noninteractive +COPY ./ /home/pi/dev/bossjones-github/scarlett_os -# Workaround for bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=807948 -RUN chmod 0777 /tmp +WORKDIR /home/pi/dev/bossjones-github/scarlett_os -# ensure local python is preferred over distribution python -ENV PATH /usr/local/bin:$PATH +RUN set -x cd /home/pi/dev/bossjones-github/scarlett_os \ + && pwd \ + && jhbuild run python3 setup.py install \ + && jhbuild run -- pip install -e .[test] -# http://bugs.python.org/issue19846 -# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. -ENV LANG C.UTF-8 - -RUN apt-get update -q && \ - apt-get upgrade -yqq && \ - apt-get install -yqq \ - git \ - curl \ - wget \ - curl \ - software-properties-common \ - ca-certificates \ - && \ - locale-gen en_US.UTF-8 && export LANG=en_US.UTF-8 && \ - add-apt-repository ppa:git-core/ppa -y && \ - add-apt-repository ppa:ricotz/testing -y && \ - add-apt-repository ppa:gnome3-team/gnome3 -y && \ - add-apt-repository ppa:gnome3-team/gnome3-staging -y && \ - apt-get update && apt-get install -y --no-install-recommends \ - tcl \ - tk \ - wget \ - curl \ - ca-certificates && \ - apt-get update && apt-get install -y --no-install-recommends \ - bzr \ - git \ - mercurial \ - openssh-client \ - subversion \ - procps && \ - apt-get update && apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - bzip2 \ - file \ - g++ \ - gcc \ - imagemagick \ - libbz2-dev \ - libc6-dev \ - libcurl4-openssl-dev \ - libdb-dev \ - libevent-dev \ - libffi-dev \ - libgeoip-dev \ - libglib2.0-dev \ - libjpeg-dev \ - libkrb5-dev \ - liblzma-dev \ - libmagickcore-dev \ - libmagickwand-dev \ - libmysqlclient-dev \ - libncurses-dev \ - libpng-dev \ - libpq-dev \ - libreadline-dev \ - libsqlite3-dev \ - libssl-dev \ - libtool \ - libwebp-dev \ - libxml2-dev \ - libxslt-dev \ - libyaml-dev \ - make \ - patch \ - xz-utils \ - zlib1g-dev \ - bash \ - && rm -rf /var/lib/apt/lists/* - -ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D -ENV PYTHON_VERSION 3.5.2 - -# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" -ENV PYTHON_PIP_VERSION 8.1.2 - -RUN set -ex \ - && buildDeps=' \ - tcl-dev \ - tk-dev \ - ' \ - && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \ - \ - && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ - && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ - && export GNUPGHOME="$(mktemp -d)" \ - && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ - && gpg --batch --verify python.tar.xz.asc python.tar.xz \ - && rm -r "$GNUPGHOME" python.tar.xz.asc \ - && mkdir -p /usr/src/python \ - && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ - && rm python.tar.xz \ - \ - && cd /usr/src/python \ - && ./configure \ - --enable-loadable-sqlite-extensions \ - --enable-shared \ - && make -j$(nproc) \ - && make install \ - && ldconfig \ - \ -# explicit path to "pip3" to ensure distribution-provided "pip3" cannot interfere - && if [ ! -e /usr/local/bin/pip3 ]; then : \ - && wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ - && python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \ - && rm /tmp/get-pip.py \ - ; fi \ -# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python -# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages") -# https://github.com/docker-library/python/pull/143#issuecomment-241032683 - && pip3 install --no-cache-dir --upgrade --force-reinstall "pip==$PYTHON_PIP_VERSION" \ -# then we use "pip list" to ensure we don't have more than one pip version installed -# https://github.com/docker-library/python/pull/100 - && [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \ - \ - && find /usr/local -depth \ - \( \ - \( -type d -a -name test -o -name tests \) \ - -o \ - \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ - \) -exec rm -rf '{}' + \ - && apt-get purge -y --auto-remove $buildDeps \ - && rm -rf /usr/src/python ~/.cache - -# make some useful symlinks that are expected to exist -RUN cd /usr/local/bin \ - && { [ -e easy_install ] || ln -s easy_install-* easy_install; } \ - && ln -s idle3 idle \ - && ln -s pydoc3 pydoc \ - && ln -s python3 python \ - && ln -s python3-config python-config \ - && pip3 install virtualenv virtualenvwrapper ipython numpy tox coveralls - -# RUN pip3 install virtualenv virtualenvwrapper ipython numpy tox coveralls - -ENV PYTHON_VERSION_MAJOR '3' -ENV GSTREAMER '1.0' -ENV USER 'pi' -ENV USER_HOME "/home/${USER}" -ENV LANGUAGE_ID 1473 -ENV GITHUB_BRANCH "master" -ENV GITHUB_REPO_NAME 'scarlett_os' -ENV GITHUB_REPO_ORG 'bossjones' -ENV PI_HOME '/home/pi' -ENV MAIN_DIR '${PI_HOME}/dev/${GITHUB_REPO_ORG}-github/${GITHUB_REPO_NAME}' -ENV VIRT_ROOT '${PI_HOME}/.virtualenvs/${GITHUB_REPO_NAME}' -ENV PKG_CONFIG_PATH '${PI_HOME}/.virtualenvs/${GITHUB_REPO_NAME}/lib/pkgconfig' -ENV SCARLETT_CONFIG '${PI_HOME}/dev/${GITHUB_REPO_ORG}-github/${GITHUB_REPO_NAME}/tests/fixtures/.scarlett' -ENV SCARLETT_HMM '${PI_HOME}/dev/${GITHUB_REPO_ORG}-github/${GITHUB_REPO_NAME}/.virtualenvs/${GITHUB_REPO_NAME}/share/pocketsphinx/model/en-us/en-us' -ENV SCARLETT_LM '${PI_HOME}/dev/${GITHUB_REPO_ORG}-github/${GITHUB_REPO_NAME}/tests/fixtures/lm/${LANGUAGE_ID}.lm' -ENV SCARLETT_DICT '${PI_HOME}/dev/${GITHUB_REPO_ORG}-github/${GITHUB_REPO_NAME}/tests/fixtures/dict/${LANGUAGE_ID}.dic' -ENV LD_LIBRARY_PATH '${PI_HOME}/.virtualenvs/${GITHUB_REPO_NAME}/lib' -ENV GST_PLUGIN_PATH '${PI_HOME}/.virtualenvs/${GITHUB_REPO_NAME}/lib/gstreamer-${GSTREAMER}' -ENV PYTHON '/usr/local/bin/python3' -ENV PYTHON_VERSION '3.5' -ENV VIRTUALENVWRAPPER_PYTHON '/usr/local/bin/python3' -ENV VIRTUALENVWRAPPER_VIRTUALENV '/usr/local/bin/virtualenv' -ENV VIRTUALENVWRAPPER_SCRIPT '/usr/local/bin/virtualenvwrapper.sh' -ENV PYTHONSTARTUP '${USER_HOME}/.pythonrc' -ENV PIP_DOWNLOAD_CACHE '${USER_HOME}/.pip/cache' -ENV WORKON_HOME '${VIRT_ROOT}' - -RUN set -xe \ - && useradd -U -d ${PI_HOME} -m -r -G adm,sudo,dip,plugdev,tty,audio ${USER} \ - && usermod -a -G ${USER} ${USER} \ - && mkdir -p ${MAIN_DIR} \ - && mkdir -p ${PI_HOME}/dev/${GITHUB_REPO_ORG}-github \ - && chown -hR ${USER}:${USER} ${PI_HOME}/dev/${GITHUB_REPO_ORG}-github \ - && chown -hR ${USER}:${USER} ${MAIN_DIR} \ - && echo '${USER} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers \ - && echo '%${USER} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers \ - && chown -hR ${USER}:${USER} /usr/local/lib/python3.5/site-packages - -COPY ./dotfiles/.bashrc /home/pi/.bashrc -COPY ./dotfiles/.profile /home/pi/.profile - -RUN set -xe \ - && chown -hR ${USER}:${USER} ${MAIN_DIR} \ - && apt-get autoclean -y \ - && apt-get autoremove -y \ - && rm -rf /tmp/* /var/tmp/* \ - && rm -rf /var/lib/apt/lists/* - -# Layer customizations over existing structure COPY ./container/root / -# USER ${USER} - -# Ensure application code makes it into the /app directory -COPY ./ /home/pi/dev/bossjones-github/scarlett_os/ - -RUN ls -lta /home/pi/dev/bossjones-github/scarlett_os/ && \ - bash -c "source /usr/local/bin/virtualenvwrapper.sh && mkvirtualenv --system-site-packages ${GITHUB_REPO_NAME}" - -# RUN bash -c "source /usr/local/bin/virtualenvwrapper.sh && mkvirtualenv --system-site-packages ${GITHUB_REPO_NAME}" - -COPY ./postactivate /home/pi/.virtualenvs/scarlett_os/postactivate - -# RUN bash -c "/usr/sbin/sudo chown -hR ${USER}:${USER} /home/pi/.virtualenvs/scarlett_os/postactivate" - -# RUN bash -c "source /usr/local/bin/virtualenvwrapper.sh && workon ${GITHUB_REPO_NAME} && pip install -r /home/pi/home/pi/dev/bossjones-github/scarlett_os/requirements.txt" - -RUN set -xe \ - && chown -hR ${USER}:${USER} ${PI_HOME}/dev/${GITHUB_REPO_ORG}-github \ - && chown -hR ${USER}:${USER} ${MAIN_DIR} \ - && chown -hR ${USER}:${USER} /usr/local/lib/python3.5/site-packages \ - && chown -R ${USER}:${USER} /home/pi/.virtualenvs -# -# RUN sudo su - ${USER} -c "source /usr/local/bin/virtualenvwrapper.sh && workon ${GITHUB_REPO_NAME} && pip install -r /home/pi/home/pi/dev/bossjones-github/scarlett_os/requirements_dev.txt" - -# # virtualenv python runtime -# RUN sudo su - rdash -c "echo 'export WORKON_HOME=${WORKON_HOME}' >> /home/rdash/.profile" -# RUN sudo su - rdash -c "echo 'export PROJECT_HOME=${PROJECT_HOME}' >> /home/rdash/.profile" -# RUN sudo su - rdash -c "echo 'source /usr/local/bin/virtualenvwrapper.sh' >> /home/rdash/.profile" -# RUN sudo su - rdash -c "mkvirtualenv rdash" -# # RUN sudo su - rdash -c "mkproject rdash" -# RUN sudo su - rdash -c "echo 'workon rdash' >> /home/rdash/.profile" -# -# # Add source code -# -# #ADD . ${PROJECT_HOME} -# RUN git clone https://github.com/adysuciu/rdash-django.git ${PROJECT_HOME} -# -# # Environment info -# ADD rdash/.env ${PROJECT_HOME}/rdash/.env -# -# RUN chown -R rdash:users ${PROJECT_HOME} -# RUN chmod 755 ${PROJECT_HOME}/manage.py -# -# # Install django and dependencies -# RUN sudo su - rdash -c "${WORKON_HOME}/rdash/bin/pip install -r ${PROJECT_HOME}/requirements.txt" -# RUN sudo su - rdash -c 'echo {\"registry\":\"http://bower.herokuapp.com\"} > /home/rdash/.bowerrc' -# RUN sudo su - rdash -c "python ${PROJECT_HOME}/manage.py bower_install" -# RUN sudo su - rdash -c "python ${PROJECT_HOME}/manage.py collectstatic --noinput" -# #RUN sudo su - rdash -c "python ${PROJECT_HOME}/manage.py compilemessages" -# RUN sudo su - rdash -c "python ${PROJECT_HOME}/manage.py makemigrations" -# RUN sudo su - rdash -c "python ${PROJECT_HOME}/manage.py migrate" -# -# ENTRYPOINT ["sudo","su","-","rdash"] - -# CMD ["/bin/bash", "/run.sh"] -# ENTRYPOINT ["ls", "-lta", "/home/pi/dev/bossjones-github/scarlett_os/"] -ENTRYPOINT ["file","/bin/bash"] +ENTRYPOINT ["/docker_entrypoint.sh"] +CMD true diff --git a/Makefile b/Makefile index 83a92ef3..71e4c7c3 100644 --- a/Makefile +++ b/Makefile @@ -53,21 +53,39 @@ clean-test: ## remove test and coverage artifacts lint: ## check style with flake8 flake8 scarlett_os tests -test: ## run tests quickly with the default Python +pytest-install-test-deps: clean + pip install -e .[test] + python setup.py install - python setup.py test +pytest-run: + py.test -test-all: ## run tests on every Python version with tox - tox +jhbuild-run-test: + jhbuild run python setup.py install + jhbuild run -- pip install -e .[test] + jhbuild run -- coverage run -- setup.py test + jhbuild run -- coverage report -m -coverage: ## check code coverage quickly with the default Python +test: ## run tests quickly with the default Python + python setup.py test - coverage run --source scarlett_os setup.py test +test-clean-all: ## run tests on every Python version with tox + pip install -e .[test] + python setup.py install + coverage run setup.py test +coverage: ## check code coverage quickly with the default Python + coverage run --source scarlett_os setup.py test coverage report -m coverage html $(BROWSER) htmlcov/index.html +coverage-no-html: ## check code coverage quickly with the default Python + + coverage run --source scarlett_os setup.py test + + coverage report -m + docs: ## generate Sphinx HTML documentation, including API docs rm -f docs/scarlett_os.rst rm -f docs/modules.rst diff --git a/README.rst b/README.rst index 068057fe..79204561 100644 --- a/README.rst +++ b/README.rst @@ -3,6 +3,7 @@ ScarlettOS =============================== + .. image:: https://img.shields.io/pypi/v/scarlett_os.svg :target: https://pypi.python.org/pypi/scarlett_os @@ -17,6 +18,11 @@ ScarlettOS :target: https://pyup.io/repos/github/bossjones/scarlett_os/ :alt: Updates +.. image:: https://coveralls.io/repos/github/bossjones/scarlett_os/badge.svg?branch=master + :target: https://coveralls.io/github/bossjones/scarlett_os?branch=master + :alt: Coverage + + S.C.A.R.L.E.T.T is Tony Darks artificially programmed intelligent computer. She is programmed to speak with a female voice in a British accent. @@ -37,4 +43,3 @@ This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypack .. _Cookiecutter: https://github.com/audreyr/cookiecutter .. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage - diff --git a/ci/build.yml b/ci/build.yml new file mode 100644 index 00000000..1aa8c0ba --- /dev/null +++ b/ci/build.yml @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +scarlett_master: + build: . diff --git a/ci/travis.sh b/ci/travis.sh index f7905f5f..e55f1284 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -102,8 +102,7 @@ sudo apt-get install yasm nasm -qq # Get JHBuild # source: https://github.com/GNOME/jhbuild/commit/86d958b6778da649b559815c0a0dbe6a5d1a8cd4 (cd "${JHBUILD}" && - git clone https://github.com/GNOME/jhbuild.git && - cd jhbuild && + if test ! -d "${JHBUILD}/jhbuild"; then git clone https://github.com/GNOME/jhbuild.git && cd jhbuild; else echo "exists" && cd jhbuild; fi && git checkout 86d958b6778da649b559815c0a0dbe6a5d1a8cd4 && ./autogen.sh --prefix=/usr/local > /dev/null && make > /dev/null && @@ -133,7 +132,8 @@ fi # Need LGI from git master if [ "x${ENABLE_LUA51}" == "xyes" ]; then (cd "${JHBUILD}" && - git clone https://github.com/pavouk/lgi.git && cd lgi && + git clone https://github.com/pavouk/lgi.git && + cd lgi && jhbuild run make PREFIX="${PREFIX}" CFLAGS="${CFLAGS} -I/usr/include/lua5.1" && jhbuild run make install PREFIX="${PREFIX}"); @@ -155,7 +155,9 @@ fi # Need PyGObject built for Python 3 if [ "x${ENABLE_PYTHON3}" == "xyes" ]; then - (cd "${JHBUILD}" && cd pygobject && git checkout fb1b8fa8a67f2c7ea7ad4b53076496a8f2b4afdb && + (cd "${JHBUILD}" && + cd pygobject && + git checkout fb1b8fa8a67f2c7ea7ad4b53076496a8f2b4afdb && jhbuild run ./autogen.sh --prefix="${PREFIX}" --with-python=python3 > /dev/null && jhbuild run make install > /dev/null); fi diff --git a/container/root/clean.sh b/container/root/clean.sh new file mode 100755 index 00000000..e9286e5f --- /dev/null +++ b/container/root/clean.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +######################################################################## +# Performs cleanup, ensure unnecessary packages are removed +######################################################################## +# `apt-mark showauto` for any additional installed packages + +apt-get autoclean -y && \ +apt-get autoremove -y && \ +rm -rf /var/lib/{cache,log}/ && \ +rm -rf /var/lib/apt/lists/*.lz4 diff --git a/container/root/docker_entrypoint.sh b/container/root/docker_entrypoint.sh new file mode 100755 index 00000000..c7d5b033 --- /dev/null +++ b/container/root/docker_entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +# if [ ! -f /virtualenv/bin/activate ]; then +# virtualenv /virtualenv -p python${INSPIRE_PYTHON_VERSION} +# source /virtualenv/bin/activate +# pip install --upgrade pip setuptools wheel +# cp -r /src-cache /virtualenv/src +# else +# source /virtualenv/bin/activate +# fi + +# find \( -name __pycache__ -o -name '*.pyc' \) | xargs rm -rf +sudo chown pi:pi -R /home/pi/dev + +exec "$@" diff --git a/dotfiles/.bashrc b/container/root/dotfiles/.bashrc similarity index 100% rename from dotfiles/.bashrc rename to container/root/dotfiles/.bashrc diff --git a/dotfiles/.profile b/container/root/dotfiles/.profile similarity index 100% rename from dotfiles/.profile rename to container/root/dotfiles/.profile diff --git a/container/root/etc/services.d/scarlett_os/run b/container/root/etc/services.d/scarlett_os/run index f1d58c88..b28e40b5 100755 --- a/container/root/etc/services.d/scarlett_os/run +++ b/container/root/etc/services.d/scarlett_os/run @@ -1,3 +1,3 @@ #!/usr/bin/execlineb -P -with-contenv /home/pi/.virtualenvs/scarlett_os/bin/python3 --version +with-contenv jhbuild run python --version diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 00000000..80824df8 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,134 @@ +version: '2' + +services: + scarlett_master: + build: . + environment: + SERVER_LOG_MINIMAL: 1 + SERVER_APP_NAME: jhbuild-scarlett-os + S6_KILL_FINISH_MAXTIME: 1 + S6_KILL_GRACETIME: 1 + SERVER_WORKER_PROCESSES: 1 + volumes: + - ./:/home/pi/dev/bossjones-github/scarlett_os:rw + + default: + extends: + service: scarlett_master + volumes_from: + - scarlett_master:rw + command: "jhbuild run -- py.test --cov scarlett_os --cov-report term-missing" + # command: "jhbuild run -- python setup.py test" + # command: "ls -lta" + # command: jhbuild run -- coverage run -- setup.py test + # command: env + # unit: + # extends: + # service: scarlett_master + # volumes_from: + # - scarlett_master + # command: py.test tests/unit + # disambiguation: + # extends: + # service: scarlett_master + # command: py.test tests/integration/disambiguation + # volumes_from: + # - scarlett_master + # links: + # - database + # - indexer + # - rabbitmq + # - redis + # depends_on: + # - worker + # workflows: + # extends: + # service: scarlett_master + # command: py.test tests/integration/workflows + # volumes_from: + # - scarlett_master + # links: + # - database + # - indexer + # - rabbitmq + # - redis + # depends_on: + # - worker + # integration: + # extends: + # service: scarlett_master + # command: py.test tests/integration --ignore tests/integration/disambiguation --ignore tests/integration/workflows + # volumes_from: + # - scarlett_master + # links: + # - database + # - indexer + # - rabbitmq + # - redis + # depends_on: + # - worker + # acceptance: + # extends: + # service: scarlett_master + # command: py.test --driver Remote --host selenium --port 4444 --capability browserName firefox --html=selenium-report.html tests/acceptance + # volumes_from: + # - scarlett_master + # links: + # - database + # - indexer + # - rabbitmq + # - redis + # - selenium + # depends_on: + # - web + # - worker + # environment: + # - SERVER_NAME=web:5000 + # web: + # extends: + # service: scarlett_master + # command: gunicorn -b 0.0.0.0:5000 -t 3600 --access-logfile "-" inspirehep.wsgi_with_coverage + # volumes_from: + # - scarlett_master + # links: + # - database + # - indexer + # - rabbitmq + # - redis + # environment: + # - APP_SERVER_NAME=web:5000 + # worker: + # container_name: inspirehep-test-worker + # extends: + # service: scarlett_master + # command: celery worker -E -A inspirehep.celery --loglevel=INFO --purge + # volumes_from: + # - scarlett_master + # links: + # - database + # - indexer + # - rabbitmq + # - redis + # redis: + # container_name: inspirehep-test-redis + # image: redis + # indexer: + # container_name: inspirehep-test-indexer + # extends: + # file: services.yml + # service: indexer + # rabbitmq: + # container_name: inspirehep-test-rabbitmq + # image: rabbitmq + # database: + # container_name: inspirehep-test-database + # extends: + # file: services.yml + # service: database + # selenium: + # image: selenium/standalone-firefox:2.53.1-beryllium + # scarlett_master: + # container_name: inspirehep-test-scarlett_master + # extends: + # file: services.yml + # service: scarlett_master diff --git a/docker-compose.yml b/docker-compose.yml index 4a402098..bd75ea4c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,10 @@ scarlett_master: - build: . - environment: - - FAKE_ENV=random - - volumes: - - ./:/home/pi/dev/bossjones-github/scarlett_os + build: . + environment: + SERVER_LOG_MINIMAL: 1 + SERVER_APP_NAME: jhbuild-scarlett-os + S6_KILL_FINISH_MAXTIME: 1 + S6_KILL_GRACETIME: 1 + SERVER_WORKER_PROCESSES: 1 + volumes: + - ./:/home/pi/dev/bossjones-github/scarlett_os:rw diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 00000000..0d0330fa --- /dev/null +++ b/fabfile.py @@ -0,0 +1,294 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# NOTE: fab --show=debug if you need to debug stuff + +import sys +import os +import pprint +import re +import string +# import collections +import time +from fabric.operations import sudo, os +from fabric.api import abort, cd, env, get, hide, hosts, local, prompt, \ + put, require, roles, run, runs_once, settings, show, sudo, warn, prefix +from fabric.contrib.project import rsync_project, upload_project +from fabric.contrib.files import append, sed +from textwrap import dedent +import yaml +import csv + +pp = pprint.PrettyPrinter(indent=4, width=80) + +# from fabric.operations import run, put +# from fabric.contrib.files import exists +# from fabric.operations import reboot +# from fabric.colors import red, green, yellow, blue +# from fabric.utils import puts +# from fabric.tasks import execute +# from fabric.contrib.files import exists, sed + +VM_PATTERN = 'travis-ci/ubuntu1404' +USER = "vagrant" +HOME = "/home/{}".format(USER) +WORKON_HOME = "{}/.virtualenvs".format(HOME) +PROJECT_HOME = "{}/dev".format(HOME) +REPO_NAME = "scarlett_os" +REPO_ORG = "bossjones" +VENV_NAME = "{}".format(REPO_NAME) +PATH_TO_PROJECT = "{}/{}-github/{}".format(PROJECT_HOME, REPO_ORG, REPO_NAME) + + +def vagrant(): + """USAGE: + fab vagrant uname + + Note that the command to run Fabric might be different on different + platforms. + """ + + # global VM_PATTERN + # change from the default user to 'vagrant' + vagrant_ssh_config = local("cd $HOME/dev/{0} && vagrant ssh-config".format(VM_PATTERN), capture=True) + + hostname = re.findall(r'HostName\s+([^\n]+)', vagrant_ssh_config)[0] + port = re.findall(r'Port\s+([^\n]+)', vagrant_ssh_config)[0] + env.hosts = ['%s:%s' % (hostname, port)] + env.user = re.findall(r'User\s+([^\n]+)', vagrant_ssh_config)[0] + + identity_file = re.findall(r'IdentityFile\s+([^\n]+)', vagrant_ssh_config)[0] + + env.key_filename = identity_file[1:-1] + env.disable_known_hosts = True + env.forward_agent = True + env.colorize_errors = True + env.skip_bad_hosts = True + env.warn_only = True + + print(""" + hostname = {} + port = {} + env.hosts = {} + env.user = {} + env.key_filename = {} + env.disable_known_hosts = {} + env.forward_agent = {} +""".format(hostname, + port, + env.hosts, + env.user, + env.key_filename, + env.disable_known_hosts, + env.forward_agent)) + + result = local("cd $HOME/dev/{0} && vagrant global-status | grep running | grep '{0}'".format(VM_PATTERN), capture=True) + print("result: {}".format(result)) + machineId = result.split()[0] + print("machineId: {}".format(machineId)) + + +def uname(): + """Testing vagrant connections with uname -a.""" + run('uname -a') + + +def deploy(): + rsync_project(local_dir='.', + remote_dir='/home/vagrant/dev/bossjones-github/scarlett_os/', + exclude=['*.git', + '*.pyc', + '*.vagrant', + '*.vendor', + '.Python', + 'env/', + 'build/', + 'develop-eggs/', + 'dist/', + 'downloads/', + 'eggs/', + '.eggs/', + 'lib/', + 'lib64/', + 'parts/', + 'sdist/', + 'var/', + '*.egg-info/', + '.installed.cfg', + '*.egg', + '.tox/', + '.bundle/', + '.cache/', + '__pycache__/' + ], + ssh_opts='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + ) + + +def clean_build(): + """Nuke all testing directories before we get started.""" + # export WORKON_HOME=${HOME}/.virtualenvs + # export PROJECT_HOME=${HOME}/dev + # export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 + # export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv + # source /usr/local/bin/virtualenvwrapper.sh + # export PYTHONSTARTUP=$HOME/.pythonrc + # export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache + ################################################################################ + + with prefix('export VIRTUALENV_WRAPPER_SH=`which virtualenvwrapper.sh`'): + with prefix('export VIRTUALENVWRAPPER_PYTHON=`which python3.5`'): + with prefix('export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`'): + with prefix('export WORKON_HOME=${HOME}/.virtualenvs'): + with prefix('export PROJECT_HOME=${HOME}/dev'): + with prefix('source $VIRTUALENV_WRAPPER_SH'): + with prefix('export PYTHONSTARTUP=$HOME/.pythonrc'): + with prefix('export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache'): + with prefix('workon scarlett_os'): + with cd('/home/vagrant'): + sudo('pip3.5 install virtualenv virtualenvwrapper') + run('rm -rf /home/vagrant/dev/bossjones-github/scarlett_os') + run('rm -rf /home/vagrant/gnome') + run('rm -rf /home/vagrant/jhbuild') + with prefix('deactivate'): + run('rmvirtualenv scarlett_os') + + +def bootstrap_travisci(): + with prefix('export VIRTUALENV_WRAPPER_SH=`which virtualenvwrapper.sh`'): + with prefix('export VIRTUALENVWRAPPER_PYTHON=`which python3.5`'): + with prefix('export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`'): + with prefix('export WORKON_HOME=${HOME}/.virtualenvs'): + with prefix('export PROJECT_HOME=${HOME}/dev'): + with prefix('source $VIRTUALENV_WRAPPER_SH'): + with prefix('export PYTHONSTARTUP=$HOME/.pythonrc'): + with prefix('export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache'): + with prefix('mkvirtualenv --python=`which python3.5` scarlett_os'): + run('mkdir -p /home/vagrant/dev/bossjones-github/scarlett_os') + with prefix('workon scarlett_os'): + run('which python') + + +def read_yaml(): + with cd('/home/vagrant/dev/bossjones-github/scarlett_os'): + with open('.travis.yml', 'r') as f: + travis_config = yaml.safe_load(f) + print(yaml.dump(travis_config)) + travis_lines = ['#!/bin/bash', + 'set -x', + 'export DEBIAN_FRONTEND=noninteractive' + ] + + matrix = travis_config['matrix']['include'] + print('****************************matrix****************************') + for line in matrix: + print(line) + split_line = line['env'].split(" ") + print(split_line) + for l in split_line: + travis_lines.append("export {}".format(l)) + + before_install = travis_config['before_install'] + print(before_install) + print('****************************before_install****************************') + for line in before_install: + line = re.sub('mkvirtualenv scarlett_os', '', line) + # line = re.sub('travis_retry ', '', line) + # line = re.sub('pip install', 'pip3.5 install', line) + # line = re.sub('pip install -I path.py==7.7.1', '', line) + # line = re.sub('which python3', 'which python3.5', line) + ############################################################################# + # export TOXENV=typing + # export PYTHON="python3.5" + # export PACKAGES="python3-gi + # export python3-gi-cairo" + # export TOXENV=py35 + # export SKIP_ON_TRAVIS=yes + # export CURRENT_DIR=$(pwd) + # export GSTREAMER=1.0 + # export ENABLE_PYTHON2=yes + # export ENABLE_PYTHON3=yes + # export ENABLE_GTK=yes + # export PYTHON_VERSION_MAJOR=3 + # export PYTHON_VERSION=3.5 + # export CFLAGS="-fPIC -O0 -ggdb -fno-inline -fno-omit-frame-pointer" + # export MAKEFLAGS="-j4" + # export PREFIX="${HOME}/jhbuild" + # export JHBUILD="${HOME}/gnome" + # export PATH=${PREFIX}/bin:${PREFIX}/sbin:${PATH} + # export LD_LIBRARY_PATH=${PREFIX}/lib:${LD_LIBRARY_PATH} + # export PYTHONPATH=${PREFIX}/lib/python${PYTHON_VERSION}/site-packages:/usr/lib/python${PYTHON_VERSION}/site-packages + # export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig:/usr/lib/pkgconfig + # export XDG_DATA_DIRS=${PREFIX}/share:/usr/share + # export XDG_CONFIG_DIRS=${PREFIX}/etc/xdg + # export PACKAGES="python3-gi python3-gi-cairo" + # export CC=gcc + ############################################################################# + travis_lines.append(line) + print(line) + + install = travis_config['install'] + print('****************************install****************************') + for line in install: + line = re.sub('travis_retry ', '', line) + travis_lines.append(line) + print(line) + + print('****************************travis_lines****************************') + print(travis_lines) + + run('rm /home/vagrant/test_travis.sh') + append('/home/vagrant/test_travis.sh', travis_lines) + print('****************************patch test_travis****************************') + sed('/home/vagrant/test_travis.sh', 'travis_retry ', '') + sed('/home/vagrant/test_travis.sh', 'pip install', 'pip3.5 install') + sed('/home/vagrant/test_travis.sh', 'pip install -I path.py==7.7.1', '') + sed('/home/vagrant/test_travis.sh', 'which python3', 'which python3.5') + sed('/home/vagrant/test_travis.sh', '/usr/bin/python3', '/usr/local/bin/python3.5') + sed('/home/vagrant/test_travis.sh', 'PYTHON="python3"', 'PYTHON="python3.5"') + sed('/home/vagrant/test_travis.sh', 'pip3.5 install -I path.py==7.7.1', '') + print('****************************patch test_travis****************************') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/set_postactivate.sh', 'travis_retry ', '') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/set_postactivate.sh', 'pip install', 'pip3.5 install') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/set_postactivate.sh', 'pip install -I path.py==7.7.1', '') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/set_postactivate.sh', 'which python3', 'which python3.5') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/set_postactivate.sh', '/usr/bin/python3', '/usr/local/bin/python3.5') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/set_postactivate.sh', 'PYTHON="python3"', 'PYTHON="python3.5"') + print('****************************patch test_travis****************************') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/travis.sh', 'travis_retry ', '') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/travis.sh', 'pip install', 'pip3.5 install') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/travis.sh', 'pip install -I path.py==7.7.1', '') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/travis.sh', 'which python3', 'which python3.5') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/travis.sh', '/usr/bin/python3', '/usr/local/bin/python3.5') + sed('/home/vagrant/dev/bossjones-github/scarlett_os/ci/travis.sh', 'PYTHON="python3"', 'PYTHON="python3.5"') + print('****************************final-travis-script****************************') + run('cat /home/vagrant/test_travis.sh') + run('chmod +x /home/vagrant/test_travis.sh') + + +def run_travis(): + with cd('/home/vagrant/dev/bossjones-github/scarlett_os'): + run('/home/vagrant/test_travis.sh') + + +# fab vagrant clean_build +# fab vagrant bootstrap_travisci +# fab vagrant deploy +# fab vagrant read_yaml +# fab vagrant run_travis +# fab vagrant retest_travis + +def retest_travis(): + with prefix('export VIRTUALENV_WRAPPER_SH=`which virtualenvwrapper.sh`'): + with prefix('export VIRTUALENVWRAPPER_PYTHON=`which python3.5`'): + with prefix('export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`'): + with prefix('export WORKON_HOME=${HOME}/.virtualenvs'): + with prefix('export PROJECT_HOME=${HOME}/dev'): + with prefix('source $VIRTUALENV_WRAPPER_SH'): + with prefix('export PYTHONSTARTUP=$HOME/.pythonrc'): + with prefix('export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache'): + with prefix('workon scarlett_os'): + with cd('/home/vagrant/dev/bossjones-github/scarlett_os'): + run('jhbuild run python setup.py install') + run('jhbuild run -- pip install -e .[test]') + run('jhbuild run -- coverage run -- setup.py test') diff --git a/fs-scarlett.sh b/fs-scarlett.sh index c452a7e9..87e5391c 100755 --- a/fs-scarlett.sh +++ b/fs-scarlett.sh @@ -1,3 +1,18 @@ #!/usr/bin/env bash -fswatch -o . -e .git | xargs -n1 -I{} rsync -avz -e "ssh -i /Users/malcolm/dev/bossjones/scarlett_os/keys/vagrant_id_rsa -p 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" --port 2222 --exclude *.pyc --exclude *.git --exclude *.vagrant --exclude *.vendor . pi@127.0.0.1:/home/pi/dev/bossjones-github/scarlett_os/ +fswatch -o . -e .git | xargs -n1 -I{} rsync -avz -e \ + "ssh -i /Users/malcolm/dev/bossjones/scarlett_os/keys/vagrant_id_rsa \ + -p 2222 -o UserKnownHostsFile=/dev/null \ + -o StrictHostKeyChecking=no" \ + --port 2222 \ + --exclude *.pyc --exclude *.git --exclude *.vagrant \ + --exclude *.vendor \ + --exclude .Python --exclude env/ \ + --exclude build/ --exclude develop-eggs/ \ + --exclude dist/ --exclude downloads/ \ + --exclude eggs/ --exclude .eggs/ \ + --exclude lib/ --exclude lib64/ \ + --exclude parts/ --exclude sdist/ \ + --exclude var/ --exclude *.egg-info/ \ + --exclude .installed.cfg --exclude *.egg \ + . pi@127.0.0.1:/home/pi/dev/bossjones-github/scarlett_os/ diff --git a/requirements.txt b/requirements.txt index 6c99a389..7db786b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,6 @@ -pydbus==0.5.1 -colorlog -click==6.6 +pydbus>=0.5.0 +colorlog>=2.7 +click>=6.0 +psutil>=4.3.0 +Fabric3==1.12.post1 +PyYAML>=3.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 5ae33f2a..23e34ed3 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -pip==8.1.2 +pip>=7.0 bumpversion>=0.5.3 wheel>=0.29.0 watchdog>=0.8.3 @@ -17,6 +17,5 @@ pylint>=1.5.6 coveralls>=1.1 # data science -ipython==5.1.0 -gnureadline -pytest==3.0.3 +ipython>=5.1.0 +gnureadline>=6.3.0 diff --git a/scarlett_os/__init__.py b/scarlett_os/__init__.py index 2f4a418e..8c85fc84 100644 --- a/scarlett_os/__init__.py +++ b/scarlett_os/__init__.py @@ -1,22 +1,15 @@ # -*- coding: utf-8 -*- - from __future__ import absolute_import - -# from . import api -# from . import processor -# -# from .processor import Processor, get_processor, list_processors -# from .component import implements, interfacedoc, abstract +from .tools import package as ts_package +from .tools import verify as ts_verify __author__ = 'Malcolm Jones' __email__ = 'bossjones@theblacktonystark.com' __version__ = '0.1.0' - # source: timeside - -from .tools import package as ts_package +ts_verify.check_python3_installed() # Check Availability of Gstreamer python bindings ts_package.check_gi() @@ -33,3 +26,40 @@ # Clean-up del ts_package del absolute_import + +# Import psutil +try: + from psutil import __version__ as psutil_version +except ImportError: + print('PSutil library not found. ScarlettOS cannot start.') + sys.exit(1) + + +# def main(): +# """Main entry point for ScarlettOS. +# +# Select the mode (standalone, client or server) +# Run it... +# """ +# +# # TODO: Grabe values from cli, setup correct logging. +# # TODO: For now we'll default to scarlett_os.logger +# +# import platform +# import scarlett_os.logger +# import logging +# logger = logging.getLogger('scarlettlogger') +# +# # Log ScarlettOS and PSutil version +# logger.info('Start ScarlettOS {}'.format(__version__)) +# logger.info('{} {} and PSutil {} detected'.format( +# platform.python_implementation(), +# platform.python_version(), +# psutil_version)) +# +# # Share global var +# global core, dbus_server, listener, tasker, check_all_services +# +# # Create the ScarlettOS main instance +# # source: Glances +# # core = ScarlettOSMain() diff --git a/scarlett_os/__main__.py b/scarlett_os/__main__.py new file mode 100644 index 00000000..c5783fd3 --- /dev/null +++ b/scarlett_os/__main__.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# + +# ##################################################### +# # NOTE: THIS USE TO BE IN cli.py in ROOT folder +# ##################################################### +# from __future__ import absolute_import, division, print_function +# +# # import logging +# import click +# +# from . import __version__ +# ##################################################### + +"""Allow user to run ScarlettOS as a module.""" + +# Execute with: +# $ python -m scarlett_os + +# import scarlett_os +# import scarlett_os.cli +# +# +# if __name__ == '__main__': +# scarlett_os.cli.main() diff --git a/scarlett_os/cli.py b/scarlett_os/cli.py deleted file mode 100644 index 17f1930b..00000000 --- a/scarlett_os/cli.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import click - - -@click.command() -def main(args=None): - """Console script for scarlett_os""" - click.echo("Replace this message by putting your code into " - "scarlett_os.cli.main") - click.echo("See click documentation at http://click.pocoo.org/") - - -if __name__ == "__main__": - main() diff --git a/scarlett_os/compat.py b/scarlett_os/compat.py new file mode 100644 index 00000000..88c98076 --- /dev/null +++ b/scarlett_os/compat.py @@ -0,0 +1,9 @@ +# compatibility module. + +import itertools +import sys + +from six.moves import configparser + + +map = itertools.imap if sys.version_info < (3,) else map diff --git a/scarlett_os/tools/logger.py b/scarlett_os/logger.py similarity index 92% rename from scarlett_os/tools/logger.py rename to scarlett_os/logger.py index 6b0fec3d..7ea27949 100644 --- a/scarlett_os/tools/logger.py +++ b/scarlett_os/logger.py @@ -1,8 +1,5 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - import logging -logger = logging.getLogger('scarlett_os') +logger = logging.getLogger('scarlettlogger') try: from colorlog import ColoredFormatter diff --git a/scarlett_os/scarlett_os.py b/scarlett_os/scarlett_os.py deleted file mode 100644 index faa18be5..00000000 --- a/scarlett_os/scarlett_os.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- diff --git a/scarlett_os/scripts/__init__.py b/scarlett_os/scripts/__init__.py new file mode 100644 index 00000000..b3ab5bb3 --- /dev/null +++ b/scarlett_os/scripts/__init__.py @@ -0,0 +1 @@ +# module. diff --git a/scarlett_os/scripts/cli.py b/scarlett_os/scripts/cli.py new file mode 100644 index 00000000..d35d4d3d --- /dev/null +++ b/scarlett_os/scripts/cli.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +""" +Main click group for CLI +""" + +import logging +import os +import sys + +import click +from click_plugins import with_plugins +from pkg_resources import iter_entry_points + +import scarlett_os +from scarlett_os.compat import configparser + + +def configure_logging(verbosity): + log_level = max(10, 30 - 10 * verbosity) + logging.basicConfig(stream=sys.stderr, level=log_level) + + +def read_config(cfg): + parser = configparser.ConfigParser() + parser.read(cfg) + rv = {} + for section in parser.sections(): + for key, value in parser.items(section): + rv['{0}.{1}'.format(section, key)] = value + return rv + + +@with_plugins( + ep for ep in list(iter_entry_points('scarlett_os.scarlett_os_commands'))) +@click.group() +@click.version_option( + version=scarlett_os.__version__, + message='%(version)s' +) +@click.option( + "--name", + "-n", + help="Name ScarlettOS process explicitly.", + metavar="NAME", + default="scarlett_system" +) +@click.option( + "--daemon", + "-d", + is_flag=True, + help="Daemon mode, background process.", + default=False +) +@click.option( + '--mode', + '-m', + type=click.Choice(['dbus_server', 'listener', 'tasker', 'check_all_services']), + help="ScarlettOS type", + default='check_all_services' +) +@click.option( + "--master", + "-m", + is_flag=True, + help="Run ScarlettOS process as a Master", + default=False +) +@click.option( + "--slave", + "-s", + is_flag=True, + help="Run ScarlettOS process as a Slave", + default=False +) +@click.option( + '--etcd-host', + help="Etcd Host for distributed mode.", + default=False +) +@click.option( + "--quiet", + "-q", + is_flag=True, + help="Limit output to errors and warnings.", + default=False +) +@click.option( + "--verbose", + "-V", + is_flag=True, + help="Be verbose.", + default=False +) +@click.option( + '--config', + '-c', + type=click.Path(exists=True, resolve_path=True), + help="Config file" +) +@click.pass_context +def main_group(ctx, name, daemon, mode, master, slave, etcd_host, quiet, verbose, config): + """This is the command line interface to ScarlettOS. + """ + # NOTE: ctx + # Most public functions are actually methods of a 'context' object which + # is passed as the first parameter (ctx). The context object stores the + # precision, cached data, and a few other things. It also defines + # conversions so that the same high-level code can be used for several + # different base types (mpf, mpfs in Sage, intervals, Python floats) by + # switching contexts. + # + # The default context is called 'mp'. You can call most functions as + # mpmath.mp.foo(). The top-level function mpmath.foo() is just an alias + # for this. + + ctx.obj = {} + config = config or os.path.join(click.get_app_dir('scarlett_os'), 'scarlett_os.ini') + cfg = read_config(config) + if cfg: + ctx.obj['config_file'] = config + ctx.obj['cfg'] = cfg + ctx.default_map = cfg + + verbosity = (os.environ.get('SCARLETTOS_VERBOSE') or + ctx.lookup_default('scarlett_os.verbosity') or 0) + if verbose or quiet: + verbosity = verbose - quiet + verbosity = int(verbosity) + configure_logging(verbosity) + + ctx.obj['verbosity'] = verbosity diff --git a/scarlett_os/scripts/config.py b/scarlett_os/scripts/config.py new file mode 100644 index 00000000..447237db --- /dev/null +++ b/scarlett_os/scripts/config.py @@ -0,0 +1,37 @@ +import os + +import click + + +@click.command(short_help="Show all config settings.") +@click.pass_context +def config(ctx): + """Show access token and other configuration settings. + + The access token and command verbosity level can be set on the + command line, as environment variables, and in mapbox.ini config + files. + """ + ctx.default_map = ctx.obj['cfg'] + click.echo("CLI:") + # click.echo("access-token = {0}".format(ctx.obj['access_token'])) + # click.echo("verbosity = {0}".format(ctx.obj['verbosity'])) + click.echo("") + + click.echo("Environment:") + # if 'MAPBOX_ACCESS_TOKEN' in os.environ: + # click.echo("MAPBOX_ACCESS_TOKEN = {0}".format( + # os.environ['MAPBOX_ACCESS_TOKEN'])) + # if 'MapboxAccessToken' in os.environ: + # click.echo("MapboxAccessToken = {0}".format( + # os.environ['MapboxAccessToken'])) + # if 'MAPBOX_VERBOSE' in os.environ: + # click.echo("MAPBOX_VERBOSE = {0}".format( + # os.environ['MAPBOX_VERBOSE'])) + click.echo("") + + if 'config_file' in ctx.obj: + click.echo("Config file {0}:".format(ctx.obj['config_file'])) + for key, value in ctx.default_map.items(): + click.echo("{0} = {1}".format(key, value)) + click.echo("") diff --git a/scarlett_os/tools/package.py b/scarlett_os/tools/package.py index df38cb98..f2975f0e 100644 --- a/scarlett_os/tools/package.py +++ b/scarlett_os/tools/package.py @@ -63,6 +63,9 @@ def add_gi_packages(): python_version = sys.version[:3] global_path = os.path.join('/usr/lib', 'python' + python_version) + # import sys + # sys.path + if os.environ.get('PYTHONPATH'): py_path = os.environ.get('PYTHONPATH') py_paths = py_path.split(':') diff --git a/scarlett_os/tools/verify.py b/scarlett_os/tools/verify.py new file mode 100644 index 00000000..ef6644da --- /dev/null +++ b/scarlett_os/tools/verify.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + + +def check_python3_installed(): + import sys + if sys.version_info < (3, 4) <= sys.version_info < (3, 5): + print('ScarlettOS requires at least Python 3.5 or 3.4 to run.') + sys.exit(1) + + +def get_current_os(): + import platform + return platform.platform().split('-') diff --git a/setup.cfg b/setup.cfg index d837c4e8..fd3d5ab0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,3 +19,6 @@ universal = 1 [flake8] exclude = docs + +[tool:pytest] +addopts = --cov=scarlett_os --cov-report term-missing tests/ diff --git a/setup.py b/setup.py index 29263e43..afdac158 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,9 @@ import platform import re import warnings +import pprint +pp = pprint.PrettyPrinter(indent=4) + # Don't force people to install setuptools unless # we have to. @@ -20,19 +23,82 @@ from setuptools.command.test import test as TestCommand from setuptools.command import install_lib +PACKAGE_NAME = 'scarlett_os' +MINIMUM_PYTHON_VERSION = 3, 0 + + +print('Current Python Version, B: {}'.format(sys.version_info)) +# +# def check_python_version(): +# """Exit when the Python version is too low.""" +# if sys.version_info < (3, 4) <= sys.version_info < (3, 5): +# print('ScarlettOS requires at least Python 3.5 or 3.4 to run.') +# sys.exit(1) +# # if sys.version_info < MINIMUM_PYTHON_VERSION: +# # print("Using version: ") +# # sys.exit("Python {}.{}+ is required. Using {}".format(*MINIMUM_PYTHON_VERSION)) + with open('README.rst') as readme_file: readme = readme_file.read() with open('HISTORY.rst') as history_file: history = history_file.read() +static = {} + +for root, dirs, files in os.walk('static'): + for filename in files: + filepath = os.path.join(root, filename) + + if root not in static: + static[root] = [] + + static[root].append(filepath) + +# Might use this later +try: + here = os.path.abspath(os.path.dirname(__file__)) +except: + pass + + +def read_requirements(filename): + content = open(os.path.join(here, filename)).read() + requirements = map(lambda r: r.strip(), content.splitlines()) + return requirements + + requirements = [ 'Click>=6.0', - # TODO: put package requirements here + 'click-plugins', + 'pydbus>=0.5.0', + 'colorlog>=2.7', + 'psutil>=4.3.0', + 'six', + 'Fabric3==1.12.post1', + 'PyYAML>=3.0' ] + test_requirements = [ - 'pytest' + 'pytest>=3.0', + 'pip>=7.0', + 'bumpversion>=0.5.3', + 'wheel>=0.29.0', + 'watchdog>=0.8.3', + 'flake8>=2.6.2', + 'flake8-docstrings>=0.2.8', + 'coverage>=4.1', + 'Sphinx>=1.4.5', + 'cryptography==1.5.2', + 'PyYAML>=3.11', + 'pydocstyle>=1.0.0', + 'mypy-lang>=0.4', + 'pylint>=1.5.6', + 'coveralls>=1.1', + 'ipython>=5.1.0', + 'gnureadline>=6.3.0' + ] @@ -49,6 +115,10 @@ def run_tests(self): errno = pytest.main(self.test_args) sys.exit(errno) + +# check_python_version() + + setup( name='scarlett_os', version='0.1.0', @@ -62,10 +132,35 @@ def run_tests(self): ], package_dir={'scarlett_os': 'scarlett_os'}, - entry_points={ - 'console_scripts': [ - 'scarlett_os=scarlett_os.cli:main' - ] + # , + # entry_points={ + # 'console_scripts': [ + # 'hass = homeassistant.__main__:main' + # ] + # }, + # entry_points={ + # 'console_scripts': [ + # 'scarlett_os=scarlett_os.cli:main' + # ] + # }, + # source: mapbox-cli-py + entry_points=""" + [console_scripts] + scarlett_os=scarlett_os.scripts.cli:main_group + + [scarlett_os.scarlett_os_commands] + config=scarlett_os.scripts.config:config + """, + # geocoding=mapboxcli.scripts.geocoding:geocoding + # directions=mapboxcli.scripts.directions:directions + # distance=mapboxcli.scripts.distance:distance + # mapmatching=mapboxcli.scripts.mapmatching:match + # upload=mapboxcli.scripts.uploads:upload + # staticmap=mapboxcli.scripts.static:staticmap + # surface=mapboxcli.scripts.surface:surface + # dataset=mapboxcli.scripts.datasets:datasets + extras_require={ + 'test': ['coveralls', 'pytest>=3.0', 'pytest-cov'], }, include_package_data=True, install_requires=requirements, @@ -78,6 +173,7 @@ def run_tests(self): 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', ], test_suite='tests', diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 00000000..20d82efa --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +test_scarlett_os +---------------------------------- + +Tests for `scarlett_os` module. +""" + + +import sys +import unittest +import pytest +import click +import importlib +from contextlib import contextmanager +from click.testing import CliRunner + +import scarlett_os +from scarlett_os.scripts.cli import main_group +from scarlett_os.tools import verify + +import pprint + +ubuntu_version = verify.get_current_os() +pp = pprint.PrettyPrinter(indent=4) + + +class TestScarlettCli(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_command_line_interface_help(self): + runner = CliRunner() + result = runner.invoke(main_group) + assert result.exit_code == 0 + assert 'main_group' in result.output + assert 'This is the command line interface to ScarlettOS' in result.output + help_result = runner.invoke(main_group, ['--help']) + assert help_result.exit_code == 0 + print(help_result.output) + assert 'dbus_server|listener|tasker|check_all_services' in help_result.output + + +if __name__ == '__main__': + sys.exit(unittest.main()) diff --git a/tests/test_scarlett_os.py b/tests/test_scarlett_os.py index 49dbd911..ebabee00 100644 --- a/tests/test_scarlett_os.py +++ b/tests/test_scarlett_os.py @@ -11,13 +11,48 @@ import sys import unittest +import pytest import click +import importlib from contextlib import contextmanager from click.testing import CliRunner -from scarlett_os import scarlett_os -from scarlett_os import cli +import scarlett_os +from scarlett_os.scripts.cli import main_group +from scarlett_os.tools import verify +import pprint + +ubuntu_version = verify.get_current_os() +pp = pprint.PrettyPrinter(indent=4) + + +# from IPython.core.debugger import Tracer # NOQA +# from IPython.core import ultratb +# import traceback +# +# import logging +# logger = logging.getLogger('scarlettlogger') +# # from pydbus import SessionBus +# # from pydbus.green import sleep +# +# sys.excepthook = ultratb.FormattedTB(mode='Verbose', +# color_scheme='Linux', +# call_pdb=True, +# ostream=sys.__stdout__) + +# @pytest.fixture +# def runner(): +# """ +# Click's test helper. +# """ +# return CliRunner() + + +# @pytest.fixture +# def ubuntu_version(): +# """ubuntu_version.""" +# return ubuntu_version class TestScarlett_os(unittest.TestCase): @@ -28,8 +63,14 @@ def setUp(self): def tearDown(self): pass - def test_000_something(self): - pass + def test_imports_something(self): + assert importlib.util.find_spec("platform") is not None + assert importlib.util.find_spec("scarlett_os.logger") is not None + assert importlib.util.find_spec("logging") is not None + pp.pprint(dir(scarlett_os)) + print(scarlett_os.__name__) + print(scarlett_os.__package__) + print(scarlett_os.__file__) def test_gstreamer_versions(self): import gi @@ -39,19 +80,20 @@ def test_gstreamer_versions(self): Gst.debug_set_active(True) Gst.debug_set_default_threshold(1) - assert GObject.pygobject_version == (3, 22, 0) - # assert Gst.version_string() == 'GStreamer 1.8.2' + pp.pprint(ubuntu_version) + # ubuntu 16.04 says: + # ['Linux', '4.4.0', '38', 'generic', 'x86_64', 'with', 'Ubuntu', '16.04', 'xenial'] + # travis says + # ['Linux', '4.4.0', '38', 'generic', 'x86_64', 'with', 'debian', 'jessie', 'sid'] + # docker says: + # ['Linux', '4.4.17', 'boot2docker', 'x86_64', 'with', 'debian', 'stretch', 'sid'] + + if 'trusty' in ubuntu_version or 'jessie' in ubuntu_version or 'stretch' in ubuntu_version: + assert GObject.pygobject_version == (3, 22, 0) + else: + assert GObject.pygobject_version == (3, 20, 0) assert Gst.version_string() == 'GStreamer 1.8.2' - def test_command_line_interface(self): - runner = CliRunner() - result = runner.invoke(cli.main) - assert result.exit_code == 0 - assert 'scarlett_os.cli.main' in result.output - help_result = runner.invoke(cli.main, ['--help']) - assert help_result.exit_code == 0 - assert '--help Show this message and exit.' in help_result.output - if __name__ == '__main__': sys.exit(unittest.main())