Skip to content

skpkg: pre-commit auto fixes with line length of 79 #57

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 6 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion doc/source/examples/distanceprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def _resetValue(self):

def _addPairContribution(self, bnds, sumscale):
self.count += bnds.multiplicity() * sumscale / 2.0
print("%i %g %i %i" % (self.count, bnds.distance(), bnds.site0(), bnds.site1()))
print(
"%i %g %i %i"
% (self.count, bnds.distance(), bnds.site0(), bnds.site1())
)
return


Expand Down
6 changes: 5 additions & 1 deletion doc/source/examples/parallelPDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

# configure options parsing
parser = optparse.OptionParser("%prog [options]\n" + __doc__)
parser.add_option("--pyobjcryst", action="store_true", help="Use pyobjcryst to load the CIF file.")
parser.add_option(
"--pyobjcryst",
action="store_true",
help="Use pyobjcryst to load the CIF file.",
)
parser.allow_interspersed_args = True
opts, args = parser.parse_args(sys.argv[1:])

Expand Down
23 changes: 23 additions & 0 deletions news/pc-blackv2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Configure ``black`` to have a linelength requirement of 79 characters.

**Security:**

* <news item>
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ignore-words = ".codespell/ignore_words.txt"
skip = "*.cif,*.dat"

[tool.black]
line-length = 115
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
Expand Down
15 changes: 11 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def get_boost_config():
conda_prefix = os.environ.get("CONDA_PREFIX")
if not conda_prefix:
raise EnvironmentError(
"Neither BOOST_PATH nor CONDA_PREFIX are set. " "Please install Boost or set BOOST_PATH."
"Neither BOOST_PATH nor CONDA_PREFIX are set. "
"Please install Boost or set BOOST_PATH."
)
if os.name == "nt":
inc = Path(conda_prefix) / "Library" / "include"
Expand All @@ -52,7 +53,8 @@ def get_objcryst_libraries():
conda_prefix = os.environ.get("CONDA_PREFIX")
if not conda_prefix:
raise EnvironmentError(
"CONDA_PREFIX is not set. Please install ObjCryst using conda and activate the environment."
"CONDA_PREFIX is not set. "
"Please install ObjCryst using conda and activate the environment."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual line length fix (1 of 2 fixes)

)
if os.name == "nt":
libdir = Path(conda_prefix) / "Library" / "lib"
Expand All @@ -64,7 +66,8 @@ def get_objcryst_libraries():
stem = Path(fn).stem
if "objcryst" not in stem.lower():
continue
# strip a leading "lib" so that setuptools does -lObjCryst, not -llibObjCryst
# strip a leading "lib"
# so that setuptools does -lObjCryst, not -llibObjCryst
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manual line length fix (2 of 2 fixes)

if os.name != "nt" and stem.startswith("lib"):
stem = stem[3:]
libs.append(stem)
Expand Down Expand Up @@ -99,7 +102,11 @@ def get_objcryst_libraries():

def create_extensions():
"Initialize Extension objects for the setup function."
ext = Extension("diffpy.srreal.srreal_ext", glob.glob("src/extensions/*.cpp"), **ext_kws)
ext = Extension(
"diffpy.srreal.srreal_ext",
glob.glob("src/extensions/*.cpp"),
**ext_kws,
)
return [ext]


Expand Down
9 changes: 7 additions & 2 deletions src/diffpy/srreal/devutils/tunePeakPrecision.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def comparePDFCalculators(qmax, peakprecision=None):
rv = {}
rv["qmax"] = qmax
rv["peakprecision"] = (
peakprecision is None and PDFCalculator()._getDoubleAttr("peakprecision") or peakprecision
peakprecision is None
and PDFCalculator()._getDoubleAttr("peakprecision")
or peakprecision
)
ttic = time.clock()
rg0 = Gpdffit2(qmax)
Expand Down Expand Up @@ -175,7 +177,10 @@ def main():
processCommandLineArguments()
cmpdata = comparePDFCalculators(qmax, peakprecision)
print(
("qmax = %(qmax)g pkprec = %(peakprecision)g " + "grmsd = %(grmsd)g t0 = %(t0).3f t1 = %(t1).3f")
(
"qmax = %(qmax)g pkprec = %(peakprecision)g "
+ "grmsd = %(grmsd)g t0 = %(t0).3f t1 = %(t1).3f"
)
% cmpdata
)
if createplot:
Expand Down
4 changes: 3 additions & 1 deletion src/diffpy/srreal/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def proxymethod(self, *args, **kwargs):
return proxymethod

