Skip to content

Commit

Permalink
Merge pull request #1 from ITJamie/master
Browse files Browse the repository at this point in the history
pip19 support plus kitchen plus ubuntu 18 fix for distutils
  • Loading branch information
pescetto authored Jun 21, 2019
2 parents 4a4983a + 042fd62 commit d76a828
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 6 deletions.
65 changes: 65 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
driver:
name: vagrant

provisioner:
name: chef_zero
product_name: chef
product_version: "14"
require_chef_omnibus: "14"
data_bags_path: "test/data_bags"
log_level: info

platforms:
- name: ubuntu-18.04
driver:
provision: true
vagrantfiles:
- vagrant.rb
- name: ubuntu-16.04
driver:
provision: true
vagrantfiles:
- vagrant.rb
- name: ubuntu-14.04
driver:
provision: true
vagrantfiles:
- vagrant.rb

verifier:
name: inspec

suites:
- name: Python3and2_pip19
driver_config:
vm_hostname: test-node1
customize:
memory: 512
cpus: 1
run_list:
- recipe[poise-python]
verifier:
inspec_tests:
- test/integration/base_python_tests
attributes:
poise-python:
install_python3: true
options:
pip_version: 19
- name: Python3and2_pip18
driver_config:
vm_hostname: test-node1
customize:
memory: 512
cpus: 1
run_list:
- recipe[poise-python]
verifier:
inspec_tests:
- test/integration/base_python_tests
attributes:
poise-python:
install_python3: true
options:
pip_version: 18
17 changes: 17 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cookbook_path = File.expand_path '../'

if File.directory? cookbook_path
puts 'COOKBOOK PATH ' + cookbook_path
else
abort "CAN'T FIND MY COOKBOOK PATH. You may need to edit the Berksfile to fit your environment."
end

source 'https://supermarket.chef.io'

# Upstream cookbooks
cookbook 'poise'
cookbook 'poise-languages'


metadata

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is a patched fork for other users who still use it and need fixes

It can be used by adding the following to your berks file
```
cookbook 'poise-python', git: 'https://github.com/ITJamie/poise-python-patched.git'
cookbook 'poise-python', git: 'https://github.com/enova/enova-python.git'
```

if you need the install function youll need to lock to pip 18 currently in your attributes or recipe
Expand Down
22 changes: 22 additions & 0 deletions files/halite_gem/poise_python/python_providers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def action_install
# Second inner converge for the support tools. This is needed because
# we run a python command to check if venv is available.
notifying_block do
install_distutils
install_pip
install_setuptools
install_wheel
Expand Down Expand Up @@ -98,6 +99,27 @@ def uninstall_python
raise NotImplementedError
end

