Skip to content

Commit

Permalink
Run black over the codebase (#1760)
Browse files Browse the repository at this point in the history
* Run black over the codebase; update flake8 config; add pyproject.toml for black.

* Add changelog snippet.

* Fix pyproject.toml values.
  • Loading branch information
corranwebster committed Sep 27, 2021
1 parent 114b291 commit 88182ca
Show file tree
Hide file tree
Showing 537 changed files with 10,429 additions and 10,901 deletions.
1 change: 1 addition & 0 deletions docs/releases/upcoming/1760.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used Black to ensure a uniform codestyle for TraitsUI. (#1760)
74 changes: 40 additions & 34 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#sys.path.append(os.path.abspath('some/directory'))
# sys.path.append(os.path.abspath('some/directory'))

# General configuration
# ---------------------
Expand Down Expand Up @@ -51,30 +51,30 @@

# 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'

# List of documents that shouldn't be included in the build.
#unused_docs = []
# unused_docs = []

# List of directories, relative to source directories, that shouldn't be searched
# for source files.
#exclude_dirs = []
# exclude_dirs = []

# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# 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'
Expand All @@ -86,29 +86,28 @@
# The style sheet to use for HTML and HTML Help pages. A file of that name
# must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path.
#html_style = 'default.css'
# html_style = 'default.css'

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
html_title = "TraitsUI {} Documentation".format(version.split('.')[0])

# 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 (within the static path) to place at the top of
# the sidebar.
#html_logo = "e-logo-rev.png"
# html_logo = "e-logo-rev.png"

# 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 = "favicon.ico"
# html_favicon = "favicon.ico"

# 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,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static',
os.path.join('tutorials', 'code_snippets')]
html_static_path = ['_static', os.path.join('tutorials', 'code_snippets')]

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
Expand All @@ -119,31 +118,31 @@
html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}

# 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_use_modindex = False

# If false, no index is generated.
#html_use_index = False
# html_use_index = False

# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False

# If true, the reST sources are included in the HTML build as _sources/<name>.
#html_copy_source = True
# html_copy_source = 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 = ''

# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# html_file_suffix = ''

# Output file base name for HTML help builder.
htmlhelp_basename = 'Traitsuidoc'
Expand All @@ -156,6 +155,7 @@
html_theme = 'enthought'
except ImportError as exc:
import warnings

