I am trying to build a Django project with Travis
My builds keep showing the error below
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
/home/travis/build.sh: line 298: syntax error in conditional expression
/home/travis/build.sh: line 298: syntax error near `2.7/bin/activate'
/home/travis/build.sh: line 298: `if [[ ! -f ~/virtualenv/python– 2.7/bin/activate ]]; then'
Here is my .travis.yml file:
language: python
services:
– mysql
python:
– 2.7
env:
- DJANGO=1.9.2
before_install:
- export DJANGO_SETTINGS_MODULE=happny.settings.travis
install:
– pip install -r requirements/test.txt
before_script:
– python manage.py makemigrations
– python manage.py migrate
script:
– python manage.py test
branches:
only:
- master
The problem was the dash (-) character in the yaml file. Copying from a web page resulted in some formatting mismatch
I noticed the length of the dash was longer than normal. I fixed it by retyping the .travis.yml file by hand.
Try wrapping the python version in ""
python:
- "2.7"
Related
I am trying to build a CI with Travis for my docker app. In my docker compose I import a file called ".env". This file is gitignored so Travis cant use it. To fix the problem, I create the empty file in my .travis.yml file and set the environment variables on the website :
language: python
python:
- "3.6"
services:
- docker
before_script:
- touch .env
- pip install docker-compose
script:
- docker-compose run web sh -c "python manage.py test"
When I push on git, everything seem to work Travis side until the test start and Travis come to this line of code in my app :
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
There I have this error in Travis logs :
File "/home/pur_beurre/web/pur_beurre/settings.py", line 29, in <module>
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
AttributeError: 'NoneType' object has no attribute 'split'
1
The command "docker-compose run web sh -c "python manage.py test"" exited with 1.
Note : DJANGO_ALLOWED_HOSTS = localhost
When and where do you run export DJANGO_ALLOWED_HOSTS = localhost?
Also how do you call docker-compose run etc.?
You should consider that in order for your environment variables to be available to your docker-compose.yml file they need to be called from the same terminal where you exported DJANGO_ALLOWED_HOSTS.
You need to source your env file before you call docker-compose up -d as described in this answer:
set -a
source .my-env
docker-compose up -d
I advise you to read the answer I linked above.
I want to specify a GitLab job that creates a sphinx html documentation.
I am using a Python 3 alpine image (cannot specify which exactly).
the build stage within my .gitlab-ci.yml looks like this:
pages:
stage: build
tags:
- buildtag
script:
- pip install -U sphinx
- sphinx-build -b html docs/ public/
only:
- master
however, the pipeline fails: sphinx-build: command not found. (same error for make html)
According to This Tutorial, my .gitlab-ci.yml should be more or less correct.
What am I doing wrong? Is this issue related to the alpine image I am using?
As #Yasen correctly noted, the path to sphinx-build was not contained in $PATH. However, adding command in before sphinx-build did not solve the problem for me.
Anyway I found the solution in the the runner logs: The output of pip install -U sphinx produced the following warning:
WARNING: The scripts sphinx-apidoc, sphinx-autogen, sphinx-build and sphinx-quickstart are installed in 'some/path' which is not on PATH.
so I added export PATH="some/path" to the script-step in the .gitlab-ci.yml:
script:
- pip install -U sphinx
- export PATH="some/path"
- sphinx-build -b html docs/ public/
Did the command pip install -U sphinx succeed? (You should be able to tell that from the CI job log.)
If so, you may need to specify the full path to sphinx-build, as Yasen said.
If it did not succeed, you should troubleshoot the installation of Sphinx.
Most likely the reason is that $PATH doesn't contain path to sphinx-build
TL;DR try to use command
Try this:
pages:
stage: build
tags:
- buildtag
script:
- pip install -U sphinx
- command sphinx-build -b html docs/ public/
only:
- master
Explanation
GitLab runners run different way
Since GitLab CI uses runners, runner's shell profile may differ from commonly used.
So, your runner may be configured without declared $PATH to the directory that contains sphinx-build
Zsh/Bash startup files loading order (.bashrc, .zshrc etc.)
See this explanation:
The issue is that Bash sources from a different file based on what kind of shell it thinks it is in. For an “interactive non-login shell”, it reads .bashrc, but for an “interactive login shell” it reads from the first of .bash_profile, .bash_login and .profile (only). There is no sane reason why this should be so; it’s just historical.
What command does mean?
Since we don't know the path where sphinx-build installed, you may use commands like: which, type, etc.
As per this great answer(shell - Why not use "which"? What to use then? - Unix & Linux Stack Exchange, author recommends to use command <name>, or $(command -v <name>)
I have a travis job that looks like this:
jobs:
include:
- stage: "Unit tests"
language: python
python:
- "3.6"
- "3.7"
install:
- pip install -r requirements.txt
script:
- python -m unittest test.client
I would expect this unit test to run two jobs one for python 3.6 and one for 3.7 however it always only runs for the first version listed. Am I missing something here? I followed the guide from the docs
Thanks
The python versions are not defined within the jobs but on the root level.
python:
- "3.6"
- "3.7"
jobs:
...
I found this out because travis recently introduced a build config validation. It can be found under your build -> View config -> Build config validation
I know there are a number of these questions, but none seem to solve my issue.
I'm running ruby SASS via django-pipelines.
During deployment, pipelines compiles some SASS files through the command python manage.py collectstatic --noinput which is done by Heroku automatically.
Previously I had no problems deploying this. I've recently come back to the code and now when I deploy to Heroku, I receive the following errors (full error log can be found here):
File "/app/.heroku/python/lib/python2.7/site-packages/pipeline/compilers/__init__.py", line 126, in execute_command
"{0!r} exit code {1}\n{2}".format(argument_list, compiling.returncode, stderr))
pipeline.exceptions.CompilerError: ['/usr/bin/env', 'sass', '--load-path', '/app/app/static', '--load-path', '/app/app2/static', u'/app/staticfiles/app2/stylesheets/app2.scss', u'/app/staticfiles/app2/stylesheets/app2.css'] exit code 1
/tmp/build_8d2e04464970e15667c8f825fc387c8a/myapp-8b763976868799a3f147ac8cedbd82421efa7525/vendor/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- bundler/setup (LoadError)
from /tmp/build_8d2e04464970e15667c8f825fc387c8a/myapp-8b763976868799a3f147ac8cedbd82421efa7525/vendor/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /tmp/build_8d2e04464970e15667c8f825fc387c8a/myapp-8b763976868799a3f147ac8cedbd82421efa7525/vendor/bundle/bin/sass:14:in `<main>'
! Error while running '$ python manage.py collectstatic --noinput'.
As you can see, I've deployed using Ruby 2.2.2 previously, but now bundler has been updated on Heroku from 1.9.7 to 1.11.2.
Sass is the same version (3.4.19).
Line 14 of bin/sass from the last successful deployment on heroku.
$ sass --version
Sass 3.4.19 (Selective Steve)
$ cat ./vendor/bundle/bin/sass | sed '14!d'
require 'bundler/setup'
$ bundle --version
Bundler version 1.9.7
Curiously, the contents of my local version of bin/sass look nothing like the one on Heroku.
$ cat ~/.rvm/gems/ruby-2.2.2#app/bin/sass | sed '14!d'
str = ARGV.first
Locally, I'm running Ruby 2.2.2 and have tried both bundler 1.10.6 and 1.11.2.
Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.2.2'
gem 'sass', '3.4.19'
I had the same problem as yours and found that the only solution was to switch out the SASS Compiler with Compass Compiler (installed with the django-pipeline-compass package). See Andrew's answer here: https://stackoverflow.com/a/31420009/6080975
tl;dr:
I'm setting up CI for a project of mine, hosted on github, using tox and travis-ci. At the end of the build, I run converalls to push the coverage reports to coveralls.io. I would like to make this command 'conditional' - for execution only when the tests are run on travis; not when they are run on my local machine. Is there a way to make this happen?
The details:
The package I'm trying to test is a python package. I'm using / planning to use the following 'infrastructure' to set up the tests :
The tests themselves are of the py.test variety.
The CI scripting, so to speak, is from tox. This lets me run the tests locally, which is rather important to me. I don't want to have to push to github every time I need a test run. I also use numpy and matplotlib in my package, so running an inane number of test cycles on travis-ci seems overly wasteful to me. As such, ditching tox and simply using .travis.yml alone is not an option.
The CI server is travis-ci
The relevant test scripts look something like this :
.travis.yml
language: python
python: 2.7
env:
- TOX_ENV=py27
install:
- pip install tox
script:
- tox -e $TOX_ENV
tox.ini
[tox]
envlist = py27
[testenv]
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
deps =
pytest
coverage
pytest-cov
coveralls
commands =
py.test --cov={envsitepackagesdir}/mypackage --cov-report=term --basetemp={envtmpdir}
coveralls
This file lets me run the tests locally. However, due to the final coveralls call, the test fails in principle, with :
py27 runtests: commands[1] | coveralls
You have to provide either repo_token in .coveralls.yml, or launch via Travis
ERROR: InvocationError: ...coveralls'
This is an expected error. The passenv bit sends along the necessary information from travis to be able to write to coveralls, and without travis there to provide this information, the command should fail. I don't want this to push the results to coveralls.io, either. I'd like to have coveralls run only if the test is occuring on travis-ci. Is there any way in which I can have this command run conditionally, or set up a build configuration which achieves the same effect?
I've already tried moving the coveralls portion into .travis.yml, but when that is executed coveralls seems to be unable to locate the appropriate .coverage file to send over. I made various attempts in this direction, none of which resulted in a successful submission to coveralls.io except the combination listed above. The following was what I would have hoped would work, given that when I run tox locally I do end up with a .coverage file where I'd expect it - in the root folder of my source tree.
No submission to coveralls.io
language: python
python: 2.7
env:
- TOX_ENV=py27
install:
- pip install tox
- pip install python-coveralls
script:
- tox -e $TOX_ENV
after_success:
- coveralls
An alternative solution would be to prefix the coveralls command with a dash (-) to tell tox to ignore its exit code as explained in the documentation. This way even failures from coveralls will be ignored and tox will consider the test execution as successful when executed locally.
Using the example configuration above, it would be as follows:
[tox]
envlist = py27
[testenv]
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
deps =
pytest
coverage
pytest-cov
coveralls
commands =
py.test --cov={envsitepackagesdir}/mypackage --cov-report=term --basetemp={envtmpdir}
- coveralls
I have a similar setup with Travis, tox and coveralls. My idea was to only execute coveralls if the TRAVIS environment variable is set. However, it seems this is not so easy to do as tox has trouble parsing commands with quotes and ampersands. Additionally, this confused Travis me a lot.
Eventually I wrote a simple python script run_coveralls.py:
#!/bin/env/python
import os
from subprocess import call
if __name__ == '__main__':
if 'TRAVIS' in os.environ:
rc = call('coveralls')
raise SystemExit(rc)
In tox.ini, replace your coveralls command with python {toxinidir}/run_coveralls.py.
I am using a environmental variable to run additional commands.
tox.ini
commands =
coverage run runtests.py
{env:POST_COMMAND:python --version}
.travis.yml
language: python
python:
- "3.6"
install: pip install tox-travis
script: tox
env:
- POST_COMMAND=codecov -e TOX_ENV
Now in my local setup, it print the python version. When run from Travis it runs codecov.
Alternative solution if you use a Makefile and dont want a new py file:
define COVERALL_PYSCRIPT
import os
from subprocess import call
if __name__ == '__main__':
if 'TRAVIS' in os.environ:
rc = call('coveralls')
raise SystemExit(rc)
print("Not in Travis CI, skipping coveralls")
endef
export COVERALL_PYSCRIPT
coveralls: ## runs coveralls if TRAVIS in env
#python -c "$$COVERALL_PYSCRIPT"
In tox.ini add make coveralls to commands