├── .gitignore ├── .kitchen.yml ├── .travis.yml ├── Berksfile ├── Berksfile.lock ├── CHANGELOG.md ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── NOTICE.txt ├── README.md ├── Rakefile ├── TESTING.md ├── ZPL.txt ├── attributes └── default.rb ├── files └── default │ └── get-pip.py ├── libraries └── matchers.rb ├── metadata.rb ├── providers ├── pip.rb └── virtualenv.rb ├── recipes ├── default.rb ├── package.rb ├── pip.rb ├── source.rb └── virtualenv.rb ├── resources ├── pip.rb └── virtualenv.rb ├── spec ├── default_spec.rb └── spec_helper.rb └── test ├── cookbooks └── python_test │ ├── README.md │ ├── files │ └── default │ │ └── tests │ │ └── minitest │ │ ├── cook-3084_test.rb │ │ └── test_pip_test.rb │ ├── metadata.rb │ └── recipes │ ├── cook-3084.rb │ ├── test_exert.rb │ ├── test_pip.rb │ └── test_virtualenv.rb └── integration ├── exert └── bats │ └── exert.bats ├── source └── bats │ └── source.bats └── virtualenv └── bats └── virtualenv.bats /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | *~ 3 | *# 4 | .#* 5 | \#*# 6 | .*.sw[a-z] 7 | *.un~ 8 | /cookbooks 9 | 10 | # Bundler 11 | bin/* 12 | .bundle/* 13 | .kitchen/ 14 | .kitchen.local.yml 15 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver_plugin: vagrant 3 | driver_config: 4 | require_chef_omnibus: true 5 | 6 | platforms: 7 | - name: ubuntu-12.10 8 | driver_config: 9 | box: opscode-ubuntu-12.10 10 | box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.10_provisionerless.box 11 | run_list: ["recipe[apt]"] 12 | 13 | - name: ubuntu-12.04 14 | driver_config: 15 | box: opscode-ubuntu-12.04 16 | box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box 17 | run_list: ["recipe[apt]"] 18 | 19 | - name: ubuntu-10.04 20 | driver_config: 21 | box: opscode-ubuntu-10.04 22 | box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box 23 | run_list: ["recipe[apt]"] 24 | 25 | - name: centos-5.9 26 | driver_config: 27 | box: opscode-centos-5.9 28 | box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box 29 | 30 | - name: centos-6.4 31 | driver_config: 32 | box: opscode-centos-6.4 33 | box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box 34 | 35 | suites: 36 | - name: default 37 | run_list: 38 | - recipe[minitest-handler] 39 | - recipe[python] 40 | - recipe[python_test::cook-3084] 41 | attributes: {} 42 | - name: pip 43 | run_list: 44 | - recipe[minitest-handler] 45 | - recipe[python] 46 | - recipe[python_test::test_pip] 47 | 48 | - name: source 49 | run_list: 50 | - recipe[minitest-handler] 51 | - recipe[python] 52 | - recipe[python_test::cook-3084] 53 | attributes: {python: {install_method: "source"}} 54 | - name: exert 55 | excludes: ["centos-5.9"] 56 | run_list: 57 | - recipe[python] 58 | - recipe[python_test::test_exert] 59 | - name: virtualenv 60 | run_list: 61 | - recipe[python] 62 | - recipe[python_test::test_virtualenv] 63 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.9.3 4 | - 2.0.0 5 | bundler_args: --deployment --binstubs 6 | before_script: 7 | - ./bin/berks install 8 | script: 9 | - ./bin/foodcritic -f any . 10 | - ./bin/rake 11 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | site 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook "minitest-handler" 7 | cookbook "apt" 8 | cookbook "yum" 9 | cookbook "build-essential" 10 | cookbook "python_test", :path => "./test/cookbooks/python_test" 11 | end 12 | -------------------------------------------------------------------------------- /Berksfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "sources": { 3 | "python": { 4 | "path": "." 5 | }, 6 | "minitest-handler": { 7 | "locked_version": "1.1.2" 8 | }, 9 | "apt": { 10 | "locked_version": "2.3.4" 11 | }, 12 | "yum": { 13 | "locked_version": "3.0.2" 14 | }, 15 | "build-essential": { 16 | "locked_version": "1.4.2" 17 | }, 18 | "python_test": { 19 | "path": "./test/cookbooks/python_test" 20 | }, 21 | "chef_handler": { 22 | "locked_version": "1.1.4" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | python Cookbook CHANGELOG 2 | ========================= 3 | This file is used to list changes made in each version of the python cookbook. 4 | 5 | v1.4.6 6 | ------ 7 | 8 | - **[#61](https://github.com/poise/python/pull/61)** – Python packages specified for Fedora platform. 9 | - **[#62](https://github.com/poise/python/pull/62)** – Use tgz archive instead of tbz2 as new releases no longer offer tb2 10 | - **[#72](https://github.com/poise/python/pull/72)** – Set $HOME in virtualenv provider 11 | - **[#74](https://github.com/poise/python/pull/74)** – Allow setting of virtualenv version 12 | - **[#78](https://github.com/poise/python/pull/78)** – AFix the pip version_check_cmd to use the virtualenv pip when applicable 13 | - **[#79](https://github.com/poise/python/pull/79)** – Add ability in pip lwrp to send custom env vars 14 | - **[#80](https://github.com/poise/python/pull/80)** – Update to yum3 yum-epel cookbook 15 | - Remove ez_setup.py usage and upgrade get-pip.py to 1.5.2. 16 | 17 | v1.4.4 18 | ------ 19 | [COOK-3816] - Including ez_setup script with cookbook instead of downloading from the internet 20 | 21 | 22 | v1.4.2 23 | ------ 24 | ### Bug 25 | - **[COOK-3796](https://tickets.chef.io/browse/COOK-3796)** - Virtualenv can fail 26 | 27 | ### Improvement 28 | - **[COOK-3719](https://tickets.chef.io/browse/COOK-3719)** - Allow alternative install python, update pip location 29 | - **[COOK-3703](https://tickets.chef.io/browse/COOK-3703)** - Create symlink for source built python [python3 support] 30 | 31 | 32 | v1.4.0 33 | ------ 34 | ### New Feature 35 | - **[COOK-3248](https://tickets.chef.io/browse/COOK-3248)** - Improve testing suite 36 | 37 | ### Improvement 38 | - **[COOK-3125](https://tickets.chef.io/browse/COOK-3125)** - Don't use `normal` attributes 39 | 40 | ### Bug 41 | - **[COOK-3084](https://tickets.chef.io/browse/COOK-3084)** - Fix `python_virtualenv` on EL 5 42 | 43 | v1.3.6 44 | ------ 45 | ### Bug 46 | - [COOK-3305]: distribute merged back into setuptools 47 | 48 | ### New Feature 49 | - [COOK-3248]: Improve testing suite in the python cookbook 50 | 51 | v1.3.4 52 | ------ 53 | ### Bug 54 | - [COOK-3137]: `python_pip` LWRP cannot have differnent name and `package_name` 55 | 56 | v1.3.2 57 | ------ 58 | ### Bug 59 | - [COOK-2917]: python::source fails on CentOS 6.3 minimal (make: command not found) 60 | - [COOK-3077]: Python - pip fails to install when `['python']['install_method'] == 'source'` 61 | 62 | v1.3.0 63 | ------ 64 | ### Bug 65 | - [COOK-2376]: Python pip default action 66 | - [COOK-2468]: python cookbook - Chef 11 compat fixes 67 | - [COOK-2882]: Python source recipe fails on Ubuntu 12.10 because of unavailable libdb4.8-dev package 68 | - [COOK-3009]: fix build time dependencies and gcc flags for python source on newer ubuntus 69 | 70 | ### New Feature 71 | - [COOK-2449]: Make the distribute download location an attribute 72 | - [COOK-3008]: Update python::source to install 2.7.5 73 | 74 | ### Sub-task 75 | - [COOK-2866]: python::source checks existence of a directory that already exists 76 | 77 | v1.2.2 78 | ------ 79 | - [COOK-2297] - more gracefully handle pip packages from VCS and source archives 80 | 81 | v1.2.0 82 | ------ 83 | - [COOK-1866] - /usr/bin is not a pip binary location in source installs on RHEL 84 | - [COOK-1925] - add smartos support 85 | 86 | v1.1.0 87 | ------ 88 | - [COOK-1715] - Add user and group to python_pip 89 | - [COOK-1727] - Python cookbook cannot install `pip` on CentOS versions < 6 90 | 91 | v1.0.8 92 | ------ 93 | - [COOK-1016] - python package needs separate names for centos/rhel 5.x vs 6.x 94 | - [COOK-1048] - installation of pip does not honor selected python version 95 | - [COOK-1282] - catch Chef::Exceptions::ShellCommandFailed for chef 0.10.8 compatibility 96 | - [COOK-1311] - virtualenv should have options attribute 97 | - [COOK-1320] - pip provider doesn't catch correct exception 98 | - [COOK-1415] - use plain 'python' binary instead of versioned one for default interpreter 99 | 100 | v1.0.6 101 | ------ 102 | - [COOK-1036] - correctly grep for python-module version 103 | - [COOK-1046] - run pip inside the virtualenv 104 | 105 | v1.0.4 106 | ------ 107 | - [COOK-960] - add timeout to python_pip 108 | - [COOK-651] - 'install_path' not correctly resolved when using python::source 109 | - [COOK-650] - Add ability to specify version when installing distribute. 110 | - [COOK-553] - FreeBSD support in the python cookbook 111 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'foodcritic', '>= 3.0.3' 4 | gem 'berkshelf', '~> 2.0' 5 | gem 'chefspec', '~> 3.0' 6 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | activesupport (3.2.16) 5 | i18n (~> 0.6, >= 0.6.4) 6 | multi_json (~> 1.0) 7 | addressable (2.3.5) 8 | akami (1.2.0) 9 | gyoku (>= 0.4.0) 10 | nokogiri (>= 1.4.0) 11 | berkshelf (2.0.10) 12 | activesupport (~> 3.2.0) 13 | addressable (~> 2.3.4) 14 | buff-shell_out (~> 0.1) 15 | chozo (>= 0.6.1) 16 | faraday (>= 0.8.5) 17 | hashie (>= 2.0.2) 18 | minitar (~> 0.5.4) 19 | rbzip2 (~> 0.2.0) 20 | retryable (~> 1.3.3) 21 | ridley (~> 1.5.0) 22 | solve (>= 0.5.0) 23 | thor (~> 0.18.0) 24 | buff-config (0.4.0) 25 | buff-extensions (~> 0.3) 26 | varia_model (~> 0.1) 27 | buff-extensions (0.5.0) 28 | buff-ignore (1.1.1) 29 | buff-ruby_engine (0.1.0) 30 | buff-shell_out (0.1.1) 31 | buff-ruby_engine (~> 0.1.0) 32 | builder (3.2.2) 33 | celluloid (0.14.1) 34 | timers (>= 1.0.0) 35 | celluloid-io (0.14.1) 36 | celluloid (>= 0.14.1) 37 | nio4r (>= 0.4.5) 38 | chef (11.8.0) 39 | chef-zero (~> 1.6, >= 1.6.2) 40 | diff-lcs (~> 1.2, >= 1.2.4) 41 | erubis (~> 2.7) 42 | highline (~> 1.6, >= 1.6.9) 43 | json (>= 1.4.4, <= 1.7.7) 44 | mime-types (~> 1.16) 45 | mixlib-authentication (~> 1.3) 46 | mixlib-cli (~> 1.3) 47 | mixlib-config (~> 2.0) 48 | mixlib-log (~> 1.3) 49 | mixlib-shellout (~> 1.2) 50 | net-ssh (~> 2.6) 51 | net-ssh-multi (~> 1.1.0) 52 | ohai (~> 6.0) 53 | pry (~> 0.9) 54 | puma (~> 1.6) 55 | rest-client (>= 1.0.4, < 1.7.0) 56 | yajl-ruby (~> 1.1) 57 | chef-zero (1.7.2) 58 | hashie (~> 2.0) 59 | json 60 | mixlib-log (~> 1.3) 61 | moneta (< 0.7.0) 62 | rack 63 | chefspec (3.0.2) 64 | chef (~> 11.0) 65 | fauxhai (~> 2.0) 66 | rspec (~> 2.14) 67 | chozo (0.6.1) 68 | activesupport (>= 3.2.0) 69 | hashie (>= 2.0.2) 70 | multi_json (>= 1.3.0) 71 | coderay (1.1.0) 72 | diff-lcs (1.2.5) 73 | erubis (2.7.0) 74 | faraday (0.8.8) 75 | multipart-post (~> 1.2.0) 76 | fauxhai (2.0.1) 77 | net-ssh 78 | ohai 79 | ffi (1.9.3) 80 | foodcritic (3.0.3) 81 | erubis 82 | gherkin (~> 2.11.7) 83 | nokogiri (~> 1.5.4) 84 | rake 85 | treetop (~> 1.4.10) 86 | yajl-ruby (~> 1.1.0) 87 | gherkin (2.11.8) 88 | multi_json (~> 1.3) 89 | gssapi (1.0.3) 90 | ffi (>= 1.0.1) 91 | gyoku (1.1.0) 92 | builder (>= 2.1.2) 93 | hashie (2.0.5) 94 | highline (1.6.20) 95 | httpclient (2.3.4.1) 96 | httpi (0.9.7) 97 | rack 98 | i18n (0.6.9) 99 | ipaddress (0.8.0) 100 | json (1.7.7) 101 | little-plugger (1.1.3) 102 | logging (1.8.1) 103 | little-plugger (>= 1.1.3) 104 | multi_json (>= 1.3.6) 105 | method_source (0.8.2) 106 | mime-types (1.25.1) 107 | minitar (0.5.4) 108 | mixlib-authentication (1.3.0) 109 | mixlib-log 110 | mixlib-cli (1.4.0) 111 | mixlib-config (2.1.0) 112 | mixlib-log (1.6.0) 113 | mixlib-shellout (1.3.0) 114 | moneta (0.6.0) 115 | multi_json (1.8.2) 116 | multipart-post (1.2.0) 117 | net-http-persistent (2.9) 118 | net-ssh (2.7.0) 119 | net-ssh-gateway (1.2.0) 120 | net-ssh (>= 2.6.5) 121 | net-ssh-multi (1.1) 122 | net-ssh (>= 2.1.4) 123 | net-ssh-gateway (>= 0.99.0) 124 | nio4r (0.5.0) 125 | nokogiri (1.5.11) 126 | nori (1.1.5) 127 | ohai (6.20.0) 128 | ipaddress 129 | mixlib-cli 130 | mixlib-config 131 | mixlib-log 132 | mixlib-shellout 133 | systemu (~> 2.5.2) 134 | yajl-ruby 135 | polyglot (0.3.3) 136 | pry (0.9.12.4) 137 | coderay (~> 1.0) 138 | method_source (~> 0.8) 139 | slop (~> 3.4) 140 | puma (1.6.3) 141 | rack (~> 1.2) 142 | rack (1.5.2) 143 | rake (10.1.1) 144 | rbzip2 (0.2.0) 145 | rest-client (1.6.7) 146 | mime-types (>= 1.16) 147 | retryable (1.3.3) 148 | ridley (1.5.3) 149 | addressable 150 | buff-config (~> 0.2) 151 | buff-extensions (~> 0.3) 152 | buff-ignore (~> 1.1) 153 | buff-shell_out (~> 0.1) 154 | celluloid (~> 0.14.0) 155 | celluloid-io (~> 0.14.0) 156 | erubis 157 | faraday (>= 0.8.4) 158 | hashie (>= 2.0.2) 159 | json (>= 1.7.7) 160 | mixlib-authentication (>= 1.3.0) 161 | net-http-persistent (>= 2.8) 162 | net-ssh 163 | nio4r (>= 0.5.0) 164 | retryable 165 | solve (>= 0.4.4) 166 | varia_model (~> 0.1) 167 | winrm (~> 1.1.0) 168 | rspec (2.14.1) 169 | rspec-core (~> 2.14.0) 170 | rspec-expectations (~> 2.14.0) 171 | rspec-mocks (~> 2.14.0) 172 | rspec-core (2.14.7) 173 | rspec-expectations (2.14.4) 174 | diff-lcs (>= 1.1.3, < 2.0) 175 | rspec-mocks (2.14.4) 176 | rubyntlm (0.1.1) 177 | savon (0.9.5) 178 | akami (~> 1.0) 179 | builder (>= 2.1.2) 180 | gyoku (>= 0.4.0) 181 | httpi (~> 0.9) 182 | nokogiri (>= 1.4.0) 183 | nori (~> 1.0) 184 | wasabi (~> 1.0) 185 | slop (3.4.7) 186 | solve (0.8.2) 187 | systemu (2.5.2) 188 | thor (0.18.1) 189 | timers (1.1.0) 190 | treetop (1.4.15) 191 | polyglot 192 | polyglot (>= 0.3.1) 193 | uuidtools (2.1.4) 194 | varia_model (0.2.0) 195 | buff-extensions (~> 0.2) 196 | hashie (>= 2.0.2) 197 | wasabi (1.0.0) 198 | nokogiri (>= 1.4.0) 199 | winrm (1.1.3) 200 | gssapi (~> 1.0.0) 201 | httpclient (~> 2.2, >= 2.2.0.2) 202 | logging (~> 1.6, >= 1.6.1) 203 | nokogiri (~> 1.5) 204 | rubyntlm (~> 0.1.1) 205 | savon (= 0.9.5) 206 | uuidtools (~> 2.1.2) 207 | yajl-ruby (1.1.0) 208 | 209 | PLATFORMS 210 | ruby 211 | 212 | DEPENDENCIES 213 | berkshelf (~> 2.0) 214 | chefspec (~> 3.0) 215 | foodcritic (>= 3.0.3) 216 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | The script located at files/default/ez_setup.py is licensed under the 2 | Zope Public License, found at the root of this cookbook at ZPL.txt. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | python Cookbook 2 | =============== 3 | 4 | [![Build Status](https://travis-ci.org/poise/python.png?branch=master)](https://travis-ci.org/poise/python) 5 | 6 | Installs and configures Python. Also includes LWRPs for managing python packages with `pip` and `virtualenv` isolated Python environments. 7 | 8 | ## **THIS COOKBOOK IS DEPRECATED** 9 | 10 | [Poise-python](https://github.com/poise/poise-python) is a vastly better cookbook 11 | for managing Python-related things. This cookbook will remain for compatibility 12 | but any future release will only be to gut it and turn it into a wrapper for 13 | `poise-python`. 14 | 15 | ## **I REPEAT, THIS COOKBOOK IS DEPRECATED** 16 | 17 | Requirements 18 | ------------ 19 | ### Platforms 20 | - Debian, Ubuntu 21 | - CentOS, Red Hat, Fedora 22 | 23 | ### Cookbooks 24 | - build-essential 25 | - yum 26 | 27 | NOTE: The `yum` cookbook is a dependency of the cookbook, and will be used to install [EPEL](http://fedoraproject.org/wiki/EPEL) on RedHet/CentOS 5.x systems to provide the Python 2.6 packages. 28 | 29 | 30 | Attributes 31 | ---------- 32 | See `attributes/default.rb` for default values. 33 | 34 | - `node["python"]["install_method"]` - method to install python with, default `package`. 35 | 36 | The file also contains the following attributes: 37 | 38 | - platform specific locations and settings 39 | - source installation settings 40 | 41 | 42 | Resource/Provider 43 | ----------------- 44 | This cookbook includes LWRPs for managing: 45 | 46 | - pip packages 47 | - virtualenv isolated Python environments 48 | 49 | ### python_pip 50 | Install packages using the new hotness in Python package management...[`pip`](http://pypi.python.org/pypi/pip). Yo dawg...easy_install is so 2009, you better ask your local Pythonista if you don't know! The usage semantics are like that of any normal package provider. 51 | 52 | #### Actions 53 | 54 | - :install: Install a pip package - if version is provided, install that specific version (default) 55 | - :upgrade: Upgrade a pip package - if version is provided, upgrade to that specific version 56 | - :remove: Remove a pip package 57 | - :user: User to run pip as, for using with virtualenv 58 | - :group: Group to run pip as, for using with virtualenv 59 | - :purge: Purge a pip package (this usually entails removing configuration files as well as the package itself). With pip packages this behaves the same as `:remove` 60 | 61 | #### Attribute Parameters 62 | 63 | - package_name: name attribute. The name of the pip package to install 64 | - version: the version of the package to install/upgrade. If no version is given latest is assumed. 65 | - virtualenv: virtualenv environment to install pip package into 66 | - options: Add additional options to the underlying pip package command 67 | - timeout: timeout in seconds for the command to execute. Useful for pip packages that may take a long time to install. Default 900 seconds. 68 | 69 | #### Examples 70 | 71 | ```ruby 72 | # install latest gunicorn into system path 73 | python_pip "gunicorn" 74 | 75 | # target a virtualenv 76 | python_pip "gunicorn" do 77 | virtualenv "/home/ubuntu/my_ve" 78 | end 79 | ``` 80 | 81 | ```ruby 82 | # install Django 1.1.4 83 | python_pip "django" do 84 | version "1.1.4" 85 | end 86 | ``` 87 | 88 | ### python_virtualenv 89 | [`virtualenv`](http://pypi.python.org/pypi/virtualenv) is a great tool that creates isolated python environments. Think of it as RVM without all those hipsters and tight jeans. 90 | 91 | #### Actions 92 | - :create: creates a new virtualenv 93 | - :delete: deletes an existing virtualenv 94 | 95 | #### Attribute Parameters 96 | - path: name attribute. The path where the virtualenv will be created 97 | - interpreter: The Python interpreter to use. default is null (i.e. use whatever python the virtualenv command is using). 98 | - owner: The owner for the virtualenv 99 | - group: The group owner of the file (string or id) 100 | - options : Command line options (string) 101 | 102 | #### Examples 103 | 104 | ```ruby 105 | # create a 2.6 virtualenv owned by ubuntu user 106 | python_virtualenv "/home/ubuntu/my_cool_ve" do 107 | owner "ubuntu" 108 | group "ubuntu" 109 | action :create 110 | end 111 | ``` 112 | 113 | ```ruby 114 | # create a Python 2.4 virtualenv 115 | python_virtualenv "/home/ubuntu/my_old_ve" do 116 | interpreter "python2.4" 117 | owner "ubuntu" 118 | group "ubuntu" 119 | action :create 120 | end 121 | ``` 122 | 123 | ```ruby 124 | # create a Python 2.6 virtualenv with access to the global packages owned by ubuntu user 125 | python_virtualenv "/home/ubuntu/my_old_ve" do 126 | owner "ubuntu" 127 | group "ubuntu" 128 | options "--system-site-packages" 129 | action :create 130 | end 131 | ``` 132 | 133 | 134 | Usage 135 | ----- 136 | ### default 137 | Include default recipe in a run list, to get `python`, `pip` and `virtualenv`. Installs python by package or source depending on the platform. 138 | 139 | ### package 140 | Installs Python from packages. 141 | 142 | ### source 143 | Installs Python from source. 144 | 145 | ### pip 146 | Installs `pip` from source. 147 | 148 | ### virtualenv 149 | 150 | Installs virtualenv using the `python_pip` resource. 151 | 152 | 153 | License & Authors 154 | ----------------- 155 | - Author:: Seth Chisamore () 156 | 157 | ```text 158 | Copyright:: 2011, Chef Software, Inc 159 | 160 | Licensed under the Apache License, Version 2.0 (the "License"); 161 | you may not use this file except in compliance with the License. 162 | You may obtain a copy of the License at 163 | 164 | http://www.apache.org/licenses/LICENSE-2.0 165 | 166 | Unless required by applicable law or agreed to in writing, software 167 | distributed under the License is distributed on an "AS IS" BASIS, 168 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 169 | See the License for the specific language governing permissions and 170 | limitations under the License. 171 | ``` 172 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rspec/core/rake_task' 2 | 3 | RSpec::Core::RakeTask.new(:spec) 4 | 5 | task :default => :spec 6 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | This cookbook includes support for running tests via Test Kitchen (1.0). This has some requirements. 2 | 3 | 1. You must be using the Git repository, rather than the downloaded cookbook from the Chef Community Site. 4 | 2. You must have Vagrant 1.1 installed. 5 | 3. You must have a "sane" Ruby 1.9.3 environment. 6 | 7 | Once the above requirements are met, install the additional requirements: 8 | 9 | Install the berkshelf plugin for vagrant, and berkshelf to your local Ruby environment. 10 | 11 | vagrant plugin install vagrant-berkshelf 12 | gem install berkshelf 13 | 14 | Install Test Kitchen 1.0 (unreleased yet, use the alpha / prerelease version). 15 | 16 | gem install test-kitchen --pre 17 | 18 | Install the Vagrant driver for Test Kitchen. 19 | 20 | gem install kitchen-vagrant 21 | 22 | Once the above are installed, you should be able to run Test Kitchen: 23 | 24 | kitchen list 25 | kitchen test 26 | -------------------------------------------------------------------------------- /ZPL.txt: -------------------------------------------------------------------------------- 1 | Zope Public License (ZPL) Version 2.0 2 | ----------------------------------------------- 3 | 4 | This software is Copyright (c) Zope Corporation (tm) and 5 | Contributors. All rights reserved. 6 | 7 | This license has been certified as open source. It has also 8 | been designated as GPL compatible by the Free Software 9 | Foundation (FSF). 10 | 11 | Redistribution and use in source and binary forms, with or 12 | without modification, are permitted provided that the 13 | following conditions are met: 14 | 15 | 1. Redistributions in source code must retain the above 16 | copyright notice, this list of conditions, and the following 17 | disclaimer. 18 | 19 | 2. Redistributions in binary form must reproduce the above 20 | copyright notice, this list of conditions, and the following 21 | disclaimer in the documentation and/or other materials 22 | provided with the distribution. 23 | 24 | 3. The name Zope Corporation (tm) must not be used to 25 | endorse or promote products derived from this software 26 | without prior written permission from Zope Corporation. 27 | 28 | 4. The right to distribute this software or to use it for 29 | any purpose does not give you the right to use Servicemarks 30 | (sm) or Trademarks (tm) of Zope Corporation. Use of them is 31 | covered in a separate agreement (see 32 | http://www.zope.com/Marks). 33 | 34 | 5. If any files are modified, you must cause the modified 35 | files to carry prominent notices stating that you changed 36 | the files and the date of any change. 37 | 38 | Disclaimer 39 | 40 | THIS SOFTWARE IS PROVIDED BY ZOPE CORPORATION ``AS IS'' 41 | AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 42 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 43 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 44 | NO EVENT SHALL ZOPE CORPORATION OR ITS CONTRIBUTORS BE 45 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 46 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 47 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 48 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 50 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 51 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 52 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 53 | DAMAGE. 54 | 55 | 56 | This software consists of contributions made by Zope 57 | Corporation and many individuals on behalf of Zope 58 | Corporation. Specific attributions are listed in the 59 | accompanying credits file. 60 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: python 4 | # Attribute:: default 5 | # 6 | # Copyright 2011, Chef Software, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | default['python']['install_method'] = 'package' 22 | 23 | if python['install_method'] == 'package' 24 | case platform 25 | when "smartos" 26 | default['python']['prefix_dir'] = '/opt/local' 27 | else 28 | default['python']['prefix_dir'] = '/usr' 29 | end 30 | else 31 | default['python']['prefix_dir'] = '/usr/local' 32 | end 33 | 34 | default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/python" 35 | 36 | default['python']['url'] = 'http://www.python.org/ftp/python' 37 | default['python']['version'] = '2.7.7' 38 | default['python']['checksum'] = '7f49c0a6705ad89d925181e27d0aaa025ee4731ce0de64776c722216c3e66c42' 39 | default['python']['configure_options'] = %W{--prefix=#{node['python']['prefix_dir']}} 40 | default['python']['make_options'] = %W{install} 41 | 42 | default['python']['pip_location'] = "#{node['python']['prefix_dir']}/bin/pip" 43 | default['python']['virtualenv_location'] = "#{node['python']['prefix_dir']}/bin/virtualenv" 44 | default['python']['setuptools_version'] = nil # defaults to latest 45 | default['python']['virtualenv_version'] = nil 46 | -------------------------------------------------------------------------------- /libraries/matchers.rb: -------------------------------------------------------------------------------- 1 | if defined?(ChefSpec) 2 | def install_python_pip(package_name) 3 | ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :install, package_name) 4 | end 5 | 6 | def upgrade_python_pip(package_name) 7 | ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :upgrade, package_name) 8 | end 9 | 10 | def remove_python_pip(package_name) 11 | ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :remove, package_name) 12 | end 13 | 14 | def purge_python_pip(package_name) 15 | ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :purge, package_name) 16 | end 17 | 18 | def create_python_virtualenv(virtualenv_name) 19 | ChefSpec::Matchers::ResourceMatcher.new(:python_virtualenv, :create, virtualenv_name) 20 | end 21 | 22 | def delete_python_virtualenv(virtualenv_name) 23 | ChefSpec::Matchers::ResourceMatcher.new(:python_virtualenv, :delete, virtualenv_name) 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name "python" 2 | maintainer "Noah Kantrowitz" 3 | maintainer_email "noah@coderanger.net" 4 | license "Apache 2.0" 5 | description "Installs Python, pip and virtualenv. Includes LWRPs for managing Python packages with `pip` and `virtualenv` isolated Python environments." 6 | version "1.4.7" 7 | 8 | depends "build-essential" 9 | depends "yum-epel" 10 | 11 | recipe "python", "Installs python, pip, and virtualenv" 12 | recipe "python::package", "Installs python using packages." 13 | recipe "python::source", "Installs python from source." 14 | recipe "python::pip", "Installs pip from source." 15 | recipe "python::virtualenv", "Installs virtualenv using the python_pip resource." 16 | 17 | %w{ debian ubuntu centos redhat fedora freebsd smartos }.each do |os| 18 | supports os 19 | end 20 | -------------------------------------------------------------------------------- /providers/pip.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Provider:: pip 5 | # 6 | # Copyright:: 2011, Chef Software, Inc 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | require 'chef/mixin/shell_out' 22 | require 'chef/mixin/language' 23 | include Chef::Mixin::ShellOut 24 | 25 | def whyrun_supported? 26 | true 27 | end 28 | 29 | # the logic in all action methods mirror that of 30 | # the Chef::Provider::Package which will make 31 | # refactoring into core chef easy 32 | 33 | action :install do 34 | # If we specified a version, and it's not the current version, move to the specified version 35 | if new_resource.version != nil && new_resource.version != current_resource.version 36 | install_version = new_resource.version 37 | # If it's not installed at all, install it 38 | elsif current_resource.version == nil 39 | install_version = candidate_version 40 | end 41 | 42 | if install_version 43 | description = "install package #{new_resource} version #{install_version}" 44 | converge_by(description) do 45 | Chef::Log.info("Installing #{new_resource} version #{install_version}") 46 | status = install_package(install_version) 47 | if status 48 | new_resource.updated_by_last_action(true) 49 | end 50 | end 51 | end 52 | end 53 | 54 | action :upgrade do 55 | if current_resource.version != candidate_version 56 | orig_version = current_resource.version || "uninstalled" 57 | description = "upgrade #{current_resource} version from #{current_resource.version} to #{candidate_version}" 58 | converge_by(description) do 59 | Chef::Log.info("Upgrading #{new_resource} version from #{orig_version} to #{candidate_version}") 60 | status = upgrade_package(candidate_version) 61 | if status 62 | new_resource.updated_by_last_action(true) 63 | end 64 | end 65 | end 66 | end 67 | 68 | action :remove do 69 | if removing_package? 70 | description = "remove package #{new_resource}" 71 | converge_by(description) do 72 | Chef::Log.info("Removing #{new_resource}") 73 | remove_package(new_resource.version) 74 | new_resource.updated_by_last_action(true) 75 | end 76 | end 77 | end 78 | 79 | def removing_package? 80 | if current_resource.version.nil? 81 | false # nothing to remove 82 | elsif new_resource.version.nil? 83 | true # remove any version of a package 84 | elsif new_resource.version == current_resource.version 85 | true # remove the version we have 86 | else 87 | false # we don't have the version we want to remove 88 | end 89 | end 90 | 91 | # these methods are the required overrides of 92 | # a provider that extends from Chef::Provider::Package 93 | # so refactoring into core Chef should be easy 94 | 95 | def load_current_resource 96 | @current_resource = Chef::Resource::PythonPip.new(new_resource.name) 97 | @current_resource.package_name(new_resource.package_name) 98 | @current_resource.version(nil) 99 | 100 | unless current_installed_version.nil? 101 | @current_resource.version(current_installed_version) 102 | end 103 | 104 | @current_resource 105 | end 106 | 107 | def current_installed_version 108 | @current_installed_version ||= begin 109 | out = nil 110 | package_name = new_resource.package_name.gsub('_', '-') 111 | pattern = Regexp.new("^#{Regexp.escape(package_name)} \\(([^)]+)\\)$", true) 112 | shell_out("#{which_pip(new_resource)} list").stdout.lines.find do |line| 113 | out = pattern.match(line) 114 | end 115 | out.nil? ? nil : out[1] 116 | end 117 | end 118 | 119 | def candidate_version 120 | @candidate_version ||= begin 121 | # `pip search` doesn't return versions yet 122 | # `pip list` may be coming soon: 123 | # https://bitbucket.org/ianb/pip/issue/197/option-to-show-what-version-would-be 124 | new_resource.version||'latest' 125 | end 126 | end 127 | 128 | def install_package(version) 129 | # if a version isn't specified (latest), is a source archive (ex. http://my.package.repo/SomePackage-1.0.4.zip), 130 | # or from a VCS (ex. git+https://git.repo/some_pkg.git) then do not append a version as this will break the source link 131 | if version == 'latest' || new_resource.package_name.downcase.start_with?('http:', 'https:') || ['git', 'hg', 'svn'].include?(new_resource.package_name.downcase.split('+')[0]) 132 | version = '' 133 | else 134 | version = "==#{version}" 135 | end 136 | pip_cmd('install', version) 137 | end 138 | 139 | def upgrade_package(version) 140 | new_resource.options "#{new_resource.options} --upgrade" 141 | install_package(version) 142 | end 143 | 144 | def remove_package(version) 145 | new_resource.options "#{new_resource.options} --yes" 146 | pip_cmd('uninstall') 147 | end 148 | 149 | def pip_cmd(subcommand, version='') 150 | options = { :timeout => new_resource.timeout, :user => new_resource.user, :group => new_resource.group } 151 | environment = Hash.new 152 | environment['HOME'] = Dir.home(new_resource.user) if new_resource.user 153 | environment.merge!(new_resource.environment) if new_resource.environment && !new_resource.environment.empty? 154 | options[:environment] = environment 155 | shell_out!("#{which_pip(new_resource)} #{subcommand} #{new_resource.options} #{new_resource.package_name}#{version}", options) 156 | end 157 | 158 | # TODO remove when provider is moved into Chef core 159 | # this allows PythonPip to work with Chef::Resource::Package 160 | def which_pip(nr) 161 | if (nr.respond_to?("virtualenv") && nr.virtualenv) 162 | ::File.join(nr.virtualenv,'/bin/pip') 163 | elsif ::File.exists?(node['python']['pip_location']) 164 | node['python']['pip_location'] 165 | else 166 | 'pip' 167 | end 168 | end 169 | -------------------------------------------------------------------------------- /providers/virtualenv.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Provider:: virtualenv 5 | # 6 | # Copyright:: 2011, Chef Software, Inc 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | require 'chef/mixin/shell_out' 22 | require 'chef/mixin/language' 23 | include Chef::Mixin::ShellOut 24 | 25 | def whyrun_supported? 26 | true 27 | end 28 | 29 | action :create do 30 | unless exists? 31 | directory new_resource.path do 32 | user new_resource.owner if new_resource.owner 33 | group new_resource.group if new_resource.group 34 | end 35 | Chef::Log.info("Creating virtualenv #{new_resource} at #{new_resource.path}") 36 | interpreter = new_resource.interpreter ? " --python=#{new_resource.interpreter}" : "" 37 | execute "#{virtualenv_cmd}#{interpreter} #{new_resource.options} #{new_resource.path}" do 38 | user new_resource.owner if new_resource.owner 39 | group new_resource.group if new_resource.group 40 | environment ({ 'HOME' => ::Dir.home(new_resource.owner) }) if new_resource.owner 41 | end 42 | new_resource.updated_by_last_action(true) 43 | end 44 | end 45 | 46 | action :delete do 47 | if exists? 48 | description = "delete virtualenv #{new_resource} at #{new_resource.path}" 49 | converge_by(description) do 50 | Chef::Log.info("Deleting virtualenv #{new_resource} at #{new_resource.path}") 51 | FileUtils.rm_rf(new_resource.path) 52 | end 53 | end 54 | end 55 | 56 | def load_current_resource 57 | @current_resource = Chef::Resource::PythonVirtualenv.new(new_resource.name) 58 | @current_resource.path(new_resource.path) 59 | 60 | if exists? 61 | cstats = ::File.stat(current_resource.path) 62 | @current_resource.owner(cstats.uid) 63 | @current_resource.group(cstats.gid) 64 | end 65 | @current_resource 66 | end 67 | 68 | def virtualenv_cmd() 69 | if ::File.exists?(node['python']['virtualenv_location']) 70 | node['python']['virtualenv_location'] 71 | else 72 | "virtualenv" 73 | end 74 | end 75 | 76 | private 77 | def exists? 78 | ::File.exist?(current_resource.path) && ::File.directory?(current_resource.path) \ 79 | && ::File.exists?("#{current_resource.path}/bin/activate") 80 | end 81 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Recipe:: default 5 | # 6 | # Copyright 2011, Chef Software, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | include_recipe "python::#{node['python']['install_method']}" 22 | include_recipe "python::pip" 23 | include_recipe "python::virtualenv" 24 | -------------------------------------------------------------------------------- /recipes/package.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Recipe:: package 5 | # 6 | # Copyright 2011, Chef Software, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | major_version = node['platform_version'].split('.').first.to_i 22 | 23 | # COOK-1016 Handle RHEL/CentOS namings of python packages, by installing EPEL 24 | # repo & package 25 | if platform_family?('rhel') && major_version < 6 26 | include_recipe 'yum-epel' 27 | python_pkgs = ["python26", "python26-devel"] 28 | node.default['python']['binary'] = "/usr/bin/python26" 29 | else 30 | python_pkgs = value_for_platform_family( 31 | "debian" => ["python","python-dev"], 32 | "rhel" => ["python","python-devel"], 33 | "fedora" => ["python","python-devel"], 34 | "freebsd" => ["python"], 35 | "smartos" => ["python27"], 36 | "default" => ["python","python-dev"] 37 | ) 38 | end 39 | 40 | python_pkgs.each do |pkg| 41 | package pkg do 42 | action :install 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /recipes/pip.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Recipe:: pip 5 | # 6 | # Copyright 2011, Chef Software, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | # Where does pip get installed? 22 | # platform/method: path (proof) 23 | # redhat/package: /usr/bin/pip (sha a8a3a3) 24 | # omnibus/source: /opt/local/bin/pip (sha 29ce9874) 25 | 26 | if node['python']['install_method'] == 'source' 27 | pip_binary = "#{node['python']['prefix_dir']}/bin/pip" 28 | elsif platform_family?("rhel", "fedora") 29 | pip_binary = "/usr/bin/pip" 30 | elsif platform_family?("smartos") 31 | pip_binary = "/opt/local/bin/pip" 32 | else 33 | pip_binary = "/usr/local/bin/pip" 34 | end 35 | 36 | cookbook_file "#{Chef::Config[:file_cache_path]}/get-pip.py" do 37 | source 'get-pip.py' 38 | mode "0644" 39 | not_if { ::File.exists?(pip_binary) } 40 | end 41 | 42 | execute "install-pip" do 43 | cwd Chef::Config[:file_cache_path] 44 | command <<-EOF 45 | #{node['python']['binary']} get-pip.py 46 | EOF 47 | not_if { ::File.exists?(pip_binary) } 48 | end 49 | 50 | python_pip 'setuptools' do 51 | action :upgrade 52 | version node['python']['setuptools_version'] 53 | end 54 | -------------------------------------------------------------------------------- /recipes/source.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Recipe:: source 5 | # 6 | # Copyright 2011, Chef Software, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | include_recipe "build-essential" 22 | 23 | configure_options = node['python']['configure_options'].join(" ") 24 | make_options = node['python']['make_options'].join(" ") 25 | 26 | packages = value_for_platform_family( 27 | "rhel" => ["openssl-devel","bzip2-devel","zlib-devel","expat-devel","db4-devel","sqlite-devel","ncurses-devel","readline-devel"], 28 | "default" => ["libssl-dev","libbz2-dev","zlib1g-dev","libexpat1-dev","libdb-dev","libsqlite3-dev","libncursesw5-dev","libncurses5-dev","libreadline-dev","libsasl2-dev", "libgdbm-dev"] 29 | ) 30 | # 31 | packages.each do |dev_pkg| 32 | package dev_pkg 33 | end 34 | 35 | version = node['python']['version'] 36 | install_path = "#{node['python']['prefix_dir']}/bin/python#{version.split(/(^\d+\.\d+)/)[1]}" 37 | 38 | remote_file "#{Chef::Config[:file_cache_path]}/Python-#{version}.tgz" do 39 | source "#{node['python']['url']}/#{version}/Python-#{version}.tgz" 40 | checksum node['python']['checksum'] 41 | mode "0644" 42 | not_if { ::File.exists?(install_path) } 43 | end 44 | 45 | bash "build-and-install-python" do 46 | cwd Chef::Config[:file_cache_path] 47 | code <<-EOF 48 | tar -zxvf Python-#{version}.tgz 49 | (cd Python-#{version} && ./configure #{configure_options}) 50 | (cd Python-#{version} && make && make #{make_options}) 51 | EOF 52 | environment({ 53 | "LDFLAGS" => "-L#{node['python']['prefix_dir']} -L/usr/lib", 54 | "CPPFLAGS" => "-I#{node['python']['prefix_dir']} -I/usr/lib", 55 | "CXXFLAGS" => "-I#{node['python']['prefix_dir']} -I/usr/lib", 56 | "CFLAGS" => "-I#{node['python']['prefix_dir']} -I/usr/lib" 57 | }) if platform?("ubuntu") && node['platform_version'].to_f >= 12.04 58 | not_if { ::File.exists?(install_path) } 59 | end 60 | 61 | # Link install as the default python, to support Python 3.x 62 | # Otherwise the pip and virtualenv recipes won't work properly 63 | link node['python']['binary'] do 64 | to install_path 65 | not_if { ::File.exists?(node['python']['binary']) } 66 | end 67 | 68 | 69 | -------------------------------------------------------------------------------- /recipes/virtualenv.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Recipe:: virtualenv 5 | # 6 | # Copyright 2011, Chef Software, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | include_recipe "python::pip" 22 | 23 | python_pip "virtualenv" do 24 | action :upgrade 25 | version node['python']['virtualenv_version'] 26 | end 27 | -------------------------------------------------------------------------------- /resources/pip.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Resource:: pip 5 | # 6 | # Copyright:: 2011, Chef Software, Inc 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | actions :install, :upgrade, :remove, :purge 22 | default_action :install if defined?(default_action) # Chef > 10.8 23 | 24 | # Default action for Chef <= 10.8 25 | def initialize(*args) 26 | super 27 | @action = :install 28 | end 29 | 30 | attribute :package_name, :kind_of => String, :name_attribute => true 31 | attribute :version, :default => nil 32 | attribute :timeout, :default => 900 33 | attribute :virtualenv, :kind_of => String 34 | attribute :user, :regex => Chef::Config[:user_valid_regex] 35 | attribute :group, :regex => Chef::Config[:group_valid_regex] 36 | attribute :options, :kind_of => String, :default => '' 37 | attribute :environment, :kind_of => Hash, :default => {} 38 | -------------------------------------------------------------------------------- /resources/virtualenv.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: python 4 | # Resource:: virtualenv 5 | # 6 | # Copyright:: 2011, Chef Software, Inc 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | actions :create, :delete 22 | default_action :create if defined?(default_action) # Chef > 10.8 23 | 24 | # Default action for Chef <= 10.8 25 | def initialize(*args) 26 | super 27 | @action = :create 28 | end 29 | 30 | attribute :path, :kind_of => String, :name_attribute => true 31 | attribute :interpreter, :kind_of => String 32 | attribute :owner, :regex => Chef::Config[:user_valid_regex] 33 | attribute :group, :regex => Chef::Config[:group_valid_regex] 34 | attribute :options, :kind_of => String 35 | -------------------------------------------------------------------------------- /spec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'python::default' do 4 | let :chef_run do 5 | ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge described_recipe 6 | end 7 | 8 | before do 9 | stub_command("/usr/bin/python -c 'import setuptools'").and_return(true) 10 | end 11 | 12 | it 'includes python::package by default' do 13 | expect(chef_run).to include_recipe('python::package') 14 | end 15 | 16 | it 'includes python::pip' do 17 | expect(chef_run).to include_recipe('python::pip') 18 | end 19 | 20 | it 'includes python::virtualenv' do 21 | expect(chef_run).to include_recipe('python::virtualenv') 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/README.md: -------------------------------------------------------------------------------- 1 | python_test Cookbook 2 | ==================== 3 | 4 | This cookbook tests the pip and virtualenv providers 5 | 6 | Requirements 7 | ------------ 8 | 9 | #### packages 10 | - `python` - Version *2.5* or higher 11 | 12 | License and Authors 13 | ------------------- 14 | Authors: Scott Likens 15 | Sean Porter 16 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/files/default/tests/minitest/cook-3084_test.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/spec' 2 | 3 | describe_recipe 'python_test::cook-3084' do 4 | include MiniTest::Chef::Assertions 5 | include MiniTest::Chef::Context 6 | include MiniTest::Chef::Resources 7 | 8 | it "created a virtualenv in cook-3084" do 9 | result = assert_sh("cook-3084/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'") 10 | assert_match /cook-3084\n/, result 11 | end 12 | 13 | it "created a virtualenv in cook-3084-interpreter" do 14 | result = assert_sh("cook-3084-interpreter/bin/python -c 'import sys; from os.path import basename; print basename(sys.prefix)'") 15 | assert_match /cook-3084-interpreter\n/, result 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/files/default/tests/minitest/test_pip_test.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/spec' 2 | 3 | describe_recipe 'python_test::test_pip' do 4 | include MiniTest::Chef::Assertions 5 | include MiniTest::Chef::Context 6 | include MiniTest::Chef::Resources 7 | 8 | it "ran first should_dsl pip install" do 9 | assert File.exist?("/tmp/first-install.txt"), `/tmp/virtualenv/bin/pip freeze` 10 | end 11 | 12 | it "did not run second should_dsl pip install" do 13 | assert !File.exist?("/tmp/second-install.txt"), `/tmp/virtualenv/bin/pip freeze` 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'python_test' 2 | maintainer 'Scott Likens' 3 | maintainer_email 'scott@mopub.com' 4 | license 'Apache 2.0' 5 | description 'Installs/Configures python_test' 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 7 | version '0.1.0' 8 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/recipes/cook-3084.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Alex Kiernan () 3 | # Cookbook Name:: python 4 | # Recipe:: cook-3084 5 | # 6 | # Copyright 2013, Alex Kiernan 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | include_recipe "python" 22 | 23 | python_virtualenv "cook-3084" do 24 | end 25 | 26 | python_virtualenv "cook-3084-interpreter" do 27 | # on EL5 the default python we install is called python26 28 | if !node['python']['install_method'].eql?("source") && 29 | platform_family?('rhel') && 30 | node['platform_version'].split('.').first.to_i < 6 31 | interpreter '/usr/bin/python26' 32 | else 33 | interpreter 'python' 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/recipes/test_exert.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Scott M. Likens 3 | # Cookbook Name:: python 4 | # Recipe:: test_exert 5 | # 6 | # Copyright 2013, MoPub, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | python_virtualenv "#{Chef::Config[:file_cache_path]}/virtualenv" do 22 | interpreter "python" 23 | owner "root" 24 | group "root" 25 | action :create 26 | end 27 | 28 | python_pip "boto" do 29 | action :install 30 | virtualenv "#{Chef::Config[:file_cache_path]}/virtualenv" 31 | end 32 | 33 | python_pip "psutil" do 34 | action :install 35 | end 36 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/recipes/test_pip.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Hugo Lopes Tavares 3 | # Cookbook Name:: python 4 | # Recipe:: test_virtualenv 5 | # 6 | # Copyright 2013, Heavy Water Operations, LLC. 7 | # Copyright 2014, Yipit, Inc. 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | 22 | file "/tmp/first-install.txt" do 23 | content "test" 24 | action :nothing 25 | end 26 | 27 | file "/tmp/second-install.txt" do 28 | content "test" 29 | action :nothing 30 | end 31 | 32 | python_virtualenv "/tmp/virtualenv" do 33 | owner "root" 34 | group "root" 35 | action :create 36 | end 37 | 38 | python_pip "should_dsl first install" do 39 | package_name "should_dsl" 40 | virtualenv "/tmp/virtualenv" 41 | version "2.1.2" 42 | notifies :create, "file[/tmp/first-install.txt]" 43 | end 44 | 45 | python_pip "should_dsl second install" do 46 | package_name "should_dsl" 47 | virtualenv "/tmp/virtualenv" 48 | # same version as before 49 | version "2.1.2" 50 | notifies :create, "file[/tmp/second-install.txt]" 51 | end 52 | -------------------------------------------------------------------------------- /test/cookbooks/python_test/recipes/test_virtualenv.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Sean Porter 3 | # Cookbook Name:: python 4 | # Recipe:: test_virtualenv 5 | # 6 | # Copyright 2013, Heavy Water Operations, LLC. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | python_virtualenv "/tmp/virtualenv" do 22 | owner "root" 23 | group "root" 24 | action :create 25 | end 26 | 27 | python_virtualenv "isolated python environment" do 28 | path "/tmp/tobedestroyed" 29 | action :create 30 | end 31 | 32 | python_virtualenv "deleting the isolated python environment" do 33 | path "/tmp/tobedestroyed" 34 | action :delete 35 | end 36 | -------------------------------------------------------------------------------- /test/integration/exert/bats/exert.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | @test "virtualenv test environment should exist" { 4 | [ -f "/tmp/kitchen-chef-solo/cache/virtualenv/bin/activate" ] 5 | } 6 | 7 | @test "virtualenv test environment should be owned by root" { 8 | ls -l /tmp/kitchen-chef-solo/cache/virtualenv | grep "root root" 9 | } 10 | 11 | @test "virtualenv test environment should have boto working" { 12 | /tmp/kitchen-chef-solo/cache/virtualenv/bin/python -c 'import boto; boto.Version' 13 | } 14 | -------------------------------------------------------------------------------- /test/integration/source/bats/source.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | @test "python bin should exist" { 4 | [ -x "/usr/local/bin/python" ] 5 | } 6 | 7 | @test "python should be version 2.7.7" { 8 | /usr/local/bin/python -c 'import sys; print sys.version' | grep '2.7.7' 9 | } 10 | -------------------------------------------------------------------------------- /test/integration/virtualenv/bats/virtualenv.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | @test "virtualenv test environment should exist" { 4 | [ -f "/tmp/virtualenv/bin/activate" ] 5 | } 6 | 7 | @test "virtualenv test environment should be owned by root" { 8 | ls -l /tmp/virtualenv | grep "root root" 9 | } 10 | 11 | @test "virtualenv test environment should have a working python" { 12 | /tmp/virtualenv/bin/python -c 'import sys; print sys.version' 13 | } 14 | 15 | @test "virtualenv resource should be able to delete an environment" { 16 | [ ! -d "/tmp/tobedestroyed" ] 17 | } 18 | --------------------------------------------------------------------------------