Apply codestyle checks to all Python code.

This commit is contained in:
Dave Page 2019-03-20 11:17:51 +00:00
parent 6a8367beb9
commit bb1e908b54
7 changed files with 129 additions and 112 deletions

View File

@ -6,4 +6,4 @@ show-source = False
show-pep8 = False
count = True
format = pylint
exclude = ./migrations,./node_modules,./config_local.py,./config_distro.py
exclude = migrations,node_modules,config_local.py,config_distro.py

View File

@ -35,8 +35,10 @@ check: install-node bundle linter
cd web && pycodestyle --config=.pycodestyle . && yarn run karma start --single-run && python regression/runtests.py
check-pep8:
cd web && pycodestyle --config=../.pycodestyle .
cd tools && pycodestyle --config=../.pycodestyle .
pycodestyle --config=.pycodestyle docs/
pycodestyle --config=.pycodestyle pkg/
pycodestyle --config=.pycodestyle web/
pycodestyle --config=.pycodestyle tools/
check-python:
cd web && python regression/runtests.py --exclude feature_tests

View File

@ -11,10 +11,10 @@ else:
builtins.SERVER_MODE = None
root = os.path.realpath(
os.path.dirname(
os.path.realpath(__file__)
) + '{0}..{0}..{0}web'.format(os.sep)
)
os.path.dirname(
os.path.realpath(__file__)
) + '{0}..{0}..{0}web'.format(os.sep)
)
if sys.path[0] != root:
sys.path.insert(0, root)
@ -32,18 +32,19 @@ This document contains code for some of the important classes, listed as
below:\n\n""")
for m in [
'PgAdminModule', 'NodeView',
'BaseDriver', 'BaseConnection'
]:
'PgAdminModule', 'NodeView',
'BaseDriver', 'BaseConnection'
]:
target.write("* {0}_\n".format(m))
def print_code(outstream, name, module, info=None):
l = len(name)
name_len = len(name)
outstream.write("\n\n.. _{0}:\n\n{0}\n".format(name))
idx = 0
while idx < l:
while idx < name_len:
idx += 1
outstream.write("*")
@ -60,21 +61,24 @@ def print_code(outstream, name, module, info=None):
print_code(
target, "PgAdminModule", PgAdminModule,
"""
target, "PgAdminModule", PgAdminModule,
"""
PgAdminModule is inherted from Flask.Blueprint module.
This module defines a set of methods, properties and attributes, that every module should implement.
This module defines a set of methods, properties and attributes,
that every module should implement.
""")
from pgadmin.browser.utils import NodeView
print_code(
target, "NodeView", NodeView,
"""
NodeView class helps exposing basic REST APIs for different operations used by
pgAdmin Browser. The basic idea has been taken from the `Flask's MethodView
target, "NodeView", NodeView,
"""
The NodeView class exposes basic REST APIs for different operations used by
the pgAdmin Browser. The basic idea has been taken from `Flask's MethodView
<http://flask.pocoo.org/docs/1.0/api/#flask.views.MethodView>`_ class. Because
- we need a lot more operations (not, just CRUD), we can not use it directly.""")
we need a lot more operations (not, just CRUD), we can not use it directly.""")
from pgadmin.utils.driver.abstract import BaseDriver, BaseConnection
print_code(target, "BaseDriver", BaseDriver)
print_code(target, "BaseConnection", BaseConnection)

View File

