Check python package version in virtualenv

I have this code

python_runtime 'python3' do
  version '3.5'
  action :install
end

%w{sup1 sup2 sup3}.each do |sup|
  sup_version = node[sup]['version']

  python_virtualenv "/#{sup}/.virtualenv" do
    python 'python3'
  end
  
  python_execute "-m pip install -i #{node]['pypi_repository']} #{sup}==#{sup_version}" do
    python 'python3'
    virtualenv "/#{sup}/.virtualenv"
    not_if { "pip3 show #{sup} | grep #{sup_version}" }
  end

It installs packages (with specified versions) in required virtualenv. The problem is not_if code is run outside virtualenv. If I install package without virtualenv this not_if works. If I install package inside virtualenv only - it doesn’t.
I tried to activate virtualenv in not_if but it didn’t work.

not_if { "source /#{sup}/.virtualenv/bin/activate ; pip3 show #{sup} | grep #{sup_version}" }

Assuming you're using poise-python, the python-package resource supports virtualenv; why not just use that?

Hi, Yes. I’m using poise-python and I missed part I can use options property, thanks.

    python_package sup do 
      version sup_version
      options "-i  #{node['pypi_repository']"
    end