Skip to content
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

black edits #118

Merged
merged 1 commit into from
Jul 22, 2024
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
8 changes: 4 additions & 4 deletions conda-recipe/expandpdfguibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import sys
from pkg_resources import Requirement, resource_filename

pkg = Requirement.parse('diffpy.pdfgui')
PDFGUIPATH = resource_filename(pkg, '')
pkg = Requirement.parse("diffpy.pdfgui")
PDFGUIPATH = resource_filename(pkg, "")
assert PDFGUIPATH.lower().startswith(sys.prefix.lower())
PDFGUIBASE = PDFGUIPATH[len(sys.prefix):].replace('\\', '/').strip('/')
PDFGUIBASE = PDFGUIPATH[len(sys.prefix) :].replace("\\", "/").strip("/")

if __name__ == "__main__":
with open(sys.argv[1]) as fp:
content = fp.read()
output = content.replace('@PDFGUIBASE@', PDFGUIBASE)
output = content.replace("@PDFGUIBASE@", PDFGUIBASE)
sys.stdout.write(output)
1 change: 1 addition & 0 deletions conda-recipe/run_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python

import diffpy.pdfgui.tests

assert diffpy.pdfgui.tests.testdeps().wasSuccessful()
151 changes: 78 additions & 73 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,29 @@

# Use this version when git data are not available, like in git zip archive.
# Update when tagging a new release.
FALLBACK_VERSION = '2.0.4'
FALLBACK_VERSION = "2.0.4"

# determine if we run with Python 3.
PY3 = (sys.version_info[0] == 3)
PY3 = sys.version_info[0] == 3

# versioncfgfile holds version data for git commit hash and date.
# It must reside in the same directory as version.py.
MYDIR = os.path.dirname(os.path.abspath(__file__))
versioncfgfile = os.path.join(MYDIR, 'src/diffpy/pdfgui/version.cfg')
gitarchivecfgfile = os.path.join(MYDIR, '.gitarchive.cfg')
versioncfgfile = os.path.join(MYDIR, "src/diffpy/pdfgui/version.cfg")
gitarchivecfgfile = os.path.join(MYDIR, ".gitarchive.cfg")


def gitinfo():
from subprocess import Popen, PIPE

kw = dict(stdout=PIPE, cwd=MYDIR, universal_newlines=True)
proc = Popen(['git', 'describe', '--tags', '--match=v[[:digit:]]*'], **kw)
proc = Popen(["git", "describe", "--tags", "--match=v[[:digit:]]*"], **kw)
desc = proc.stdout.read()
proc = Popen(['git', 'log', '-1', '--format=%H %ct %ci'], **kw)
proc = Popen(["git", "log", "-1", "--format=%H %ct %ci"], **kw)
glog = proc.stdout.read()
rv = {}
rv['version'] = '.post'.join(desc.strip().split('-')[:2]).lstrip('v')
rv['commit'], rv['timestamp'], rv['date'] = glog.strip().split(None, 2)
rv["version"] = ".post".join(desc.strip().split("-")[:2]).lstrip("v")
rv["commit"], rv["timestamp"], rv["date"] = glog.strip().split(None, 2)
return rv


