Skip to content

Commit 5df5dfb

Browse files
committed
add precommit and fix related checks
1 parent 6198d35 commit 5df5dfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+683
-717
lines changed

Diff for: .codespell/ignore_lines.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
;; Please include filenames and explanations for each ignored line.
2+
;; See https://docs.openverse.org/meta/codespell.html for docs.

Diff for: .codespell/ignore_words.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
;; Please include explanations for each ignored word (lowercase).
2+
;; See https://docs.openverse.org/meta/codespell.html for docs.
3+
4+
;; abbreviation for "materials" often used in a journal title
5+
mater
6+
7+
;; alternative use of socioeconomic
8+
socio-economic
9+
10+
;; Frobenius norm used in np.linalg.norm
11+
fro
12+
13+
;; abbreviation for "structure"
14+
struc
15+
16+
;; method name within JournalPanel class
17+
onText
18+
19+
;; a method name within JournalPanel class
20+
delt
21+
22+
;; structure file format
23+
discus
24+
25+
;; variable name within pdfbaseline module
26+
aline
27+
28+
;; variable name within TestSFAverageObjCryst class
29+
fo

Diff for: .flake8

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# As of now, flake8 does not natively support configuration via pyproject.toml
2+
# https://github.com/microsoft/vscode-flake8/issues/135
3+
[flake8]
4+
exclude =
5+
.git,
6+
__pycache__,
7+
build,
8+
dist,
9+
doc/source/conf.py
10+
max-line-length = 115
11+
# Ignore some style 'errors' produced while formatting by 'black'
12+
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#labels-why-pycodestyle-warnings
13+
extend-ignore = E203

Diff for: .isort.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[settings]
2+
# Keep import statement below line_length character limit
3+
line_length = 115
4+
multi_line_output = 3
5+
include_trailing_comma = True

Diff for: .pre-commit-config.yaml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
default_language_version:
2+
python: python3
3+
ci:
4+
autofix_commit_msg: |
5+
[pre-commit.ci] auto fixes from pre-commit hooks
6+
autofix_prs: true
7+
autoupdate_branch: "pre-commit-autoupdate"
8+
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
9+
autoupdate_schedule: monthly
10+
skip: [no-commit-to-branch]
11+
submodules: false
12+
repos:
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v4.6.0
15+
hooks:
16+
- id: check-yaml
17+
exclude: ^conda-recipe/meta\.yaml$
18+
- id: end-of-file-fixer
19+
- id: trailing-whitespace
20+
- id: check-case-conflict
21+
- id: check-merge-conflict
22+
- id: check-toml
23+
- id: check-added-large-files
24+
- repo: https://github.com/psf/black
25+
rev: 24.4.2
26+
hooks:
27+
- id: black
28+
- repo: https://github.com/pycqa/flake8
29+
rev: 7.0.0
30+
hooks:
31+
- id: flake8
32+
- repo: https://github.com/pycqa/isort
33+
rev: 5.13.2
34+
hooks:
35+
- id: isort
36+
args: ["--profile", "black"]
37+
- repo: https://github.com/kynan/nbstripout
38+
rev: 0.7.1
39+
hooks:
40+
- id: nbstripout
41+
- repo: https://github.com/pre-commit/pre-commit-hooks
42+
rev: v4.4.0
43+
hooks:
44+
- id: no-commit-to-branch
45+
name: Prevent Commit to Main Branch
46+
args: ["--branch", "main"]
47+
stages: [pre-commit]
48+
- repo: https://github.com/codespell-project/codespell
49+
rev: v2.3.0
50+
hooks:
51+
- id: codespell
52+
additional_dependencies:
53+
- tomli
54+
# prettier - multi formatter for .json, .yml, and .md files
55+
- repo: https://github.com/pre-commit/mirrors-prettier
56+
rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8
57+
hooks:
58+
- id: prettier
59+
additional_dependencies:
60+
- "prettier@^3.2.4"
61+
# docformatter - PEP 257 compliant docstring formatter
62+
- repo: https://github.com/s-weigand/docformatter
63+
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
64+
hooks:
65+
- id: docformatter
66+
additional_dependencies: [tomli]
67+
args: [--in-place, --config, ./pyproject.toml]

