From d94f981405451cbab68b9564b3ec10679ca0ffae Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:10:32 +0200 Subject: [PATCH 1/9] switch to `src` based project structure --- {odmltables/gui => src}/__init__.py | 0 {odmltables => src/odmltables}/__init__.py | 14 ++++---------- .../odmltables}/compare_section_csv_table.py | 0 .../odmltables}/compare_section_table.py | 0 .../odmltables}/compare_section_xls_table.py | 0 .../odmltables}/create_examples.py | 0 .../tests => src/odmltables/gui}/__init__.py | 0 .../odmltables}/gui/compsectionpages.py | 7 +++---- .../odmltables}/gui/compsectionwiz.py | 0 .../odmltables}/gui/converterpages.py | 2 +- .../odmltables}/gui/converterwiz.py | 0 .../odmltables}/gui/filterpages.py | 2 +- {odmltables => src/odmltables}/gui/filterwiz.py | 0 .../odmltables}/gui/generatetemplatepages.py | 2 +- .../odmltables}/gui/generatetemplatewiz.py | 0 .../odmltables}/gui/graphics/comparetable.svg | 0 .../odmltables}/gui/graphics/comparetable.tex | 0 .../odmltables}/gui/graphics/convertodml.svg | 0 .../odmltables}/gui/graphics/convertodml.tex | 0 .../odmltables}/gui/graphics/createtemplate.svg | 0 .../odmltables}/gui/graphics/createtemplate.tex | 0 .../odmltables}/gui/graphics/filterodml.svg | 0 .../odmltables}/gui/graphics/filterodml.tex | 0 .../odmltables}/gui/graphics/mergeappend.svg | 0 .../odmltables}/gui/graphics/mergeappend.tex | 0 .../odmltables}/gui/graphics/mergeodml.svg | 0 .../odmltables}/gui/graphics/mergeodml.tex | 0 .../odmltables}/gui/graphics/mergestrict.svg | 0 .../odmltables}/gui/graphics/mergestrict.tex | 0 .../odmltables}/gui/graphics/odmlA.svg | 0 .../odmltables}/gui/graphics/odmlA.tex | 0 .../odmltables}/gui/graphics/odmlB.svg | 0 .../odmltables}/gui/graphics/odmlB.tex | 0 {odmltables => src/odmltables}/gui/main.py | 0 .../odmltables}/gui/mainwindow.py | 12 +++++------- .../odmltables}/gui/mergepages.py | 2 +- {odmltables => src/odmltables}/gui/mergewiz.py | 0 {odmltables => src/odmltables}/gui/pageutils.py | 0 {odmltables => src/odmltables}/gui/settings.py | 0 {odmltables => src/odmltables}/gui/wizutils.py | 13 ++++++------- {logo => src/odmltables/logo}/odMLtables.eps | 0 {logo => src/odmltables/logo}/odMLtables.pdf | Bin {logo => src/odmltables/logo}/odMLtables.png | Bin {logo => src/odmltables/logo}/odMLtables.svg | 0 .../odmltables/logo}/odMLtables_100x100.png | Bin .../odmltables}/odml_csv_table.py | 0 {odmltables => src/odmltables}/odml_table.py | 16 +++++++++------- .../odmltables}/odml_xls_table.py | 10 +++++----- src/odmltables/tests/__init__.py | 0 .../odmltables}/tests/create_test_odmls.py | 0 .../tests/test_compare_section_table.py | 0 .../odmltables}/tests/test_odml_csv_table.py | 0 .../odmltables}/tests/test_odml_table.py | 0 .../odmltables}/tests/test_odml_xls_table.py | 4 ++-- {odmltables => src/odmltables}/xls_style.py | 0 55 files changed, 38 insertions(+), 46 deletions(-) rename {odmltables/gui => src}/__init__.py (100%) rename {odmltables => src/odmltables}/__init__.py (50%) rename {odmltables => src/odmltables}/compare_section_csv_table.py (100%) rename {odmltables => src/odmltables}/compare_section_table.py (100%) rename {odmltables => src/odmltables}/compare_section_xls_table.py (100%) rename {odmltables => src/odmltables}/create_examples.py (100%) rename {odmltables/tests => src/odmltables/gui}/__init__.py (100%) rename {odmltables => src/odmltables}/gui/compsectionpages.py (98%) rename {odmltables => src/odmltables}/gui/compsectionwiz.py (100%) rename {odmltables => src/odmltables}/gui/converterpages.py (99%) rename {odmltables => src/odmltables}/gui/converterwiz.py (100%) rename {odmltables => src/odmltables}/gui/filterpages.py (99%) rename {odmltables => src/odmltables}/gui/filterwiz.py (100%) rename {odmltables => src/odmltables}/gui/generatetemplatepages.py (99%) rename {odmltables => src/odmltables}/gui/generatetemplatewiz.py (100%) rename {odmltables => src/odmltables}/gui/graphics/comparetable.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/comparetable.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/convertodml.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/convertodml.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/createtemplate.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/createtemplate.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/filterodml.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/filterodml.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/mergeappend.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/mergeappend.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/mergeodml.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/mergeodml.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/mergestrict.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/mergestrict.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/odmlA.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/odmlA.tex (100%) rename {odmltables => src/odmltables}/gui/graphics/odmlB.svg (100%) rename {odmltables => src/odmltables}/gui/graphics/odmlB.tex (100%) rename {odmltables => src/odmltables}/gui/main.py (100%) rename {odmltables => src/odmltables}/gui/mainwindow.py (95%) rename {odmltables => src/odmltables}/gui/mergepages.py (99%) rename {odmltables => src/odmltables}/gui/mergewiz.py (100%) rename {odmltables => src/odmltables}/gui/pageutils.py (100%) rename {odmltables => src/odmltables}/gui/settings.py (100%) rename {odmltables => src/odmltables}/gui/wizutils.py (88%) rename {logo => src/odmltables/logo}/odMLtables.eps (100%) rename {logo => src/odmltables/logo}/odMLtables.pdf (100%) rename {logo => src/odmltables/logo}/odMLtables.png (100%) rename {logo => src/odmltables/logo}/odMLtables.svg (100%) rename {logo => src/odmltables/logo}/odMLtables_100x100.png (100%) rename {odmltables => src/odmltables}/odml_csv_table.py (100%) rename {odmltables => src/odmltables}/odml_table.py (99%) rename {odmltables => src/odmltables}/odml_xls_table.py (97%) create mode 100644 src/odmltables/tests/__init__.py rename {odmltables => src/odmltables}/tests/create_test_odmls.py (100%) rename {odmltables => src/odmltables}/tests/test_compare_section_table.py (100%) rename {odmltables => src/odmltables}/tests/test_odml_csv_table.py (100%) rename {odmltables => src/odmltables}/tests/test_odml_table.py (100%) rename {odmltables => src/odmltables}/tests/test_odml_xls_table.py (99%) rename {odmltables => src/odmltables}/xls_style.py (100%) diff --git a/odmltables/gui/__init__.py b/src/__init__.py similarity index 100% rename from odmltables/gui/__init__.py rename to src/__init__.py diff --git a/odmltables/__init__.py b/src/odmltables/__init__.py similarity index 50% rename from odmltables/__init__.py rename to src/odmltables/__init__.py index 36c4634..c3f5195 100644 --- a/odmltables/__init__.py +++ b/src/odmltables/__init__.py @@ -1,8 +1,7 @@ -import os.path - -with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'VERSION.txt')) as version_file: - VERSION = version_file.read().strip() - +import importlib.metadata +# this need to be at the begining because some sub module will need the version +__version__ = importlib.metadata.version("odmltables") +VERSION = __version__ # -*- coding: utf-8 -*- """ @@ -15,9 +14,4 @@ .. autoclass:: odmltables.compare_section_csv_table.CompareSectionCsvTable """ - -from odmltables.odml_table import OdmlTable from odmltables.odml_csv_table import OdmlCsvTable -from odmltables.odml_xls_table import OdmlXlsTable -from odmltables.compare_section_csv_table import CompareSectionCsvTable -from odmltables.compare_section_xls_table import CompareSectionXlsTable diff --git a/odmltables/compare_section_csv_table.py b/src/odmltables/compare_section_csv_table.py similarity index 100% rename from odmltables/compare_section_csv_table.py rename to src/odmltables/compare_section_csv_table.py diff --git a/odmltables/compare_section_table.py b/src/odmltables/compare_section_table.py similarity index 100% rename from odmltables/compare_section_table.py rename to src/odmltables/compare_section_table.py diff --git a/odmltables/compare_section_xls_table.py b/src/odmltables/compare_section_xls_table.py similarity index 100% rename from odmltables/compare_section_xls_table.py rename to src/odmltables/compare_section_xls_table.py diff --git a/odmltables/create_examples.py b/src/odmltables/create_examples.py similarity index 100% rename from odmltables/create_examples.py rename to src/odmltables/create_examples.py diff --git a/odmltables/tests/__init__.py b/src/odmltables/gui/__init__.py similarity index 100% rename from odmltables/tests/__init__.py rename to src/odmltables/gui/__init__.py diff --git a/odmltables/gui/compsectionpages.py b/src/odmltables/gui/compsectionpages.py similarity index 98% rename from odmltables/gui/compsectionpages.py rename to src/odmltables/gui/compsectionpages.py index 75a0bcf..923803c 100644 --- a/odmltables/gui/compsectionpages.py +++ b/src/odmltables/gui/compsectionpages.py @@ -9,10 +9,9 @@ import subprocess from PyQt5.QtWidgets import (QVBoxLayout, QHBoxLayout, QMessageBox, - QLineEdit, QPushButton, QLabel, QGroupBox, - QGridLayout, QTreeWidget, QTreeWidgetItem, - QToolButton, QFileDialog, QCheckBox, QComboBox, - QFrame, QSizePolicy, QRadioButton) + QLineEdit, QPushButton, QLabel, QGroupBox, + QGridLayout, QTreeWidget, QTreeWidgetItem, + QToolButton, QFileDialog, QCheckBox, QRadioButton) from PyQt5.QtCore import Qt diff --git a/odmltables/gui/compsectionwiz.py b/src/odmltables/gui/compsectionwiz.py similarity index 100% rename from odmltables/gui/compsectionwiz.py rename to src/odmltables/gui/compsectionwiz.py diff --git a/odmltables/gui/converterpages.py b/src/odmltables/gui/converterpages.py similarity index 99% rename from odmltables/gui/converterpages.py rename to src/odmltables/gui/converterpages.py index 6af81bb..d97fd36 100644 --- a/odmltables/gui/converterpages.py +++ b/src/odmltables/gui/converterpages.py @@ -12,7 +12,7 @@ import PyQt5.QtGui as Qtg from .pageutils import QIWizardPage, clearLayout, get_property, get_rgb, shorten_path -from odmltables import odml_table, odml_xls_table, odml_csv_table, xls_style +from .. import odml_csv_table, odml_xls_table, xls_style, odml_table class LoadFilePage(QIWizardPage): diff --git a/odmltables/gui/converterwiz.py b/src/odmltables/gui/converterwiz.py similarity index 100% rename from odmltables/gui/converterwiz.py rename to src/odmltables/gui/converterwiz.py diff --git a/odmltables/gui/filterpages.py b/src/odmltables/gui/filterpages.py similarity index 99% rename from odmltables/gui/filterpages.py rename to src/odmltables/gui/filterpages.py index e2ee537..4b3d467 100644 --- a/odmltables/gui/filterpages.py +++ b/src/odmltables/gui/filterpages.py @@ -16,7 +16,7 @@ from PyQt5.QtCore import Qt import PyQt5.QtWidgets as Qtw -from odmltables import odml_table +from .. import odml_table from .pageutils import QIWizardPage, clearLayout, shorten_path diff --git a/odmltables/gui/filterwiz.py b/src/odmltables/gui/filterwiz.py similarity index 100% rename from odmltables/gui/filterwiz.py rename to src/odmltables/gui/filterwiz.py diff --git a/odmltables/gui/generatetemplatepages.py b/src/odmltables/gui/generatetemplatepages.py similarity index 99% rename from odmltables/gui/generatetemplatepages.py rename to src/odmltables/gui/generatetemplatepages.py index 5aba2b0..f1f0e81 100644 --- a/odmltables/gui/generatetemplatepages.py +++ b/src/odmltables/gui/generatetemplatepages.py @@ -12,7 +12,7 @@ from PyQt5.QtCore import Qt import odml -from odmltables import odml_table, odml_xls_table, odml_csv_table, xls_style +from .. import odml_xls_table, odml_table from .pageutils import QIWizardPage, clearLayout, shorten_path mandatory_headers = ['Path to Section', diff --git a/odmltables/gui/generatetemplatewiz.py b/src/odmltables/gui/generatetemplatewiz.py similarity index 100% rename from odmltables/gui/generatetemplatewiz.py rename to src/odmltables/gui/generatetemplatewiz.py diff --git a/odmltables/gui/graphics/comparetable.svg b/src/odmltables/gui/graphics/comparetable.svg similarity index 100% rename from odmltables/gui/graphics/comparetable.svg rename to src/odmltables/gui/graphics/comparetable.svg diff --git a/odmltables/gui/graphics/comparetable.tex b/src/odmltables/gui/graphics/comparetable.tex similarity index 100% rename from odmltables/gui/graphics/comparetable.tex rename to src/odmltables/gui/graphics/comparetable.tex diff --git a/odmltables/gui/graphics/convertodml.svg b/src/odmltables/gui/graphics/convertodml.svg similarity index 100% rename from odmltables/gui/graphics/convertodml.svg rename to src/odmltables/gui/graphics/convertodml.svg diff --git a/odmltables/gui/graphics/convertodml.tex b/src/odmltables/gui/graphics/convertodml.tex similarity index 100% rename from odmltables/gui/graphics/convertodml.tex rename to src/odmltables/gui/graphics/convertodml.tex diff --git a/odmltables/gui/graphics/createtemplate.svg b/src/odmltables/gui/graphics/createtemplate.svg similarity index 100% rename from odmltables/gui/graphics/createtemplate.svg rename to src/odmltables/gui/graphics/createtemplate.svg diff --git a/odmltables/gui/graphics/createtemplate.tex b/src/odmltables/gui/graphics/createtemplate.tex similarity index 100% rename from odmltables/gui/graphics/createtemplate.tex rename to src/odmltables/gui/graphics/createtemplate.tex diff --git a/odmltables/gui/graphics/filterodml.svg b/src/odmltables/gui/graphics/filterodml.svg similarity index 100% rename from odmltables/gui/graphics/filterodml.svg rename to src/odmltables/gui/graphics/filterodml.svg diff --git a/odmltables/gui/graphics/filterodml.tex b/src/odmltables/gui/graphics/filterodml.tex similarity index 100% rename from odmltables/gui/graphics/filterodml.tex rename to src/odmltables/gui/graphics/filterodml.tex diff --git a/odmltables/gui/graphics/mergeappend.svg b/src/odmltables/gui/graphics/mergeappend.svg similarity index 100% rename from odmltables/gui/graphics/mergeappend.svg rename to src/odmltables/gui/graphics/mergeappend.svg diff --git a/odmltables/gui/graphics/mergeappend.tex b/src/odmltables/gui/graphics/mergeappend.tex similarity index 100% rename from odmltables/gui/graphics/mergeappend.tex rename to src/odmltables/gui/graphics/mergeappend.tex diff --git a/odmltables/gui/graphics/mergeodml.svg b/src/odmltables/gui/graphics/mergeodml.svg similarity index 100% rename from odmltables/gui/graphics/mergeodml.svg rename to src/odmltables/gui/graphics/mergeodml.svg diff --git a/odmltables/gui/graphics/mergeodml.tex b/src/odmltables/gui/graphics/mergeodml.tex similarity index 100% rename from odmltables/gui/graphics/mergeodml.tex rename to src/odmltables/gui/graphics/mergeodml.tex diff --git a/odmltables/gui/graphics/mergestrict.svg b/src/odmltables/gui/graphics/mergestrict.svg similarity index 100% rename from odmltables/gui/graphics/mergestrict.svg rename to src/odmltables/gui/graphics/mergestrict.svg diff --git a/odmltables/gui/graphics/mergestrict.tex b/src/odmltables/gui/graphics/mergestrict.tex similarity index 100% rename from odmltables/gui/graphics/mergestrict.tex rename to src/odmltables/gui/graphics/mergestrict.tex diff --git a/odmltables/gui/graphics/odmlA.svg b/src/odmltables/gui/graphics/odmlA.svg similarity index 100% rename from odmltables/gui/graphics/odmlA.svg rename to src/odmltables/gui/graphics/odmlA.svg diff --git a/odmltables/gui/graphics/odmlA.tex b/src/odmltables/gui/graphics/odmlA.tex similarity index 100% rename from odmltables/gui/graphics/odmlA.tex rename to src/odmltables/gui/graphics/odmlA.tex diff --git a/odmltables/gui/graphics/odmlB.svg b/src/odmltables/gui/graphics/odmlB.svg similarity index 100% rename from odmltables/gui/graphics/odmlB.svg rename to src/odmltables/gui/graphics/odmlB.svg diff --git a/odmltables/gui/graphics/odmlB.tex b/src/odmltables/gui/graphics/odmlB.tex similarity index 100% rename from odmltables/gui/graphics/odmlB.tex rename to src/odmltables/gui/graphics/odmlB.tex diff --git a/odmltables/gui/main.py b/src/odmltables/gui/main.py similarity index 100% rename from odmltables/gui/main.py rename to src/odmltables/gui/main.py diff --git a/odmltables/gui/mainwindow.py b/src/odmltables/gui/mainwindow.py similarity index 95% rename from odmltables/gui/mainwindow.py rename to src/odmltables/gui/mainwindow.py index 5f0b792..5816162 100644 --- a/odmltables/gui/mainwindow.py +++ b/src/odmltables/gui/mainwindow.py @@ -2,13 +2,14 @@ """ Created on Tue Jan 26 12:57:46 2016 -@author: zehl +@author: Lyuba Zehl, Julia Sprenger """ import datetime import os import sys import traceback +from importlib.resources import files, as_file from PyQt5 import QtCore, QtWidgets, QtGui @@ -149,13 +150,10 @@ def initUI(self): icon = QtWidgets.QLabel() # icon.setGeometry(10, 10, 4, 100) logo_filename = "odMLtables_100x100.png" - logo_dirs = [os.path.join(os.path.dirname(__file__), '..', '..', 'logo'), - os.path.join(sys.prefix, 'share/pixmaps')] - for logo_dir in logo_dirs: - filepath = os.path.join(logo_dir, logo_filename) + logo_dir_object = files('odmltables.logo').joinpath(logo_filename) + with as_file(logo_dir_object) as filepath: if os.path.exists(filepath): - icon.setPixmap(QtGui.QPixmap(filepath)) - + icon.setPixmap(QtGui.QPixmap(str(filepath))) grid.addWidget(self.convertbutton, 0, 0, 1, 2, QtCore.Qt.AlignCenter) grid.addWidget(self.comparebutton, 1, 1) diff --git a/odmltables/gui/mergepages.py b/src/odmltables/gui/mergepages.py similarity index 99% rename from odmltables/gui/mergepages.py rename to src/odmltables/gui/mergepages.py index 91183db..c64b7d8 100644 --- a/odmltables/gui/mergepages.py +++ b/src/odmltables/gui/mergepages.py @@ -8,7 +8,7 @@ import PyQt5.QtWidgets as Qtw from PyQt5.QtCore import QSize, Qt -from odmltables import odml_table, odml_xls_table, odml_csv_table, xls_style +from .. import odml_table from .pageutils import QIWizardPage, shorten_path from .wizutils import get_graphic_path diff --git a/odmltables/gui/mergewiz.py b/src/odmltables/gui/mergewiz.py similarity index 100% rename from odmltables/gui/mergewiz.py rename to src/odmltables/gui/mergewiz.py diff --git a/odmltables/gui/pageutils.py b/src/odmltables/gui/pageutils.py similarity index 100% rename from odmltables/gui/pageutils.py rename to src/odmltables/gui/pageutils.py diff --git a/odmltables/gui/settings.py b/src/odmltables/gui/settings.py similarity index 100% rename from odmltables/gui/settings.py rename to src/odmltables/gui/settings.py diff --git a/odmltables/gui/wizutils.py b/src/odmltables/gui/wizutils.py similarity index 88% rename from odmltables/gui/wizutils.py rename to src/odmltables/gui/wizutils.py index 54b51b3..fcbfbb0 100644 --- a/odmltables/gui/wizutils.py +++ b/src/odmltables/gui/wizutils.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- -import os, sys +import os +from importlib.resources import files, as_file + from PyQt5.QtWidgets import (QWizard, QMessageBox) from PyQt5.QtGui import QPixmap from PyQt5.QtCore import pyqtSlot, Qt try: import odmltables - have_odmltables = True except: have_odmltables = False @@ -36,12 +37,10 @@ def __init__(self, wizname, parent=None): self.setWizardStyle(self.ModernStyle) self.setOption(self.HaveHelpButton, True) logo_filename = "odMLtables_100x100.png" - logo_dirs = [os.path.join(os.path.dirname(__file__), '..', '..', 'logo'), - os.path.join(sys.prefix, 'share/pixmaps')] - for logo_dir in logo_dirs: - filepath = os.path.join(logo_dir, logo_filename) + logo_dir_object = files('odmltables.logo').joinpath(logo_filename) + with as_file(logo_dir_object) as filepath: if os.path.exists(filepath): - self.setPixmap(QWizard.LogoPixmap, QPixmap(filepath)) + self.setPixmap(QWizard.LogoPixmap, QPixmap(str(filepath))) # set up help messages self._lastHelpMsg = '' diff --git a/logo/odMLtables.eps b/src/odmltables/logo/odMLtables.eps similarity index 100% rename from logo/odMLtables.eps rename to src/odmltables/logo/odMLtables.eps diff --git a/logo/odMLtables.pdf b/src/odmltables/logo/odMLtables.pdf similarity index 100% rename from logo/odMLtables.pdf rename to src/odmltables/logo/odMLtables.pdf diff --git a/logo/odMLtables.png b/src/odmltables/logo/odMLtables.png similarity index 100% rename from logo/odMLtables.png rename to src/odmltables/logo/odMLtables.png diff --git a/logo/odMLtables.svg b/src/odmltables/logo/odMLtables.svg similarity index 100% rename from logo/odMLtables.svg rename to src/odmltables/logo/odMLtables.svg diff --git a/logo/odMLtables_100x100.png b/src/odmltables/logo/odMLtables_100x100.png similarity index 100% rename from logo/odMLtables_100x100.png rename to src/odmltables/logo/odMLtables_100x100.png diff --git a/odmltables/odml_csv_table.py b/src/odmltables/odml_csv_table.py similarity index 100% rename from odmltables/odml_csv_table.py rename to src/odmltables/odml_csv_table.py diff --git a/odmltables/odml_table.py b/src/odmltables/odml_table.py similarity index 99% rename from odmltables/odml_table.py rename to src/odmltables/odml_table.py index 94c4d44..9b55fcd 100644 --- a/odmltables/odml_table.py +++ b/src/odmltables/odml_table.py @@ -2,14 +2,14 @@ """ """ -import os -import re import copy -import odml import csv import datetime -import xlrd +import os +import re +import odml +import xlrd from future.utils import iteritems from six import string_types @@ -725,12 +725,14 @@ def filter_func(dict_prop): def merge(self, odmltable, overwrite_values=False, **kwargs): """ Merge odmltable into current odmltable. + :param odmltable: OdmlTable object or odML document object :param overwrite_values: Bool value to indicate whether values of odML Properties should - be merged (appended) or overwritten by the entries of the other odmltable object. - Default is False. - :return: + be merged (appended) or overwritten by the entries of the other odmltable object. + Default is False. + :return: None """ + if hasattr(odmltable, 'convert2odml'): doc2 = odmltable.convert2odml() else: diff --git a/odmltables/odml_xls_table.py b/src/odmltables/odml_xls_table.py similarity index 97% rename from odmltables/odml_xls_table.py rename to src/odmltables/odml_xls_table.py index d7d064f..27e0075 100644 --- a/odmltables/odml_xls_table.py +++ b/src/odmltables/odml_xls_table.py @@ -225,10 +225,10 @@ def write_row(row_id, row_content, stylestrings): row_id += 1 # set default styles as bool values for simplicity - if self._pattern is "checkerboard": + if self._pattern == "checkerboard": row_style_default = np.array([0, 1] * (len(self._header)), dtype=bool) row_style_default = row_style_default[:len(self._header)] - elif self._pattern is "alternating": + elif self._pattern == "alternating": row_style_default = np.array([0] * len(self._header), dtype=bool) else: raise Exception(f"{self._pattern} is not a valid pattern") @@ -268,9 +268,9 @@ def _switch_row_style(): # row_dic[h] = "" # handling row styles - if self._changing_point is 'properties': + if self._changing_point == 'properties': _switch_row_style() - elif self._changing_point is 'sections' and (row_dic["Path"] != oldpath): + elif self._changing_point == 'sections' and (row_dic["Path"] != oldpath): _switch_row_style() # row_content: only those elements of row_dic, that will be visible in the table @@ -301,7 +301,7 @@ def _switch_row_style(): if 'Value' not in self._header: break - if self._changing_point is 'values': + if self._changing_point == 'values': _switch_row_style() # adjust section and property entries for next value diff --git a/src/odmltables/tests/__init__.py b/src/odmltables/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/odmltables/tests/create_test_odmls.py b/src/odmltables/tests/create_test_odmls.py similarity index 100% rename from odmltables/tests/create_test_odmls.py rename to src/odmltables/tests/create_test_odmls.py diff --git a/odmltables/tests/test_compare_section_table.py b/src/odmltables/tests/test_compare_section_table.py similarity index 100% rename from odmltables/tests/test_compare_section_table.py rename to src/odmltables/tests/test_compare_section_table.py diff --git a/odmltables/tests/test_odml_csv_table.py b/src/odmltables/tests/test_odml_csv_table.py similarity index 100% rename from odmltables/tests/test_odml_csv_table.py rename to src/odmltables/tests/test_odml_csv_table.py diff --git a/odmltables/tests/test_odml_table.py b/src/odmltables/tests/test_odml_table.py similarity index 100% rename from odmltables/tests/test_odml_table.py rename to src/odmltables/tests/test_odml_table.py diff --git a/odmltables/tests/test_odml_xls_table.py b/src/odmltables/tests/test_odml_xls_table.py similarity index 99% rename from odmltables/tests/test_odml_xls_table.py rename to src/odmltables/tests/test_odml_xls_table.py index b386a1d..b67f4d6 100644 --- a/odmltables/tests/test_odml_xls_table.py +++ b/src/odmltables/tests/test_odml_xls_table.py @@ -11,8 +11,8 @@ import unittest import os from odmltables.tests.create_test_odmls import (create_2samerows_test_odml, - create_datatype_test_odml, - create_complex_test_odml, create_showall_test_odml) + create_datatype_test_odml, + create_complex_test_odml, create_showall_test_odml) import xlrd diff --git a/odmltables/xls_style.py b/src/odmltables/xls_style.py similarity index 100% rename from odmltables/xls_style.py rename to src/odmltables/xls_style.py From 6e1ae3b2330ea0fce4a36f427d0fbbcb1814b739 Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:11:23 +0200 Subject: [PATCH 2/9] replace requirement and setup files by toml --- .gitignore | 2 +- doc/conf.py | 31 ++++++++--------- odmltables/VERSION.txt | 1 - pyproject.toml | 79 ++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 8 ----- requirements_doc.txt | 2 -- requirements_gui.txt | 1 - requirements_test.txt | 1 - setup.cfg | 2 -- setup.py | 69 ------------------------------------ 10 files changed, 95 insertions(+), 101 deletions(-) delete mode 100644 odmltables/VERSION.txt create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 requirements_doc.txt delete mode 100644 requirements_gui.txt delete mode 100644 requirements_test.txt delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.gitignore b/.gitignore index ce2bb99..50e2dad 100644 --- a/.gitignore +++ b/.gitignore @@ -74,7 +74,7 @@ odmltables/gui/graphics/*.dvi odmltables/gui/graphics/*.ps odmltables/gui/graphics/*.txt odmltables/gui/graphics/*.tex.backup -odmltables/gui/testfiles/* +src/odmltables/gui/testfiles/* doc/build/* doc/_build/* doc/requirements*.rst diff --git a/doc/conf.py b/doc/conf.py index e231947..afa1b71 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -13,10 +13,9 @@ # serve to show the default. import sys -import glob import subprocess import os - +import tomllib # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -24,7 +23,7 @@ #sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('../src')) sys.path.insert(0, os.path.abspath('../../python-odml/')) -sys.path.insert(0, os.path.abspath('../odmltables')) +sys.path.insert(0, os.path.abspath('../src/odmltables')) sys.path.insert(0, os.path.abspath('..')) # installing current odMLtables version @@ -33,25 +32,25 @@ output, error = process.communicate() import odmltables + VERSION = odmltables.VERSION # reformatting requirements files to be automatically included in docu -requirement_files = glob.glob('../requirements*.txt') -for requirement_file in requirement_files: - with open(requirement_file, 'r') as f: - lines = f.readlines() - # listify and increase readability - for line_id in range(len(lines)): - lines[line_id] = '* ' + lines[line_id] - lines[line_id] = lines[line_id].replace(';', ' in case of ') - new_filename = f'{os.path.splitext(os.path.basename(requirement_file))[0]}.rst' - with open(new_filename, 'w+') as f: - f.writelines(lines) - - +with open("../pyproject.toml", "rb") as f: + data = tomllib.load(f) +def format_dependencies(dependency_list): + # format a list of dependencies into a block text list + formatted_dependencies = '\n* '.join(dependency_list).replace(';', ' in case of ') + return formatted_dependencies +dependencies = data["project"]["dependencies"] +with open('requirements.rst', 'w+') as f: + f.write(format_dependencies(dependencies)) +for option, optional_dependencies in data["project"]["optional-dependencies"].items(): + with open(f'requirements_{option}.rst', 'w+') as f: + f.write(format_dependencies(optional_dependencies)) # -- General configuration ------------------------------------------------ diff --git a/odmltables/VERSION.txt b/odmltables/VERSION.txt deleted file mode 100644 index e29964d..0000000 --- a/odmltables/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -1.0.1dev diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d79275d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,79 @@ +[project] +name = "odmltables" +version = "1.0.1dev" +authors = [ + {name = "odMLtables authors and contributors"}, + {email = "julia.sprenger@rwth-aachen.de"} +] +description = "Interface to convert odML structures to and from table-like representations" +readme = "README.rst" +requires-python = ">=3.6" +license = {text = "BSD 3-Clause License"} +keywords = ["odml", "excel", "metadata management"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Intended Audience :: Science/Research", + "Natural Language :: English", + "Topic :: Scientific/Engineering", + "License :: OSI Approved :: BSD License", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3 :: Only", +] + +dependencies = [ + "xlrd >= 0.9.4", + "xlwt >= 1.0.0", + "numpy >= 1.8.2", + "quantities >= 0.10.1", + "odml >= 1.4.2", + "future >= 0.16.0", + "argparse >= 1.0.0", +] + +[project.urls] +documentation = "http://odmltables.readthedocs.io/" +repository = "https://github.com/INM-6/python-odmltables" +download = "http://pypi.python.org/pypi/odmltables" + + +[build-system] +requires = ["setuptools>=62.0"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.package-data] +odmltables = ["gui/graphics/*", "logo/*"] + +[tool.pytest.ini_options] +minversion = "7.0" +addopts = "-ra -q" +testpaths = [ + "tests", + "integration", +] +pythonpath = [ + "src" +] + +[project.gui-scripts] +odmltables = "odmltables.gui.main:parse_args" + +[project.optional-dependencies] + +doc = [ + "numpydoc>=0.5.0", + "sphinx>=1.2.2", +] + +gui = ["PyQt5>=5.0.0"] + +test = ["pytest>=3.0.0"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 55b5ebd..0000000 --- a/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -xlrd >= 0.9.4 -xlwt >= 1.0.0 -numpy >= 1.8.2 -quantities >= 0.10.1 -odml >= 1.4.2 -future >= 0.16.0 -argparse >= 1.0.0 -enum34 >= 0.4.6;python_version<"3.4" \ No newline at end of file diff --git a/requirements_doc.txt b/requirements_doc.txt deleted file mode 100644 index a812a3d..0000000 --- a/requirements_doc.txt +++ /dev/null @@ -1,2 +0,0 @@ -numpydoc>=0.5.0 -sphinx>=1.2.2 \ No newline at end of file diff --git a/requirements_gui.txt b/requirements_gui.txt deleted file mode 100644 index fdb6880..0000000 --- a/requirements_gui.txt +++ /dev/null @@ -1 +0,0 @@ -PyQt5>=5.0.0 \ No newline at end of file diff --git a/requirements_test.txt b/requirements_test.txt deleted file mode 100644 index 2e005dc..0000000 --- a/requirements_test.txt +++ /dev/null @@ -1 +0,0 @@ -pytest>=3.0.0 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 11e9ec4..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[metadata] -description-file = README.rst \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index df0f085..0000000 --- a/setup.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys, os, glob -import warnings -from setuptools import setup, find_packages - -with open("README.rst") as f: - long_description = f.read() -with open('requirements.txt') as f: - install_requires = f.read().splitlines() -with open('requirements_doc.txt') as f: - doc_requires = f.read().splitlines() -with open('requirements_test.txt') as f: - test_requires = f.read().splitlines() -with open('requirements_gui.txt') as f: - gui_requires = f.read().splitlines() - -extras_require = {'doc': doc_requires, - 'test': test_requires, - 'gui': gui_requires - } - -# PyQt5 needs to be installed manually with python 2 when installing odmltables gui. -if sys.version_info.major < 3: - warnings.warn('The odMLtables gui requires PyQt5. Please install this dependency first before ' - 'installing the odmltables gui, eg. using "conda install -c anaconda ' - '\'pyqt>=5\'"') - -if sys.version_info.major < 3 or (sys.version_info.major == 3 and sys.version_info.minor < 6): - raise EnvironmentError('odMLtables requires Python version 3.6 or later.') - -VERSION = open('./odmltables/VERSION.txt', 'r').read().strip() - -setup( - name="odmltables", - version=VERSION, - packages=find_packages(), - package_data={'odmltables': ['gui/graphics/*', 'VERSION.txt']}, - install_requires=install_requires, - extras_require=extras_require, - - author="odMLtables authors and contributors", - author_email="j.sprenger@fz-juelich.de", - description="Interface to convert odML structures to and from table-like representations", - long_description=long_description, - license="BSD", - url='https://github.com/INM-6/python-odmltables', - download_url="https://github.com/INM-6/python-odmltables/archive/{}.tar.gz".format(VERSION), - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: BSD License', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Topic :: Scientific/Engineering'], - entry_points={ - 'gui_scripts': ['odmltables = odmltables.gui.main:parse_args []']}, - zip_safe=False, - keywords=['odml', 'excel', 'metadata management'], - # Extension('foo', ['foo.c'], include_dirs=['.']), - data_files=[('share/pixmaps', glob.glob(os.path.join("logo", "*"))), - ('.', ['odmltables/VERSION.txt', - 'requirements.txt', - 'requirements_doc.txt', - 'requirements_gui.txt', - 'requirements_test.txt'])] -) \ No newline at end of file From 23bab76264be8f4e30fbd99ccadc535db6e3b9e6 Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:12:42 +0200 Subject: [PATCH 3/9] update documentation building --- doc/environment.yml | 3 +-- doc/tutorial.rst | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/environment.yml b/doc/environment.yml index af1f85f..12f6584 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -1,6 +1,6 @@ name: odmltables dependencies: -- python=3.7 +- python=3.11 - setuptools - snowballstemmer - sphinx @@ -8,4 +8,3 @@ dependencies: - pip - pip: - odml - - sphinx-rtd-theme diff --git a/doc/tutorial.rst b/doc/tutorial.rst index 29836fe..90b7663 100644 --- a/doc/tutorial.rst +++ b/doc/tutorial.rst @@ -15,10 +15,11 @@ version `1.0 `_. -In addition to the detailed step-by-step instructions presented here, there are also two **interactive tutorials** available as `jupyter notebooks`_. Both tutorials can be directly executed using binder_ or run locally from the odmltables sources (:any:`tutorials/tutorial-1_scenarios/demo_scenarios.ipynb`) folder. The first notebook (|notebook1|) is giving a quick overview on how odMLtables can be used in a metadata workflow by presenting a number of small application scenarios. The second notebook (|notebook2|) shows the usage of odMLtables for handling large metadata collections and is based on two published experimental datasets. +In addition to the detailed step-by-step instructions presented here, there are also two **interactive tutorials** available as `jupyter notebooks`_. Both tutorials can be directly executed using binder_ or run locally from the odmltables `tutorial folder`_. The first notebook (|notebook1|) is giving a quick overview on how odMLtables can be used in a metadata workflow by presenting a number of small application scenarios. The second notebook (|notebook2|) shows the usage of odMLtables for handling large metadata collections and is based on two published experimental datasets. .. _binder: https://mybinder.org/ .. _jupyter notebooks: http://jupyter.org/ +.. _tutorial folder: https://github.com/INM-6/python-odmltables/tree/master/tutorials .. |notebook1| image:: https://mybinder.org/badge.svg :target: https://mybinder.org/v2/gh/inm-6/python-odmltables/master?filepath=tutorials%2Ftutorial-1_scenarios%2Fdemo_scenarios.ipynb From f4ae21e3ba7edeee5cfa12b24bfeef71a8efea9b Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:37:50 +0200 Subject: [PATCH 4/9] debugging readthedocs building --- doc/environment.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/environment.yml b/doc/environment.yml index 12f6584..1986599 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -1,10 +1,12 @@ name: odmltables +channels: + - free dependencies: -- python=3.11 -- setuptools -- snowballstemmer -- sphinx -- sphinx_rtd_theme -- pip -- pip: - - odml + - python=3.11 + - setuptools + - snowballstemmer + - sphinx + - sphinx_rtd_theme + - pip + - pip: + - odml From f1815dfba3b558c0e5c5dfaf1e079bd7bc78c87f Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:44:06 +0200 Subject: [PATCH 5/9] debugging readthedocs building --- doc/environment.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/environment.yml b/doc/environment.yml index 1986599..ada2dae 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -1,6 +1,4 @@ name: odmltables -channels: - - free dependencies: - python=3.11 - setuptools @@ -10,3 +8,4 @@ dependencies: - pip - pip: - odml + - sphinx_rtd_theme From 9e388f64af496398ba4b89584cc6c96f5a1586ce Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:47:44 +0200 Subject: [PATCH 6/9] debugging readthedocs building --- doc/environment.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/environment.yml b/doc/environment.yml index ada2dae..ae74154 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -1,6 +1,6 @@ name: odmltables dependencies: - - python=3.11 + - python ==3.11 - setuptools - snowballstemmer - sphinx @@ -8,4 +8,3 @@ dependencies: - pip - pip: - odml - - sphinx_rtd_theme From a3e6edab9275800771b2c065d67abd1c94f759d8 Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:49:11 +0200 Subject: [PATCH 7/9] debugging readthedocs building --- doc/environment.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/environment.yml b/doc/environment.yml index ae74154..97ef149 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -1,6 +1,12 @@ name: odmltables dependencies: - python ==3.11 + - zlib + - libgcc-ng + - ncurses + - libuuid + - sqlite + - xz - setuptools - snowballstemmer - sphinx From b7ead717d2ab2adefbc5b0e395944a4c79209d2b Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 16:50:41 +0200 Subject: [PATCH 8/9] debugging readthedocs building --- doc/environment.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/environment.yml b/doc/environment.yml index 97ef149..1bdc1de 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -1,12 +1,10 @@ name: odmltables +channels: + - conda-forge + - free + - anaconda dependencies: - python ==3.11 - - zlib - - libgcc-ng - - ncurses - - libuuid - - sqlite - - xz - setuptools - snowballstemmer - sphinx From ae680367c28646dc8db0c3af028e1b75c5bda85b Mon Sep 17 00:00:00 2001 From: Julia Sprenger Date: Fri, 19 May 2023 20:32:40 +0200 Subject: [PATCH 9/9] add test to cover #124 --- src/odmltables/tests/test_odml_table.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/odmltables/tests/test_odml_table.py b/src/odmltables/tests/test_odml_table.py index f9c10c6..6cdabc2 100644 --- a/src/odmltables/tests/test_odml_table.py +++ b/src/odmltables/tests/test_odml_table.py @@ -371,6 +371,16 @@ def test_filter_errors(self): with self.assertRaises(ValueError): self.test_table.filter(mode='wrongmode', Property='Property') + def test_filter_single_value_comparison(self): + """ + test for single value comparison + """ + + search_value = self.test_table._odmldict[0]['Value'][0] + # searching for a single value + self.test_table.filter(Value=search_value) + self.assertEqual(1, len(self.test_table._odmldict)) + def test_filter_mode_and(self): """ testing mode='and' setting of filter function