for n, f in inspect.getmembers(pqtype, inspect.isroutine):
ignore = n not in proxy_forced and (n.startswith("_") or hasattr(ParallelPairQuantity, n))
ignore = n not in proxy_forced and (
n.startswith("_") or hasattr(ParallelPairQuantity, n)
)
if ignore:
continue
setattr(ParallelPairQuantity, n, _make_proxymethod(n, f))
Expand Down
4 changes: 3 additions & 1 deletion src/diffpy/srreal/pdfbaseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def fshiftedline(x, aline, bline):
"""
from diffpy.srreal.wraputils import _wrapAsRegisteredUnaryFunction

rv = _wrapAsRegisteredUnaryFunction(PDFBaseline, name, fnc, replace=replace, **dbattrs)
rv = _wrapAsRegisteredUnaryFunction(
PDFBaseline, name, fnc, replace=replace, **dbattrs
)
return rv


Expand Down
4 changes: 3 additions & 1 deletion src/diffpy/srreal/pdfenvelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def fexpdecay(x, expscale, exptail):
"""
from diffpy.srreal.wraputils import _wrapAsRegisteredUnaryFunction

rv = _wrapAsRegisteredUnaryFunction(PDFEnvelope, name, fnc, replace=replace, **dbattrs)
rv = _wrapAsRegisteredUnaryFunction(
PDFEnvelope, name, fnc, replace=replace, **dbattrs
)
return rv


Expand Down
7 changes: 6 additions & 1 deletion src/diffpy/srreal/peakwidthmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@


# exported items
__all__ = ["PeakWidthModel", "ConstantPeakWidth", "DebyeWallerPeakWidth", "JeongPeakWidth"]
__all__ = [
"PeakWidthModel",
"ConstantPeakWidth",
"DebyeWallerPeakWidth",
"JeongPeakWidth",
]

