diff --git a/.codecov.yml b/.codecov.yml index 86671410..04dd6510 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,2 +1,34 @@ -fixes: - - ".*/site-packages/::src/" +# codecov can find this file anywhere in the repo, so we don't need to clutter +# the root folder. +#comment: false + +codecov: + notify: + require_ci_to_pass: no + +coverage: + status: + patch: + default: + target: '70' + if_no_uploads: error + if_not_found: success + if_ci_failed: failure + project: + default: false + library: + target: auto + if_no_uploads: error + if_not_found: success + if_ci_failed: error + paths: '!*/tests/.*' + + tests: + target: 97.9% + paths: '*/tests/.*' + if_not_found: success + +flags: + tests: + paths: + - tests/ diff --git a/.coveragerc b/.coveragerc index 63f0ec9c..77556cdf 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,22 +1,13 @@ -# Configuration of the coverage.py tool for reporting test coverage. - -[report] -# RE patterns for lines to be excluded from consideration. -exclude_lines = - # Have to re-enable the standard pragma - pragma: no cover - # Don't complain if tests don't hit defensive assertion code: - raise AssertionError - raise NotImplementedError - ^[ ]*assert False - - # Don't complain if non-runnable code isn't run: - ^[ ]*@unittest.skip\b - ^[ ]{4}unittest.main() - if __name__ == .__main__.: - - [run] +source = + diffpy.pdfgui +[report] omit = - # exclude debug.py from codecov report - */tests/debug.py + */python?.?/* + */site-packages/nose/* + # ignore _version.py and versioneer.py + .*version.* + *_version.py + +exclude_lines = + if __name__ == '__main__': diff --git a/.gitattributes b/.gitattributes index 9d58a8cd..0caa8f9f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1 @@ -/.gitattributes export-ignore -/.gitignore export-ignore -/.travis.yml export-ignore -/conda-recipe/ export-ignore -/devutils export-ignore -.gitarchive.cfg export-subst -*.bat text eol=crlf +diffpy.pdfgui/_version.py export-subst diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3ade008..80bbfb71 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,31 +23,32 @@ jobs: path: . fetch-depth: 0 # avoid shallow clone with no tags - - name: Install Mamba - run: | - wget "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh" -O mambaforge.sh - bash mambaforge.sh -b -p $HOME/mambaforge - echo "$HOME/mambaforge/bin" >> $GITHUB_PATH - source $HOME/mambaforge/etc/profile.d/conda.sh - conda init bash + - name: initialize miniconda + # this uses a marketplace action that sets up miniconda in a way that makes + # it easier to use. I tried setting it up without this and it was a pain + uses: conda-incubator/setup-miniconda@v2 + with: + activate-environment: test + # environment.yml file is needed by this action. Because I don't want + # maintain this but rather maintain the requirements files it just has + # basic things in it like conda and pip + environment-file: ./environment.yml + python-version: 3 + auto-activate-base: false - - name: Create conda environment + - name: install diffpy.pdfgui requirements + shell: bash -l {0} run: | - source $HOME/mambaforge/etc/profile.d/conda.sh - conda create -n test_env python=3.12 xonsh regolith -c conda-forge -y - conda activate test_env - pip install case_insensitive_dict - - - name: Install dependencies + conda config --set always_yes yes --set changeps1 no + conda config --add channels conda-forge + conda activate test + conda install --file requirements/run.txt + conda install --file requirements/test.txt + pip install . + - name: Validate diffpy.pdfgui + shell: bash -l {0} run: | - source $HOME/mambaforge/etc/profile.d/conda.sh - conda activate test_env - mamba install --file requirements/run.txt - mamba install --file requirements/test.txt - pip install -e . - - - name: Use Xvfb Action - uses: GabrielBB/xvfb-action@v1 - with: - run: | - bash -c "source $HOME/mambaforge/etc/profile.d/conda.sh && conda activate test_env && python -m run_tests.py" + conda activate test + coverage run -m pytest -vv -s + coverage report -m + codecov diff --git a/.gitignore b/.gitignore index b1f18e26..a25212ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,99 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ *.py[cod] +*$py.class # C extensions *.so -# Packages -*.egg -*.egg-info -dist -build -eggs -parts -bin -var -sdist -temp -develop-eggs +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +venv/ +*.egg-info/ .installed.cfg -lib -lib64 -tags +*.egg +bin/ +temp/ +tags/ errors.err -.idea + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec # Installer logs pip-log.txt +pip-delete-this-directory.txt MANIFEST # Unit test / coverage reports +htmlcov/ +.tox/ .coverage -.tox +.coverage.* +.cache nosetests.xml +coverage.xml +*,cover +.hypothesis/ # Translations *.mo +*.pot # Mr Developer .mr.developer.cfg .project .pydevproject +# Django stuff: +*.log + +# Sphinx documentation +docs/build/ +docs/source/generated/ + +# pytest +.pytest_cache/ + +# PyBuilder +target/ + +# Editor files +# mac +.DS_Store +*~ + +# vim +*.swp +*.swo + +# pycharm +.idea/ + +# VSCode +.vscode/ + +# Ipython Notebook +.ipynb_checkpoints + # version information setup.cfg /src/diffpy/*/version.cfg + +# Rever +rever/ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fc5d6241..4280491e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,6 @@ -========================= -Diffpy.pdfgui Change Log -========================= +============= +Release Notes +============= .. current developments diff --git a/MANIFEST.in b/MANIFEST.in index ddcda5e8..85df1efd 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,23 +1,14 @@ -recursive-include src * -recursive-exclude src *.py[co] -include AUTHORS.txt LICENSE*.txt README* -recursive-include doc * -prune doc/epydoc -prune doc/manual/images/originals -exclude doc/manual/images/*.pdf -recursive-exclude doc/manual Makefile *.py *.texinfo -recursive-exclude doc/manual *.aux *.cp *.cps *.err *.log *.toc *.vr *.vrs -recursive-include icons *.png *.ico -recursive-exclude icons *.m *.xcf -global-exclude .gitattributes .gitignore .gitarchive.cfg -global-exclude .DS_Store +include AUTHORS.rst +include LICENSE +include README.rst +include requirements.txt -# Avoid user content in setup.cfg to make distribution reproducible. -exclude setup.cfg +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] -# Exclude git-tracked files spuriously added by setuptools_scm -exclude .coveragerc -exclude .travis* -prune conda-recipe -prune devutils -#prune doc +recursive-include docs *.rst conf.py Makefile make.bat + +include diffpy.pdfgui/version.py + +# If including data files in the package, add them like: +# include path/to/data_file diff --git a/README.rst b/README.rst index bb30e2e4..809d4f3c 100644 --- a/README.rst +++ b/README.rst @@ -1,11 +1,41 @@ -.. image:: https://travis-ci.org/diffpy/diffpy.pdfgui.svg?branch=master - :target: https://travis-ci.org/diffpy/diffpy.pdfgui +|Icon| |title|_ +=============== -.. image:: https://codecov.io/gh/diffpy/diffpy.pdfgui/branch/master/graph/badge.svg - :target: https://codecov.io/gh/diffpy/diffpy.pdfgui +.. |title| replace:: diffpy.pdfgui +.. _title: https://diffpy.github.io/diffpy.pdfgui +.. |Icon| image:: https://avatars.githubusercontent.com/diffpy + :target: https://diffpy.github.io/diffpy.pdfgui + :height: 100px -PDFgui +|PyPi| |Forge| |PythonVersion| |PR| + +|CI| |Codecov| |Black| |Tracking| + +.. |Black| image:: https://img.shields.io/badge/code_style-black-black + :target: https://github.com/psf/black + +.. |CI| image:: https://github.com/diffpy/diffpy.pdfgui/actions/workflows/main.yml/badge.svg + :target: https://github.com/diffpy/diffpy.pdfgui/actions/workflows/main.yml + +.. |Codecov| image:: https://codecov.io/gh/diffpy/diffpy.pdfgui/branch/main/graph/badge.svg + :target: https://codecov.io/gh/diffpy/diffpy.pdfgui + +.. |Forge| image:: https://img.shields.io/conda/vn/conda-forge/diffpy.pdfgui + :target: https://anaconda.org/conda-forge/diffpy.pdfgui + +.. |PR| image:: https://img.shields.io/badge/PR-Welcome-29ab47ff + +.. |PyPi| image:: https://img.shields.io/pypi/v/diffpy.pdfgui + :target: https://pypi.org/project/diffpy.pdfgui/ + +.. |PythonVersion| image:: https://img.shields.io/pypi/pyversions/diffpy.pdfgui + :target: https://pypi.org/project/diffpy.pdfgui/ + +.. |Tracking| image:: https://img.shields.io/badge/issue_tracking-github-blue + :target: https://github.com/diffpy/diffpy.pdfgui/issues + +diffpy.pdfgui ======================================================================== Graphical user interface program for structure refinements to atomic @@ -43,101 +73,76 @@ possible for it to read .ddp files that were saved by the Python2 PDFgui but it will sometimes fail to read these. We are working on a solution that will be available in a future version. -INSTALLATION ------------------------------------------------------------------------- - -The preferred method is to use Anaconda Python and install from the -"conda-forge" channel of Anaconda packages. `pdfgui` can be installed with `conda` :: - - conda install -c conda-forge diffpy.pdfgui - -PDFgui can be then started from a terminal ("Anaconda Prompt" on -Windows) by executing the "pdfgui" program. An alternative -method on Windows is to start PDFgui through the DiffPy start menu. - -If you don't use Anaconda or prefer to install from sources, make -sure the required software is all in place :: + diffpy.pdfgui Package, https://github.com/diffpy/diffpy.pdfgui - conda install -c conda-forge diffpy.utils diffpy.pdffit2 matplotlib wxpython +Installation +------------ -Then you are ready to install diffpy.pdfgui from source codes:: +The preferred method is to use `Miniconda Python +`_ +and install from the "conda-forge" channel of Conda packages. - python setup.py install +To add "conda-forge" to the conda channels, run the following in a terminal. :: -By default the files are installed to standard system directories, -which may require the use of ``sudo`` for write privileges. If -administrator (root) access is not available, see the output from -``python setup.py install --help`` for options to install as a regular -user to user-writable locations. Note that installation to non-standard -directories may require adjustments to the PATH and PYTHONPATH -environment variables. The installation integrity can be verified by -changing to the HOME directory and running :: + conda config --add channels conda-forge - python -m diffpy.pdfgui.tests.rundeps +We want to install our packages in a suitable conda environment. +The following creates and activates a new environment named ``diffpy.pdfgui_env`` :: -To use PDFgui, you can simply type `pdfgui`, or run the following command :: + conda create -n diffpy.pdfgui_env python=3 + conda activate diffpy.pdfgui_env - python diffpy.pdfgui/src/diffpy/pdfgui/application/pdfgui.py +Then, to fully install ``diffpy.pdfgui`` in our active environment, run :: -If it shows some error like "This program needs access to the screen.". For Mac, you could install `python.app` from conda -(`conda install python.app`), then run as follows :: + conda install diffpy.pdfgui - python.app diffpy.pdfgui/src/diffpy/pdfgui/application/pdfgui.py +Another option is to use ``pip`` to download and install the latest release from +`Python Package Index `_. +To install using ``pip`` into your ``diffpy.pdfgui_env`` environment, we will also have to install dependencies :: -With Anaconda PDFgui can be later upgraded to the latest released -version using :: + pip install -r https://raw.githubusercontent.com/diffpy/diffpy.pdfgui/main/requirements/run.txt - conda update -c conda-forge diffpy.pdfgui +and then install the package :: -With other Python distributions the program can be upgraded to -the latest version as follows :: + pip install diffpy.pdfgui - easy_install --upgrade diffpy.pdfgui +If you prefer to install from sources, after installing the dependencies, obtain the source archive from +`GitHub `_. Once installed, ``cd`` into your ``diffpy.pdfgui`` directory +and run the following :: -If you would like to use other Python distributions except Anaconda, -it is necessary to install the required software separately. As an -example, on Ubuntu Linux some of the required software can be -installed using :: + pip install . - sudo apt-get install \ - python-setuptools python-wxtools python-numpy \ - python-matplotlib +Support and Contribute +---------------------- -To install the remaining packages see the installation instructions -at their respective web pages. +`Diffpy user group `_ is the discussion forum for general questions and discussions about the use of diffpy.pdfgui. Please join the diffpy.pdfgui users community by joining the Google group. The diffpy.pdfgui project welcomes your expertise and enthusiasm! -Other software -```````````````````````````````````````````````````````````````````````` +If you see a bug or want to request a feature, please `report it as an issue `_ and/or `submit a fix as a PR `_. You can also post it to the `Diffpy user group `_. -PDFgui can use an external structure viewer for displaying analyzed -structures. We have tested with several structure viewers such as +Feel free to fork the project and contribute. To install diffpy.pdfgui +in a development mode, with its sources being directly used by Python +rather than copied to a package directory, use the following in the root +directory :: -* AtomEye, http://li.mit.edu/A/Graphics/A/ -* PyMol, https://www.pymol.org -* VESTA, http://jp-minerals.org/vesta/en/ + pip install -e . -Other viewers should work as well, as long as they understand one of -the output structure formats supported by PDFgui. +To ensure code quality and to prevent accidental commits into the default branch, please set up the use of our pre-commit +hooks. +1. Install pre-commit in your working environment by running ``conda install pre-commit``. -DEVELOPMENT ------------------------------------------------------------------------- - -PDFgui is an open-source software available in a git repository at -https://github.com/diffpy/diffpy.pdfgui. - -Feel free to fork the project and contribute. To install PDFgui -in a development mode where the source files are used directly -rather than copied to a system directory, use :: +2. Initialize pre-commit (one time only) ``pre-commit install``. - python setup.py develop --user +Thereafter your code will be linted by black and isort and checked against flake8 before you can commit. +If it fails by black or isort, just rerun and it should pass (black and isort will modify the files so should +pass after they are modified). If the flake8 test fails please see the error messages and fix them manually before +trying to commit again. +Improvements and fixes are always appreciated. -CONTACTS ------------------------------------------------------------------------- - -For more information on PDFgui please visit the project web-page: +Before contribuing, please read our `Code of Conduct `_. -https://www.diffpy.org/products/pdfgui.html +Contact +------- -or email Prof. Simon Billinge at sb2896@columbia.edu +For more information on diffpy.pdfgui please visit the project `web-page `_ or email Prof. Simon Billinge at sb2896@columbia.edu. diff --git a/pyproject.toml b/pyproject.toml index e537e24a..273ea25e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,52 @@ +[build-system] +requires = ["setuptools>=62.0", "setuptools-git-versioning<2"] +build-backend = "setuptools.build_meta" + +[project] +name = "diffpy.pdfgui" +dynamic=['version'] +authors = [ + { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" }, +] +maintainers = [ + { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" }, +] +description = "GUI for PDF simulation and structure refinement." +keywords = ['PDF structure refinement GUI'] +readme = "README.rst" +requires-python = ">=3.10" +classifiers = [ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: BSD License', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: Unix', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Topic :: Scientific/Engineering :: Physics', + 'Topic :: Scientific/Engineering :: Chemistry', +] + +[project.urls] +Homepage = "https://github.com/diffpy/diffpy.pdfgui/" +Issues = "https://github.com/diffpy/diffpy.pdfgui/issues/" + +[tool.setuptools-git-versioning] +enabled = true +template = "{tag}" +dev_template = "{tag}" +dirty_template = "{tag}" + +[tool.setuptools.packages.find] +where = ["src"] # list of folders that contain the packages (["."] by default) +include = ["*"] # package names should match these glob patterns (["*"] by default) +exclude = ["diffpy.pdfgui.tests*"] # exclude packages matching these glob patterns (empty by default) +namespaces = false # to disable scanning PEP 420 namespaces (true by default) + [tool.black] line-length = 115 include = '\.pyi?$' diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..87226211 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = test*.py diff --git a/requirements/run.txt b/requirements/run.txt index 1bad6988..23796adc 100644 --- a/requirements/run.txt +++ b/requirements/run.txt @@ -1,5 +1,6 @@ -numpy==1.26 -wxpython -diffpy.pdffit2 -diffpy.utils -matplotlib-base +importlib_resources +numpy<2.0 +wxpython +diffpy.pdffit2 +diffpy.utils +matplotlib-base diff --git a/setup.py b/setup.py deleted file mode 100755 index 1738fd08..00000000 --- a/setup.py +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env python - -# Installation script for diffpy.pdfgui - -"""PDFgui - graphical user interface for real space structure refinement. - -Packages: diffpy.pdfgui -Scripts: pdfgui -""" - -import os -import re -import sys - -from setuptools import find_packages, setup - -# Use this version when git data are not available, like in git zip archive. -# Update when tagging a new release. -FALLBACK_VERSION = "2.0.4" - -# determine if we run with Python 3. -PY3 = sys.version_info[0] == 3 - -# versioncfgfile holds version data for git commit hash and date. -# It must reside in the same directory as version.py. -MYDIR = os.path.dirname(os.path.abspath(__file__)) -versioncfgfile = os.path.join(MYDIR, "src/diffpy/pdfgui/version.cfg") -gitarchivecfgfile = os.path.join(MYDIR, ".gitarchive.cfg") - - -def gitinfo(): - from subprocess import PIPE, Popen - - kw = dict(stdout=PIPE, cwd=MYDIR, universal_newlines=True) - proc = Popen(["git", "describe", "--tags", "--match=v[[:digit:]]*"], **kw) - desc = proc.stdout.read() - proc = Popen(["git", "log", "-1", "--format=%H %ct %ci"], **kw) - glog = proc.stdout.read() - rv = {} - rv["version"] = ".post".join(desc.strip().split("-")[:2]).lstrip("v") - rv["commit"], rv["timestamp"], rv["date"] = glog.strip().split(None, 2) - return rv - - -def getversioncfg(): - if PY3: - from configparser import RawConfigParser - else: - from ConfigParser import RawConfigParser - vd0 = dict(version=FALLBACK_VERSION, commit="", date="", timestamp=0) - # first fetch data from gitarchivecfgfile, ignore if it is unexpanded - g = vd0.copy() - cp0 = RawConfigParser(vd0) - cp0.read(gitarchivecfgfile) - if len(cp0.get("DEFAULT", "commit")) > 20: - g = cp0.defaults() - mx = re.search(r"\btag: v(\d[^,]*)", g.pop("refnames")) - if mx: - g["version"] = mx.group(1) - # then try to obtain version data from git. - gitdir = os.path.join(MYDIR, ".git") - if os.path.exists(gitdir) or "GIT_DIR" in os.environ: - try: - g = gitinfo() - except OSError: - pass - # finally, check and update the active version file - cp = RawConfigParser() - cp.read(versioncfgfile) - d = cp.defaults() - rewrite = not d or (g["commit"] and (g["version"] != d.get("version") or g["commit"] != d.get("commit"))) - if rewrite: - cp.set("DEFAULT", "version", g["version"]) - cp.set("DEFAULT", "commit", g["commit"]) - cp.set("DEFAULT", "date", g["date"]) - cp.set("DEFAULT", "timestamp", g["timestamp"]) - with open(versioncfgfile, "w") as fp: - cp.write(fp) - return cp - - -versiondata = getversioncfg() - - -def dirglob(d, *patterns): - from glob import glob - - rv = [] - for p in patterns: - rv += glob(os.path.join(d, p)) - return rv - - -with open(os.path.join(MYDIR, "README.rst")) as fp: - long_description = fp.read() - -# define distribution -setup_args = dict( - name="diffpy.pdfgui", - version="3.0.5", - packages=find_packages(os.path.join(MYDIR, "src")), - package_dir={"": "src"}, - include_package_data=True, - test_suite="diffpy.pdfgui.tests", - entry_points={ - "gui_scripts": [ - "pdfgui=diffpy.pdfgui.applications.pdfgui:main", - ], - }, - data_files=[ - ("icons", dirglob("icons", "*.png", "*.ico")), - ("doc", dirglob("doc", "*.pdf")), - ("doc/manual", dirglob("doc/manual", "*.html", "*.pdf")), - ("doc/manual/images", dirglob("doc/manual/images", "*.png")), - ("doc/tutorial", dirglob("doc/tutorial", "*")), - ], - # manual and tutorial files should not be zipped - zip_safe=False, - install_requires=[ - "six", - "diffpy.structure>=3", - "diffpy.pdffit2", - "diffpy.utils", - ], - author="Simon J.L. Billinge", - author_email="sb2896@columbia.edu", - maintainer="Pavol Juhas", - maintainer_email="pavol.juhas@gmail.com", - url="https://github.com/diffpy/diffpy.pdfgui", - description="GUI for PDF simulation and structure refinement.", - long_description=long_description, - long_description_content_type="text/x-rst", - license="BSD", - keywords="PDF structure refinement GUI", - classifiers=[ - # List of possible values at - # http://pypi.python.org/pypi?:action=list_classifiers - "Development Status :: 5 - Production/Stable", - "Environment :: MacOS X", - "Environment :: Win32 (MS Windows)", - "Environment :: X11 Applications", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Operating System :: MacOS", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.10", - "Topic :: Scientific/Engineering :: Chemistry", - "Topic :: Scientific/Engineering :: Physics", - ], -) - -if __name__ == "__main__": - setup(**setup_args) - -# End of file diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index 50128bcc..42bc4ce3 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,15 +1,16 @@ #!/usr/bin/env python ############################################################################## # -# diffpy by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2008 trustees of the Michigan State University. -# All rights reserved. +# (c) 2008 trustees of the Michigan State University. +# (c) 2024 The Trustees of Columbia University in the City of New York. +# All rights reserved. # -# File coded by: Pavol Juhas +# 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.pdfgui/graphs/contributors +# +# See LICENSE.rst for license information. # ############################################################################## @@ -23,5 +24,4 @@ __path__ = extend_path(__path__, __name__) - # End of file diff --git a/src/diffpy/pdfgui/__init__.py b/src/diffpy/pdfgui/__init__.py index c12002ca..a78889bc 100644 --- a/src/diffpy/pdfgui/__init__.py +++ b/src/diffpy/pdfgui/__init__.py @@ -1,23 +1,22 @@ #!/usr/bin/env python ############################################################################## # -# diffpy.pdfgui by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2006 trustees of the Michigan State University. -# All rights reserved. +# (c) 2006 trustees of the Michigan State University. +# (c) 2024 The Trustees of Columbia University in the City of New York. +# All rights reserved. # -# File coded by: Pavol Juhas +# 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.pdfgui/graphs/contributors +# +# See LICENSE.rst for license information. # ############################################################################## -"""Constants: - __version__ -- full version of this PDFgui release -""" - +"""GUI for PDF simulation and structure refinement.""" +# package version from diffpy.pdfgui.version import __version__ # silence the pyflakes syntax checker diff --git a/src/diffpy/pdfgui/control/fitdataset.py b/src/diffpy/pdfgui/control/fitdataset.py index eb3d6a80..8b60f3eb 100644 --- a/src/diffpy/pdfgui/control/fitdataset.py +++ b/src/diffpy/pdfgui/control/fitdataset.py @@ -783,10 +783,10 @@ def grid_interpolation(x0, y0, x1, youtleft=0.0, youtright=0.0): Return numpy.array of interpolated y1 values. """ - x0 = numpy.array(x0, copy=False, dtype=float) - y0 = numpy.array(y0, copy=False, dtype=float) + x0 = numpy.asarray(x0, dtype=float) + y0 = numpy.asarray(y0, dtype=float) n0 = len(x0) - x1 = numpy.array(x1, copy=False, dtype=float) + x1 = numpy.asarray(x1, dtype=float) n1 = len(x1) y1 = youtright * numpy.ones(n1, dtype=float) if n0: diff --git a/src/diffpy/pdfgui/control/pdfguicontrol.py b/src/diffpy/pdfgui/control/pdfguicontrol.py index c6619417..06694d98 100644 --- a/src/diffpy/pdfgui/control/pdfguicontrol.py +++ b/src/diffpy/pdfgui/control/pdfguicontrol.py @@ -89,7 +89,7 @@ def run(self): def startQueue(self): """start queue manager""" - self.queueManager.setDaemon(True) + self.queueManager.ddaemon = True self.queueManager.start() def checkQueue(self): diff --git a/src/diffpy/pdfgui/gui/aboutdialog.py b/src/diffpy/pdfgui/gui/aboutdialog.py index 51012e01..03de2ced 100644 --- a/src/diffpy/pdfgui/gui/aboutdialog.py +++ b/src/diffpy/pdfgui/gui/aboutdialog.py @@ -21,7 +21,7 @@ import wx.lib.agw.hyperlink from diffpy.pdfgui.gui.pdfguiglobals import iconpath -from diffpy.pdfgui.version import __date__, __version__ +from diffpy.pdfgui.version import __version__, __year__ _acknowledgement = """\ This software was developed by the Billinge-group as part of the Distributed @@ -42,7 +42,7 @@ computer programs for studying nanostructure in crystals, J. Phys.: Condens. Matter 19, 335219 (2007).""" -_copyright = "(c) 2005-{year},".format(year=__date__[:4]) +_copyright = "(c) 2005-{year},".format(year=__year__) _homepage = "https://www.diffpy.org" diff --git a/src/diffpy/pdfgui/gui/extendedplotframe.py b/src/diffpy/pdfgui/gui/extendedplotframe.py index 297a7670..a1a052a8 100644 --- a/src/diffpy/pdfgui/gui/extendedplotframe.py +++ b/src/diffpy/pdfgui/gui/extendedplotframe.py @@ -183,8 +183,11 @@ def insertCurve(self, xData, yData, style): return: internal reference to the newly added curve """ stylestr, properties = self.__translateStyles(style) - curveRef = self.subplot.plot(xData, yData, stylestr, **properties)[0] - self.subplot.legend(**legendBoxProperties()) + if stylestr == "": # blank stylestring throws warning for duplicated information + curveRef = self.subplot.plot(xData, yData, **properties)[0] + else: + curveRef = self.subplot.plot(xData, yData, stylestr, **properties)[0] + self.subplot.legend([], **legendBoxProperties()) # add blank list argument to prevent warning try: self.datalims[curveRef] = (min(xData), max(xData), min(yData), max(yData)) except ValueError: @@ -314,7 +317,7 @@ def __translateStyles(self, style): # not 'points', so line properties are required as well lineStyle = lineStyleDict.get(style["line"], "-") # prefer solid lineWidth = style["width"] - stylestr += lineStyle + # stylestr += lineStyle # no need to add lineStyle to stylestr when in properties properties.update({"color": color, "linestyle": lineStyle, "linewidth": lineWidth}) if "legend" in style: diff --git a/src/diffpy/pdfgui/gui/pdfguiglobals.py b/src/diffpy/pdfgui/gui/pdfguiglobals.py index 96f20538..fc5f5e57 100644 --- a/src/diffpy/pdfgui/gui/pdfguiglobals.py +++ b/src/diffpy/pdfgui/gui/pdfguiglobals.py @@ -17,7 +17,7 @@ import os.path -from pkg_resources import Requirement, resource_filename +from importlib_resources import as_file, files from diffpy.pdfgui.gui import debugoptions @@ -31,14 +31,15 @@ isAltered = False # Resolve APPDATADIR base path to application data files. -_mydir = os.path.abspath(resource_filename(__name__, "")) -_upbasedir = os.path.normpath(_mydir + "/../../..") -_development_mode = os.path.basename(_upbasedir) == "src" and os.path.isfile( - os.path.join(_upbasedir, "../setup.py") -) +with as_file(files(__name__)) as file: + _mydir = os.path.abspath(file) + _upbasedir = os.path.normpath(_mydir + "/../../..") + _development_mode = os.path.basename(_upbasedir) == "src" and os.path.isfile( + os.path.join(_upbasedir, "../setup.py") + ) # Requirement must have egg-info. Do not use in _development_mode. -_req = Requirement.parse("diffpy.pdfgui") +_req = "diffpy.pdfgui" # pavol # APPDATADIR = (os.path.dirname(_upbasedir) if _development_mode @@ -47,9 +48,11 @@ if _development_mode: APPDATADIR = os.path.dirname(_mydir) else: - APPDATADIR = os.path.join(resource_filename(_req, ""), "diffpy/pdfgui") + with as_file(files(_req)) as file: + APPDATADIR = os.path.join(file, "") APPDATADIR = os.path.abspath(APPDATADIR) +print(APPDATADIR) # Location of the HTML manual docMainFile = os.path.join(APPDATADIR, "doc/manual/pdfgui.html") diff --git a/src/diffpy/pdfgui/tests/__init__.py b/src/diffpy/pdfgui/tests/__init__.py index 863e9949..a0a02efa 100644 --- a/src/diffpy/pdfgui/tests/__init__.py +++ b/src/diffpy/pdfgui/tests/__init__.py @@ -38,31 +38,32 @@ def testsuite(pattern=""): from itertools import chain from os.path import dirname - from pkg_resources import resource_filename + from importlib_resources import as_file, files loader = unittest.defaultTestLoader - thisdir = resource_filename(__name__, "") - depth = __name__.count(".") + 1 - topdir = thisdir - for i in range(depth): - topdir = dirname(topdir) - suite_all = loader.discover(thisdir, top_level_dir=topdir) - # always filter the suite by pattern to test-cover the selection code. - suite = unittest.TestSuite() - rx = re.compile(pattern) - tsuites = list(chain.from_iterable(suite_all)) - tsok = all(isinstance(ts, unittest.TestSuite) for ts in tsuites) - if not tsok: # pragma: no cover - return suite_all - tcases = chain.from_iterable(tsuites) - for tc in tcases: - tcwords = tc.id().split(".") - shortname = ".".join(tcwords[-3:]) - if rx.search(shortname): - suite.addTest(tc) - # verify all tests are found for an empty pattern. - assert pattern or suite_all.countTestCases() == suite.countTestCases() - return suite + ref = files(__name__) + with as_file(ref) as thisdir: + depth = __name__.count(".") + 1 + topdir = thisdir + for i in range(depth): + topdir = dirname(topdir) + suite_all = loader.discover(thisdir, top_level_dir=topdir) + # always filter the suite by pattern to test-cover the selection code. + suite = unittest.TestSuite() + rx = re.compile(pattern) + tsuites = list(chain.from_iterable(suite_all)) + tsok = all(isinstance(ts, unittest.TestSuite) for ts in tsuites) + if not tsok: # pragma: no cover + return suite_all + tcases = chain.from_iterable(tsuites) + for tc in tcases: + tcwords = tc.id().split(".") + shortname = ".".join(tcwords[-3:]) + if rx.search(shortname): + suite.addTest(tc) + # verify all tests are found for an empty pattern. + assert pattern or suite_all.countTestCases() == suite.countTestCases() + return suite def test(): diff --git a/src/diffpy/pdfgui/version.py b/src/diffpy/pdfgui/version.py index 416dcb46..f05e9201 100644 --- a/src/diffpy/pdfgui/version.py +++ b/src/diffpy/pdfgui/version.py @@ -1,54 +1,33 @@ #!/usr/bin/env python ############################################################################## # -# PDFgui by DANSE Diffraction group -# Simon J. L. Billinge -# (c) 2008 trustees of the Michigan State University. -# All rights reserved. +# (c) 2008 trustees of the Michigan State University. +# (c) 2024 The Trustees of Columbia University in the City of New York. +# All rights reserved. # -# File coded by: Pavol Juhas +# 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.pdfgui/graphs/contributors +# +# See LICENSE.rst for license information. # ############################################################################## -""" -Definition of __version__, __date__, __timestamp__, __git_commit__. - -Notes ------ -Variable `__gitsha__` is deprecated as of version 1.2. -Use `__git_commit__` instead. -""" - -__all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"] - -import os.path - -from pkg_resources import resource_filename - -# obtain version information from the version.cfg file -cp = dict(version="", date="", commit="", timestamp="0") -fcfg = resource_filename(__name__, "version.cfg") -if not os.path.isfile(fcfg): # pragma: no cover - from warnings import warn +"""Definition of __version__.""" - warn('Package metadata not found, execute "./setup.py egg_info".') - fcfg = os.devnull -with open(fcfg) as fp: - kwords = [[w.strip() for w in line.split(" = ", 1)] for line in fp if line[:1].isalpha() and " = " in line] -assert all(w[0] in cp for w in kwords), "received unrecognized keyword" -cp.update(kwords) +# We do not use the other three variables, but can be added back if needed. +# __all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"] -__version__ = cp["version"] -__date__ = cp["date"] -__git_commit__ = cp["commit"] -__timestamp__ = int(cp["timestamp"]) +# from importlib_resources import files, as_file +import os +import time -# TODO remove deprecated __gitsha__ in version 1.3. -__gitsha__ = __git_commit__ +# obtain version information +from importlib.metadata import distribution, version -del cp, fcfg, fp, kwords +# with as_file(distribution("diffpy.pdfgui")) as file: +__year__ = time.ctime(os.path.getctime(distribution("diffpy.pdfgui")._path))[-4:] +__version__ = version("diffpy.pdfgui") # End of file