diff --git a/manifests/install.pp b/manifests/install.pp index c32dee1..1aae0ec 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -7,6 +7,7 @@ ) { ensure_resource('file', $prefix, { 'ensure' => 'directory' }) ensure_resource('file', "${prefix}/bin", { 'ensure' => 'directory', require => File[$prefix] }) + ensure_resource('file', "${prefix}/requirements", { 'ensure' => 'directory', require => File[$prefix] }) $arch = $::facts['os']['architecture'] archive { 'install_uv': path => '/tmp/uv', diff --git a/manifests/venv.pp b/manifests/venv.pp index c9e5d89..af88d86 100644 --- a/manifests/venv.pp +++ b/manifests/venv.pp @@ -34,9 +34,11 @@ if $python =~ Stdlib::Absolutepath { $path = ["${uv_prefix}/bin", dirname($python),'/bin', '/usr/bin'] $environ = [] + $target = $python } else { $path = ["${uv_prefix}/bin"] $environ = ["XDG_DATA_HOME=${uv_prefix}/share"] + $target = "${uv_prefix}/share/uv/python/*/bin/python${python}" } if $system_site_packages { @@ -45,9 +47,50 @@ $ssp_flag = '' } + $uv_req_prefix = "${uv_prefix}/requirements" + $requirement_prefix = "${uv_req_prefix}/${name}" + file { $requirement_prefix: + ensure => directory, + require => File[$uv_req_prefix], + } + + file { "${requirement_prefix}/requirements.1.txt": + ensure => file, + require => File[$requirement_prefix], + } + if $requirements_path { + File["${requirement_prefix}/requirements.1.txt"] { + source => "file://${requirements_path}", + notify => [ + Exec["${name}_clear_pipfreeze"], + ], + } + } + + file { "${requirement_prefix}/requirements.2.txt": + ensure => file, + require => File[$requirement_prefix], + } + if $requirements { + File["${requirement_prefix}/requirements.2.txt"] { + content => $requirements, + notify => [ + Exec["${name}_clear_pipfreeze"], + ], + } + } + + exec { "${name}_clear_pipfreeze": + command => "/bin/rm -f ${prefix}/.pipfreeze", + refreshonly => true, + before => [ + Exec["${name}_venv"], + ], + } + exec { "${name}_venv": - command => "uv venv --seed -p ${python} ${ssp_flag} ${prefix}", - creates => "${prefix}/bin/python", + command => "uv venv --clear --seed -p ${python} ${ssp_flag} ${prefix}", + unless => "/usr/bin/test $(/usr/bin/readlink ${prefix}/bin/python) == ${target} && /usr/bin/test -f ${prefix}/.pipfreeze", require => Class['uv::install'], path => $path, environment => $environ, @@ -63,32 +106,20 @@ $pip_path = ["${uv_prefix}/bin", '/usr/bin'] } - file { "${prefix}/${name}-requirements.1.txt": - ensure => file, - } - if $requirements_path { - File["${prefix}/${name}-requirements.1.txt"] { - source => "file://${requirements_path}", - notify => Exec["${name}_pip_install"], - } - } - - file { "${prefix}/${name}-requirements.2.txt": - ensure => file, - } - if $requirements { - File["${prefix}/${name}-requirements.2.txt"] { - content => $requirements, - notify => Exec["${name}_pip_install"], - } - } - exec { "${name}_pip_install": - command => "${pip_cmd} -r ${prefix}/${name}-requirements.1.txt -r ${prefix}/${name}-requirements.2.txt", + command => "${pip_cmd} -r ${requirement_prefix}/requirements.1.txt -r ${requirement_prefix}/requirements.2.txt", refreshonly => true, environment => $pip_environ, timeout => 0, path => $pip_path, - require => Exec["${name}_venv"], + subscribe => Exec["${name}_venv"], + } + + exec { "${name}_pip_freeze": + command => "uv pip freeze > ${prefix}/.pipfreeze", + creates => "${prefix}/.pipfreeze", + environment => ["VIRTUAL_ENV=${prefix}"], + require => Exec["${name}_pip_install"], + path => ["${uv_prefix}/bin"], } }