0

I would like to be able to do the following so that I can compare different versions more easily:

import pvlib
import pvlib_old

I can clone pvlib into two separate local directories, check out the desired versions and install in editable/developer mode. But what would I need to do to change the name of one of them?

Would it be enough to make this change in setup.py:

DISTNAME = 'pvlib_old'

[EDIT: I tried this at some point, and it doesn't work.]

Or is there another way?

adr
  • 1,731
  • 10
  • 18
  • Can't you put them in separate virtual environments? – Dan Jun 18 '19 at 12:31
  • That would not allow me to run the old and new version of the same function in the same script in order to compare them. – adr Jun 18 '19 at 12:40
  • Write tests and run the tests in each environment? Tox could help you automate this. – Dan Jun 18 '19 at 12:42
  • I don't know if this is possible, but https://stackoverflow.com/a/6572017/2802993 might help – Will Holmgren Jul 23 '19 at 17:34
  • The "import alias" suggestion does seem promising, but I can't quite see how to use it here. – adr Jul 24 '19 at 10:41

2 Answers2

0

The developers of the pvlib have chosen that name. And they are almost certainly using that name inside of their own source files to import code from submodules and multiple files of their library. It's not for you to change the name by a simple file system operation. You'd have to process all source files, adjust all imports there, and hope that there isn't some unexpected corner case that depends on the package name in unforeseen ways. Just don't.

Install the two versions in two separate Anaconda environments, write one script that uses the API, and run that script in two separate consoles, one for each Anaconda environment.

Roland Weber
  • 3,395
  • 12
  • 26
0

You have to clone the tag ("version") that you are looking for, and only that one defining the branch and avoiding any further depth (is this is your case). For example, to clone version 0.6.1 to your local folder "pvlib_0.6.1" to distinguish between versions:

$ git clone --branch v0.6.1 --depth 1 https://github.com/pvlib/pvlib-python.git ./pvlib_0.6.1

Now, you can import that version including in sys path on the first position by:

$ python
>>> import sys
>>> sys.path.insert(0, './pvlib_0.6.1')   # Or full path if you store it in another place
>>> import pvlib
>>> pvlib.__version__
u'0.6.1'

You cannot call multiple versions in the same script as your first proposal, but you can do something like:

$ python
>>> DISTNAME = '0.6.1'
>>> import sys
>>> sys.path.insert(0, './pvlib_%s' % DISTNAME) 
>>> import pvlib
>>> pvlib.__version__
u'0.6.1'

Remember the position of the inserted path must be in position 0, if not and you already installed a pvlib version with pip in your system, when you import the library, the system could be loaded with priority respect to other version that you might want to use.

iblasi
  • 1,269
  • 9
  • 21
  • Unfortunately this doesn't get me any closer to being able to compare the two versions. – adr Sep 08 '19 at 10:16
  • If you can explain a little bit better why you cannot run twice the script with different versions, and it must be at the same time, I may help with a better answer. e.g., Do you want to check an output (which one) for different versions? – iblasi Sep 08 '19 at 13:45
  • One example is that I would like to make a graph comparing the output of two versions of a function. Of course I can make two scripts, save the output to a file or something like that. But I'm looking for the convenience of doing it in one script or ipython session so I can interactively explore the differences. – adr Sep 10 '19 at 07:04