diff --git a/README.md b/README.md index 689e6bc..19da3ef 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Pythons outside of your platforms package manager's purview. 3. [Setup - The basics of getting started with pyenv](#setup) * [Beginning with pyenv - Installation](#beginning-with-pyenv) * [Installing a Python - Basic options for getting started](#installing-a-python) - * [Resource ordering](#resource-ordering) * [Relocating pyenv](#relocating-the-pyenv-installation) 4. [Usage - The classes and types available for configuration](#usage) * [Classes](#classes) @@ -75,31 +74,6 @@ the Python: pyenv_python { '3.4.0-debug': } ``` -### Resource ordering -Unfortunately due to how Puppet works there is no way to instruct the provider -that in order for it to work it needs to wait on the *vcsrepo* resource and only -then evaluate possible candidates. - -Because of this we provide a fact called `pyenv_installed` which will try to -detect if pyenv is installed. The fact takes into account the value of the -`pyenv_binary` fact, searches through `$PATH` and tries to find pyenv at -`/usr/local/pyenv/bin/pyenv`. If any of those succeed the value will be `true`, -else it will return `false`. - -This means you can now do: - -```puppet -if str2bool($::pyenv_installed) { - pyenv_python { '3.4.0': } -} -``` - -Using this trick means that you will need two Puppet runs the first time: - -* The first to setup pyenv, at this point `pyenv_installed` will be `false`; -* The second run will now detect that pyenv is installed, `pyenv_installed` - will be `true` and the Pythons will be built. - ### Relocation the pyenv installation The module installs pyenv to `/usr/local/pyenv` by default and symlinks the `pyenv` binary onto your path. This is needed so that the provider can find diff --git a/lib/facter/pyenv_installed.rb b/lib/facter/pyenv_installed.rb deleted file mode 100644 index 299b0c5..0000000 --- a/lib/facter/pyenv_installed.rb +++ /dev/null @@ -1,28 +0,0 @@ -Facter.add(:pyenv_installed) do - has_weight 20 - setcode do - if not Facter.value('pyenv_binary').nil? and File.exists?(Facter.value('pyenv_binary')) - true - end - end -end - -Facter.add(:pyenv_installed) do - has_weight 10 - setcode do - if not Facter::Util::Resolution.which('pyenv').nil? - true - end - end -end - -Facter.add(:pyenv_installed) do - has_weight 0 - setcode do - if File.exists?('/usr/local/pyenv/bin/pyenv') - true - else - false - end - end -end diff --git a/lib/puppet/feature/pyenv.rb b/lib/puppet/feature/pyenv.rb new file mode 100644 index 0000000..1c44420 --- /dev/null +++ b/lib/puppet/feature/pyenv.rb @@ -0,0 +1,9 @@ +require 'puppet/util/feature' + +Puppet.features.add(:pyenv) { + if not Facter.value('pyenv_binary').nil? + File.executable?(Facter.value('pyenv_binary')) + else + File.executable?('/usr/local/bin/pyenv') + end +} diff --git a/lib/puppet/provider/pyenv_python/pyenv.rb b/lib/puppet/provider/pyenv_python/pyenv.rb index 4a8add1..8b10113 100644 --- a/lib/puppet/provider/pyenv_python/pyenv.rb +++ b/lib/puppet/provider/pyenv_python/pyenv.rb @@ -5,6 +5,7 @@ Puppet::Type.type(:pyenv_python).provide(:pyenv) do defaultfor :feature => :posix + confine :feature => :pyenv if not Facter.value(:pyenv_binary).nil? has_command(:pyenv, Facter.value(:pyenv_binary)) do