diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..88077af --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +# As of now, flake8 does not natively support configuration via pyproject.toml +# https://github.com/microsoft/vscode-flake8/issues/135 +[flake8] +exclude = + .git, + __pycache__, + build, + dist, + docs/source/conf.py +max-line-length = 79 +# Ignore some style 'errors' produced while formatting by 'black' +# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings +extend-ignore = E203 diff --git a/.gitignore b/.gitignore index bcd8ba5..1be1fdf 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,4 @@ setup.cfg /DistancePrinter/gitarchive.cfg # test output -actual.res \ No newline at end of file +actual.res diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..86f162b --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,5 @@ +[settings] +# Keep import statement below line_length character limit +line_length = 79 +multi_line_output = 3 +include_trailing_comma = True diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0e4a84d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,66 @@ +default_language_version: + python: python3 +ci: + autofix_commit_msg: | + [pre-commit.ci] auto fixes from pre-commit hooks + autofix_prs: true + autoupdate_branch: "pre-commit-autoupdate" + autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate" + autoupdate_schedule: monthly + skip: [no-commit-to-branch] + submodules: false +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-case-conflict + - id: check-merge-conflict + - id: check-toml + - id: check-added-large-files + - repo: https://github.com/psf/black + rev: 24.4.2 + hooks: + - id: black + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + args: ["--profile", "black"] + - repo: https://github.com/kynan/nbstripout + rev: 0.7.1 + hooks: + - id: nbstripout + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: no-commit-to-branch + name: Prevent Commit to Main Branch + args: ["--branch", "main"] + stages: [pre-commit] + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + additional_dependencies: + - tomli + # prettier - multi formatter for .json, .yml, and .md files + - repo: https://github.com/pre-commit/mirrors-prettier + rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8 + hooks: + - id: prettier + additional_dependencies: + - "prettier@^3.2.4" + # docformatter - PEP 257 compliant docstring formatter + - repo: https://github.com/s-weigand/docformatter + rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c + hooks: + - id: docformatter + additional_dependencies: [tomli] + args: [--in-place, --config, ./pyproject.toml] diff --git a/AUTHORS.txt b/AUTHORS.txt index f0671d8..e36df7d 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -1 +1 @@ -Xiaohao Yang \ No newline at end of file +Xiaohao Yang diff --git a/MANIFEST.in b/MANIFEST.in index 35a5d8c..0ecc683 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ recursive-include DistancePrinter * prune doc -exclude MANIFEST.in \ No newline at end of file +exclude MANIFEST.in diff --git a/README.rst b/README.rst index 0e636ba..15b7d2a 100644 --- a/README.rst +++ b/README.rst @@ -18,10 +18,10 @@ To install the DistancePrinter package: python setup.py install -By default the files are installed in the system directories, which are -usually only writeable by the root. See the usage info "./setup.py install ---help" for options to install as a normal user under a different location. -Note that installation to non-standard directories you may require adjustments +By default the files are installed in the system directories, which are +usually only writeable by the root. See the usage info "./setup.py install +--help" for options to install as a normal user under a different location. +Note that installation to non-standard directories you may require adjustments to the PATH and PYTHONPATH environment variables. CONTACTS diff --git a/src/diffpy/distanceprinter/__init__.py b/src/diffpy/distanceprinter/__init__.py index 72d8855..57b5f4d 100644 --- a/src/diffpy/distanceprinter/__init__.py +++ b/src/diffpy/distanceprinter/__init__.py @@ -12,9 +12,7 @@ # ############################################################################## -""" -Blank namespace package. -""" +"""Blank namespace package.""" __import__("pkg_resources").declare_namespace(__name__) diff --git a/src/diffpy/distanceprinter/distanceprinter.py b/src/diffpy/distanceprinter/distanceprinter.py index daeaaf1..5dcd81f 100644 --- a/src/diffpy/distanceprinter/distanceprinter.py +++ b/src/diffpy/distanceprinter/distanceprinter.py @@ -13,6 +13,7 @@ ############################################################################## import sys + import numpy as np from diffpy.pdffit2 import PdfFit @@ -70,9 +71,7 @@ def calDistance(strufile, atomi, atomj, lb, ub, complete): def formatResults(stru, distlist, complete, all0ddij, **kw): - """ - format the distlist to string - """ + """Format the distlist to string.""" lines = [] # header lines.append("# Structure file: %s" % kw["strufile"]) diff --git a/src/diffpy/distanceprinter/version.py b/src/diffpy/distanceprinter/version.py index ec518ce..5664eb5 100644 --- a/src/diffpy/distanceprinter/version.py +++ b/src/diffpy/distanceprinter/version.py @@ -15,8 +15,8 @@ """Definition of __version__, __date__, __gitsha__.""" -from pkg_resources import resource_filename from ConfigParser import RawConfigParser +from pkg_resources import resource_filename # obtain version information from the version.cfg file cp = RawConfigParser(dict(version="", date="", commit="", timestamp=0)) diff --git a/tests/outputs/expected.res b/tests/outputs/expected.res index a9dcd12..845f832 100644 --- a/tests/outputs/expected.res +++ b/tests/outputs/expected.res @@ -1,11 +1,11 @@ # Structure file: /home/zthatcher/GitLab/dev/dpx.distanceprinter/tests/test_files/Ni-9008476.cif -# +# # lattice=Lattice(a=3.52387, b=3.52387, c=3.52387, alpha=90, beta=90, gamma=90) # 0 Ni 0.000000 0.000000 0.000000 1.0000 # 1 Ni 0.000000 0.500000 0.500000 1.0000 # 2 Ni 0.500000 0.000000 0.500000 1.0000 # 3 Ni 0.500000 0.500000 0.000000 1.0000 -# +# # Inter-atomic distance of (all, all) in (1.00, 10.00) A Ni.0-Ni.1: 2.491752 @@ -1527,4 +1527,4 @@ Ni.3-Ni.3: 9.967009 Ni.3-Ni.3: 9.967009 Ni.3-Ni.3: 9.967009 Ni.3-Ni.3: 9.967009 -Ni.3-Ni.3: 9.967009 \ No newline at end of file +Ni.3-Ni.3: 9.967009