{"id":255,"date":"2016-10-05T04:39:34","date_gmt":"2016-10-04T20:39:34","guid":{"rendered":"http:\/\/vinta.ws\/code\/?p=255"},"modified":"2026-03-17T01:19:24","modified_gmt":"2026-03-16T17:19:24","slug":"speed-up-python-and-node-js-builds-on-travis-ci","status":"publish","type":"post","link":"https:\/\/vinta.ws\/code\/speed-up-python-and-node-js-builds-on-travis-ci.html","title":{"rendered":"Speed up Python and Node.js builds on Travis CI"},"content":{"rendered":"<p>Travis CI's caching archives all directories listed in the configuration and uploads them to Amazon S3. Cached contents are available to any build on the repository, including Pull Requests. For Python and Node.js projects, you could cache both <code>site-packages<\/code> and <code>node_modules<\/code> directories in every Travis CI build.<\/p>\n<p>Here is an example of <code>.travis.yml<\/code>:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-yaml\">sudo: false\n\nlanguage: python\n\npython:\n  - \"2.7\"\n\nnode_js: 4\n\ncache:\n  directories:\n    - $HOME\/.cache\/pip\n    - $HOME\/virtualenv\/python2.7.9\/lib\/python2.7\/site-packages\n    - node_modules\n\nbefore_install:\n  - pip install -U pip\n\ninstall:\n  - pip install -r requirements.txt\n  - pip install coverage --ignore-installed\n  - npm install\n\nscript:\n  - coverage run manage.py test<\/code><\/pre>\n<p>In my case, after applying these changes, the installation time of <code>pip<\/code> and <code>npm<\/code> reduces from 180 seconds to 5 seconds.<\/p>\n<p>One thing should be mentioned here: Since we didn't specify any <code>bin<\/code> folder in the configuration (and I don't think that's necessary), any executable file that is installed by <code>pip<\/code> such as <code>coverage<\/code> or <code>django-admin.py<\/code> will not exist in subsequent builds. If you need those commands, you could just force install them by adding <code>pip install some_package --ignore-installed<\/code>.<\/p>\n<p>ref:<br \/>\n<a href=\"https:\/\/docs.travis-ci.com\/user\/caching\/\">https:\/\/docs.travis-ci.com\/user\/caching\/<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/19422229\/how-to-cache-requirements-for-a-django-project-on-travis-ci\">https:\/\/stackoverflow.com\/questions\/19422229\/how-to-cache-requirements-for-a-django-project-on-travis-ci<\/a><br \/>\n<a href=\"https:\/\/tzangms.com\/how-to-speed-up-python-unit-test-on-travis-ci\/\">https:\/\/tzangms.com\/how-to-speed-up-python-unit-test-on-travis-ci\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For Python and Node.js projects, you could totally cache both site-packages and node_modules directories in every Travis CI build.<\/p>\n","protected":false},"author":1,"featured_media":271,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,7,4],"tags":[128,11,12,2,45],"class_list":["post-255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-about-devops","category-about-javascript","category-about-python","tag-ci","tag-javascript","tag-node-js","tag-python","tag-testing"],"_links":{"self":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/comments?post=255"}],"version-history":[{"count":0,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media\/271"}],"wp:attachment":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media?parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}