Expand All @@ -44,19 +46,19 @@ def getversioncfg():
from configparser import RawConfigParser
else:
from ConfigParser import RawConfigParser
vd0 = dict(version=FALLBACK_VERSION, commit='', date='', timestamp=0)
vd0 = dict(version=FALLBACK_VERSION, commit="", date="", timestamp=0)
# first fetch data from gitarchivecfgfile, ignore if it is unexpanded
g = vd0.copy()
cp0 = RawConfigParser(vd0)
cp0.read(gitarchivecfgfile)
if len(cp0.get('DEFAULT', 'commit')) > 20:
if len(cp0.get("DEFAULT", "commit")) > 20:
g = cp0.defaults()
mx = re.search(r'\btag: v(\d[^,]*)', g.pop('refnames'))
mx = re.search(r"\btag: v(\d[^,]*)", g.pop("refnames"))
if mx:
g['version'] = mx.group(1)
g["version"] = mx.group(1)
# then try to obtain version data from git.
gitdir = os.path.join(MYDIR, '.git')
if os.path.exists(gitdir) or 'GIT_DIR' in os.environ:
gitdir = os.path.join(MYDIR, ".git")
if os.path.exists(gitdir) or "GIT_DIR" in os.environ:
try:
g = gitinfo()
except OSError:
Expand All @@ -65,94 +67,97 @@ 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'])
cp.set('DEFAULT', 'date', g['date'])
cp.set('DEFAULT', 'timestamp', g['timestamp'])
with open(versioncfgfile, 'w') as fp:
cp.set("DEFAULT", "version", g["version"])
cp.set("DEFAULT", "commit", g["commit"])
cp.set("DEFAULT", "date", g["date"])
cp.set("DEFAULT", "timestamp", g["timestamp"])
with open(versioncfgfile, "w") as fp:
cp.write(fp)
return cp


versiondata = getversioncfg()


def dirglob(d, *patterns):
from glob import glob

rv = []
for p in patterns:
rv += glob(os.path.join(d, p))
return rv


with open(os.path.join(MYDIR, 'README.rst')) as fp:
with open(os.path.join(MYDIR, "README.rst")) as fp:
long_description = fp.read()