msg = '''Can't find Enthought Sphinx Theme, using default.
Exception was: {}
Enthought Sphinx Theme can be downloaded from
Expand All @@ -174,24 +174,32 @@
# #html_theme = 'classic'

# Useful aliases to avoid repeating long URLs.
extlinks = {'github-demo': (
f'https://github.com/enthought/traitsui/tree/{version}/traitsui/examples/demo/%s',
'github-demo')
extlinks = {
'github-demo': (
f'https://github.com/enthought/traitsui/tree/{version}/traitsui/examples/demo/%s',
'github-demo',
)
}

# 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, document class [howto/manual]).
latex_documents = [
('index', 'TraitsUI.tex', 'TraitsUI 4 User Manual', 'Enthought, Inc.', 'manual'),
(
'index',
'TraitsUI.tex',
'TraitsUI 4 User Manual',
'Enthought, Inc.',
'manual',
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -201,21 +209,19 @@

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# latex_use_parts = 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_use_modindex = True
# latex_use_modindex = True

# Autodoc options
autodo_mock_imports = [
"wx", "PySide", "PyQt", "PyQt5"
]
autodo_mock_imports = ["wx", "PySide", "PyQt", "PyQt5"]

# Intersphinx configuration
intersphinx_mapping = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class TC_Handler(Handler):

def setattr(self, info, object, name, value):
Handler.setattr(self, info, object, name, value)
info.object._updated = True
Expand Down
2 changes: 1 addition & 1 deletion docs/source/traitsui_user_manual/examples/key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


class CodeHandler(Handler):
""" Handler class for bound methods. """
"""Handler class for bound methods."""

def save_file(self, info):
info.object.status = "save file"
Expand Down
22 changes: 11 additions & 11 deletions docs/source/traitsui_user_manual/examples/mixed_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ class MixedStyles(HasTraits):
position_type = Enum("Full-Time", "Part-Time", "Contract")

traits_view = View(
Group(
Item(name='first_name'),
Item(name='last_name'),
Group(
Item(name='department'),
Item(name='position_type', style='custom'),
style='simple',
),
),
title='Mixed Styles',
style='readonly',
Group(
Item(name='first_name'),
Item(name='last_name'),
Group(
Item(name='department'),
Item(name='position_type', style='custom'),
style='simple',
),
),
title='Mixed Styles',
style='readonly',
)


Expand Down
25 changes: 19 additions & 6 deletions docs/source/traitsui_user_manual/examples/tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@

from traits.api import HasTraits, Instance, List, Str, Regex
from traitsui.api import (
Action, Group, Handler, HGroup, Item, Menu, Separator, TreeEditor,
TreeNode, View, VSplit,
Action,
Group,
Handler,
HGroup,
Item,
Menu,
Separator,
TreeEditor,
TreeNode,
View,
VSplit,
)
from traitsui.editors.tree_editor import (
NewAction, CopyAction, CutAction, PasteAction, DeleteAction, RenameAction,
NewAction,
CopyAction,
CutAction,
PasteAction,
DeleteAction,
RenameAction,
)


Expand Down Expand Up @@ -88,7 +102,6 @@ class Owner(HasTraits):


class TreeHandler(Handler):

def employee_department(self, editor, object):
dept = editor.get_parent(object)
print(f'{object.name} works in the {dept.name} department.')
Expand Down Expand Up @@ -176,8 +189,8 @@ def employee_department(self, editor, object):
handler=TreeHandler(),
buttons=['Undo', 'OK', 'Cancel'],
resizable=True,
width=.3,
height=.3,
width=0.3,
height=0.3,
)

if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


def _is_python_file(path):
""" Return true if the given path is (public) non-test Python file."""
"""Return true if the given path is (public) non-test Python file."""
_, basename = os.path.split(path)
_, ext = os.path.splitext(basename)
return (
Expand All @@ -42,7 +42,7 @@ def _is_python_file(path):


def get_python_files(directory):
""" Report Python files to be run or to be skipped.
"""Report Python files to be run or to be skipped.
Returns
-------
Expand Down Expand Up @@ -82,8 +82,7 @@ def replaced_configure_traits(
screenshot_name=None,
**args,
):
""" Mocked configure_traits to launch then close the GUI.
"""
"""Mocked configure_traits to launch then close the GUI."""
ui_kwargs = dict(
view=view,
parent=None,
Expand All @@ -102,14 +101,14 @@ def replaced_configure_traits(
"source",
"traitsui_user_manual",
"images",
screenshot_name
screenshot_name,
)
)


@contextlib.contextmanager
def replace_configure_traits(screenshot_name):
""" Context manager to temporarily replace HasTraits.configure_traits
"""Context manager to temporarily replace HasTraits.configure_traits
with a mocked version such that GUI launched are closed soon after they
are open.
"""
Expand All @@ -124,7 +123,7 @@ def replace_configure_traits(screenshot_name):


def run_file(file_path):
""" Execute a given Python file.
"""Execute a given Python file.
Parameters
----------
Expand All @@ -140,8 +139,9 @@ def run_file(file_path):
"__name__": "__main__",
"__file__": file_path,
}
with replace_configure_traits(screenshot_name), \
mock.patch("sys.argv", [file_path]):
with replace_configure_traits(screenshot_name), mock.patch(
"sys.argv", [file_path]
):
# Mock argv: Some example reads sys.argv to allow more arguments
# But all examples should support being run without additional
# arguments.
Expand Down
15 changes: 8 additions & 7 deletions docs/source/tutorials/code_snippets/code_block0.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

from numpy import cos, sin


class Point(object):
""" 3D Points objects """
x = 0.
y = 0.
z = 0.
"""3D Points objects"""

x = 0.0
y = 0.0
z = 0.0

def rotate_z(self, theta):
""" rotate the point around the Z axis """
xtemp = cos(theta) * self.x + sin(theta) * self.y
"""rotate the point around the Z axis"""
xtemp = cos(theta) * self.x + sin(theta) * self.y
ytemp = -sin(theta) * self.x + cos(theta) * self.y
self.x = xtemp
self.y = ytemp

0 comments on commit 88182ca

Please sign in to comment.