-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Conversation
case $systempkgs { | ||
true: { $system_pkgs_flag = '--system-site-packages' } | ||
false: { | ||
if ( versioncmp($_virtualenv_version, '20.0.1') < 0 ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = '' | ||
} | ||
} | ||
default: { fail('Invalid value for systempkgs. Boolean value is expected') } |
There was a problem hiding this comment.
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)
case $systempkgs { | ||
true: { $system_pkgs_flag = '--system-site-packages' } | ||
false: { | ||
if ( versioncmp($_virtualenv_version, '20.0.1') < 0 ) { |
There was a problem hiding this comment.
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
Type annotations would indeed help here a bit and I was thinking about it. Is there a plan on adding them? Maybe this part can be marked as "needs some work" after annotations are there. I'm also curious on how many users are still using virtualenv < 1.7... |
file this under "things i don't wanna know", like, how many people still use CentOS / RHEL 5 |
i think that mostly depends on what the oldest operating system is that ships it, before we get to update it |
Personally not a big fan of potentially breaking changes unless it's a major release. That said, I doubt that users that are running older versions do keep this puppet module up to date. I had a look at the changelog you found, and I guess this solution would suffice: |
That's the hardest part to find, as not all OSs have a version stated somewhere related to virtualenv. @thebigb Okay, let's use this one. Should I update this PR or how should we proceed? |
Go ahead. Did you test it? I tested it on my local setup, but I might've overlooked something. |
@saz you might need to rebase your branch. |
Looks like a variant of this was included in #593; is this sorted now? |
Looks good to me. Closing this. |
--no-site-packages
argument isn't available in all versions of virtualenv > 20.0.1