Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, version the data format separately from the app, if not already doing so. Second, have separate classes for newer versions of the format. If the format is completely backwards compatible, you can drop the classes for older versions. As for the file structure, you could have something like:</p> <ul> <li>DF <ul> <li>__init__.py</li> <li>dfbase.py</li> <li>v1_1 <ul> <li>__init__.py</li> <li>format.py</li> </ul> </li> <li>v2_0 <ul> <li>__init__.py</li> <li>format.py</li> </ul> </li> </ul> </li> </ul> <p>where "df" stands for the data format name. The package initialization files import the appropriate packages and define a structure or function to make them accessible. The top-level __init__.py should also define a factory function to create data format objects, so you don't have to.</p> <p>DF/__init__.py:</p> <pre><code>from df.dfbase import DFBase from v1_1 import DF as DF1 from v2_0 import DF as DF2 versions = { '1.0': DF1, # let's say minor versions are fully backwards compatible '1.1': DF1, '2.0': DF2 } def create(file): """Factory function. Loads data from 'file', returns a DF of the appropriate version. """ ... </code></pre> <p>DF/v1_1/__init__.py:</p> <pre><code>__version__ = '1.1' # previous versions that this one is backwards compatible with previous = ['1.0'] from format import DF </code></pre> <p>DF/v1_1/format.py:</p> <pre><code>from df import DFBase class DF(DFBase): ... </code></pre> <p>DF/v2_0/__init__.py:</p> <pre><code>__version__ = '2.0' from format import DF </code></pre> <p>With a little more coding in DF/__init__.py, you could automate the import and registration of format versions.</p> <pre><code>import glob, sys from ndf.ndfbase import NDFBase formats={} for ver in glob.iglob('v*_*'): pkg = '{0}.{1}'.format(__package__, ver) __import__(pkg) formats[sys.modules[pkg].__version__] = sys.modules[pkg] if hasattr(sys.modules[pkg], 'previous'): for prev in sys.modules[pkg].previous: formats[prev] = sys.modules[pkg] def create(file): """Factory function. Loads data from 'file', returns a DF of the appropriate version. """ ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload