diff --git a/src/icartt/__init__.py b/src/icartt/__init__.py index 9edd2591e65fe79d51f29f69fbe2a4863b121ac7..d94e8e256ee46a2e640f2ed4ef0d6f93cfc02a89 100644 --- a/src/icartt/__init__.py +++ b/src/icartt/__init__.py @@ -1,5 +1,20 @@ from .dataset import Dataset, StandardNormalComments, Variable, Formats, VariableType -# TODO: add __version__ ? -# TODO: add __all__ = ("names of exported classes etc.",) ? \ No newline at end of file +def get_version(): + try: + # Python >= 3.8 + from importlib import metadata + + return metadata.version("icartt") + except ImportError: + # Python <= 3.7 + import pkg_resources + + return pkg_resources.get_distribution("icartt").version + + +__version__ = get_version() + + +# TODO: add __all__ = ("names of exported classes etc.",) ? diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py index ffd0a3226b168c3f4a994349b784568e8389b911..7167b0cb7861876c31c1319de0943d648b10a76a 100644 --- a/src/icartt/dataset.py +++ b/src/icartt/dataset.py @@ -214,10 +214,14 @@ class KeywordComment: class StandardNormalComments(collections.UserList): @property def nlines(self): - n = 1 # shortnames line, and keywords might be multiline... - n += len(self.freeform) - n += sum(len(k.data) or 1 for k in self.keywords.values()) - # was: len(self.freeform) + 1 + sum([len(k.data) for k in self.keywords.values()]) + """calculates the number of lines in the normal comments section""" + n = 1 # shortnames line + n += len(self.freeform) # freeform comment + for k in self.keywords.values(): + try: + n += len(k.data[0].split("\n")) # and keywords might be multiline... + except IndexError: # ok we have no list, + n += 1 # just add 1 return n @property