Skip to content

Commit

Permalink
Significant refactor of the formatting logic.
Browse files Browse the repository at this point in the history
* Move ``format_tests`` into ``command_tests.misc_tests``
* Prototype sidecar tests for easier readability/maintainability
* ArgGroupNodes gain representation in the layout tree
* Get rid of ``WrapAlgo``
* Eliminate vertical/nest as separate decisions. Nesting is just the wrap
  decision for StatementNode and KwargNode wheras vertical is the wrap
  decision for PargGroupnode and ArgGroupNode.
* Replace ``algorithm_order`` with ``_layout_passes``
* Get rid of ``default_accept_layout`` and move logic into a member function
* Move configuration and ``node_path`` into new ``StackContext``
* Stricter valid-child-set for most layout nodes
  • Loading branch information
cheshirekow committed Oct 15, 2019
1 parent 7abe24f commit 2a4d453
Show file tree
Hide file tree
Showing 48 changed files with 4,043 additions and 3,821 deletions.
83 changes: 32 additions & 51 deletions cmake_format/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,59 @@ package(default_visibility=["//visibility:public"])
py_library(
name="cmake_format",
srcs=[
"doc/gendoc_sources.py",
"doc/conf.py",
"screw_users_test.py",
"__init__.py",
"__main__.py",
"parser_tests.py",
"annotate.py",
"commands.py",
"common.py",
"markup_tests.py",
"format_tests.py",
"layout_tests.py",
"invocation_tests.py",
"__init__.py",
"formatter.py",
"configuration.py",
"command_tests/file_tests.py",
"command_tests/add_library_tests.py",
"command_tests/install_tests.py",
"command_tests/add_executable_tests.py",
"command_tests/__init__.py",
"command_tests/export_tests.py",
"command_tests/conditional_tests.py",
"command_tests/set_tests.py",
"command_tests/add_custom_command_tests.py",
"doc/conf.py",
"doc/gendoc_sources.py",
"formatter.py",
"invocation_tests.py",
"layout_tests.py",
"lexer.py",
"lexer_tests.py",
"markup.py",
"markup_tests.py",
"parse_funs/add_executable.py",
"parse_funs/add_library.py",
"parse_funs/add_xxx.py",
"parse_funs/external_project.py",
"parse_funs/fetch_content.py",
"parse_funs/file.py",
"parse_funs/add_library.py",
"parse_funs/__init__.py",
"parse_funs/add_executable.py",
"parse_funs/add_xxx.py",
"parse_funs/install.py",
"parse_funs/fetch_content.py",
"tests.py",
"commands.py",
"parser.py",
"parser_tests.py",
"pypi/setup.py",
"render.py",
"parser.py",
"lexer_tests.py",
"screw_users_test.py",
"test/cmake-format.py",
"lexer.py",
"annotate.py",
"markup.py"],
"test/cmake-format-split-1.py",
"test/cmake-format-split-2.py",
"tests.py"],
data=["templates/layout.html.tpl",
"templates/style.css"])

py_library(
name="testdata",
data=glob(["test/*"]),
)

# -- Python 2 --

py_binary(
name="cmake-format",
srcs=["__main__.py"],
deps=[":cmake_format"],
main="__main__.py"
)

py_test(
name="format_tests",
srcs=["format_tests.py"],
deps=[":cmake_format"],
data=glob(["test/*"]),
python_version="PY2",
)

py_test(
name="invocation_tests",
srcs=["invocation_tests.py"],
deps=[":cmake_format"],
data=glob(["test/*"]),
deps=[":cmake_format", ":testdata"],
python_version="PY2",
)

Expand Down Expand Up @@ -97,22 +87,13 @@ py_test(
python_version="PY2",
)


py_test(
name="format_tests_py3",
srcs=["format_tests.py"],
main="format_tests.py",
deps=[":cmake_format"],
data=glob(["test/*"]),
python_version="PY3",
)
# -- Python 3 --

py_test(
name="invocation_tests_py3",
srcs=["invocation_tests.py"],
main="invocation_tests.py",
deps=[":cmake_format"],
data=glob(["test/*"]),
deps=[":cmake_format", ":testdata"],
python_version="PY3",
)