Diff for: .prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/conda-recipe/*

Diff for: .travis.yml

-130
This file was deleted.

Diff for: README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ parallel jobs (-j4) ::
114114

115115
sudo scons -j4 install
116116

117-
See ``scons -h`` for decription of build targets and options.
117+
See ``scons -h`` for description of build targets and options.
118118

119119

120120
DEVELOPMENT

Diff for: devutils/makesdist

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
11
#!/usr/bin/env python
22

3-
'''Create source distribution tar.gz archive, where each file belongs
4-
to a root user and modification time is set to the git commit time.
5-
'''
3+
"""Create source distribution tar.gz archive, where each file belongs to a root
4+
user and modification time is set to the git commit time."""
65

7-
import sys
6+
import glob
7+
import gzip
88
import os
99
import subprocess
10-
import glob
10+
import sys
1111
import tarfile
12-
import gzip
12+
13+
from setup import FALLBACK_VERSION, versiondata
1314

1415
BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
1516
sys.path.insert(0, BASEDIR)
1617

17-
from setup import versiondata, FALLBACK_VERSION
18-
timestamp = versiondata.getint('DEFAULT', 'timestamp')
18+
timestamp = versiondata.getint("DEFAULT", "timestamp")
1919

20-
vfb = versiondata.get('DEFAULT', 'version').split('.post')[0] + '.post0'
20+
vfb = versiondata.get("DEFAULT", "version").split(".post")[0] + ".post0"
2121
emsg = "Invalid FALLBACK_VERSION. Expected %r got %r."
2222
assert vfb == FALLBACK_VERSION, emsg % (vfb, FALLBACK_VERSION)
2323

24+
2425
def inform(s):
2526
sys.stdout.write(s)
2627
sys.stdout.flush()
2728
return
2829

30+
2931
inform('Run "setup.py sdist --formats=tar" ')
30-
cmd_sdist = ([sys.executable, '-Wignore:Cannot detect name suffix'] +
31-
'setup.py sdist --formats=tar'.split())
32-
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, 'w'))
33-
if ec: sys.exit(ec)
32+
cmd_sdist = [sys.executable, "-Wignore:Cannot detect name suffix"] + "setup.py sdist --formats=tar".split()
33+
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, "w"))
34+
if ec:
35+
sys.exit(ec)
3436
inform("[done]\n")
3537

36-
tarname = max(glob.glob(BASEDIR + '/dist/*.tar'), key=os.path.getmtime)
38+
tarname = max(glob.glob(BASEDIR + "/dist/*.tar"), key=os.path.getmtime)
3739

3840
tfin = tarfile.open(tarname)
39-
fpout = gzip.GzipFile(tarname + '.gz', 'w', mtime=0)
40-
tfout = tarfile.open(fileobj=fpout, mode='w')
41+
fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0)
42+
tfout = tarfile.open(fileobj=fpout, mode="w")
43+
4144

4245
def fixtarinfo(tinfo):
4346
tinfo.uid = tinfo.gid = 0
44-
tinfo.uname = tinfo.gname = 'root'
47+
tinfo.uname = tinfo.gname = "root"
4548
tinfo.mtime = timestamp
4649
tinfo.mode &= ~0o022
4750
return tinfo
4851

49-
inform('Filter %s --> %s.gz ' % (2 * (os.path.basename(tarname),)))
52+
53+
inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),)))
5054
for ti in tfin:
5155
tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti))
5256

Diff for: devutils/tunePeakPrecision.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#!/usr/bin/env python
22

3-
"""Tune the peak precision parameter so that PDFCalculator
4-
gives equivalent results to diffpy.pdffit2.
3+
"""Tune the peak precision parameter so that PDFCalculator gives equivalent
4+
results to diffpy.pdffit2.
55
66
Usage: tunePeakPrecision.py [qmax] [peakprecision] [createplot]
77
"""
88

9+
# global imports
10+
import sys
11+
import time
12+
13+
import numpy
14+
15+
import diffpy.pdffit2
16+
from diffpy.srreal.pdf_ext import PDFCalculator
17+
from diffpy.structure import Structure
18+
919
# Results:
1020
# Qmax peakprecision CPU Notes
1121
# 15 3.2e-6 clear minimum
@@ -21,16 +31,6 @@
2131
peakprecision = None
2232
createplot = False
2333

24-
# global imports
25-
import sys
26-
import time
27-
28-
import numpy
29-
30-
from diffpy.structure import Structure
31-
from diffpy.srreal.pdf_ext import PDFCalculator
32-
import diffpy.pdffit2
33-
3434
# make PdfFit silent
3535
diffpy.pdffit2.redirect_stdout(open("/dev/null", "w"))
3636

@@ -52,7 +52,7 @@
5252

5353

5454
def Gpdffit2(qmax):
55-
"""Calculate reference nickel PDF using diffpy.pdffit2
55+
"""Calculate reference nickel PDF using diffpy.pdffit2.
5656
5757
qmax -- vawevector cutoff value in 1/A
5858
@@ -68,7 +68,7 @@ def Gpdffit2(qmax):
6868

6969

7070
def Gsrreal(qmax, peakprecision=None):
71-
"""Calculate nickel PDF using PDFCalculator from diffpy.srreal
71+
"""Calculate nickel PDF using PDFCalculator from diffpy.srreal.
7272
7373
qmax -- vawevector cutoff value in 1/A
7474
peakprecision -- precision factor affecting peak cutoff,

0 commit comments

Comments
 (0)