From ab0bb40f8a9427ef3bb1e0893d60a60b6a621637 Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 1 Jun 2022 13:32:43 +0200 Subject: [PATCH 01/24] Improve code quality of unittests by adding docstrings. --- tests/test_create_id.py | 11 ++++- tests/test_publish.py | 41 +++++++++++++---- tests/test_save_plot.py | 19 +++++--- tests/test_tagplot.py | 78 ++++++++++++++++---------------- tests/test_tagplot_matplotlib.py | 50 +++++++++----------- 5 files changed, 113 insertions(+), 86 deletions(-) diff --git a/tests/test_create_id.py b/tests/test_create_id.py index 68a8a8d..d7c4b2e 100644 --- a/tests/test_create_id.py +++ b/tests/test_create_id.py @@ -1,25 +1,32 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Unittests for CreateID -''' +""" + import unittest from create_id import create_id class TestCreateID(unittest.TestCase): + """ + Class for all unittests of the create_id module. + """ def test_existence(self): + """Test if create_id returns a string.""" self.assertIsInstance(create_id(1), str) self.assertIsInstance(create_id(2), str) def test_errors(self): + """ Test if Errors are raised when id_method is wrong. """ with self.assertRaises(ValueError): create_id(3) with self.assertRaises(ValueError): create_id('h') def test_length(self): + """ Test if figure_id has the correct length. """ self.assertEqual(len(create_id(1)), 10) self.assertEqual(len(create_id(2)), 8) diff --git a/tests/test_publish.py b/tests/test_publish.py index a01e727..40a6096 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -1,20 +1,18 @@ # -*- coding: utf-8 -*- -''' -Unittests for Publish -''' +""" +Unittests for publish +""" import unittest import os import sys import shutil -import base64 -import matplotlib.pyplot as plt from unittest.mock import patch +import matplotlib.pyplot as plt from publish import publish SRC_DIR = 'test_src_folder' -IMG_DATA = b'iVBORw0KGgoAAAANSUhEUgAAAUAAAAFAAgMAAACw/k05AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAAxQTFRFAAAAHBwcVFRU////6irJIAAAAIVJREFUeNrt3TERACAQBLHTgQlMU6GQDkz8MF9kBcTCJmrY2IWtJPMWdoBAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAv+A5RMHtesBZRvjTSF8ofkAAAAASUVORK5CYII=' # noqa: E501 PIC_NAME = 'test_picture' DST_DIR = 'test_dst_folder' DST_PARENT_DIR = 'test_parent' @@ -24,27 +22,32 @@ fig = plt.figure() class TestPublish(unittest.TestCase): + """ + Class for all unittests of the publish module. + """ def setUp(self): + """ Generate source and destination directory and test image. """ os.makedirs(SRC_DIR, exist_ok=True) os.makedirs(DST_PARENT_DIR, exist_ok=True) - with open(PIC_NAME, "wb") as test_pic: - test_pic.write(base64.decodebytes(IMG_DATA)) # Skip test if tests are run from command line. @unittest.skipIf(not os.path.isfile(sys.argv[0]), 'Publish is not called ' 'from a Python script. Therefore, the script cannot be ' 'copied.') def test_publish(self): + """ Test publish and check if an exported picture file exists. """ publish(SRC_DIR, DST_PATH, fig, PIC_NAME, 'individual') assert os.path.isfile(os.path.join(DST_PATH, PIC_NAME + '.png')) def test_src_directory(self): + """ Test if Error is raised when source directory does not exist.""" with self.assertRaises(FileNotFoundError): publish('not_existing_folder', DST_PATH, fig, PIC_NAME, 'individual') def test_dst_directory(self): + """ Test if Error is raised when destination dir does not exist.""" with self.assertRaises(FileNotFoundError): publish(SRC_DIR, 'not_existing_folder', fig, PIC_NAME, 'individual') @@ -54,6 +57,10 @@ class TestPublish(unittest.TestCase): 'from a Python script. Therefore, the script cannot be ' 'copied.') def test_dst_already_exists_yes(self): + """ + Test if publish succeeds if the user wants to overwrite an existing + destination directory. + """ os.mkdir(DST_PATH) # Mock user input as 'yes' with patch('builtins.input', return_value='yes'): @@ -64,6 +71,10 @@ class TestPublish(unittest.TestCase): 'from a Python script. Therefore, the script cannot be ' 'copied.') def test_dst_already_exists_no(self): + """ + Test if publish exits with error if the user does not want to overwrite + an existing destination directory by user input 'no'. + """ os.mkdir(DST_PATH) # Mock user input as 'no' with patch('builtins.input', return_value='no'): @@ -75,6 +86,10 @@ class TestPublish(unittest.TestCase): 'from a Python script. Therefore, the script cannot be ' 'copied.') def test_dst_already_exists_empty(self): + """ + Test if publish exits with error if the user does not want to overwrite + an existing destination directory by missing user input. + """ os.mkdir(DST_PATH) # Mock user input as empty (no should be default). with patch('builtins.input', return_value=''): @@ -86,21 +101,29 @@ class TestPublish(unittest.TestCase): 'from a Python script. Therefore, the script cannot be ' 'copied.') def test_dst__invisible_already_exists(self): + """ + Test if publish succeeds when there is already an invisible + directory from a previous run (delete the folder and proceed). + """ os.mkdir(INVISIBLE_PATH) publish(SRC_DIR, DST_PATH, fig, PIC_NAME, 'individual') def test_picture(self): + """ Test if Error is raised if fig is not a valid figure object. """ with self.assertRaises(TypeError): publish(SRC_DIR, DST_PATH, 'fig', PIC_NAME, 'individual') def test_data_storage(self): + """ + Test if Error is raised when unsupported storage method was chosen. + """ with self.assertRaises(ValueError): publish(SRC_DIR, DST_PATH, fig, PIC_NAME, 'none_existing_method') def tearDown(self): + """ Delete all files created in setUp. """ shutil.rmtree(SRC_DIR) shutil.rmtree(DST_PARENT_DIR) - os.remove(PIC_NAME) if __name__ == '__main__': diff --git a/tests/test_save_plot.py b/tests/test_save_plot.py index 7678751..a015223 100644 --- a/tests/test_save_plot.py +++ b/tests/test_save_plot.py @@ -1,25 +1,30 @@ # -*- coding: utf-8 -*- -''' +""" Unittests for save_plot -''' +""" import os import unittest import matplotlib.pyplot as plt from save_plot import save_plot -figure = plt.figure() -plot_name = 'PLOT_NAME' +FIGURE = plt.figure() +PLOT_NAME = 'PLOT_NAME' -class TestSave_Plot(unittest.TestCase): +class TestSavePlot(unittest.TestCase): + """ + Class for all unittests of the save_plot module. + """ def test_save_plot(self): - save_plot(figure, plot_name, extension='jpg') - os.remove(plot_name + '.jpg') + """ Test if save_plot succeeds with valid arguments. """ + save_plot(FIGURE, PLOT_NAME, extension='jpg') + os.remove(PLOT_NAME + '.jpg') def test_wrong_fig_type(self): + """ Test if Error is raised when not a figure object is given. """ with self.assertRaises(TypeError): save_plot('figure', 'PLOT_NAME', extension='jpg') diff --git a/tests/test_tagplot.py b/tests/test_tagplot.py index 25c1ee2..d0e5af2 100644 --- a/tests/test_tagplot.py +++ b/tests/test_tagplot.py @@ -1,72 +1,72 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -''' +""" Unittests for tagplot -''' +""" + import unittest -import numpy as np import matplotlib.pyplot as plt from tagplot import tagplot - -# %% Create data -x = np.linspace(0, 10, 100) -y = np.random.rand(100) + 2 -y_2 = np.sin(x) + 2 - -# %% Create figure -color1 = 'black' -color2 = 'yellow' - -# 1.Figure -fig1 = plt.figure() -plt.plot(x, y, color=color1) -plt.plot(x, y_2, color=color2) - -# 2.Figure -fig2 = plt.figure() -plt.plot(x, y, color=color2) -plt.plot(x, y_2, color=color1) - -fig = [fig1, fig2] - # Constants for tests -ProjectID = "MR01" -plot_engine = "matplotlib" -method = 1 +FIG1 = plt.figure() +FIG2 = plt.figure() +FIGS_AS_LIST = [FIG1, FIG2] + +PROJECT_ID = "MR01" +PLOT_ENGINE = "matplotlib" +METHOD = 1 -class Test_tagplot(unittest.TestCase): +class TestTagplot(unittest.TestCase): + """ + Class for all unittests of the tagplot module. + """ def test_figures(self): + """ + Test if Errors are raised when the provided figure is not given + as list. + """ with self.assertRaises(TypeError): - tagplot('fig', ProjectID, plot_engine, method) + tagplot('fig', PLOT_ENGINE, PROJECT_ID, METHOD) with self.assertRaises(TypeError): - tagplot(fig1, plot_engine, prefix=ProjectID) + tagplot(FIG1, PLOT_ENGINE, prefix=PROJECT_ID) def test_prefix(self): + """ Test if Error is raised if prefix is not a string. """ with self.assertRaises(TypeError): - tagplot(fig, plot_engine, 3, method) + tagplot(FIGS_AS_LIST, PLOT_ENGINE, 3, METHOD) def test_plotengine(self): + """ + Test if Errors are raised if the provided plot engine is not supported. + """ with self.assertRaises(ValueError): - tagplot(fig, 1, ProjectID, method) + tagplot(FIGS_AS_LIST, 1, PROJECT_ID, METHOD) with self.assertRaises(ValueError): - tagplot(fig, 'xyz', ProjectID, method) + tagplot(FIGS_AS_LIST, 'xyz', PROJECT_ID, METHOD) def test_idmethod(self): + """ + Test if Errors are raised if the id_method is not an integer. + """ with self.assertRaises(TypeError): - tagplot(fig, plot_engine, ProjectID, method='(0,1)') + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method='(0,1)') with self.assertRaises(TypeError): - tagplot(fig, plot_engine, ProjectID, method='h') + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method='h') with self.assertRaises(TypeError): - tagplot(fig, plot_engine, ProjectID, method='[0,1]') + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method='[0,1]') def test_location(self): + """ + Test if Errors are raised if the provided location is not supported. + """ with self.assertRaises(TypeError): - tagplot(fig, plot_engine, ProjectID, method, location=1) + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, METHOD, location=1) with self.assertWarns(Warning): - tagplot(fig, plot_engine, ProjectID, method, location='up') + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, METHOD, + location='up') if __name__ == '__main__': diff --git a/tests/test_tagplot_matplotlib.py b/tests/test_tagplot_matplotlib.py index a73c955..c190231 100644 --- a/tests/test_tagplot_matplotlib.py +++ b/tests/test_tagplot_matplotlib.py @@ -6,53 +6,45 @@ Unittests for TagPlot_matplotlib import unittest from tagplot_matplotlib import tagplot_matplotlib -import numpy as np import matplotlib.pyplot as plt from matplotlib.figure import Figure -from tagplot import PlotOptions +from plotoptions import PlotOptions -# %% Create data -x = np.linspace(0, 10, 100) -y = np.random.rand(100) + 2 -y_2 = np.sin(x) + 2 -# %% Create figure -color1 = 'black' -color2 = 'yellow' - -# 1.Figure -fig1 = plt.figure() -plt.plot(x, y, color=color1) -plt.plot(x, y_2, color=color2) - -# 2.Figure -fig2 = plt.figure() -plt.plot(x, y, color=color2) -plt.plot(x, y_2, color=color1) - -fig = [fig1, fig2] +FIG1 = plt.figure() +FIG2 = plt.figure() +FIGS_AS_LIST = [FIG1, FIG2] # Constants for tests -ProjectID = "MR01" -method = 1 -rotation = 90 -position = (0.975, 0.35) +PROJECT_ID = "MR01" +METHOD = 1 +ROTATION = 90 +POSITION = (0.975, 0.35) -class Test_tagplot_matplotlib(unittest.TestCase): +class TestTagplotMatplotlib(unittest.TestCase): + """ + Class for all unittests of the tagplot_matplotlib module. + """ def test_mplfigures(self): - options = PlotOptions(fig, ProjectID, method, rotation, position) - [figs, ID] = tagplot_matplotlib(options) + """ Test of returned objects. Check if they are matplotlib figures. """ + options = PlotOptions(FIGS_AS_LIST, PROJECT_ID, METHOD, ROTATION, + POSITION) + [figs, _] = tagplot_matplotlib(options) self.assertIsInstance(figs[0], Figure) self.assertIsInstance(figs[1], Figure) def test_mplerror(self): - options = PlotOptions(3, ProjectID, method, rotation, position) + """ Test if Error is raised if wrong type of figures is given. """ + options = PlotOptions(3, PROJECT_ID, METHOD, ROTATION, POSITION) with self.assertRaises(TypeError): tagplot_matplotlib(options) def test_mpl_plotoptions(self): + """ + Test if Error is raised if not an instance of PlotOptions is passed. + """ with self.assertRaises(TypeError): tagplot_matplotlib('wrong_object') -- GitLab From a4b89e4b7f75ec0b852a22e8550683d9c7de82bc Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 1 Jun 2022 13:51:55 +0200 Subject: [PATCH 02/24] Further polish code. Adjust pylint failure to below 9 and do not allow the pipeline to fail anymore. --- .gitlab-ci.yml | 4 ++-- create_id.py | 12 ++++++------ HDF5_externalLink.py => hdf5_external_link.py | 0 tagplot_matplotlib.py | 12 ++++++------ tests/test_tagplot_matplotlib.py | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) rename HDF5_externalLink.py => hdf5_external_link.py (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1147c71..75c602c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,8 +47,8 @@ PEP8: Pylint: stage: linting - allow_failure: true - script: find . -type f -name '*.py' | xargs pylint -rn --fail-under=7 # Find all python files and check the code with pylint. + # allow_failure: true + script: find . -type f -name '*.py' | xargs pylint -rn --fail-under=9 # Find all python files and check the code with pylint. test: stage: testing diff --git a/create_id.py b/create_id.py index 84f2b83..ff759e3 100644 --- a/create_id.py +++ b/create_id.py @@ -18,19 +18,19 @@ def create_id(id_method): Returns ------- - ID + figure_id """ if id_method == 1: - ID = time.time() # UNIX Time - ID = hex(int(ID)) # convert time to hexadecimal + figure_id = time.time() # UNIX Time + figure_id = hex(int(figure_id)) # convert time to hexadecimal time.sleep(0.5) # break for avoiding duplicate IDs elif id_method == 2: - ID = str(uuid.uuid4()) # creates a random UUID - ID = ID[0:8] # only use first 8 numbers + figure_id = str(uuid.uuid4()) # creates a random UUID + figure_id = figure_id[0:8] # only use first 8 numbers else: raise ValueError( f'Your chosen ID method "{id_method}" is not supported.\n' 'At the moment these methods are available:\n' '"1": Unix time converted to hexadecimal\n' '"2": Random UUID') - return ID + return figure_id diff --git a/HDF5_externalLink.py b/hdf5_external_link.py similarity index 100% rename from HDF5_externalLink.py rename to hdf5_external_link.py diff --git a/tagplot_matplotlib.py b/tagplot_matplotlib.py index a94e2b4..b558b3c 100644 --- a/tagplot_matplotlib.py +++ b/tagplot_matplotlib.py @@ -36,18 +36,18 @@ def tagplot_matplotlib(plotid_object): fontsize = 'small' color = 'grey' - IDs = [] + all_ids_as_list = [] # Loop to create and position the IDs for fig in plotid_object.figs: - ID = create_id.create_id(plotid_object.id_method) - ID = plotid_object.prefix + str(ID) - IDs.append(ID) + figure_id = create_id.create_id(plotid_object.id_method) + figure_id = plotid_object.prefix + str(figure_id) + all_ids_as_list.append(figure_id) plt.figure(fig.number) plt.figtext(x=plotid_object.position[0], y=plotid_object.position[1], - s=ID, ha='left', wrap=True, + s=figure_id, ha='left', wrap=True, rotation=plotid_object.rotation, fontsize=fontsize, color=color) fig.tight_layout() - return [plotid_object.figs, IDs] + return [plotid_object.figs, all_ids_as_list] diff --git a/tests/test_tagplot_matplotlib.py b/tests/test_tagplot_matplotlib.py index c190231..50040d4 100644 --- a/tests/test_tagplot_matplotlib.py +++ b/tests/test_tagplot_matplotlib.py @@ -5,9 +5,9 @@ Unittests for TagPlot_matplotlib """ import unittest -from tagplot_matplotlib import tagplot_matplotlib import matplotlib.pyplot as plt from matplotlib.figure import Figure +from tagplot_matplotlib import tagplot_matplotlib from plotoptions import PlotOptions -- GitLab From 198d707df80662c8a083f2e0333571413a7bbe45 Mon Sep 17 00:00:00 2001 From: nugget Date: Mon, 13 Jun 2022 15:31:19 +0200 Subject: [PATCH 03/24] Move input validation into PlotOption class. --- plotoptions.py | 41 ++++++++++++++++++++++++++++++++++++++++- tagplot.py | 18 +----------------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/plotoptions.py b/plotoptions.py index 52699fb..53ffe2a 100644 --- a/plotoptions.py +++ b/plotoptions.py @@ -9,7 +9,12 @@ class PlotOptions: Methods ------- - __init__figs : figure object + __init__ + validate_input: Check if input is correct type. + + Attributes + ---------- + figs : figure object Figure that will be tagged. prefix : str Prefix that is placed before the ID. @@ -28,3 +33,37 @@ class PlotOptions: self.id_method = id_method self.rotation = rotation self.position = position + + def validate_input(self): + """ + Validate if input for PlotOptions is correct type. + + Raises + ------ + TypeError + TypeError is thrown if one of the attributes is not the correct + type. + + Returns + ------- + 0, if all checks succeeded. + + """ + # %% Validate inputs + if isinstance(self.prefix, str): + pass + else: + raise TypeError("Prefix is not a string.") + + if isinstance(self.figs, list): + pass + else: + raise TypeError("Figures are not a list.") + + # TODO: Change id_method key from integer to (more meaningful) string. + try: + self.id_method = int(self.id_method) + except ValueError: + raise TypeError('The chosen ID id_method is not an integer.') + + return 0 diff --git a/tagplot.py b/tagplot.py index ff08960..e075dc6 100644 --- a/tagplot.py +++ b/tagplot.py @@ -48,23 +48,6 @@ def tagplot(figs, engine, prefix='', id_method=1, location='east'): figures were given. The first list contains the tagged figures. The second list contains the corresponding IDs as strings. """ - # %% Validate inputs - if isinstance(prefix, str): - pass - else: - raise TypeError("Prefix is not a string.") - - if isinstance(figs, list): - pass - else: - raise TypeError("Figures are not a list.") - - # TODO: Change id_method key from integer to (more meaningful) string. - try: - id_method = int(id_method) - except ValueError: - raise TypeError('The chosen ID id_method is not an integer.') - if isinstance(location, str): pass else: @@ -99,6 +82,7 @@ def tagplot(figs, engine, prefix='', id_method=1, location='east'): option_container = PlotOptions(figs, prefix, id_method, rotation, position) + option_container.validate_input() match engine: case 'matplotlib' | 'pyplot': -- GitLab From 5a5bf77bceaa1ce87f71861e36f1bad4fb2c6a82 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 17 May 2022 15:30:53 +0200 Subject: [PATCH 04/24] First packaging try. --- pyproject.toml | 3 + setup.cfg | 24 ++++++ src/plotid/HDF5_externalLink.py | 11 +++ src/plotid/TagPlot.py | 92 +++++++++++++++++++++ src/plotid/TagPlot_matplotlib.py | 43 ++++++++++ src/plotid/__init__.py | 1 + create_id.py => src/plotid/create_id.py | 0 example.py => src/plotid/example.py | 0 filecompare.py => src/plotid/filecompare.py | 0 publish.py => src/plotid/publish.py | 0 save_plot.py => src/plotid/save_plot.py | 0 runner_tests.py => tests/runner_tests.py | 1 + 12 files changed, 175 insertions(+) create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 src/plotid/HDF5_externalLink.py create mode 100644 src/plotid/TagPlot.py create mode 100644 src/plotid/TagPlot_matplotlib.py create mode 100644 src/plotid/__init__.py rename create_id.py => src/plotid/create_id.py (100%) rename example.py => src/plotid/example.py (100%) rename filecompare.py => src/plotid/filecompare.py (100%) rename publish.py => src/plotid/publish.py (100%) rename save_plot.py => src/plotid/save_plot.py (100%) rename runner_tests.py => tests/runner_tests.py (96%) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d7e8400 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=42"] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..774fe72 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,24 @@ +[metadata] +name = example-package-Cory-Doctorov-Dr +version = 0.0.1 +author = Example Author +author_email = author@example.com +description = A small example package +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/pypa/sampleproject +project_urls = + Bug Tracker = https://github.com/pypa/sampleproject/issues +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: Apache Software License + Operating System :: OS Independent + +[options] +package_dir = + = src +packages = find: +python_requires = >=3.10 + +[options.packages.find] +where = src diff --git a/src/plotid/HDF5_externalLink.py b/src/plotid/HDF5_externalLink.py new file mode 100644 index 0000000..09b96fa --- /dev/null +++ b/src/plotid/HDF5_externalLink.py @@ -0,0 +1,11 @@ +"""Handling of hdf5 data files.""" + +import h5py + +# Shows how to create an externalLink (symbolic) to a hdf5 File +# Documentation available at: +# https://docs.h5py.org/en/stable/high/group.html#external-links +myfile = h5py.File('./example.h5', 'w') +myfile['ext link'] = h5py.ExternalLink("testdata_2.h5", "/") + +myfile.close() diff --git a/src/plotid/TagPlot.py b/src/plotid/TagPlot.py new file mode 100644 index 0000000..e075dc6 --- /dev/null +++ b/src/plotid/TagPlot.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Tag your plot with an ID. + +For publishing the tagged plot along your research data have a look at the +module publish. + +Functions: + TagPlot(figure object, string) -> list +""" + +import warnings +from plotoptions import PlotOptions +from tagplot_matplotlib import tagplot_matplotlib + + +def tagplot(figs, engine, prefix='', id_method=1, location='east'): + """ + Tag your figure/plot with an ID. + + After determining the plot engine, TagPlot calls the corresponding + function which tags the plot. + + Parameters + ---------- + figs : list + Figures that should be tagged. + engine : string + Plot engine which should be used to tag the plot. + prefix : string + Will be added as prefix to the ID. + id_method : int, optional + id_method for creating the ID. Create an ID by Unix time is referenced + as 1, create a random ID with id_method=2. The default is 1. + location : string, optional + Location for ID to be displayed on the plot. Default is 'east'. + + Raises + ------ + RuntimeWarning + DESCRIPTION. + + Returns + ------- + list + The resulting list contains two lists each with as many entries as + figures were given. The first list contains the tagged figures. + The second list contains the corresponding IDs as strings. + """ + if isinstance(location, str): + pass + else: + raise TypeError("Location is not a string.") + + match location: + case 'north': + rotation = 0 + position = (0.35, 0.975) + case 'east': + rotation = 90 + position = (0.975, 0.35) + case 'south': + rotation = 0 + position = (0.35, 0.015) + case 'west': + rotation = 90 + position = (0.025, 0.35) + case 'southeast': + rotation = 0 + position = (0.75, 0.015) + case 'custom': + # TODO: Get rotation and position from user input & check if valid + rotation = 0 + position = (0.5, 0.5) + case _: + warnings.warn(f'Location "{location}" is not a defined ' + 'location, TagPlot uses location "east" ' + 'instead.') + rotation = 90 + position = (0.975, 0.35) + + option_container = PlotOptions(figs, prefix, id_method, + rotation, position) + option_container.validate_input() + + match engine: + case 'matplotlib' | 'pyplot': + return tagplot_matplotlib(option_container) + case _: + raise ValueError( + f'The plot engine "{engine}" is not supported.') diff --git a/src/plotid/TagPlot_matplotlib.py b/src/plotid/TagPlot_matplotlib.py new file mode 100644 index 0000000..364522e --- /dev/null +++ b/src/plotid/TagPlot_matplotlib.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +# from fcn_help.FST_colors import Colors +import matplotlib +import matplotlib.pyplot as plt +import create_id +# plt.style.use('./fcn_help/FST.mplstyle') + + +def TagPlot_matplotlib(figs, prefix, method, rotation, position): + """ + Add IDs to figures with matplotlib. + + The ID is placed visual on the figure window and + as Tag (Property of figure). + TagPlot can tag multiple figures at once + """ + # Check if figs is a valid figure or a list of valid figures + if isinstance(figs, matplotlib.figure.Figure): + pass + elif isinstance(figs, list): + for figure in figs: + if isinstance(figure, matplotlib.figure.Figure): + pass + else: + raise TypeError('Figure is not a valid matplotlib-figure.') + + fontsize = 'small' + color = 'grey' + IDs = [] + + # Loop to create and position the IDs + for fig in figs: + + ID = create_id.create_id(method) + ID = prefix + str(ID) + IDs.append(ID) + + plt.figure(fig.number) + plt.figtext(x=position[0], y=position[1], s=ID, ha='left', wrap=True, + rotation=rotation, fontsize=fontsize, color=color) + fig.tight_layout() + return [figs, IDs] diff --git a/src/plotid/__init__.py b/src/plotid/__init__.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/src/plotid/__init__.py @@ -0,0 +1 @@ + diff --git a/create_id.py b/src/plotid/create_id.py similarity index 100% rename from create_id.py rename to src/plotid/create_id.py diff --git a/example.py b/src/plotid/example.py similarity index 100% rename from example.py rename to src/plotid/example.py diff --git a/filecompare.py b/src/plotid/filecompare.py similarity index 100% rename from filecompare.py rename to src/plotid/filecompare.py diff --git a/publish.py b/src/plotid/publish.py similarity index 100% rename from publish.py rename to src/plotid/publish.py diff --git a/save_plot.py b/src/plotid/save_plot.py similarity index 100% rename from save_plot.py rename to src/plotid/save_plot.py diff --git a/runner_tests.py b/tests/runner_tests.py similarity index 96% rename from runner_tests.py rename to tests/runner_tests.py index cb159c4..48b9db8 100644 --- a/runner_tests.py +++ b/tests/runner_tests.py @@ -8,6 +8,7 @@ Includes starting all tests and measuring the code coverage. import sys import unittest import coverage +from sys import exit cov = coverage.Coverage() cov.start() -- GitLab From 04c851a7d5ca8fb7754725ea802d4b54333360c4 Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 18 May 2022 10:17:25 +0200 Subject: [PATCH 05/24] Fix tests and coverage for new project structure. --- .coveragerc | 4 +++ .gitlab-ci.yml | 2 +- src/plotid/example.py | 2 +- tests/__init__.py | 1 + tests/runner_tests.py | 9 ++++-- tests/test_TagPlot_matplotlib.py | 54 ++++++++++++++++++++++++++++++++ tests/test_create_id.py | 14 ++++----- tests/test_publish.py | 3 +- tests/test_save_plot.py | 2 +- 9 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 .coveragerc create mode 100644 tests/__init__.py create mode 100644 tests/test_TagPlot_matplotlib.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..096ae14 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,4 @@ +[run] +omit = + *example.py + */usr/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 75c602c..7a57b4a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -56,7 +56,7 @@ test: - docker script: # - python -m unittest discover -s ./tests/ -p "test*" # deprecated unittest command - - python runner_tests.py + - python tests/runner_tests.py # - pip install tox flake8 # you can also use tox # - tox -e py36,flake8 diff --git a/src/plotid/example.py b/src/plotid/example.py index b6302f7..0cf85f4 100644 --- a/src/plotid/example.py +++ b/src/plotid/example.py @@ -57,5 +57,5 @@ for i, figure in enumerate(figs): figure.savefig(name) # %% Publish -publish('tests', '/home/chief/Dokumente/fst/plotid_python/data', +publish('../../tests', '/home/chief/Dokumente/fst/plotid_python/data', fig1, 'Bild', 'individual') diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/runner_tests.py b/tests/runner_tests.py index 48b9db8..20beec9 100644 --- a/tests/runner_tests.py +++ b/tests/runner_tests.py @@ -8,16 +8,19 @@ Includes starting all tests and measuring the code coverage. import sys import unittest import coverage -from sys import exit +import os + +path = os.path.abspath('src/plotid') +sys.path.append(path) cov = coverage.Coverage() cov.start() loader = unittest.TestLoader() -tests = loader.discover('tests') +tests = loader.discover('.') testRunner = unittest.runner.TextTestRunner(verbosity=2) - result = testRunner.run(tests) + cov.stop() cov.save() cov.report(show_missing=True) diff --git a/tests/test_TagPlot_matplotlib.py b/tests/test_TagPlot_matplotlib.py new file mode 100644 index 0000000..3e53cf6 --- /dev/null +++ b/tests/test_TagPlot_matplotlib.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +''' +Unittests for TagPlot_matplotlib +''' +import unittest +from src.plotid.TagPlot_matplotlib import TagPlot_matplotlib +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.figure import Figure + +# %% Create data +x = np.linspace(0, 10, 100) +y = np.random.rand(100) + 2 +y_2 = np.sin(x) + 2 + +# %% Create figure +color1 = 'black' +color2 = 'yellow' + +# 1.Figure +fig1 = plt.figure() +plt.plot(x, y, color=color1) +plt.plot(x, y_2, color=color2) +plt.clf # Close figure + +# 2.Figure +fig2 = plt.figure() +plt.plot(x, y, color=color2) +plt.plot(x, y_2, color=color1) +plt.clf # Close figure + +fig = [fig1, fig2] + +# Constants for tests +ProjectID = "MR01" +method = 1 +rotation = 90 +position = (0.975, 0.35) + + +class TestTagPlot_matplotlib(unittest.TestCase): + + def test_mplfigures(self): + [figs, ID] = TagPlot_matplotlib( + fig, ProjectID, method, rotation, position) + self.assertIsInstance(figs[0], Figure) + self.assertIsInstance(figs[1], Figure) + with self.assertRaises(TypeError): + TagPlot_matplotlib(3, ProjectID, method, rotation, position) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_create_id.py b/tests/test_create_id.py index d7c4b2e..d456062 100644 --- a/tests/test_create_id.py +++ b/tests/test_create_id.py @@ -5,7 +5,7 @@ Unittests for CreateID """ import unittest -from create_id import create_id +import src.plotid.create_id as cid class TestCreateID(unittest.TestCase): @@ -15,20 +15,20 @@ class TestCreateID(unittest.TestCase): def test_existence(self): """Test if create_id returns a string.""" - self.assertIsInstance(create_id(1), str) - self.assertIsInstance(create_id(2), str) + self.assertIsInstance(cid.create_id(1), str) + self.assertIsInstance(cid.create_id(2), str) def test_errors(self): """ Test if Errors are raised when id_method is wrong. """ with self.assertRaises(ValueError): - create_id(3) + cid.create_id(3) with self.assertRaises(ValueError): - create_id('h') + cid.create_id('h') def test_length(self): """ Test if figure_id has the correct length. """ - self.assertEqual(len(create_id(1)), 10) - self.assertEqual(len(create_id(2)), 8) + self.assertEqual(len(cid.create_id(1)), 10) + self.assertEqual(len(cid.create_id(2)), 8) if __name__ == '__main__': diff --git a/tests/test_publish.py b/tests/test_publish.py index 40a6096..86c3192 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -10,7 +10,8 @@ import sys import shutil from unittest.mock import patch import matplotlib.pyplot as plt -from publish import publish +from src.plotid.publish import publish + SRC_DIR = 'test_src_folder' PIC_NAME = 'test_picture' diff --git a/tests/test_save_plot.py b/tests/test_save_plot.py index a015223..14b8dee 100644 --- a/tests/test_save_plot.py +++ b/tests/test_save_plot.py @@ -7,7 +7,7 @@ Unittests for save_plot import os import unittest import matplotlib.pyplot as plt -from save_plot import save_plot +from src.plotid.save_plot import save_plot FIGURE = plt.figure() PLOT_NAME = 'PLOT_NAME' -- GitLab From dfa24d1cd1dfea1c47afe0a94bf51377574e12fa Mon Sep 17 00:00:00 2001 From: nugget Date: Mon, 23 May 2022 10:13:14 +0200 Subject: [PATCH 06/24] Fix empty line in __init__.py. --- src/plotid/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plotid/__init__.py b/src/plotid/__init__.py index 8d1c8b6..8b13789 100644 --- a/src/plotid/__init__.py +++ b/src/plotid/__init__.py @@ -1 +1 @@ - + -- GitLab From a1f62077eac03502d367a7c3b3b22ffafa6a7760 Mon Sep 17 00:00:00 2001 From: nugget Date: Mon, 23 May 2022 10:20:26 +0200 Subject: [PATCH 07/24] Add comments in example.py and rename package in setup. --- setup.cfg | 2 +- src/plotid/example.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 774fe72..2102a30 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = example-package-Cory-Doctorov-Dr +name = example-package-plotid-test version = 0.0.1 author = Example Author author_email = author@example.com diff --git a/src/plotid/example.py b/src/plotid/example.py index 0cf85f4..f8156f2 100644 --- a/src/plotid/example.py +++ b/src/plotid/example.py @@ -57,5 +57,7 @@ for i, figure in enumerate(figs): figure.savefig(name) # %% Publish +# Arguments: Source directory, destination directory, figure, plot (which is +# already saved as picture, publish-mode). publish('../../tests', '/home/chief/Dokumente/fst/plotid_python/data', fig1, 'Bild', 'individual') -- GitLab From e5d98f18ce924ab55934fca6774b6dcaf82c9d20 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 14 Jun 2022 12:32:06 +0200 Subject: [PATCH 08/24] Rebuild packaging structure. --- src/plotid/HDF5_externalLink.py | 11 --- src/plotid/TagPlot.py | 92 ------------------- src/plotid/TagPlot_matplotlib.py | 43 --------- .../plotid/hdf5_external_link.py | 0 plotoptions.py => src/plotid/plotoptions.py | 0 tagplot.py => src/plotid/tagplot.py | 0 .../plotid/tagplot_matplotlib.py | 0 tests/test_TagPlot_matplotlib.py | 54 ----------- 8 files changed, 200 deletions(-) delete mode 100644 src/plotid/HDF5_externalLink.py delete mode 100644 src/plotid/TagPlot.py delete mode 100644 src/plotid/TagPlot_matplotlib.py rename hdf5_external_link.py => src/plotid/hdf5_external_link.py (100%) rename plotoptions.py => src/plotid/plotoptions.py (100%) rename tagplot.py => src/plotid/tagplot.py (100%) rename tagplot_matplotlib.py => src/plotid/tagplot_matplotlib.py (100%) delete mode 100644 tests/test_TagPlot_matplotlib.py diff --git a/src/plotid/HDF5_externalLink.py b/src/plotid/HDF5_externalLink.py deleted file mode 100644 index 09b96fa..0000000 --- a/src/plotid/HDF5_externalLink.py +++ /dev/null @@ -1,11 +0,0 @@ -"""Handling of hdf5 data files.""" - -import h5py - -# Shows how to create an externalLink (symbolic) to a hdf5 File -# Documentation available at: -# https://docs.h5py.org/en/stable/high/group.html#external-links -myfile = h5py.File('./example.h5', 'w') -myfile['ext link'] = h5py.ExternalLink("testdata_2.h5", "/") - -myfile.close() diff --git a/src/plotid/TagPlot.py b/src/plotid/TagPlot.py deleted file mode 100644 index e075dc6..0000000 --- a/src/plotid/TagPlot.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Tag your plot with an ID. - -For publishing the tagged plot along your research data have a look at the -module publish. - -Functions: - TagPlot(figure object, string) -> list -""" - -import warnings -from plotoptions import PlotOptions -from tagplot_matplotlib import tagplot_matplotlib - - -def tagplot(figs, engine, prefix='', id_method=1, location='east'): - """ - Tag your figure/plot with an ID. - - After determining the plot engine, TagPlot calls the corresponding - function which tags the plot. - - Parameters - ---------- - figs : list - Figures that should be tagged. - engine : string - Plot engine which should be used to tag the plot. - prefix : string - Will be added as prefix to the ID. - id_method : int, optional - id_method for creating the ID. Create an ID by Unix time is referenced - as 1, create a random ID with id_method=2. The default is 1. - location : string, optional - Location for ID to be displayed on the plot. Default is 'east'. - - Raises - ------ - RuntimeWarning - DESCRIPTION. - - Returns - ------- - list - The resulting list contains two lists each with as many entries as - figures were given. The first list contains the tagged figures. - The second list contains the corresponding IDs as strings. - """ - if isinstance(location, str): - pass - else: - raise TypeError("Location is not a string.") - - match location: - case 'north': - rotation = 0 - position = (0.35, 0.975) - case 'east': - rotation = 90 - position = (0.975, 0.35) - case 'south': - rotation = 0 - position = (0.35, 0.015) - case 'west': - rotation = 90 - position = (0.025, 0.35) - case 'southeast': - rotation = 0 - position = (0.75, 0.015) - case 'custom': - # TODO: Get rotation and position from user input & check if valid - rotation = 0 - position = (0.5, 0.5) - case _: - warnings.warn(f'Location "{location}" is not a defined ' - 'location, TagPlot uses location "east" ' - 'instead.') - rotation = 90 - position = (0.975, 0.35) - - option_container = PlotOptions(figs, prefix, id_method, - rotation, position) - option_container.validate_input() - - match engine: - case 'matplotlib' | 'pyplot': - return tagplot_matplotlib(option_container) - case _: - raise ValueError( - f'The plot engine "{engine}" is not supported.') diff --git a/src/plotid/TagPlot_matplotlib.py b/src/plotid/TagPlot_matplotlib.py deleted file mode 100644 index 364522e..0000000 --- a/src/plotid/TagPlot_matplotlib.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- - -# from fcn_help.FST_colors import Colors -import matplotlib -import matplotlib.pyplot as plt -import create_id -# plt.style.use('./fcn_help/FST.mplstyle') - - -def TagPlot_matplotlib(figs, prefix, method, rotation, position): - """ - Add IDs to figures with matplotlib. - - The ID is placed visual on the figure window and - as Tag (Property of figure). - TagPlot can tag multiple figures at once - """ - # Check if figs is a valid figure or a list of valid figures - if isinstance(figs, matplotlib.figure.Figure): - pass - elif isinstance(figs, list): - for figure in figs: - if isinstance(figure, matplotlib.figure.Figure): - pass - else: - raise TypeError('Figure is not a valid matplotlib-figure.') - - fontsize = 'small' - color = 'grey' - IDs = [] - - # Loop to create and position the IDs - for fig in figs: - - ID = create_id.create_id(method) - ID = prefix + str(ID) - IDs.append(ID) - - plt.figure(fig.number) - plt.figtext(x=position[0], y=position[1], s=ID, ha='left', wrap=True, - rotation=rotation, fontsize=fontsize, color=color) - fig.tight_layout() - return [figs, IDs] diff --git a/hdf5_external_link.py b/src/plotid/hdf5_external_link.py similarity index 100% rename from hdf5_external_link.py rename to src/plotid/hdf5_external_link.py diff --git a/plotoptions.py b/src/plotid/plotoptions.py similarity index 100% rename from plotoptions.py rename to src/plotid/plotoptions.py diff --git a/tagplot.py b/src/plotid/tagplot.py similarity index 100% rename from tagplot.py rename to src/plotid/tagplot.py diff --git a/tagplot_matplotlib.py b/src/plotid/tagplot_matplotlib.py similarity index 100% rename from tagplot_matplotlib.py rename to src/plotid/tagplot_matplotlib.py diff --git a/tests/test_TagPlot_matplotlib.py b/tests/test_TagPlot_matplotlib.py deleted file mode 100644 index 3e53cf6..0000000 --- a/tests/test_TagPlot_matplotlib.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -''' -Unittests for TagPlot_matplotlib -''' -import unittest -from src.plotid.TagPlot_matplotlib import TagPlot_matplotlib -import numpy as np -import matplotlib.pyplot as plt -from matplotlib.figure import Figure - -# %% Create data -x = np.linspace(0, 10, 100) -y = np.random.rand(100) + 2 -y_2 = np.sin(x) + 2 - -# %% Create figure -color1 = 'black' -color2 = 'yellow' - -# 1.Figure -fig1 = plt.figure() -plt.plot(x, y, color=color1) -plt.plot(x, y_2, color=color2) -plt.clf # Close figure - -# 2.Figure -fig2 = plt.figure() -plt.plot(x, y, color=color2) -plt.plot(x, y_2, color=color1) -plt.clf # Close figure - -fig = [fig1, fig2] - -# Constants for tests -ProjectID = "MR01" -method = 1 -rotation = 90 -position = (0.975, 0.35) - - -class TestTagPlot_matplotlib(unittest.TestCase): - - def test_mplfigures(self): - [figs, ID] = TagPlot_matplotlib( - fig, ProjectID, method, rotation, position) - self.assertIsInstance(figs[0], Figure) - self.assertIsInstance(figs[1], Figure) - with self.assertRaises(TypeError): - TagPlot_matplotlib(3, ProjectID, method, rotation, position) - - -if __name__ == '__main__': - unittest.main() -- GitLab From c31e046ba462c2cae53231758ffe930fa2e79fc6 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 14 Jun 2022 13:09:13 +0200 Subject: [PATCH 09/24] Adjust runner so that pylint finds modules. --- .gitlab-ci.yml | 2 +- src/plotid/__init__.py | 1 - tests/__init__.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7a57b4a..5ef0029 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,7 +48,7 @@ PEP8: Pylint: stage: linting # allow_failure: true - script: find . -type f -name '*.py' | xargs pylint -rn --fail-under=9 # Find all python files and check the code with pylint. + script: find src/plotid/ tests/ -type f -name '*.py' | xargs pylint -rn --fail-under=9 # Find all python files and check the code with pylint. test: stage: testing diff --git a/src/plotid/__init__.py b/src/plotid/__init__.py index 8b13789..e69de29 100644 --- a/src/plotid/__init__.py +++ b/src/plotid/__init__.py @@ -1 +0,0 @@ - diff --git a/tests/__init__.py b/tests/__init__.py index 8d1c8b6..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +0,0 @@ - -- GitLab From 022474de634d5b39e3f40c2582bcc0f29e23615d Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 14 Jun 2022 13:54:55 +0200 Subject: [PATCH 10/24] Fix pylint. --- .pylintrc | 2 ++ src/plotid/.pylintrc | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 .pylintrc create mode 100644 src/plotid/.pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..0b39a7b --- /dev/null +++ b/.pylintrc @@ -0,0 +1,2 @@ +[MASTER] +init-hook='import sys; sys.path.append("./src/plotid")' diff --git a/src/plotid/.pylintrc b/src/plotid/.pylintrc new file mode 100644 index 0000000..0b39a7b --- /dev/null +++ b/src/plotid/.pylintrc @@ -0,0 +1,2 @@ +[MASTER] +init-hook='import sys; sys.path.append("./src/plotid")' -- GitLab From 46e7cd3173634744e1aaf4bcba733ce389e6f068 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 14 Jun 2022 17:15:11 +0200 Subject: [PATCH 11/24] Code cleanup. Improve example.py with more and clearer comments. --- .gitlab-ci.yml | 2 +- src/plotid/create_id.py | 27 +++++++------- src/plotid/example.py | 61 +++++++++++++++----------------- src/plotid/plotoptions.py | 13 +++---- src/plotid/publish.py | 8 ++--- src/plotid/tagplot.py | 2 +- src/plotid/tagplot_matplotlib.py | 2 +- tests/runner_tests.py | 2 +- tests/test_create_id.py | 8 ++--- tests/test_publish.py | 5 --- tests/test_tagplot.py | 27 +++++--------- tests/test_tagplot_matplotlib.py | 11 +++++- 12 files changed, 75 insertions(+), 93 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5ef0029..7a57b4a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,7 +48,7 @@ PEP8: Pylint: stage: linting # allow_failure: true - script: find src/plotid/ tests/ -type f -name '*.py' | xargs pylint -rn --fail-under=9 # Find all python files and check the code with pylint. + script: find . -type f -name '*.py' | xargs pylint -rn --fail-under=9 # Find all python files and check the code with pylint. test: stage: testing diff --git a/src/plotid/create_id.py b/src/plotid/create_id.py index ff759e3..fa7febc 100644 --- a/src/plotid/create_id.py +++ b/src/plotid/create_id.py @@ -20,17 +20,18 @@ def create_id(id_method): ------- figure_id """ - if id_method == 1: - figure_id = time.time() # UNIX Time - figure_id = hex(int(figure_id)) # convert time to hexadecimal - time.sleep(0.5) # break for avoiding duplicate IDs - elif id_method == 2: - figure_id = str(uuid.uuid4()) # creates a random UUID - figure_id = figure_id[0:8] # only use first 8 numbers - else: - raise ValueError( - f'Your chosen ID method "{id_method}" is not supported.\n' - 'At the moment these methods are available:\n' - '"1": Unix time converted to hexadecimal\n' - '"2": Random UUID') + match id_method: + case 'time': + figure_id = time.time() # UNIX Time + figure_id = hex(int(figure_id)) # convert time to hexadecimal + time.sleep(0.5) # break for avoiding duplicate IDs + case 'random': + figure_id = str(uuid.uuid4()) # creates a random UUID + figure_id = figure_id[0:8] # only use first 8 numbers + case _: + raise ValueError( + f'Your chosen ID method "{id_method}" is not supported.\n' + 'At the moment these methods are available:\n' + '"time": Unix time converted to hexadecimal\n' + '"random": Random UUID') return figure_id diff --git a/src/plotid/example.py b/src/plotid/example.py index f8156f2..491c986 100644 --- a/src/plotid/example.py +++ b/src/plotid/example.py @@ -9,55 +9,50 @@ the function publish. # %% Import modules import numpy as np -from numpy import random # import h5py as h5 -# import matplotlib import matplotlib.pyplot as plt from tagplot import tagplot from publish import publish -# %% Project ID -ProjectID = "MR04_" +# %% Set Project ID +PROJECT_ID = "MR04_" -# %% Plot engine -plot_engine = "matplotlib" +# %% Choose Plot engine +PLOT_ENGINE = "matplotlib" # %% Create sample data x = np.linspace(0, 10, 100) -y = random.rand(100) + 2 +y = np.random.rand(100) + 2 y_2 = np.sin(x) + 2 -# %% Create figure +# %% Create figures -# Create plot -color1 = 'black' -color2 = 'yellow' -# 1.Figure -fig1 = plt.figure() -plt.plot(x, y, color=color1) -plt.plot(x, y_2, color=color2) +# 1. figure +FIG1 = plt.figure() +plt.plot(x, y, color='black') +plt.plot(x, y_2, color='yellow') -# 2.Figure -fig2 = plt.figure() -plt.plot(x, y, color=color2) -plt.plot(x, y_2, color=color1) - -fig = [fig1, fig2] +# 2. figure +FIG2 = plt.figure() +plt.plot(x, y, color='blue') +plt.plot(x, y_2, color='red') # %% TagPlot -# p1 = PlotOptions(fig, plot_engine, prefix=ProjectID, -# method='2', location='east') -# [figs, ID] = p1.tagplot() -[figs, ID] = tagplot(fig, plot_engine, prefix=ProjectID, - id_method='2', location='west') -# %% Figure als tiff-Datei abspeichern -for i, figure in enumerate(figs): - name = "Test"+str(i)+".tiff" - figure.savefig(name) +# If multiple figures should be tagged, figures must be provided as list. +FIGS_AS_LIST = [FIG1, FIG2] + +[TAGGED_FIGS, ID] = tagplot(FIGS_AS_LIST, PLOT_ENGINE, prefix=PROJECT_ID, + id_method='random', location='west') + +# %% Save figure as tiff-file, but publish also exports the plot to a picture +# file in the destination folder. +for i, figure in enumerate(TAGGED_FIGS): + NAME = "Test"+str(i)+".tiff" + figure.savefig(NAME) # %% Publish -# Arguments: Source directory, destination directory, figure, plot (which is -# already saved as picture, publish-mode). +# Arguments: Source directory, destination directory, figure, plot name, +# publish-mode). publish('../../tests', '/home/chief/Dokumente/fst/plotid_python/data', - fig1, 'Bild', 'individual') + FIG1, 'Bild', 'individual') diff --git a/src/plotid/plotoptions.py b/src/plotid/plotoptions.py index 53ffe2a..6503422 100644 --- a/src/plotid/plotoptions.py +++ b/src/plotid/plotoptions.py @@ -46,24 +46,19 @@ class PlotOptions: Returns ------- - 0, if all checks succeeded. + 0, if all checks succeed. """ # %% Validate inputs + # Input validation for figs is done in submodules tagplot_$engine.py if isinstance(self.prefix, str): pass else: raise TypeError("Prefix is not a string.") - if isinstance(self.figs, list): + if isinstance(self.id_method, str): pass else: - raise TypeError("Figures are not a list.") - - # TODO: Change id_method key from integer to (more meaningful) string. - try: - self.id_method = int(self.id_method) - except ValueError: - raise TypeError('The chosen ID id_method is not an integer.') + raise TypeError('The chosen id_method is not a string.') return 0 diff --git a/src/plotid/publish.py b/src/plotid/publish.py index 77486c8..3462825 100644 --- a/src/plotid/publish.py +++ b/src/plotid/publish.py @@ -55,10 +55,6 @@ def publish(src_datapath, dst_path, figure, plot_name, data_storage): raise FileNotFoundError('The specified destination directory ' 'does not exist.') - # Check if handed over figure is not empty. - if not figure: - raise TypeError('No figure was given. ') - # If dst dir already exists ask user if it should be overwritten or not. if os.path.isdir(dst_path): warnings.warn(f'Folder "{dst_dirname}" already exists – ' @@ -87,9 +83,10 @@ def publish(src_datapath, dst_path, figure, plot_name, data_storage): # Does nothing, not implemented yet pass case 'individual': - # Copy data to invisible folder + # Copy all files to destination directory print('Copying data has been started. Depending on the size of ' 'your data this may take a while...') + # Copy data to invisible folder shutil.copytree(src_datapath, dst_path_invisible) # Copy script that calls this function to folder @@ -107,4 +104,3 @@ def publish(src_datapath, dst_path, figure, plot_name, data_storage): print(f'Publish was successful.\nYour plot "{plot_path}",\n' f'your data "{src_datapath}"\nand your script "{sys.argv[0]}"\n' f'were copied to {dst_path}\nin {data_storage} mode.') - return diff --git a/src/plotid/tagplot.py b/src/plotid/tagplot.py index e075dc6..d0258ff 100644 --- a/src/plotid/tagplot.py +++ b/src/plotid/tagplot.py @@ -15,7 +15,7 @@ from plotoptions import PlotOptions from tagplot_matplotlib import tagplot_matplotlib -def tagplot(figs, engine, prefix='', id_method=1, location='east'): +def tagplot(figs, engine, prefix='', id_method='time', location='east'): """ Tag your figure/plot with an ID. diff --git a/src/plotid/tagplot_matplotlib.py b/src/plotid/tagplot_matplotlib.py index b558b3c..f527fb2 100644 --- a/src/plotid/tagplot_matplotlib.py +++ b/src/plotid/tagplot_matplotlib.py @@ -26,7 +26,7 @@ def tagplot_matplotlib(plotid_object): 'of PlotOptions.') # Check if figs is a valid figure or a list of valid figures if isinstance(plotid_object.figs, matplotlib.figure.Figure): - pass + plotid_object.figs = [plotid_object.figs] elif isinstance(plotid_object.figs, list): for figure in plotid_object.figs: if isinstance(figure, matplotlib.figure.Figure): diff --git a/tests/runner_tests.py b/tests/runner_tests.py index 20beec9..613dde1 100644 --- a/tests/runner_tests.py +++ b/tests/runner_tests.py @@ -6,9 +6,9 @@ Includes starting all tests and measuring the code coverage. """ import sys +import os import unittest import coverage -import os path = os.path.abspath('src/plotid') sys.path.append(path) diff --git a/tests/test_create_id.py b/tests/test_create_id.py index d456062..0310ca4 100644 --- a/tests/test_create_id.py +++ b/tests/test_create_id.py @@ -15,8 +15,8 @@ class TestCreateID(unittest.TestCase): def test_existence(self): """Test if create_id returns a string.""" - self.assertIsInstance(cid.create_id(1), str) - self.assertIsInstance(cid.create_id(2), str) + self.assertIsInstance(cid.create_id('time'), str) + self.assertIsInstance(cid.create_id('random'), str) def test_errors(self): """ Test if Errors are raised when id_method is wrong. """ @@ -27,8 +27,8 @@ class TestCreateID(unittest.TestCase): def test_length(self): """ Test if figure_id has the correct length. """ - self.assertEqual(len(cid.create_id(1)), 10) - self.assertEqual(len(cid.create_id(2)), 8) + self.assertEqual(len(cid.create_id('time')), 10) + self.assertEqual(len(cid.create_id('random')), 8) if __name__ == '__main__': diff --git a/tests/test_publish.py b/tests/test_publish.py index 86c3192..f157600 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -109,11 +109,6 @@ class TestPublish(unittest.TestCase): os.mkdir(INVISIBLE_PATH) publish(SRC_DIR, DST_PATH, fig, PIC_NAME, 'individual') - def test_picture(self): - """ Test if Error is raised if fig is not a valid figure object. """ - with self.assertRaises(TypeError): - publish(SRC_DIR, DST_PATH, 'fig', PIC_NAME, 'individual') - def test_data_storage(self): """ Test if Error is raised when unsupported storage method was chosen. diff --git a/tests/test_tagplot.py b/tests/test_tagplot.py index d0e5af2..cb71137 100644 --- a/tests/test_tagplot.py +++ b/tests/test_tagplot.py @@ -15,7 +15,7 @@ FIGS_AS_LIST = [FIG1, FIG2] PROJECT_ID = "MR01" PLOT_ENGINE = "matplotlib" -METHOD = 1 +METHOD = 'time' class TestTagplot(unittest.TestCase): @@ -23,40 +23,31 @@ class TestTagplot(unittest.TestCase): Class for all unittests of the tagplot module. """ - def test_figures(self): - """ - Test if Errors are raised when the provided figure is not given - as list. - """ - with self.assertRaises(TypeError): - tagplot('fig', PLOT_ENGINE, PROJECT_ID, METHOD) - with self.assertRaises(TypeError): - tagplot(FIG1, PLOT_ENGINE, prefix=PROJECT_ID) - def test_prefix(self): """ Test if Error is raised if prefix is not a string. """ with self.assertRaises(TypeError): - tagplot(FIGS_AS_LIST, PLOT_ENGINE, 3, METHOD) + tagplot(FIGS_AS_LIST, PLOT_ENGINE, 3, METHOD, location='southeast') def test_plotengine(self): """ Test if Errors are raised if the provided plot engine is not supported. """ with self.assertRaises(ValueError): - tagplot(FIGS_AS_LIST, 1, PROJECT_ID, METHOD) + tagplot(FIGS_AS_LIST, 1, PROJECT_ID, METHOD, location='north') with self.assertRaises(ValueError): - tagplot(FIGS_AS_LIST, 'xyz', PROJECT_ID, METHOD) + tagplot(FIGS_AS_LIST, 'xyz', PROJECT_ID, METHOD, location='south') def test_idmethod(self): """ - Test if Errors are raised if the id_method is not an integer. + Test if Errors are raised if the id_method is not an string. """ with self.assertRaises(TypeError): - tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method='(0,1)') + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method=(0, 1), + location='west') with self.assertRaises(TypeError): - tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method='h') + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method=1) with self.assertRaises(TypeError): - tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method='[0,1]') + tagplot(FIGS_AS_LIST, PLOT_ENGINE, PROJECT_ID, id_method=[0, 1]) def test_location(self): """ diff --git a/tests/test_tagplot_matplotlib.py b/tests/test_tagplot_matplotlib.py index 50040d4..4a6abf2 100644 --- a/tests/test_tagplot_matplotlib.py +++ b/tests/test_tagplot_matplotlib.py @@ -17,7 +17,7 @@ FIGS_AS_LIST = [FIG1, FIG2] # Constants for tests PROJECT_ID = "MR01" -METHOD = 1 +METHOD = 'time' ROTATION = 90 POSITION = (0.975, 0.35) @@ -35,6 +35,15 @@ class TestTagplotMatplotlib(unittest.TestCase): self.assertIsInstance(figs[0], Figure) self.assertIsInstance(figs[1], Figure) + def test_single_mplfigure(self): + """ + Test of returned objects. Check if matplotlib figures are returned, + if a single matplot figure is given (not as a list). + """ + options = PlotOptions(FIG1, PROJECT_ID, METHOD, ROTATION, POSITION) + [figs, _] = tagplot_matplotlib(options) + self.assertIsInstance(figs[0], Figure) + def test_mplerror(self): """ Test if Error is raised if wrong type of figures is given. """ options = PlotOptions(3, PROJECT_ID, METHOD, ROTATION, POSITION) -- GitLab From d6c2925ee65723995b9d1a834e570f32cab987f4 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 14 Jun 2022 20:29:20 +0200 Subject: [PATCH 12/24] Change imports to absolute imports. That makes the package when installed via pip work. BUT it breaks the code if it is run not as a package. --- setup.cfg | 2 +- src/plotid/example.py | 4 ++-- src/plotid/publish.py | 2 +- src/plotid/tagplot.py | 4 ++-- src/plotid/tagplot_matplotlib.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/setup.cfg b/setup.cfg index 2102a30..c63491b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = example-package-plotid-test -version = 0.0.1 +version = 0.0.2 author = Example Author author_email = author@example.com description = A small example package diff --git a/src/plotid/example.py b/src/plotid/example.py index 491c986..fcf7713 100644 --- a/src/plotid/example.py +++ b/src/plotid/example.py @@ -11,8 +11,8 @@ the function publish. import numpy as np # import h5py as h5 import matplotlib.pyplot as plt -from tagplot import tagplot -from publish import publish +from plotid.tagplot import tagplot +from plotid.publish import publish # %% Set Project ID PROJECT_ID = "MR04_" diff --git a/src/plotid/publish.py b/src/plotid/publish.py index 3462825..41b4ae1 100644 --- a/src/plotid/publish.py +++ b/src/plotid/publish.py @@ -15,7 +15,7 @@ import os import shutil import sys import warnings -from save_plot import save_plot +import plotid.save_plot as save_plot def publish(src_datapath, dst_path, figure, plot_name, data_storage): diff --git a/src/plotid/tagplot.py b/src/plotid/tagplot.py index d0258ff..695d2b1 100644 --- a/src/plotid/tagplot.py +++ b/src/plotid/tagplot.py @@ -11,8 +11,8 @@ Functions: """ import warnings -from plotoptions import PlotOptions -from tagplot_matplotlib import tagplot_matplotlib +from plotid.plotoptions import PlotOptions +from plotid.tagplot_matplotlib import tagplot_matplotlib def tagplot(figs, engine, prefix='', id_method='time', location='east'): diff --git a/src/plotid/tagplot_matplotlib.py b/src/plotid/tagplot_matplotlib.py index f527fb2..b67acfc 100644 --- a/src/plotid/tagplot_matplotlib.py +++ b/src/plotid/tagplot_matplotlib.py @@ -8,8 +8,8 @@ Functions: import matplotlib import matplotlib.pyplot as plt -import create_id -from plotoptions import PlotOptions +import plotid.create_id as create_id +from plotid.plotoptions import PlotOptions def tagplot_matplotlib(plotid_object): -- GitLab From 75dc1c360f313c657726faa18ba4ce79edaab754 Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 15 Jun 2022 09:56:08 +0200 Subject: [PATCH 13/24] Imports with absolute paths. --- src/plotid/create_id.py | 2 +- src/plotid/example.py | 4 ++-- src/plotid/publish.py | 2 +- src/plotid/tagplot.py | 4 ++-- src/plotid/tagplot_matplotlib.py | 4 ++-- tests/test_tagplot_matplotlib.py | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plotid/create_id.py b/src/plotid/create_id.py index fa7febc..450e2da 100644 --- a/src/plotid/create_id.py +++ b/src/plotid/create_id.py @@ -3,7 +3,7 @@ Create an identifier to print it on a plot. Functions: - create_id(int) -> string + create_id(str) -> string """ import time import uuid diff --git a/src/plotid/example.py b/src/plotid/example.py index fcf7713..5187d2b 100644 --- a/src/plotid/example.py +++ b/src/plotid/example.py @@ -11,8 +11,8 @@ the function publish. import numpy as np # import h5py as h5 import matplotlib.pyplot as plt -from plotid.tagplot import tagplot -from plotid.publish import publish +from src.plotid.tagplot import tagplot +from src.plotid.publish import publish # %% Set Project ID PROJECT_ID = "MR04_" diff --git a/src/plotid/publish.py b/src/plotid/publish.py index 41b4ae1..f7a59e4 100644 --- a/src/plotid/publish.py +++ b/src/plotid/publish.py @@ -15,7 +15,7 @@ import os import shutil import sys import warnings -import plotid.save_plot as save_plot +from src.plotid.save_plot import save_plot def publish(src_datapath, dst_path, figure, plot_name, data_storage): diff --git a/src/plotid/tagplot.py b/src/plotid/tagplot.py index 695d2b1..429a1e7 100644 --- a/src/plotid/tagplot.py +++ b/src/plotid/tagplot.py @@ -11,8 +11,8 @@ Functions: """ import warnings -from plotid.plotoptions import PlotOptions -from plotid.tagplot_matplotlib import tagplot_matplotlib +from src.plotid.plotoptions import PlotOptions +from src.plotid.tagplot_matplotlib import tagplot_matplotlib def tagplot(figs, engine, prefix='', id_method='time', location='east'): diff --git a/src/plotid/tagplot_matplotlib.py b/src/plotid/tagplot_matplotlib.py index b67acfc..1b1ba9a 100644 --- a/src/plotid/tagplot_matplotlib.py +++ b/src/plotid/tagplot_matplotlib.py @@ -8,8 +8,8 @@ Functions: import matplotlib import matplotlib.pyplot as plt -import plotid.create_id as create_id -from plotid.plotoptions import PlotOptions +import src.plotid.create_id as create_id +from src.plotid.plotoptions import PlotOptions def tagplot_matplotlib(plotid_object): diff --git a/tests/test_tagplot_matplotlib.py b/tests/test_tagplot_matplotlib.py index 4a6abf2..78e3d14 100644 --- a/tests/test_tagplot_matplotlib.py +++ b/tests/test_tagplot_matplotlib.py @@ -7,8 +7,8 @@ Unittests for TagPlot_matplotlib import unittest import matplotlib.pyplot as plt from matplotlib.figure import Figure -from tagplot_matplotlib import tagplot_matplotlib -from plotoptions import PlotOptions +from src.plotid.tagplot_matplotlib import tagplot_matplotlib +from src.plotid.plotoptions import PlotOptions FIG1 = plt.figure() -- GitLab From 28c6353b9efa042bf9285151c36d61e5c53201af Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 15 Jun 2022 10:58:48 +0200 Subject: [PATCH 14/24] Adjust project structure that packaging works and unittests work as well. --- plotid/.pylintrc | 2 ++ {src/plotid => plotid}/__init__.py | 0 {src/plotid => plotid}/create_id.py | 0 {src/plotid => plotid}/example.py | 4 ++-- {src/plotid => plotid}/filecompare.py | 0 {src/plotid => plotid}/hdf5_external_link.py | 0 {src/plotid => plotid}/plotoptions.py | 0 {src/plotid => plotid}/publish.py | 2 +- {src/plotid => plotid}/save_plot.py | 0 {src/plotid => plotid}/tagplot.py | 4 ++-- {src/plotid => plotid}/tagplot_matplotlib.py | 4 ++-- pyproject.toml | 2 +- setup.cfg | 13 ++++++++++--- src/plotid/.pylintrc | 2 -- tests/runner_tests.py | 2 +- tests/test_create_id.py | 2 +- tests/test_publish.py | 2 +- tests/test_save_plot.py | 2 +- tests/test_tagplot_matplotlib.py | 4 ++-- 19 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 plotid/.pylintrc rename {src/plotid => plotid}/__init__.py (100%) rename {src/plotid => plotid}/create_id.py (100%) rename {src/plotid => plotid}/example.py (94%) rename {src/plotid => plotid}/filecompare.py (100%) rename {src/plotid => plotid}/hdf5_external_link.py (100%) rename {src/plotid => plotid}/plotoptions.py (100%) rename {src/plotid => plotid}/publish.py (98%) rename {src/plotid => plotid}/save_plot.py (100%) rename {src/plotid => plotid}/tagplot.py (96%) rename {src/plotid => plotid}/tagplot_matplotlib.py (95%) delete mode 100644 src/plotid/.pylintrc diff --git a/plotid/.pylintrc b/plotid/.pylintrc new file mode 100644 index 0000000..e50585e --- /dev/null +++ b/plotid/.pylintrc @@ -0,0 +1,2 @@ +[MASTER] +init-hook='import sys; sys.path.append("./plotid")' diff --git a/src/plotid/__init__.py b/plotid/__init__.py similarity index 100% rename from src/plotid/__init__.py rename to plotid/__init__.py diff --git a/src/plotid/create_id.py b/plotid/create_id.py similarity index 100% rename from src/plotid/create_id.py rename to plotid/create_id.py diff --git a/src/plotid/example.py b/plotid/example.py similarity index 94% rename from src/plotid/example.py rename to plotid/example.py index 5187d2b..fcf7713 100644 --- a/src/plotid/example.py +++ b/plotid/example.py @@ -11,8 +11,8 @@ the function publish. import numpy as np # import h5py as h5 import matplotlib.pyplot as plt -from src.plotid.tagplot import tagplot -from src.plotid.publish import publish +from plotid.tagplot import tagplot +from plotid.publish import publish # %% Set Project ID PROJECT_ID = "MR04_" diff --git a/src/plotid/filecompare.py b/plotid/filecompare.py similarity index 100% rename from src/plotid/filecompare.py rename to plotid/filecompare.py diff --git a/src/plotid/hdf5_external_link.py b/plotid/hdf5_external_link.py similarity index 100% rename from src/plotid/hdf5_external_link.py rename to plotid/hdf5_external_link.py diff --git a/src/plotid/plotoptions.py b/plotid/plotoptions.py similarity index 100% rename from src/plotid/plotoptions.py rename to plotid/plotoptions.py diff --git a/src/plotid/publish.py b/plotid/publish.py similarity index 98% rename from src/plotid/publish.py rename to plotid/publish.py index f7a59e4..e2b43c5 100644 --- a/src/plotid/publish.py +++ b/plotid/publish.py @@ -15,7 +15,7 @@ import os import shutil import sys import warnings -from src.plotid.save_plot import save_plot +from plotid.save_plot import save_plot def publish(src_datapath, dst_path, figure, plot_name, data_storage): diff --git a/src/plotid/save_plot.py b/plotid/save_plot.py similarity index 100% rename from src/plotid/save_plot.py rename to plotid/save_plot.py diff --git a/src/plotid/tagplot.py b/plotid/tagplot.py similarity index 96% rename from src/plotid/tagplot.py rename to plotid/tagplot.py index 429a1e7..695d2b1 100644 --- a/src/plotid/tagplot.py +++ b/plotid/tagplot.py @@ -11,8 +11,8 @@ Functions: """ import warnings -from src.plotid.plotoptions import PlotOptions -from src.plotid.tagplot_matplotlib import tagplot_matplotlib +from plotid.plotoptions import PlotOptions +from plotid.tagplot_matplotlib import tagplot_matplotlib def tagplot(figs, engine, prefix='', id_method='time', location='east'): diff --git a/src/plotid/tagplot_matplotlib.py b/plotid/tagplot_matplotlib.py similarity index 95% rename from src/plotid/tagplot_matplotlib.py rename to plotid/tagplot_matplotlib.py index 1b1ba9a..b67acfc 100644 --- a/src/plotid/tagplot_matplotlib.py +++ b/plotid/tagplot_matplotlib.py @@ -8,8 +8,8 @@ Functions: import matplotlib import matplotlib.pyplot as plt -import src.plotid.create_id as create_id -from src.plotid.plotoptions import PlotOptions +import plotid.create_id as create_id +from plotid.plotoptions import PlotOptions def tagplot_matplotlib(plotid_object): diff --git a/pyproject.toml b/pyproject.toml index d7e8400..b519f78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=42"] +requires = ["setuptools>=43", "wheel"] build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg index c63491b..1e0b8b5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = example-package-plotid-test -version = 0.0.2 +version = 0.0.3 author = Example Author author_email = author@example.com description = A small example package @@ -16,9 +16,16 @@ classifiers = [options] package_dir = - = src + = plotid packages = find: python_requires = >=3.10 +install_requires = + matplotlib + numpy + +[options.extras_require] +test = + coverage [options.packages.find] -where = src +where = plotid diff --git a/src/plotid/.pylintrc b/src/plotid/.pylintrc deleted file mode 100644 index 0b39a7b..0000000 --- a/src/plotid/.pylintrc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -init-hook='import sys; sys.path.append("./src/plotid")' diff --git a/tests/runner_tests.py b/tests/runner_tests.py index 613dde1..de973b1 100644 --- a/tests/runner_tests.py +++ b/tests/runner_tests.py @@ -10,7 +10,7 @@ import os import unittest import coverage -path = os.path.abspath('src/plotid') +path = os.path.abspath('plotid') sys.path.append(path) cov = coverage.Coverage() diff --git a/tests/test_create_id.py b/tests/test_create_id.py index 0310ca4..5894057 100644 --- a/tests/test_create_id.py +++ b/tests/test_create_id.py @@ -5,7 +5,7 @@ Unittests for CreateID """ import unittest -import src.plotid.create_id as cid +import plotid.create_id as cid class TestCreateID(unittest.TestCase): diff --git a/tests/test_publish.py b/tests/test_publish.py index f157600..d09b741 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -10,7 +10,7 @@ import sys import shutil from unittest.mock import patch import matplotlib.pyplot as plt -from src.plotid.publish import publish +from plotid.publish import publish SRC_DIR = 'test_src_folder' diff --git a/tests/test_save_plot.py b/tests/test_save_plot.py index 14b8dee..0f28ae7 100644 --- a/tests/test_save_plot.py +++ b/tests/test_save_plot.py @@ -7,7 +7,7 @@ Unittests for save_plot import os import unittest import matplotlib.pyplot as plt -from src.plotid.save_plot import save_plot +from plotid.save_plot import save_plot FIGURE = plt.figure() PLOT_NAME = 'PLOT_NAME' diff --git a/tests/test_tagplot_matplotlib.py b/tests/test_tagplot_matplotlib.py index 78e3d14..8f81b6f 100644 --- a/tests/test_tagplot_matplotlib.py +++ b/tests/test_tagplot_matplotlib.py @@ -7,8 +7,8 @@ Unittests for TagPlot_matplotlib import unittest import matplotlib.pyplot as plt from matplotlib.figure import Figure -from src.plotid.tagplot_matplotlib import tagplot_matplotlib -from src.plotid.plotoptions import PlotOptions +from plotid.tagplot_matplotlib import tagplot_matplotlib +from plotid.plotoptions import PlotOptions FIG1 = plt.figure() -- GitLab From f18dc1013a98c399a102b1a173ba9eabbea0c640 Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 15 Jun 2022 11:54:20 +0200 Subject: [PATCH 15/24] Adjust setup.cfg for correct packaging behaviour. --- setup.cfg | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index 1e0b8b5..a6cf4d3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = example-package-plotid-test -version = 0.0.3 +version = 0.0.5 author = Example Author author_email = author@example.com description = A small example package @@ -15,9 +15,7 @@ classifiers = Operating System :: OS Independent [options] -package_dir = - = plotid -packages = find: +packages = plotid python_requires = >=3.10 install_requires = matplotlib @@ -27,5 +25,4 @@ install_requires = test = coverage -[options.packages.find] -where = plotid + -- GitLab From aafe5d4b74279e122243ee5b0f30e08f840c1e7a Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 15 Jun 2022 14:06:57 +0200 Subject: [PATCH 16/24] Fix copy picture to destination bug caused by shutil.move. Switched to shutil.copy2 followed by os.remove. --- plotid/publish.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plotid/publish.py b/plotid/publish.py index e2b43c5..46924af 100644 --- a/plotid/publish.py +++ b/plotid/publish.py @@ -92,7 +92,9 @@ def publish(src_datapath, dst_path, figure, plot_name, data_storage): # Copy script that calls this function to folder shutil.copy2(sys.argv[0], dst_path_invisible) # Copy plot file to folder - shutil.move(plot_path, dst_path_invisible) + if os.path.isfile(plot_path): + shutil.copy2(plot_path, dst_path_invisible) + os.remove(plot_path) case _: raise ValueError('The data storage method {data_storage} ' 'is not available.') -- GitLab From 696be184bc7568344a803d4364784b88c0b89ba6 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 21 Jun 2022 11:53:32 +0200 Subject: [PATCH 17/24] Improve documentation. --- README.md | 98 ++++++++++++++++++++++++++++++++++++++++++++++- plotid/publish.py | 5 ++- plotid/tagplot.py | 5 ++- setup.cfg | 10 +++-- 4 files changed, 108 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e873d62..913a1fc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,99 @@ -# plot_ID_python +# PlotID for Python This is the python PlotID project. +PlotID is a program connected to Research Data Management (RDM). It has two main functionalities: +1. Tag your plot with an identifier. +2. Export the resulting file to a specified directory along the corresponding research data, the plot is based on. Additionally, the script that created the plot will also be copied to the directory. -To run the program python version 3.10 is required. \ No newline at end of file +**Note:** To run PlotID python version ≥ 3.10 is required. + +## Installation +Currently there are two options to run PlotID. Either install it via pip from the Python Package Index (PyPi) or install PlotID from the source code. + +### From PyPi with pip +1. *Optional* Create a virtual environment and activate it: +`pip install venv` +`mkdir venv` +`python3 -m venv` +`source venv/bin/activate` +2. Install PlotID +`pip install --upgrade --index-url https://test.pypi.org/simple/ example-package-plotid-test` + +### From source +1. Download the source code from [Gitlab](https://git.rwth-aachen.de/plotid/plotid_python): +`git clone https://git.rwth-aachen.de/plotid/plotid_python.git` +`cd plotid_python` +2. [Optional] Create a virtual environment: +`pip install venv` +`mkdir venv` +`python3 -m venv` +`source venv/bin/activate` +3. Install dependencies +`pip install -r requirements.txt` +4. Install PlotID +`pip install .` + +## Usage +PlotID has two main functionalities: +1. Tag your plot with an identifier. +2. Export the resulting file to a specified directory along the corresponding research data, the plot is based on. Additionally, the script that created the plot will also be copied to the directory. + +### tagplot() +Tag your figure/plot with an ID. +`tagplot(figures, plot_engine)` +The variable "figures" can be a single figure or a list of multiple figures. +The argument "plot_engine" defines which plot engine was used to create the figures. It also determines which plot engine PlotID uses to place the ID on the plot. Currently supported plot engines are: +- 'matplotlib' + +tagplot returns a list that contains two lists each with as many entries as figures were given. The first list contains the tagged figures. The second list contains the corresponding IDs as strings + +Optional parameters can be used to customize the tag process. +- prefix : str, optional + Will be added as prefix to the ID. +- id_method : str, optional + id_method for creating the ID. Create an ID by Unix time is referenced as 'time', create a random ID with id_method='random'. The default is 'time'. +- location : string, optional + Location for ID to be displayed on the plot. Default is 'east'. + +Example: + FIG1 = plt.figure() + FIG2 = plt.figure() + FIGS_AS_LIST = [FIG1, FIG2] + [TAGGED_FIGS, ID] = tagplot(FIGS_AS_LIST, 'matplotlib', prefix='XY23_', id_method='random', location='west') + + +### publish() +Save plot, data and measuring script. +`publish(src_datapath, dst_path, figure, plot_name)` + +- "src_datapath" specifies the path to (raw) data that should be published. +- "dst_path" is the path to the destination directory, where all the data should be copied/exported to. +- "figure" expects the figure that was tagged and now should be saved as picture. +- "plot_name" will be the file name for the exported plot. + +Optional parameters can be used to customize the publish process. +- data_storage: str, optional + Method how the data should be stored. Available options: + - centralized: The raw data will copied only once. All other plots will reference this data via sym link. + - individual: The complete raw data will be copied to a folder for every plot, respectively. +Example: +`publish('/home/user/Documents/research_data', '/home/user/Documents/exported_data', FIG1, 'Energy_over_time') + +## Build +If you want to build PlotID yourself, follow these steps: +1. Download the source code from [Gitlab](https://git.rwth-aachen.de/plotid/plotid_python): +`git clone https://git.rwth-aachen.de/plotid/plotid_python.git` +`cd plotid_python` +2. [Optional] Create a virtual environment: +`pip install venv` +`mkdir venv` +`python3 -m venv` +`source venv/bin/activate` +3. [Optional] Run unittests and coverage: +`python3 tests/runner_tests.py` +4. Build the package +`python3 -m build` + +## Documentation +If you have more questions about PlotID, please have a look at the [documentation](link-to-docs). +Also have a look at the example.py that is shipped with PlotID. \ No newline at end of file diff --git a/plotid/publish.py b/plotid/publish.py index 46924af..c5c53dd 100644 --- a/plotid/publish.py +++ b/plotid/publish.py @@ -18,7 +18,8 @@ import warnings from plotid.save_plot import save_plot -def publish(src_datapath, dst_path, figure, plot_name, data_storage): +def publish(src_datapath, dst_path, figure, plot_name, + data_storage='individual'): """ Save plot, data and measuring script. @@ -37,7 +38,7 @@ def publish(src_datapath, dst_path, figure, plot_name, data_storage): centralized: The raw data will copied only once. All other plots will reference this data via sym link. individual: The complete raw data will be copied to a folder for - every plot, respectively. + every plot, respectively. This is the default value. Returns ------- diff --git a/plotid/tagplot.py b/plotid/tagplot.py index 695d2b1..ba660b1 100644 --- a/plotid/tagplot.py +++ b/plotid/tagplot.py @@ -30,9 +30,10 @@ def tagplot(figs, engine, prefix='', id_method='time', location='east'): Plot engine which should be used to tag the plot. prefix : string Will be added as prefix to the ID. - id_method : int, optional + id_method : string, optional id_method for creating the ID. Create an ID by Unix time is referenced - as 1, create a random ID with id_method=2. The default is 1. + as 'time', create a random ID with id_method='random'. + The default is 'time'. location : string, optional Location for ID to be displayed on the plot. Default is 'east'. diff --git a/setup.cfg b/setup.cfg index a6cf4d3..bd426a9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,18 +1,20 @@ [metadata] name = example-package-plotid-test -version = 0.0.5 +version = 0.0.6 author = Example Author author_email = author@example.com description = A small example package long_description = file: README.md long_description_content_type = text/markdown -url = https://github.com/pypa/sampleproject +url = https://git.rwth-aachen.de/plotid/plotid_python project_urls = - Bug Tracker = https://github.com/pypa/sampleproject/issues + Bug Tracker = https://git.rwth-aachen.de/plotid/plotid_python/-/issues classifiers = - Programming Language :: Python :: 3 + Programming Language :: Python :: 3.10 License :: OSI Approved :: Apache Software License Operating System :: OS Independent + Development Status :: 2 - Pre-Alpha + Intended Audience :: Science/Research [options] packages = plotid -- GitLab From 0aab6868d6f5948556c7dc0837d9a6358946ac24 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 21 Jun 2022 12:36:31 +0200 Subject: [PATCH 18/24] Small corrections. --- README.md | 2 +- plotid/tagplot_matplotlib.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 913a1fc..6251db4 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Optional parameters can be used to customize the publish process. - centralized: The raw data will copied only once. All other plots will reference this data via sym link. - individual: The complete raw data will be copied to a folder for every plot, respectively. Example: -`publish('/home/user/Documents/research_data', '/home/user/Documents/exported_data', FIG1, 'Energy_over_time') +`publish('/home/user/Documents/research_data', '/home/user/Documents/exported_data', FIG1, 'EnergyOverTime-Plot') ## Build If you want to build PlotID yourself, follow these steps: diff --git a/plotid/tagplot_matplotlib.py b/plotid/tagplot_matplotlib.py index b67acfc..7230f88 100644 --- a/plotid/tagplot_matplotlib.py +++ b/plotid/tagplot_matplotlib.py @@ -3,7 +3,7 @@ Tag your matplotlib plot with an ID. Functions: - TagPlot_matplotlib(figure object, string) -> list + tagplot_matplotlib(figure object, string) -> list """ import matplotlib -- GitLab From 9af26e624865c0e62b04df5504381ff3664415e9 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 21 Jun 2022 15:34:45 +0200 Subject: [PATCH 19/24] Generate documentation from docstrings automatically. --- docs/Makefile | 20 ++++++++++ docs/make.bat | 35 +++++++++++++++++ docs/source/conf.py | 59 ++++++++++++++++++++++++++++ docs/source/index.rst | 19 +++++++++ docs/source/modules.rst | 7 ++++ docs/source/plotid.rst | 85 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 225 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/make.bat create mode 100644 docs/source/conf.py create mode 100644 docs/source/index.rst create mode 100644 docs/source/modules.rst create mode 100644 docs/source/plotid.rst diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d0c3cbf --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..747ffb7 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..4c122e5 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,59 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# 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 +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +#import os +#import sys +#sys.path.insert(0, os.path.abspath('../../plotid')) + + +# -- Project information ----------------------------------------------------- + +project = 'PlotID' +copyright = '2022, Example Author' +author = 'Example Author' + +# The full version, including alpha/beta/rc tags +release = '0.0.6' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'autoapi.extension' +] +#autosummary_generate = True # Turn on sphinx.ext.autosummary +autoapi_type = 'python' +autoapi_dirs = ['../../plotid', '../../tests'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..34d0792 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,19 @@ +.. PlotID documentation master file, created by + sphinx-quickstart on Tue Jun 21 14:09:27 2022. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to PlotID's documentation! +================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 0000000..dd354c8 --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,7 @@ +plotid +====== + +.. toctree:: + :maxdepth: 4 + + plotid diff --git a/docs/source/plotid.rst b/docs/source/plotid.rst new file mode 100644 index 0000000..005afcd --- /dev/null +++ b/docs/source/plotid.rst @@ -0,0 +1,85 @@ +plotid package +============== + +Submodules +---------- + +plotid.create\_id module +------------------------ + +.. automodule:: plotid.create_id + :members: + :undoc-members: + :show-inheritance: + +plotid.example module +--------------------- + +.. automodule:: plotid.example + :members: + :undoc-members: + :show-inheritance: + +plotid.filecompare module +------------------------- + +.. automodule:: plotid.filecompare + :members: + :undoc-members: + :show-inheritance: + +plotid.hdf5\_external\_link module +---------------------------------- + +.. automodule:: plotid.hdf5_external_link + :members: + :undoc-members: + :show-inheritance: + +plotid.plotoptions module +------------------------- + +.. automodule:: plotid.plotoptions + :members: + :undoc-members: + :show-inheritance: + +plotid.publish module +--------------------- + +.. automodule:: plotid.publish + :members: + :undoc-members: + :show-inheritance: + +plotid.save\_plot module +------------------------ + +.. automodule:: plotid.save_plot + :members: + :undoc-members: + :show-inheritance: + +plotid.tagplot module +--------------------- + +.. automodule:: plotid.tagplot + :members: + :undoc-members: + :show-inheritance: + +plotid.tagplot\_matplotlib module +--------------------------------- + +.. automodule:: plotid.tagplot_matplotlib + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: plotid + :members: + :undoc-members: + :show-inheritance: -- GitLab From a781399111289243dae38100afe192fc37f5461c Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 21 Jun 2022 16:06:47 +0200 Subject: [PATCH 20/24] Exlude conf.py of docs from pylint. --- .gitlab-ci.yml | 2 +- .pylintrc | 2 -- docs/source/conf.py | 7 +++---- plotid/.pylintrc | 1 + 4 files changed, 5 insertions(+), 7 deletions(-) delete mode 100644 .pylintrc diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7a57b4a..50940d0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,7 +48,7 @@ PEP8: Pylint: stage: linting # allow_failure: true - script: find . -type f -name '*.py' | xargs pylint -rn --fail-under=9 # Find all python files and check the code with pylint. + script: find . -type f -name '*.py' | xargs pylint -rn --fail-under=9 --ignore='docs/source/conf.py' # Find all python files and check the code with pylint. test: stage: testing diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 0b39a7b..0000000 --- a/.pylintrc +++ /dev/null @@ -1,2 +0,0 @@ -[MASTER] -init-hook='import sys; sys.path.append("./src/plotid")' diff --git a/docs/source/conf.py b/docs/source/conf.py index 4c122e5..7ca2459 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,9 +10,9 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -#import os -#import sys -#sys.path.insert(0, os.path.abspath('../../plotid')) +# import os +# import sys +# sys.path.insert(0, os.path.abspath('../../plotid')) # -- Project information ----------------------------------------------------- @@ -33,7 +33,6 @@ release = '0.0.6' extensions = [ 'autoapi.extension' ] -#autosummary_generate = True # Turn on sphinx.ext.autosummary autoapi_type = 'python' autoapi_dirs = ['../../plotid', '../../tests'] diff --git a/plotid/.pylintrc b/plotid/.pylintrc index e50585e..45cb9ea 100644 --- a/plotid/.pylintrc +++ b/plotid/.pylintrc @@ -1,2 +1,3 @@ [MASTER] init-hook='import sys; sys.path.append("./plotid")' +ignore=docs -- GitLab From a8c1f9d7bd26b65a5e343e6f04c595aae0b141c8 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 21 Jun 2022 16:23:46 +0200 Subject: [PATCH 21/24] Adjust pylint pipeline to ignore /docs/source/conf.py. --- plotid/.pylintrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plotid/.pylintrc b/plotid/.pylintrc index 45cb9ea..40743c0 100644 --- a/plotid/.pylintrc +++ b/plotid/.pylintrc @@ -1,3 +1,4 @@ [MASTER] -init-hook='import sys; sys.path.append("./plotid")' -ignore=docs +init-hook='import sys; sys.path.append("./plotid")' +fail-under=9 +ignore=conf.py -- GitLab From 7dcbd1e50100e8efac925571f47714eb34b9efd3 Mon Sep 17 00:00:00 2001 From: nugget Date: Tue, 21 Jun 2022 16:27:48 +0200 Subject: [PATCH 22/24] Adjust pylint pipeline to ignore /docs/source/conf.py. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 50940d0..27b46ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,7 +48,7 @@ PEP8: Pylint: stage: linting # allow_failure: true - script: find . -type f -name '*.py' | xargs pylint -rn --fail-under=9 --ignore='docs/source/conf.py' # Find all python files and check the code with pylint. + script: find . -type f -name '*.py' | xargs pylint -rn --rcfile='plotid/.pylintrc' # Find all python files and check the code with pylint. test: stage: testing -- GitLab From dc07c99c38b9730f7f44c6b6e7461f98ffbcc9ad Mon Sep 17 00:00:00 2001 From: "Hock, Martin" Date: Wed, 22 Jun 2022 10:19:52 +0200 Subject: [PATCH 23/24] Adjust code blocks in readme --- README.md | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6251db4..5f9a25a 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,12 @@ Currently there are two options to run PlotID. Either install it via pip from th ### From PyPi with pip 1. *Optional* Create a virtual environment and activate it: -`pip install venv` -`mkdir venv` -`python3 -m venv` -`source venv/bin/activate` +```bash +pip install venv +mkdir venv +python3 -m venv +source venv/bin/activate +``` 2. Install PlotID `pip install --upgrade --index-url https://test.pypi.org/simple/ example-package-plotid-test` @@ -24,10 +26,12 @@ Currently there are two options to run PlotID. Either install it via pip from th `git clone https://git.rwth-aachen.de/plotid/plotid_python.git` `cd plotid_python` 2. [Optional] Create a virtual environment: -`pip install venv` -`mkdir venv` -`python3 -m venv` -`source venv/bin/activate` +```bash +pip install venv +mkdir venv +python3 -m venv +source venv/bin/activate +``` 3. Install dependencies `pip install -r requirements.txt` 4. Install PlotID @@ -56,10 +60,12 @@ Optional parameters can be used to customize the tag process. Location for ID to be displayed on the plot. Default is 'east'. Example: - FIG1 = plt.figure() - FIG2 = plt.figure() - FIGS_AS_LIST = [FIG1, FIG2] - [TAGGED_FIGS, ID] = tagplot(FIGS_AS_LIST, 'matplotlib', prefix='XY23_', id_method='random', location='west') +```python +FIG1 = plt.figure() +FIG2 = plt.figure() +FIGS_AS_LIST = [FIG1, FIG2] +[TAGGED_FIGS, ID] = tagplot(FIGS_AS_LIST, 'matplotlib', prefix='XY23_', id_method='random', location='west') +``` ### publish() @@ -85,10 +91,12 @@ If you want to build PlotID yourself, follow these steps: `git clone https://git.rwth-aachen.de/plotid/plotid_python.git` `cd plotid_python` 2. [Optional] Create a virtual environment: -`pip install venv` -`mkdir venv` -`python3 -m venv` -`source venv/bin/activate` +```bash +pip install venv +mkdir venv +python3 -m venv +source venv/bin/activate +``` 3. [Optional] Run unittests and coverage: `python3 tests/runner_tests.py` 4. Build the package @@ -96,4 +104,4 @@ If you want to build PlotID yourself, follow these steps: ## Documentation If you have more questions about PlotID, please have a look at the [documentation](link-to-docs). -Also have a look at the example.py that is shipped with PlotID. \ No newline at end of file +Also have a look at the example.py that is shipped with PlotID. -- GitLab From 152632a4543ece479b5f070c92bf38a6874f2162 Mon Sep 17 00:00:00 2001 From: nugget Date: Wed, 22 Jun 2022 11:38:45 +0200 Subject: [PATCH 24/24] Final changes for Version0.1. --- README.md | 2 +- setup.cfg | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5f9a25a..8d481de 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ PlotID is a program connected to Research Data Management (RDM). It has two main Currently there are two options to run PlotID. Either install it via pip from the Python Package Index (PyPi) or install PlotID from the source code. ### From PyPi with pip -1. *Optional* Create a virtual environment and activate it: +1. [Optional] Create a virtual environment and activate it: ```bash pip install venv mkdir venv diff --git a/setup.cfg b/setup.cfg index bd426a9..cf36c1f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,9 @@ [metadata] -name = example-package-plotid-test -version = 0.0.6 -author = Example Author -author_email = author@example.com -description = A small example package +name = plotID +version = 0.1.0 +author = Institut Fluidsystemtechnik within nfdi4ing at TU Darmstadt +author_email = nfdi4ing@fst.tu-darmstadt.de +description = The plotID toolkit supports researchers in tracking and storing relevant data in plots. Plots are labelled with an ID and the corresponding data is stored. long_description = file: README.md long_description_content_type = text/markdown url = https://git.rwth-aachen.de/plotid/plotid_python @@ -15,6 +15,7 @@ classifiers = Operating System :: OS Independent Development Status :: 2 - Pre-Alpha Intended Audience :: Science/Research + Topic :: Scientific/Engineering :: Visualization [options] packages = plotid -- GitLab