Versioning libraries in python

We are creating new branches at work that all will use the same libraries.

The problem is that if we update one library, you can break all applications that are not updated.

Therefore, we would like to update our libraries.
The way I planned to do this also looks like

loader.load(name='mylib', version='1.0') 

or maybe like this:

 import mylib mylib.load(version='1.0') 

The question is how this bootloader will work.
The naive approach is for each version to be in their own folder, the problem with this, however, is that if there is a common error in all versions, each version must be fixed separately.

A slightly better approach (for ease of maintenance) is to have all versions of the library in one file and call some loading function that creates function references. I don’t know how good it will be (we could get a monster file from several thousand lines, we could, of course, delete old unused versions).

To help maintain the number of versions, I plan to only increase the number of versions when I break compatibility, and not when fixing bugs or adding new things.

Is there something like built-in in python or any other approach that would work?

Does anyone have experience with this kind of thing?


I can add that things using libraries are test cases, we just want the tester to be cd in the branch and run. /testit.py, nothing more.


Decision

The decision is based on the assumption of Gringo Suawa.

 class MyClass_1_0: def func1(self): return 'Baz' def func2(self): return 'Bar' class MyClass_1_1(MyClass_1_0): # Overwriting a function: def func1(self): return 'Foo' # Definining a new function which uses a function # from a previous version: def func3(self): print("{} {}".format(self.func1(), self.func2())) # Change this to the latest version for stuff that always wants the latest class MyClass(MyClass_1_1): pass 

Usage example:

 >>> from my.module import MyClass_1_1 as MyClass >>> m = MyClass() >>> m.func3() Foo Bar 
+6
source share
3 answers

Typically, this is done by increasing the module name. You can develop a more reliable method, but this is easiest to understand / implement.

 import package.modv2 import package.modv3 

Create a new version of the module each time the API changes.

This can also be done at the function level to minimize the number of files:

 from package.module import functionv2 from package.module import functionv3 
+3
source

I believe that was virtualenv . On the virtualenv website:

virtualenv is a tool for creating Python sandboxes.

The main problem that is being solved is one of the dependencies and versions, and indirect resolutions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both of these applications?

In this case, virtualenv can help you. It creates an environment that has its own installation directories, which do not share libraries with other virtual environments (and, optionally, do not access globally installed libraries either).

+2
source

I know that setuptools had something like this. I cannot find it right now, but that does not mean that it has disappeared. You might want to study it.

+1
source

Source: https://habr.com/ru/post/896432/


All Articles