@ -3,7 +3,8 @@
# pgAdmin III documentation build configuration file, created by
# sphinx-quickstart on Sat Jul 9 15:58:11 2011.
#
# This file is execfile()d with the current directory set to its containing dir.
# This file is execfile()d with the current directory set to its containing
# directory.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
@ -11,7 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
import os
import sys
if sys.version_info[0] >= 3:
import builtins
@ -29,15 +31,15 @@ import config
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# -- General configuration ----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
@ -47,7 +49,7 @@ templates_path = ['_templates']
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
@ -67,40 +69,41 @@ release = config.APP_VERSION
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# The reST default role (used for this markup: `text`) to use for all
# documents.
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# -- Options for HTML output --------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
@ -109,7 +112,7 @@ html_theme = 'classic'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
html_theme_options = {
'collapsiblesidebar': True,
'relbarbgcolor': '#326690',
'sidebarbgcolor': '#E2E2E2',
@ -126,23 +129,23 @@ html_theme_options = {
}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
@ -151,30 +154,30 @@ html_static_path = ['images']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}
html_sidebars = {
'**': ['localtoc.html', 'globaltoc.html', 'searchbox.html']
}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False
# If true, links to the reST sources are added to the pages.
html_show_sourcelink = False
@ -188,62 +191,62 @@ html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'pgadmin4'
# -- Options for LaTeX output --------------------------------------------------
# -- Options for LaTeX output -------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('index', 'pgadmin4.tex', u'pgAdmin 4 Documentation',
u'The pgAdmin Development Team', 'manual'),
('index', 'pgadmin4.tex', u'pgAdmin 4 Documentation',
u'The pgAdmin Development Team', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# latex_show_urls = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# latex_domain_indices = True
# Fix the indexing for our docs. See:
# https://groups.google.com/forum/#!topic/sphinx-users/ZlQ95_QikXo
latex_elements = {
'fncychap' : r'\usepackage[Sonny]{fncychap}',
'fncychap': r'\usepackage[Sonny]{fncychap}',
}
# -- Options for manual page output --------------------------------------------
# -- Options for manual page output -------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).

View File

@ -90,13 +90,14 @@ data 'STR#' (5002, "English") {
$"2C20 7072 6573 7320 2244 6973 6167 7265"
$"6522 2E"
};\n\n""")
with open(license, 'r') as l:
with open(license, 'r') as lines:
kind = 'RTF ' if license.lower().endswith('.rtf') else 'TEXT'
f.write('data \'%s\' (5000, "English") {\n' % kind)
def escape(s):
return s.strip().replace('\\', '\\\\').replace('"', '\\"')
for line in l:
for line in lines:
if len(line) < 1000:
f.write(' "' + escape(line) + '\\n"\n')
else:
@ -128,6 +129,7 @@ data 'STR#' (5002, "English") {
else:
print("Failed to add license to '%s'" % dmgFile)
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.set_usage("""%prog <dmgFile> <licenseFile> [OPTIONS]

View File

@ -7,8 +7,8 @@
#
##########################################################################
import os
import sys
import imp
from setuptools import setup
from codecs import open
@ -24,7 +24,7 @@ builtins.SERVER_MODE = None
"""This script helps to generate PIP packages"""
# Get the requirements list for the current version of Python
req_file='../requirements.txt'
req_file = '../requirements.txt'
with open(req_file, 'r') as reqf:
if sys.version_info[0] >= 3:
@ -34,12 +34,31 @@ with open(req_file, 'r') as reqf:
# Remove any requirements with environment specifiers. These
# must be explicitly listed in extras_require below.
for req in required:
if ";" in req:
for index, req in enumerate(required):
if ";" in req or req.startswith("#") or req == "":
required.remove(req)
# Get the app version
modl = imp.load_source('APP_VERSION', '../web/config.py')
if sys.version_info[:2] >= (3, 3):
from importlib.machinery import SourceFileLoader
def load_source(name, path):
if not os.path.exists(path):
print("ERROR: Could not find %s" % path)
sys.exit(1)
return SourceFileLoader(name, path).load_module()
else:
import imp
def load_source(name, path):
if not os.path.exists(path):
print("ERROR: Could not find %s" % path)
sys.exit(1)
return imp.load_source(name, path)
modl = load_source('APP_VERSION', '../web/config.py')
setup(
name='pgadmin4',
@ -47,38 +66,32 @@ setup(
version=modl.APP_VERSION,
description='PostgreSQL Tools',
long_description='Administration and management tools for the PostgreSQL database.',
long_description='Administration and management tools for '
'the PostgreSQL database.',
url='https://www.pgadmin.org/',
# Author details
author='The pgAdmin Development Team',
author_email='pgadmin-hackers@postgresql.org',
# Choose your license
license='PostgreSQL Licence',
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 5 - Production/Stable',
'Development Status :: 5 - Production/Stable',
# Supported programming languages
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6'
],
# Supported programming languages
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7'
],
keywords='pgadmin4,postgresql,postgres',
# Specify package names here.
packages=["pgadmin4",],
packages=["pgadmin4"],
# To include additional files within the package
include_package_data=True,
install_requires=required,
@ -89,13 +102,6 @@ setup(
],
},
# Specify data files to be included.
##package_data="",
# To package data files outside package directory.
##data_files=,
# 'scripts' keyword is used to provide executable scripts. It provides cross-platform support.
entry_points={
'console_scripts': ['pgadmin4=pgadmin4.pgAdmin4.__init__:main'],
},

View File

@ -1,14 +1,14 @@
import fileinput
import sys, getopt
import getopt
import sys
# Store input and output file names
infile=''
outfile=''
searchExp=''
replaceExp=''
infile = ''
outfile = ''
searchExp = ''
replaceExp = ''
# Read command line args
myopts, args = getopt.getopt(sys.argv[1:],"i:o:s:r:")
myopts, args = getopt.getopt(sys.argv[1:], "i:o:s:r:")
###############################
# o == option
@ -16,13 +16,13 @@ myopts, args = getopt.getopt(sys.argv[1:],"i:o:s:r:")
###############################
for o, a in myopts:
if o == '-i':
infile=a
infile = a
elif o == '-o':
outfile=a
outfile = a
elif o == '-s':
searchExp=a
searchExp = a
elif o == '-r':
replaceExp=a
replaceExp = a
else:
print("Usage: %s -i input -o output" % sys.argv[0])
@ -31,6 +31,6 @@ for o, a in myopts:
f1 = open(infile, 'r')
f2 = open(outfile, 'w')
for line in f1:
f2.write(line.replace(searchExp,replaceExp))
f2.write(line.replace(searchExp, replaceExp))
f1.close()
f2.close()