from diffpy.srreal import _final_imports
from diffpy.srreal.srreal_ext import (
Expand Down
9 changes: 8 additions & 1 deletion src/diffpy/srreal/scatteringfactortable.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@


# exported items, these also makes them show in pydoc.
__all__ = ["ScatteringFactorTable", "SFTXray", "SFTElectron", "SFTNeutron", "SFTElectronNumber", "SFAverage"]
__all__ = [
"ScatteringFactorTable",
"SFTXray",
"SFTElectron",
"SFTNeutron",
"SFTElectronNumber",
"SFAverage",
]

from diffpy.srreal.sfaverage import SFAverage
from diffpy.srreal.srreal_ext import (
Expand Down
6 changes: 5 additions & 1 deletion src/diffpy/srreal/sfaverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ def fromComposition(cls, composition, sftb, q=0):
sfa.f1sum = 0.0 * q
sfa.f2sum = 0.0 * q
# resolve the lookup table object `tb`
tb = sftb if not isinstance(sftb, str) else ScatteringFactorTable.createByType(sftb)
tb = (
sftb
if not isinstance(sftb, str)
else ScatteringFactorTable.createByType(sftb)
)
for smbl, cnt in sfa.composition.items():
sfq = tb.lookup(smbl, q)
sfa.f1sum += cnt * sfq
Expand Down
16 changes: 12 additions & 4 deletions src/diffpy/srreal/structureconverters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
# Converters for Molecule and Crystal from pyobjcryst ------------------------


RegisterStructureAdapter("pyobjcryst._pyobjcryst.Molecule", convertObjCrystMolecule)
RegisterStructureAdapter("pyobjcryst._pyobjcryst.Crystal", convertObjCrystCrystal)
RegisterStructureAdapter(
"pyobjcryst._pyobjcryst.Molecule", convertObjCrystMolecule
)
RegisterStructureAdapter(
"pyobjcryst._pyobjcryst.Crystal", convertObjCrystCrystal
)

# Converter for Structure class from diffpy.structure ------------------------

Expand Down Expand Up @@ -115,11 +119,15 @@ def _fetchMetadata(self, stru):
# end of class _DiffPyStructureMetadata


class DiffPyStructureAtomicAdapter(_DiffPyStructureMetadata, AtomicStructureAdapter):
class DiffPyStructureAtomicAdapter(
_DiffPyStructureMetadata, AtomicStructureAdapter
):
pass


class DiffPyStructurePeriodicAdapter(_DiffPyStructureMetadata, PeriodicStructureAdapter):
class DiffPyStructurePeriodicAdapter(
_DiffPyStructureMetadata, PeriodicStructureAdapter
):
pass


Expand Down
8 changes: 6 additions & 2 deletions src/diffpy/srreal/wraputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def setattrFromKeywordArguments(obj, **kwargs):
return


def _wrapAsRegisteredUnaryFunction(cls, regname, fnc, replace=False, **dbattrs):
def _wrapAsRegisteredUnaryFunction(
cls, regname, fnc, replace=False, **dbattrs
):
"""Helper function for wrapping Python function as PDFBaseline or
PDFEnvelope functor. Not intended for direct usage, this function is
rather called from makePDFBaseline or makePDFEnvelope wrappers.
Expand Down Expand Up @@ -149,7 +151,9 @@ def _pickle_getstate(self):

def _pickle_setstate(self, state):
if len(state) != 1:
emsg = "expected 1-item tuple in call to __setstate__, got " + repr(state)
emsg = "expected 1-item tuple in call to __setstate__, got " + repr(
state
)
raise ValueError(emsg)
self.__dict__.update(state[0])
return
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def has_periodictable():
del periodictable
except ImportError:
has_periodictable = False
logging.warning("Cannot import periodictable, periodictable tests skipped.")
logging.warning(
"Cannot import periodictable, periodictable tests skipped."
)

return has_periodictable
10 changes: 8 additions & 2 deletions tests/test_bondcalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ def test_sites(self):
self.assertEqual(5, numpy.max(bdc.sites0))
self.assertEqual(0, numpy.min(bdc.sites1))
self.assertEqual(5, numpy.max(bdc.sites1))
dij = [(tuple(d) + (i0, i1)) for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1)]
dij = [
(tuple(d) + (i0, i1))
for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1)
]
self.assertEqual(len(dij), len(set(dij)))
bdc.maskAllPairs(False)
bdc(self.rutile)
Expand Down Expand Up @@ -287,7 +290,10 @@ def test_sites(self):
self.assertEqual(1, numpy.max(bdc.sites0))
self.assertEqual(0, numpy.min(bdc.sites1))
self.assertEqual(1, numpy.max(bdc.sites1))
dij = [(tuple(d) + (i0, i1)) for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1)]
dij = [
(tuple(d) + (i0, i1))
for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1)
]
self.assertEqual(len(dij), len(set(dij)))
bdc.maskAllPairs(False)
bdc(self.rutile)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_debyepdfcalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def setUp(self):
if not TestDebyePDFCalculator.bucky:
TestDebyePDFCalculator.bucky = loadDiffPyStructure("C60bucky.stru")
if not TestDebyePDFCalculator.tio2rutile:
TestDebyePDFCalculator.tio2rutile = loadDiffPyStructure("TiO2_rutile-fit.stru")
TestDebyePDFCalculator.tio2rutile = loadDiffPyStructure(
"TiO2_rutile-fit.stru"
)
return

# def tearDown(self):
Expand Down Expand Up @@ -166,7 +168,9 @@ def test_pickling(self):
for a in dpdfc._namesOfDoubleAttributes():
self.assertEqual(getattr(dpdfc, a), getattr(dpdfc1, a))
self.assertEqual(13.3, dpdfc1.getEnvelope("sphericalshape").spdiameter)
self.assertEqual(dpdfc._namesOfDoubleAttributes(), dpdfc1._namesOfDoubleAttributes())
self.assertEqual(
dpdfc._namesOfDoubleAttributes(), dpdfc1._namesOfDoubleAttributes()
)
self.assertEqual(dpdfc.usedenvelopetypes, dpdfc1.usedenvelopetypes)
self.assertRaises(RuntimeError, pickle_with_attr, dpdfc, foo="bar")
return
Expand Down
17 changes: 13 additions & 4 deletions tests/test_overlapcalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def test_pickling(self):
self.assertEqual(getattr(olc, a), getattr(olc1, a))
self.assertFalse(olc1.getPairMask(1, 2))
self.assertTrue(olc1.getPairMask(0, 0))
self.assertTrue(numpy.array_equal(olc.sitesquareoverlaps, olc1.sitesquareoverlaps))
self.assertTrue(
numpy.array_equal(olc.sitesquareoverlaps, olc1.sitesquareoverlaps)
)
self.assertRaises(RuntimeError, pickle_with_attr, olc, foo="bar")
return

Expand Down Expand Up @@ -140,13 +142,18 @@ def test_parallel(self):
ncpu = 4
self.pool = multiprocessing.Pool(processes=ncpu)
olc = self.olc
polc = createParallelCalculator(OverlapCalculator(), ncpu, self.pool.imap_unordered)
polc = createParallelCalculator(
OverlapCalculator(), ncpu, self.pool.imap_unordered
)
olc.atomradiitable.fromString("Ti:1.6, O:0.66")
polc.atomradiitable = olc.atomradiitable
self.assertTrue(numpy.array_equal(olc(self.rutile), polc(self.rutile)))
self.assertTrue(olc.totalsquareoverlap > 0.0)
self.assertEqual(olc.totalsquareoverlap, polc.totalsquareoverlap)
self.assertEqual(sorted(zip(olc.sites0, olc.sites1)), sorted(zip(polc.sites0, polc.sites1)))
self.assertEqual(
sorted(zip(olc.sites0, olc.sites1)),
sorted(zip(polc.sites0, polc.sites1)),
)
olc.atomradiitable.resetAll()
self.assertEqual(0.0, sum(olc(self.rutile)))
self.assertEqual(0.0, sum(polc(self.rutile)))
Expand Down Expand Up @@ -288,7 +295,9 @@ def test_coordinations(self):
self.assertFalse(numpy.any(olc.coordinations))
olc.atomradiitable.fromString("Ti:1.6, O:0.66")
olc(self.rutile)
self.assertTrue(numpy.array_equal([8, 8, 3, 3, 3, 3], olc.coordinations))
self.assertTrue(
numpy.array_equal([8, 8, 3, 3, 3, 3], olc.coordinations)
)
return

def test_coordinationByTypes(self):
Expand Down
12 changes: 9 additions & 3 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def test_parallel_evaluatortype(self):
self.assertEqual("BASIC", ppdfc.evaluatortype)
self.assertEqual("BASIC", pdfc.evaluatortype)
ppdfc.evaluatortype = "BASIC"
self.assertRaises(ValueError, setattr, ppdfc, "evaluatortype", "OPTIMIZED")
self.assertRaises(
ValueError, setattr, ppdfc, "evaluatortype", "OPTIMIZED"
)
return

def test_parallel_pdf(self):
Expand All @@ -67,7 +69,9 @@ def test_parallel_pdf(self):
r1, g1 = ppdfc1(self.cdse)
self.assertTrue(numpy.array_equal(r0, r1))
self.assertTrue(numpy.allclose(g0, g1))
ppdfc2 = createParallelCalculator(PDFCalculator(), self.ncpu, self.pool.imap_unordered)
ppdfc2 = createParallelCalculator(
PDFCalculator(), self.ncpu, self.pool.imap_unordered
)
r2, g2 = ppdfc2(self.cdse)
self.assertTrue(numpy.array_equal(r0, r2))
self.assertTrue(numpy.allclose(g0, g2))
Expand All @@ -94,7 +98,9 @@ def test_parallel_bonds(self):
pbc1 = createParallelCalculator(BondCalculator(), 3, map)
d1 = pbc1(nickel)
self.assertTrue(numpy.array_equal(d0, d1))
pbc2 = createParallelCalculator(BondCalculator(), self.ncpu, self.pool.imap_unordered)
pbc2 = createParallelCalculator(
BondCalculator(), self.ncpu, self.pool.imap_unordered
)
d2 = pbc2(nickel)
self.assertTrue(numpy.array_equal(d0, d2))
bc.rmax = pbc1.rmax = pbc2.rmax = 2.5
Expand Down
Loading
Loading