Showing with 85 additions and 6 deletions.
  1. +6 −1 .github/workflows/ci.yml
  2. +1 −1 .msync.yml
  3. +8 −0 CHANGELOG.md
  4. +9 −0 REFERENCE.md
  5. +11 −3 manifests/pyvenv.pp
  6. +1 −1 metadata.json
  7. +49 −0 spec/acceptance/pyvenv_spec.rb
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

name: CI

on: pull_request
on:
pull_request: {}
push:
branches:
- main
- master

concurrency:
group: ${{ github.ref_name }}
Expand Down
2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

modulesync_config_version: '7.2.0'
modulesync_config_version: '7.3.0'
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v7.3.0](https://github.com/voxpupuli/puppet-python/tree/v7.3.0) (2024-02-08)

[Full Changelog](https://github.com/voxpupuli/puppet-python/compare/v7.2.0...v7.3.0)

**Implemented enhancements:**

- Add python\_path to pyvenv class [\#686](https://github.com/voxpupuli/puppet-python/pull/686) ([wmellema](https://github.com/wmellema))

## [v7.2.0](https://github.com/voxpupuli/puppet-python/tree/v7.2.0) (2024-01-01)

[Full Changelog](https://github.com/voxpupuli/puppet-python/compare/v7.1.0...v7.2.0)
Expand Down
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ The following parameters are available in the `python::pyvenv` defined type:
* [`path`](#-python--pyvenv--path)
* [`environment`](#-python--pyvenv--environment)
* [`prompt`](#-python--pyvenv--prompt)
* [`python_path`](#-python--pyvenv--python_path)
* [`pip_version`](#-python--pyvenv--pip_version)

##### <a name="-python--pyvenv--ensure"></a>`ensure`
Expand Down Expand Up @@ -995,6 +996,14 @@ Optionally specify the virtualenv prompt (python >= 3.6)

Default value: `undef`

##### <a name="-python--pyvenv--python_path"></a>`python_path`

Data type: `Optional[Stdlib::Absolutepath]`

Optionally specify python path for creation of virtualenv

Default value: `undef`

##### <a name="-python--pyvenv--pip_version"></a>`pip_version`

Data type: `Python::Venv::PipVersion`
Expand Down
14 changes: 11 additions & 3 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# @param path Specifies the PATH variable.
# @param environment Optionally specify environment variables for pyvenv
# @param prompt Optionally specify the virtualenv prompt (python >= 3.6)
# @param python_path Optionally specify python path for creation of virtualenv
#
# @example
# python::pyvenv { '/var/www/project1' :
Expand All @@ -34,6 +35,7 @@
Array $environment = [],
Optional[String[1]] $prompt = undef,
Python::Venv::PipVersion $pip_version = 'latest',
Optional[Stdlib::Absolutepath] $python_path = undef,
) {
include python

Expand All @@ -46,11 +48,17 @@
$python_version_parts = split($python_version, '[.]')
$normalized_python_version = sprintf('%s.%s', $python_version_parts[0], $python_version_parts[1])

$local_exec_prefix = $python_path ? {
undef => $python::exec_prefix,
default => $python_path,
}
# pyvenv is deprecated since 3.6 and will be removed in 3.8
if versioncmp($normalized_python_version, '3.6') >=0 {
$virtualenv_cmd = "${python::exec_prefix}python${normalized_python_version} -m venv"
if $python_path != undef {
$virtualenv_cmd = "${python_path} -m venv"
} elsif versioncmp($normalized_python_version, '3.6') >=0 {
$virtualenv_cmd = "${local_exec_prefix}python${normalized_python_version} -m venv"
} else {
$virtualenv_cmd = "${python::exec_prefix}pyvenv-${normalized_python_version}"
$virtualenv_cmd = "${local_exec_prefix}pyvenv-${normalized_python_version}"
}

$_path = $python::provider ? {
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-python",
"version": "7.2.0",
"version": "7.3.0",
"author": "Vox Pupuli",
"summary": "Puppet module for Python",
"license": "Apache-2.0",
Expand Down
49 changes: 49 additions & 0 deletions spec/acceptance/pyvenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,53 @@ class { 'python':
its(:stdout) { is_expected.to match %r{agent.* 0\.1\.2} }
end
end

context 'with versioned minimal python::pip and without systempkgs using custom python path' do
it 'works with no errors' do
pp = <<-PUPPET
class { 'python':
dev => 'present',
venv => 'present',
}
file { '/usr/bin/mycustompython':
ensure => link,
target => '/usr/bin/python',
}
user { 'agent':
ensure => 'present',
managehome => true,
home => '/opt/agent',
}
group { 'agent':
ensure => 'present',
system => true,
}
python::pyvenv { '/opt/agent/venv':
ensure => 'present',
systempkgs => false,
owner => 'agent',
group => 'agent',
mode => '0755',
pip_version => '<= 20.3.4',
python_path => '/usr/bin/mycustompython',
}
python::pip { 'agent' :
ensure => '0.1.2',
virtualenv => '/opt/agent/venv',
owner => 'agent',
group => 'agent',
}
PUPPET

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe command('/opt/agent/venv/bin/pip list') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{agent.* 0\.1\.2} }
end
end
end