# Setup distutils on ubuntu. this is a total PIA ubuntu!
# @return [void]
def install_distutils
# hack to workaround python not having distutils on ubuntu...
Chef::Log.info("[#{new_resource}] distutils installer - only valid on ubuntu for python 3")
# TODO: we should launch python and check if distutils can be imported. if not do the package install below \
# the logic below is not good
if options[:version].to_s == '3' && node[:platform] == "ubuntu" && node[:platform_version].split('.')[0].to_i >= 18
Chef::Log.info("[#{new_resource}] Installing distutils as this is ubuntu and its messed up")
poise_languages_system 'python3-distutils' do
parent new_resource
dev_package false
action :install
end
# this worked but we dont want to be doing apt commands raw...
#cmd = poise_shell_out('apt-get install -y python3-distutils', environment: python_environment)
#puts cmd if cmd.error?
#return unless cmd.error?
#Chef::Log.info("[#{new_resource}] Installed distutils")
end
end
# Install pip in to the Python runtime.
#
# @return [void]
Expand Down
2 changes: 1 addition & 1 deletion files/halite_gem/poise_python/python_providers/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def system_package_candidates(version)
end
# Aliases for 2 and 3.
if version == '3' || version == ''
names.concat(%w{python3.5 python35 python3.4 python34 python3.3 python33 python3.2 python32 python3.1 python31 python3.0 python30 python3})
names.concat(%w{python3.6 python3.5 python35 python3.4 python34 python3.3 python33 python3.2 python32 python3.1 python31 python3.0 python30 python3})
end
if version == '2' || version == ''
names.concat(%w{python2.7 python27 python2.6 python26 python2.5 python25})
Expand Down
20 changes: 17 additions & 3 deletions files/halite_gem/poise_python/resources/python_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ module PythonPackage
import sys
import pip
# Don't use pkg_resources because I don't want to require it before this anyway.
if re.match(r'0\\.|1\\.|6\\.0', pip.__version__):
sys.stderr.write('The python_package resource requires pip >= 6.1.0, currently '+pip.__version__+'\\n')
sys.exit(1)
tempstore = pip.__version__.split('.')
if len(tempstore) > 1:
current_version_pip_int = float(tempstore[0]+"."+tempstore[1])
else:
current_version_pip_int = float(tempstore[0])
try:
from pip.commands import InstallCommand
from pip.index import PackageFinder
Expand All @@ -50,7 +55,12 @@ module PythonPackage
# Pip 10 moved all internals to their own package.
from pip._internal.commands import InstallCommand
from pip._internal.index import PackageFinder
from pip._internal.req import InstallRequirement
if current_version_pip_int <= 18.1:
from pip._internal.req import InstallRequirement
else:
from pip._internal.req.constructors import (
install_req_from_editable, install_req_from_line,
)
packages = {}
cmd = InstallCommand()
Expand All @@ -74,7 +84,10 @@ module PythonPackage
finder = PackageFinder(**finder_options)
find_all = getattr(finder, 'find_all_candidates', getattr(finder, '_find_all_versions', None))
for arg in args:
req = InstallRequirement.from_line(arg)
if current_version_pip_int <= 18.1:
req = InstallRequirement.from_line(arg)
else:
req = install_req_from_line(arg)
found = finder.find_requirement(req, True)
all_candidates = find_all(req.name)
candidate = [c for c in all_candidates if c.location == found]
Expand Down Expand Up @@ -351,6 +364,7 @@ def pip_install(name, version, upgrade: false)
# @param requirements [Array<String>] Pip-formatted package requirements.
# @return [Mixlib::ShellOut]
def pip_outdated(requirements)
puts "checking for #{requirements.to_s}"
pip_command(nil, :list, requirements, input: PIP_HACK_SCRIPT, pip_runner: %w{-})
end

Expand Down
1 change: 0 additions & 1 deletion metadata.json

This file was deleted.

10 changes: 10 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name 'poise-python'
maintainer 'Enova International'
maintainer_email '[email protected]'
license 'Apache-2'
description 'Installs/Configures python and modules'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.7.1'

depends "poise","~> 2.7"
depends "poise-languages","~> 2.0"
6 changes: 6 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# limitations under the License.
#

if ENV['TEST_KITCHEN']
puts "TEST_OUTPUT:"
puts node['poise-python']
end


# Default runtimes, last one will be the default.
python_runtime 'pypy' if node['poise-python']['install_pypy']
python_runtime '3' if node['poise-python']['install_python3']
Expand Down
10 changes: 10 additions & 0 deletions test/integration/base_python_tests/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: python_tests
title: InSpec Profile for testing base python installs
maintainer: xxx
copyright: xxx
copyright_email: xxx
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
supports:
platform: os
Empty file.
10 changes: 10 additions & 0 deletions vagrant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Vagrant.configure(2) do |config|
config.ssh.insert_key = false
# rubocop:disable Style/HashSyntax
config.vm.provision 'shell', inline: <<-SHELL
sudo apt-get update -y && apt-get install vim git unzip build-essential -y
## sudo apt-get --only-upgrade install libssl*
##sudo apt-get install -y libssl libssl-dev
SHELL
# rubocop:enable Style/HashSyntax
end

0 comments on commit d76a828

Please sign in to comment.