Skip to content

Add precommit #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .codespell/ignore_lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
;; Please include filenames and explanations for each ignored line.
;; See https://docs.openverse.org/meta/codespell.html for docs.
29 changes: 29 additions & 0 deletions .codespell/ignore_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
;; Please include explanations for each ignored word (lowercase).
;; See https://docs.openverse.org/meta/codespell.html for docs.

;; abbreviation for "materials" often used in a journal title
mater

;; alternative use of socioeconomic
socio-economic

;; Frobenius norm used in np.linalg.norm
fro

;; abbreviation for "structure"
struc

;; method name within JournalPanel class
onText

;; a method name within JournalPanel class
delt

;; structure file format
discus

;; variable name within pdfbaseline module
aline

;; variable name within TestSFAverageObjCryst class
fo
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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,
doc/source/conf.py
max-line-length = 115
# 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
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
# Keep import statement below line_length character limit
line_length = 115
multi_line_output = 3
include_trailing_comma = True
67 changes: 67 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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
exclude: ^conda-recipe/meta\.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]
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/conda-recipe/*
130 changes: 0 additions & 130 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ parallel jobs (-j4) ::

sudo scons -j4 install

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


DEVELOPMENT
Expand Down
40 changes: 22 additions & 18 deletions devutils/makesdist
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
#!/usr/bin/env python

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

import sys
import glob
import gzip
import os
import subprocess
import glob
import sys
import tarfile
import gzip

from setup import FALLBACK_VERSION, versiondata

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

from setup import versiondata, FALLBACK_VERSION
timestamp = versiondata.getint('DEFAULT', 'timestamp')
timestamp = versiondata.getint("DEFAULT", "timestamp")

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


def inform(s):
sys.stdout.write(s)
sys.stdout.flush()
return


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

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

tfin = tarfile.open(tarname)
fpout = gzip.GzipFile(tarname + '.gz', 'w', mtime=0)
tfout = tarfile.open(fileobj=fpout, mode='w')
fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0)
tfout = tarfile.open(fileobj=fpout, mode="w")


def fixtarinfo(tinfo):
tinfo.uid = tinfo.gid = 0
tinfo.uname = tinfo.gname = 'root'
tinfo.uname = tinfo.gname = "root"
tinfo.mtime = timestamp
tinfo.mode &= ~0o022
return tinfo

inform('Filter %s --> %s.gz ' % (2 * (os.path.basename(tarname),)))

inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),)))
for ti in tfin:
tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti))

Expand Down
28 changes: 14 additions & 14 deletions devutils/tunePeakPrecision.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#!/usr/bin/env python

"""Tune the peak precision parameter so that PDFCalculator
gives equivalent results to diffpy.pdffit2.
"""Tune the peak precision parameter so that PDFCalculator gives equivalent
results to diffpy.pdffit2.

Usage: tunePeakPrecision.py [qmax] [peakprecision] [createplot]
"""

# global imports
import sys
import time

import numpy

import diffpy.pdffit2
from diffpy.srreal.pdf_ext import PDFCalculator
from diffpy.structure import Structure

# Results:
# Qmax peakprecision CPU Notes
# 15 3.2e-6 clear minimum
Expand All @@ -21,16 +31,6 @@
peakprecision = None
createplot = False

# global imports
import sys
import time

import numpy

from diffpy.structure import Structure
from diffpy.srreal.pdf_ext import PDFCalculator
import diffpy.pdffit2

# make PdfFit silent
diffpy.pdffit2.redirect_stdout(open("/dev/null", "w"))

Expand All @@ -52,7 +52,7 @@


def Gpdffit2(qmax):
"""Calculate reference nickel PDF using diffpy.pdffit2
"""Calculate reference nickel PDF using diffpy.pdffit2.

qmax -- vawevector cutoff value in 1/A

Expand All @@ -68,7 +68,7 @@ def Gpdffit2(qmax):


def Gsrreal(qmax, peakprecision=None):
"""Calculate nickel PDF using PDFCalculator from diffpy.srreal
"""Calculate nickel PDF using PDFCalculator from diffpy.srreal.

qmax -- vawevector cutoff value in 1/A
peakprecision -- precision factor affecting peak cutoff,
Expand Down
Loading