Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix virtualenv deprecated "--no-site-packages" argument #552

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions manifests/virtualenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@
} elsif (( versioncmp($_virtualenv_version,'1.7') < 0 ) and ( $systempkgs == false )) {
$system_pkgs_flag = '--no-site-packages'
} else {
$system_pkgs_flag = $systempkgs ? {
true => '--system-site-packages',
false => '--no-site-packages',
default => fail('Invalid value for systempkgs. Boolean value is expected')
case $systempkgs {
true: { $system_pkgs_flag = '--system-site-packages' }
false: {
if ( versioncmp($_virtualenv_version, '20.0.1') < 0 ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add another elsif a few lines up?

    } elsif (( versioncmp($_virtualenv_version,'20.0.1') > 0 ) and ( $systempkgs == false )) {
      $system_pkgs_flag = ''

Tbh that logic structure isn't too clean either, but at least it's consistently dirty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i agree with @thebigb on this one
this case is pretty unclean in the else, so why not avoid it altogether

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah there's actually a subtle difference in logic here. When the virtualenv_version is not yet populated (e.g. the package has been just installed in the current run), @saz's version will default to an empty $system_pkgs_flag, and my version will default to --no-site-packages.

I don't know enough about older versions virtualenv. If between 1.7 and 20.0.1 the --no-site-packages option was redundant anyway, the logic proposed by this PR is favorable. Otherwise this breaks the first run for everyone installing versions < 20.0.1.

Copy link

@thebigb thebigb Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So depending on what's desirable one of these should do the trick:

    if $_virtualenv_version != '' and versioncmp($_virtualenv_version, '1.7') > 0 and $systempkgs == true {
      $system_pkgs_flag = '--system-site-packages'
    } elsif $_virtualenv_version != '' and versioncmp($_virtualenv_version, '20.0.1') < 0 and $systempkgs == false {
      $system_pkgs_flag = '--no-site-packages'
    } else {
      $system_pkgs_flag = $systempkgs ? {
        true    => '--system-site-packages',
        false   => '',
        default => fail('Invalid value for systempkgs. Boolean value is expected')
      }
    }
    if $_virtualenv_version != '' and versioncmp($_virtualenv_version, '1.7') > 0 and $systempkgs == true {
      $system_pkgs_flag = '--system-site-packages'
    } elsif $_virtualenv_version != '' and versioncmp($_virtualenv_version, '1.7') < 0 and $systempkgs == false {
      $system_pkgs_flag = '--no-site-packages'
    } elsif $_virtualenv_version != '' and versioncmp($_virtualenv_version, '20.0.1') >= 0 and $systempkgs == false {
      $system_pkgs_flag = ''
    } else {
      $system_pkgs_flag = $systempkgs ? {
        true    => '--system-site-packages',
        false   => '--no-site-packages',
        default => fail('Invalid value for systempkgs. Boolean value is expected')
      }
    }

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a bug in the examples of my previous comment. For some reason I thought that it would jump to the else block if the virtualenv_version is empty, but that's obviously not the case. I edited the comment and the logic should work now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about older versions virtualenv. If between 1.7 and 20.0.1 the --no-site-packages option was redundant anyway, the logic proposed by this PR is favorable. Otherwise this breaks the first run for everyone installing versions < 20.0.1.
Looking at https://virtualenv.pypa.io/en/legacy/changes.html#v1-7-2011-11-30 it's the case starting from 1.7

$system_pkgs_flag = '--no-site-packages'
} else {
$system_pkgs_flag = ''
}
}
default: { fail('Invalid value for systempkgs. Boolean value is expected') }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we added type annotations, this default would be unnecessary

the question, of course would remain whether puppet lint would know that…… (that the case is already exhaustive)

}
}

Expand Down