From f861952da1aa231612139ecde7a600afa977d40d Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sun, 5 Oct 2025 21:48:49 -0400 Subject: [PATCH 1/4] skpkg: migrate tests folder --- tests/conftest.py | 19 +++++++++++++++++++ tests/test_version.py | 10 ++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/conftest.py create mode 100644 tests/test_version.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..e3b6313 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +import json +from pathlib import Path + +import pytest + + +@pytest.fixture +def user_filesystem(tmp_path): + base_dir = Path(tmp_path) + home_dir = base_dir / "home_dir" + home_dir.mkdir(parents=True, exist_ok=True) + cwd_dir = base_dir / "cwd_dir" + cwd_dir.mkdir(parents=True, exist_ok=True) + + home_config_data = {"username": "home_username", "email": "home@email.com"} + with open(home_dir / "diffpyconfig.json", "w") as f: + json.dump(home_config_data, f) + + yield tmp_path diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..008dab2 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,10 @@ +"""Unit tests for __version__.py.""" + +import diffpy.srxplanargui # noqa + + +def test_package_version(): + """Ensure the package version is defined and not set to the initial + placeholder.""" + assert hasattr(diffpy.srxplanargui, "__version__") + assert diffpy.srxplanargui.__version__ != "0.0.0" From ef02af3961130c4db1de0a79c47c581fd45a419e Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sun, 5 Oct 2025 21:52:05 -0400 Subject: [PATCH 2/4] skpkg: migrate src folder except imageploy.py(needs merge before migration) --- src/diffpy/__init__.py | 18 +++++------ src/diffpy/srxplanargui/__init__.py | 20 +++++++----- src/diffpy/srxplanargui/srxplanargui_app.py | 33 ++++++++++++++++++++ src/diffpy/srxplanargui/version.py | 34 ++++++++++----------- 4 files changed, 68 insertions(+), 37 deletions(-) mode change 100755 => 100644 src/diffpy/__init__.py mode change 100755 => 100644 src/diffpy/srxplanargui/__init__.py create mode 100644 src/diffpy/srxplanargui/srxplanargui_app.py diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py old mode 100755 new mode 100644 index 07795ce..f7af346 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,18 +1,14 @@ #!/usr/bin/env python ############################################################################## # -# dpx.pdfgetxgui by Simon J. L. Billinge group -# (c) 2012 Trustees of the Columbia University -# in the City of New York. All rights reserved. +# (c) 2025 The Trustees of Columbia University in the City of New York. +# All rights reserved. # -# File coded by: Xiaohao Yang +# File coded by: Billinge Group members and community contributors. # -# See AUTHORS.txt for a list of people who contributed. -# See LICENSE.txt for license information. +# See GitHub contributions for a more detailed list of contributors. +# https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors +# +# See LICENSE.rst for license information. # ############################################################################## -"""Blank namespace package.""" - -__import__("pkg_resources").declare_namespace(__name__) - -# End of file diff --git a/src/diffpy/srxplanargui/__init__.py b/src/diffpy/srxplanargui/__init__.py old mode 100755 new mode 100644 index 8d41a88..5ae032f --- a/src/diffpy/srxplanargui/__init__.py +++ b/src/diffpy/srxplanargui/__init__.py @@ -1,19 +1,23 @@ #!/usr/bin/env python ############################################################################## # -# dpx.pdfgetxgui by Simon J. L. Billinge group -# (c) 2012 Trustees of the Columbia University -# in the City of New York. All rights reserved. +# (c) 2025 The Trustees of Columbia University in the City of New York. +# All rights reserved. # -# File coded by: Xiaohao Yang +# File coded by: Rundong Hua, Simon Billinge, Billinge Group members. # -# See AUTHORS.txt for a list of people who contributed. -# See LICENSE.txt for license information. +# See GitHub contributions for a more detailed list of contributors. +# https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors +# +# See LICENSE.rst for license information. # ############################################################################## +"""xPDFsuite, a software for PDF transformation and visualization.""" +# package version +from diffpy.srxplanargui.version import __version__ # noqa -# obtain version information -# from diffpy.srxplanargui.version import __version__ +# silence the pyflakes syntax checker +assert __version__ or True # End of file diff --git a/src/diffpy/srxplanargui/srxplanargui_app.py b/src/diffpy/srxplanargui/srxplanargui_app.py new file mode 100644 index 0000000..5b38aeb --- /dev/null +++ b/src/diffpy/srxplanargui/srxplanargui_app.py @@ -0,0 +1,33 @@ +import argparse + +from diffpy.srxplanargui.version import __version__ # noqa + + +def main(): + parser = argparse.ArgumentParser( + prog="diffpy.srxplanargui", + description=( + "xPDFsuite, a software for PDF transformation and visualization.\n\n" + "For more information, visit: " + "https://github.com/diffpy/diffpy.srxplanargui/" + ), + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + + parser.add_argument( + "--version", + action="store_true", + help="Show the program's version number and exit", + ) + + args = parser.parse_args() + + if args.version: + print(f"diffpy.srxplanargui {__version__}") + else: + # Default behavior when no arguments are given + parser.print_help() + + +if __name__ == "__main__": + main() diff --git a/src/diffpy/srxplanargui/version.py b/src/diffpy/srxplanargui/version.py index ffac5d9..699afaa 100644 --- a/src/diffpy/srxplanargui/version.py +++ b/src/diffpy/srxplanargui/version.py @@ -1,28 +1,26 @@ #!/usr/bin/env python ############################################################################## # -# diffpy.srxplanar by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2010 Trustees of the Columbia University -# in the City of New York. All rights reserved. +# (c) 2025 The Trustees of Columbia University in the City of New York. +# All rights reserved. # -# File coded by: Xiaohao Yang +# File coded by: Rundong Hua, Simon Billinge, Billinge Group members. # -# See AUTHORS.txt for a list of people who contributed. -# See LICENSENOTICE.txt for license information. +# See GitHub contributions for a more detailed list of contributors. +# https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors # noqa: E501 +# +# See LICENSE.rst for license information. # ############################################################################## -"""Definition of __version__ and __date__ for this package.""" - -# obtain version information -from pkg_resources import get_distribution +"""Definition of __version__.""" -_pkgname = __name__.rsplit(".", 1)[0] -__version__ = get_distribution(_pkgname).version +# We do not use the other three variables, but can be added back if needed. +# __all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"] -# we assume that tag_date was used and __version__ ends in YYYYMMDD -__date__ = ( - __version__[-8:-4] + "-" + __version__[-4:-2] + "-" + __version__[-2:] -) +# obtain version information +from importlib.metadata import PackageNotFoundError, version -# End of file +try: + __version__ = version("diffpy.srxplanargui") +except PackageNotFoundError: + __version__ = "unknown" From 22c82cfa16bed9def7e6572c09a6e0b788608bb7 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 7 Oct 2025 10:15:38 -0400 Subject: [PATCH 3/4] skpkg: modify license time and author in py file --- src/diffpy/__init__.py | 4 +-- src/diffpy/srxplanargui/__init__.py | 4 +-- src/diffpy/srxplanargui/imageplot.py | 50 ++++++++++++++++++---------- src/diffpy/srxplanargui/version.py | 4 +-- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index f7af346..ffe8c8b 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,10 +1,10 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2012-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Billinge Group members and community contributors. +# File coded by: Xiaohao Yang and Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. # https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors diff --git a/src/diffpy/srxplanargui/__init__.py b/src/diffpy/srxplanargui/__init__.py index 5ae032f..aaf3e55 100644 --- a/src/diffpy/srxplanargui/__init__.py +++ b/src/diffpy/srxplanargui/__init__.py @@ -1,10 +1,10 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2012-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Rundong Hua, Simon Billinge, Billinge Group members. +# File coded by: Xiaohao Yang, Simon Billinge, Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. # https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors diff --git a/src/diffpy/srxplanargui/imageplot.py b/src/diffpy/srxplanargui/imageplot.py index c91d351..508e2e7 100644 --- a/src/diffpy/srxplanargui/imageplot.py +++ b/src/diffpy/srxplanargui/imageplot.py @@ -101,38 +101,50 @@ class ImagePlot(HasTraits): ) avgmask = DelegatesTo( "srxconfig", - desc=("Mask the pixels too bright or too dark compared to" - " the average intensity at the similar diffraction angle"), + desc=( + "Mask the pixels too bright or too dark compared to" + " the average intensity at the similar diffraction angle" + ), ) brightpixelr = DelegatesTo( "srxconfig", - desc=("Pixels with intensity large than this relative threshold" - " (times the local environment) value will be masked"), + desc=( + "Pixels with intensity large than this relative threshold" + " (times the local environment) value will be masked" + ), ) brightpixelsize = DelegatesTo( "srxconfig", desc="Size of testing area for detecting bright pixels" ) darkpixelr = DelegatesTo( "srxconfig", - desc=("Pixels with intensity less than this relative threshold" - " (times the local environment) value will be masked"), + desc=( + "Pixels with intensity less than this relative threshold" + " (times the local environment) value will be masked" + ), ) avgmaskhigh = DelegatesTo( "srxconfig", - desc=("Comparing to the average intensity at " - "similar diffraction angle, \npixels with intensity larger than" - " avg_int*high will be masked"), + desc=( + "Comparing to the average intensity at " + "similar diffraction angle, \npixels with intensity larger than" + " avg_int*high will be masked" + ), ) avgmasklow = DelegatesTo( "srxconfig", - desc=("Comparing to the average intensity at " - "similar diffraction angle, \npixels with intensity less than " - "avg_int*low will be masked"), + desc=( + "Comparing to the average intensity at " + "similar diffraction angle, \npixels with intensity less than " + "avg_int*low will be masked" + ), ) cropedges = DelegatesTo( "srxconfig", - desc=("The number of pixels masked" - " at each edge (left, right, top, bottom)"), + desc=( + "The number of pixels masked" + " at each edge (left, right, top, bottom)" + ), ) def createPlot(self): @@ -231,7 +243,7 @@ def addPointMask(self, ndx, remove=None): """Param ndx -- (x,y) float.""" x, y = ndx r = self.pts - np.array((x, y)) - r = np.sum(r ** 2, axis=1) + r = np.sum(r**2, axis=1) mask = r < ((self.pointmaskradius + 1) ** 2) mask = mask.reshape(self.staticmask.shape) if remove: @@ -318,9 +330,11 @@ def _enableMaskEditing(self): self.plot.tools.remove(self.pan) self.plot.overlays.append(self.lstool) self.titlebak = self.plot.title - self.plot.title = ("Click: add a vertex; " - "+Click: remove a vertex; \n " - ": finish the selection") + self.plot.title = ( + "Click: add a vertex; " + "+Click: remove a vertex; \n " + ": finish the selection" + ) return def _disableMaskEditing(self): diff --git a/src/diffpy/srxplanargui/version.py b/src/diffpy/srxplanargui/version.py index 699afaa..189f673 100644 --- a/src/diffpy/srxplanargui/version.py +++ b/src/diffpy/srxplanargui/version.py @@ -1,10 +1,10 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2012-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Rundong Hua, Simon Billinge, Billinge Group members. +# File coded by: Xiaohao Yang, Simon Billinge, Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. # https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors # noqa: E501 From 3b68bab0d41185bd0e74ac373d5fba9a05f171e8 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 7 Oct 2025 16:17:23 -0400 Subject: [PATCH 4/4] skpkg: change author and contributor --- src/diffpy/srxplanargui/__init__.py | 2 +- src/diffpy/srxplanargui/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffpy/srxplanargui/__init__.py b/src/diffpy/srxplanargui/__init__.py index aaf3e55..66f2325 100644 --- a/src/diffpy/srxplanargui/__init__.py +++ b/src/diffpy/srxplanargui/__init__.py @@ -4,7 +4,7 @@ # (c) 2012-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Xiaohao Yang, Simon Billinge, Billinge Group members. +# File coded by: Xiaohao Yang, Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. # https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors diff --git a/src/diffpy/srxplanargui/version.py b/src/diffpy/srxplanargui/version.py index 189f673..d278817 100644 --- a/src/diffpy/srxplanargui/version.py +++ b/src/diffpy/srxplanargui/version.py @@ -4,7 +4,7 @@ # (c) 2012-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Xiaohao Yang, Simon Billinge, Billinge Group members. +# File coded by: Xiaohao Yang, Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. # https://github.com/diffpy/diffpy.srxplanargui/graphs/contributors # noqa: E501