Expand Down
144 changes: 66 additions & 78 deletions cmake_format/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,84 +1,72 @@
format_and_lint(cmake_format
# cmake-format: sort
__init__.py
__main__.py
annotate.py
commands.py
command_tests/add_custom_command_tests.py
command_tests/add_executable_tests.py
command_tests/add_library_tests.py
command_tests/conditional_tests.py
command_tests/export_tests.py
command_tests/file_tests.py
command_tests/__init__.py
command_tests/install_tests.py
command_tests/set_tests.py
common.py
configuration.py
doc/conf.py
doc/gendoc_sources.py
formatter.py
format_tests.py
invocation_tests.py
layout_tests.py
lexer.py
lexer_tests.py
markup.py
markup_tests.py
parse_funs/add_executable.py
parse_funs/add_library.py
parse_funs/add_xxx.py
parse_funs/external_project.py
parse_funs/fetch_content.py
parse_funs/file.py
parse_funs/__init__.py
parse_funs/install.py
parser.py
parser_tests.py
pypi/setup.py
render.py
screw_users_test.py
test/cmake-format.py
tests.py)
format_and_lint(
cmake_format
# cmake-format: sort
__init__.py
__main__.py
annotate.py
commands.py
command_tests/add_custom_command_tests.py
command_tests/add_executable_tests.py
command_tests/add_library_tests.py
command_tests/conditional_tests.py
command_tests/export_tests.py
command_tests/file_tests.py
command_tests/__init__.py
command_tests/install_tests.py
command_tests/__main__.py
command_tests/misc_tests.py
command_tests/set_tests.py
common.py
configuration.py
doc/conf.py
doc/gendoc_sources.py
formatter.py
invocation_tests.py
layout_tests.py
lexer.py
lexer_tests.py
markup.py
markup_tests.py
parse_funs/add_executable.py
parse_funs/add_library.py
parse_funs/add_xxx.py
parse_funs/external_project.py
parse_funs/fetch_content.py
parse_funs/file.py
parse_funs/__init__.py
parse_funs/install.py
parser.py
parser_tests.py
pypi/setup.py
render.py
screw_users_test.py
test/cmake-format.py
test/cmake-format-split-1.py
test/cmake-format-split-2.py
tests.py)

add_test(NAME cmake_format-format_tests
COMMAND python -m cmake_format.format_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-invocation_tests
COMMAND python -m cmake_format.invocation_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-layout_tests
COMMAND python -m cmake_format.layout_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-lexer_tests
COMMAND python -m cmake_format.lexer_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-markup_tests
COMMAND python -m cmake_format.markup_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-parser_tests
COMMAND python -m cmake_format.parser_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
set(
_testnames
invocation_tests
layout_tests
lexer_tests
markup_tests
parser_tests)

foreach(_testname ${_testnames})
add_test(
NAME cmake_format-${_testname}
COMMAND python -Bm cmake_format.${_testname}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endforeach()

if(NOT IS_TRAVIS_CI)
add_test(NAME cmake_format-format_tests_py3
COMMAND python3 -m cmake_format.format_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-invocation_tests_py3
COMMAND python3 -m cmake_format.invocation_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-layout_tests_py3
COMMAND python3 -m cmake_format.layout_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-lexer_tests_py3
COMMAND python3 -m cmake_format.lexer_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-markup_tests_py3
COMMAND python3 -m cmake_format.markup_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME cmake_format-parser_tests_py3
COMMAND python3 -m cmake_format.parser_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
foreach(_testname ${_testnames})
add_test(
NAME cmake_format-${_testname}_py3
COMMAND python3 -Bm cmake_format.${_testname}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endforeach()
endif()

add_subdirectory(doc)
Expand Down
2 changes: 1 addition & 1 deletion cmake_format/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""
from __future__ import unicode_literals

VERSION = '0.5.5'
VERSION = '0.6.0'
2 changes: 1 addition & 1 deletion cmake_format/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def setup_argparser(arg_parser):
'Default is stdout.')

arg_parser.add_argument(
'-c', '--config-file', '--config-files', nargs='+',
'-c', '--config-file', '--config-files', '--config', nargs='+',
help='path to configuration file(s)')
arg_parser.add_argument('infilepaths', nargs='*')
add_config_options(arg_parser)
Expand Down
Loading

0 comments on commit 2a4d453

Please sign in to comment.