# define distribution
setup_args = dict(
name = 'diffpy.pdfgui',
version='3.0.5',
packages = find_packages(os.path.join(MYDIR, 'src')),
package_dir = {'' : 'src'},
include_package_data = True,
test_suite = 'diffpy.pdfgui.tests',
entry_points = {
'gui_scripts': [
'pdfgui=diffpy.pdfgui.applications.pdfgui:main',
name="diffpy.pdfgui",
version="3.0.5",
packages=find_packages(os.path.join(MYDIR, "src")),
package_dir={"": "src"},
include_package_data=True,
test_suite="diffpy.pdfgui.tests",
entry_points={
"gui_scripts": [
"pdfgui=diffpy.pdfgui.applications.pdfgui:main",
],
},
data_files = [
('icons', dirglob('icons', '*.png', '*.ico')),
('doc', dirglob('doc', '*.pdf')),
('doc/manual', dirglob('doc/manual', '*.html', '*.pdf')),
('doc/manual/images', dirglob('doc/manual/images', '*.png')),
('doc/tutorial', dirglob('doc/tutorial', '*')),
data_files=[
("icons", dirglob("icons", "*.png", "*.ico")),
("doc", dirglob("doc", "*.pdf")),
("doc/manual", dirglob("doc/manual", "*.html", "*.pdf")),
("doc/manual/images", dirglob("doc/manual/images", "*.png")),
("doc/tutorial", dirglob("doc/tutorial", "*")),
],
# manual and tutorial files should not be zipped
zip_safe = False,
install_requires = [
'six',
'diffpy.structure>=3',
'diffpy.pdffit2',
'diffpy.utils',
zip_safe=False,
install_requires=[
"six",
"diffpy.structure>=3",
"diffpy.pdffit2",
"diffpy.utils",
],

author = 'Simon J.L. Billinge',
author_email = '[email protected]',
maintainer = 'Pavol Juhas',
maintainer_email = '[email protected]',
url = 'https://github.com/diffpy/diffpy.pdfgui',
description = "GUI for PDF simulation and structure refinement.",
long_description = long_description,
long_description_content_type = 'text/x-rst',
license = 'BSD',
keywords = 'PDF structure refinement GUI',
classifiers = [
author="Simon J.L. Billinge",
author_email="[email protected]",
maintainer="Pavol Juhas",
maintainer_email="[email protected]",
url="https://github.com/diffpy/diffpy.pdfgui",
description="GUI for PDF simulation and structure refinement.",
long_description=long_description,
long_description_content_type="text/x-rst",
license="BSD",
keywords="PDF structure refinement GUI",
classifiers=[
# List of possible values at
# http://pypi.python.org/pypi?:action=list_classifiers
'Development Status :: 5 - Production/Stable',
'Environment :: MacOS X',
'Environment :: Win32 (MS Windows)',
'Environment :: X11 Applications',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.10',
'Topic :: Scientific/Engineering :: Chemistry',
'Topic :: Scientific/Engineering :: Physics',
"Development Status :: 5 - Production/Stable",
"Environment :: MacOS X",
"Environment :: Win32 (MS Windows)",
"Environment :: X11 Applications",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering :: Chemistry",
"Topic :: Scientific/Engineering :: Physics",
],
)

if __name__ == '__main__':
if __name__ == "__main__":
setup(**setup_args)

# End of file
1 change: 1 addition & 0 deletions src/diffpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)


Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/pdfgui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#
##############################################################################

'''Constants:
"""Constants:
__version__ -- full version of this PDFgui release
'''
"""


from diffpy.pdfgui.version import __version__
Expand Down
27 changes: 15 additions & 12 deletions src/diffpy/pdfgui/applications/pdfgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@


def usage():
"""Show usage info.
"""
"""Show usage info."""
myname = os.path.basename(sys.argv[0])
msg = __doc__.replace("pdfgui", myname)
print(msg)
Expand All @@ -50,12 +49,13 @@ def usage():

def version():
from diffpy.pdfgui import __version__

print("PDFgui", __version__)
return


def processArguments(argv1):
'''Process command line arguments and store results in pdfguiglobals.
"""Process command line arguments and store results in pdfguiglobals.
This method updates cmdopts, cmdargs and dbopts attributes in the
pdfguiglobals module.

Expand All @@ -66,13 +66,13 @@ def processArguments(argv1):
Raises GetoptError for invalid options.
Raises ValueError for more than one project file arguments or
when project is not a valid file.
'''
"""
from diffpy.pdfgui.gui import pdfguiglobals

dbopts = pdfguiglobals.dbopts
dboptions = [('db-' + o[0]) for o in dbopts.alldebugoptions]
dboptions = [("db-" + o[0]) for o in dbopts.alldebugoptions]
# default parameters
opts, args = getopt.gnu_getopt(sys.argv[1:], "hV",
["help", "version"] + dboptions)
opts, args = getopt.gnu_getopt(sys.argv[1:], "hV", ["help", "version"] + dboptions)
# process options
proceed = True
for o, a in opts:
Expand All @@ -82,13 +82,14 @@ def processArguments(argv1):
elif o in ("-V", "--version"):
version()
proceed = False
elif o.startswith('--') and o[2:] in dboptions:
elif o.startswith("--") and o[2:] in dboptions:
# strip "--db-"
dbo = o[5:]
setattr(dbopts, dbo, True)
pdfguiglobals.cmdopts = opts
# bail-out here if options contain --help or --version
if not proceed: return False
if not proceed:
return False
# otherwise continue checking arguments
if len(args) == 1 and not os.path.isfile(args[0]):
emsg = "Project file %s does not exist." % args[0]
Expand All @@ -102,8 +103,7 @@ def processArguments(argv1):


def main():
'''Main entry point to PDFgui.
'''
"""Main entry point to PDFgui."""
# process arguments
proceed = False
try:
Expand All @@ -112,12 +112,15 @@ def main():
print(err, file=sys.stderr)
sys.exit(1)
# bail out when no gui is needed
if not proceed: sys.exit()
if not proceed:
sys.exit()
# initialize gui
import diffpy.pdfgui.gui.main as guimain

# Catch control errors, that may happen during project
# loading, before the GUI gets running
from diffpy.pdfgui.control.controlerrors import ControlError

try:
guimain.main()
except ControlError as err:
Expand Down
Loading