Skip to content
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
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[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
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
exclude: '\.(rst|txt)$'
- 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]
1 change: 1 addition & 0 deletions conda-recipe/expandpdfguibase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import sys

from pkg_resources import Requirement, resource_filename

pkg = Requirement.parse("diffpy.pdfgui")
Expand Down
38 changes: 22 additions & 16 deletions devutils/makesdist
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
#!/usr/bin/env python

'''Create source distribution tar.gz archive, where each file belongs
"""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

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')
from setup import FALLBACK_VERSION, versiondata

vfb = versiondata.get('DEFAULT', 'version').split('.post')[0] + '.post0'
timestamp = versiondata.getint("DEFAULT", "timestamp")

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] + '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] + "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
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.black]
line-length = 115
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| \.rst
| \.txt
| _build
| buck-out
| build
| dist

# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
)/
'''
10 changes: 4 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import os
import re
import sys
from setuptools import setup, find_packages

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.
Expand All @@ -28,7 +29,7 @@


def gitinfo():
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen

kw = dict(stdout=PIPE, cwd=MYDIR, universal_newlines=True)
proc = Popen(["git", "describe", "--tags", "--match=v[[:digit:]]*"], **kw)
Expand Down Expand Up @@ -67,10 +68,7 @@ def getversioncfg():
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"))
)
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"])
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/pdfgui/applications/pdfgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

from __future__ import print_function

import sys
import os
import getopt
import os
import sys


def usage():
Expand Down
10 changes: 6 additions & 4 deletions src/diffpy/pdfgui/control/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import copy
import math

from diffpy.pdfgui.control.controlerrors import ControlConfigError
from diffpy.pdfgui.control.controlerrors import ControlKeyError
from diffpy.pdfgui.control.controlerrors import ControlValueError
from diffpy.pdfgui.control.controlerrors import (
ControlConfigError,
ControlKeyError,
ControlValueError,
)
from diffpy.pdfgui.control.pdfcomponent import PDFComponent
from diffpy.pdfgui.utils import safeCPickleDumps, pickle_loads
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps


class Calculation(PDFComponent):
Expand Down
6 changes: 2 additions & 4 deletions src/diffpy/pdfgui/control/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
constraints will be stored in { variable : constraint } dictionary
"""

import re
import math
import re

from diffpy.pdfgui.control.controlerrors import ControlSyntaxError

Expand Down Expand Up @@ -135,9 +135,7 @@ def __setattr__(self, name, value):
raise ControlSyntaxError(message)
# few more checks of the formula:
if newformula.find("**") != -1:
emsg = (
"invalid constraint formula '{}', " "operator '**' not supported."
).format(newformula)
emsg = ("invalid constraint formula '{}', " "operator '**' not supported.").format(newformula)
raise ControlSyntaxError(emsg)
# checks checked
self.__dict__["formula"] = newformula
Expand Down
34 changes: 10 additions & 24 deletions src/diffpy/pdfgui/control/fitdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"""

import copy

import numpy

from diffpy.pdfgui.control.pdfdataset import PDFDataSet
from diffpy.pdfgui.control.parameter import Parameter
from diffpy.pdfgui.control.controlerrors import ControlStatusError
from diffpy.pdfgui.control.parameter import Parameter
from diffpy.pdfgui.control.pdfdataset import PDFDataSet


class FitDataSet(PDFDataSet):
Expand Down Expand Up @@ -112,9 +113,7 @@ def getYNames(self):

returns list of strings
"""
ynames = ["Gobs", "Gcalc", "Gdiff", "Gtrunc", "dGcalc", "crw"] + list(
self.constraints.keys()
)
ynames = ["Gobs", "Gcalc", "Gdiff", "Gtrunc", "dGcalc", "crw"] + list(self.constraints.keys())
return ynames

def getXNames(self):
Expand Down Expand Up @@ -321,10 +320,7 @@ def writeCalcStr(self):
Gdiff = self.Gdiff
drcalc = 0.0
for i in range(len(self.rcalc)):
lines.append(
"%g %g %.1f %g %g"
% (self.rcalc[i], self.Gcalc[i], drcalc, self.dGcalc[i], Gdiff[i])
)
lines.append("%g %g %.1f %g %g" % (self.rcalc[i], self.Gcalc[i], drcalc, self.dGcalc[i], Gdiff[i]))
# lines are ready here
datastring = "\n".join(lines) + "\n"
return datastring
Expand Down Expand Up @@ -636,9 +632,7 @@ def _set_fitrmin(self, value):
self._fitrmin = float(value)
return

fitrmin = property(
_get_fitrmin, _set_fitrmin, doc="Lower boundary for simulated PDF curve."
)
fitrmin = property(_get_fitrmin, _set_fitrmin, doc="Lower boundary for simulated PDF curve.")

# fitrmax

Expand All @@ -650,9 +644,7 @@ def _set_fitrmax(self, value):
self._fitrmax = float(value)
return

fitrmax = property(
_get_fitrmax, _set_fitrmax, doc="Upper boundary for simulated PDF curve."
)
fitrmax = property(_get_fitrmax, _set_fitrmax, doc="Upper boundary for simulated PDF curve.")

# fitrstep

Expand All @@ -664,9 +656,7 @@ def _set_fitrstep(self, value):
self._fitrstep = float(value)
return

fitrstep = property(
_get_fitrstep, _set_fitrstep, doc="R-step used for simulated PDF curve."
)
fitrstep = property(_get_fitrstep, _set_fitrstep, doc="R-step used for simulated PDF curve.")

# rcalc

Expand Down Expand Up @@ -707,9 +697,7 @@ def _set_dGcalc(self, value):
self._dGcalc = value
return

dGcalc = property(
_get_dGcalc, _set_dGcalc, doc="List of standard deviations of Gcalc."
)
dGcalc = property(_get_dGcalc, _set_dGcalc, doc="List of standard deviations of Gcalc.")

# Gtrunc

Expand Down Expand Up @@ -757,9 +745,7 @@ def _get_Gdiff(self):
rv = []
return rv

Gdiff = property(
_get_Gdiff, doc="Difference between observed and calculated PDF on rcalc grid."
)
Gdiff = property(_get_Gdiff, doc="Difference between observed and calculated PDF on rcalc grid.")

# crw
def _get_crw(self):
Expand Down
Loading