Vulkan-Docs/scripts/spec_tools/file_process.py
Jon Leech 194a7f4d0d Change log for September 8, 2019 Vulkan 1.1.122 spec update:
* Update release number to 122.

Internal Issues:

  * Add style guide language on not using standalone `+` signs (internal
    issue 736); not using leading whitespace for markup (internal issue
    747); and on keeping descriptions of a single API in a contiguous block
    of markup (internal issue 949), and apply them to the specification.
  * Add a glossary definition of "`constant integral expression`", pointing
    to the SPIR-V "`constant instruction`" definition (internal issue 1225).
  * Many minor edits to improve writing style consistency and capture
    additional style guidelines (internal issue 1553).
  * Clarify that <<fragops-depth-write, depth writes are not performed>> if
    there is no depth framebuffer attachment (internal issue 1771).
  * Allow implementations to use rectangular line style of interpolation for
    <<primsrast-lines-bresenham, wide Bresenham lines>>, though replicating
    attributes is still preferred. Clarify that code:FragCoord is not
    replicated (internal issue 1772).
  * Resolve a contradiction in valid usage statements for
    slink:VkImageCreateInfo and slink:VkImageStencilUsageCreateInfoEXT
    (internal issue 1773).
  * Add style guide discussion of markup for indented equations, and use
    markup workaround for asciidoctor 2 compatibility (internal issue 1793).
  * Deprecate the `<<VK_EXT_validation_flags>>` extension in `vk.xml` and
    the extension appendix (internal issue 1801).
  * Add a new checker script `scripts/xml_consistency.py`. This is not
    currently run as part of internal CI (internal merge request 3285).
  * Correct "`an`" -> "`a`" prepositions where needed (internal merge
    request 3334).
  * Clarify that the <<features-uniformBufferStandardLayout,
    pname:uniformBufferStandardLayout>> feature is only required when the
    extension defining it is supported (internal merge request 3341).
  * Bring scripts into closer sync with OpenXR, mainly through conversion of
    comments to docstrings where appropriate, and add gen-scripts-docs.sh
    (internal merge request 3324).
  * Correct pname:maxDrawMeshTasksCount to 2^16^-1 in the <<limits-required,
    Required Limits>> table (internal merge requests 3361).

New Extensions

  * `<<VK_IMG_format_pvrtc>>` (public issue 512).
2019-09-08 20:41:02 -07:00

130 lines
4.4 KiB
Python

#!/usr/bin/python3
#
# Copyright (c) 2018-2019 Collabora, Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author(s): Ryan Pavlik <ryan.pavlik@collabora.com>
"Utilities for processing files."
from pathlib import Path
class LinewiseFileProcessor:
"""A base class for code that processes an input file (or file handle) one line at a time."""
def __init__(self):
self._lines = []
self._line_num = 0
self._next_line = None
self._line = ''
self._filename = Path()
@property
def filename(self):
"""The Path object of the currently processed file"""
return self._filename
@property
def relative_filename(self):
"""The current file's Path relative to the current working directory"""
return self.filename.relative_to(Path('.').resolve())
@property
def line(self):
"""The current line, including any trailing whitespace and the line ending."""
return self._line
@property
def line_number(self):
"""Get 1-indexed line number."""
return self._line_num
@property
def line_rstripped(self):
"""The current line without any trailing whitespace."""
if self.line is None:
return None
return self.line.rstrip()
@property
def trailing_whitespace(self):
"""The trailing whitespace of the current line that gets removed when accessing rstrippedLine"""
non_whitespace_length = len(self.line_rstripped)
return self.line[non_whitespace_length:]
@property
def next_line(self):
"""Peek at the next line, if any."""
return self._next_line
@property
def next_line_rstripped(self):
"""Peek at the next line, if any, without any trailing whitespace."""
if self.next_line is None:
return None
return self.next_line.rstrip()
def get_preceding_line(self, relative_index=-1):
"""Retrieve the line at an line number at the given relative index, if one exists. Returns None if there is no line there."""
if relative_index >= 0:
raise RuntimeError(
'relativeIndex must be negative, to retrieve a preceding line.')
if relative_index + self.line_number <= 0:
# There is no line at this index
return None
return self._lines[self.line_number + relative_index - 1]
def get_preceding_lines(self, num):
"""Get *up to* the preceding num lines. Fewer may be returned if the requested number aren't available."""
return self._lines[- (num + 1):-1]
def process_line(self, line_num, line):
"""Implement in your subclass to handle each new line."""
raise NotImplementedError
def _process_file_handle(self, file_handle):
# These are so we can process one line earlier than we're actually iterating thru.
processing_line_num = None
processing_line = None
def do_process_line():
self._line_num = processing_line_num
self._line = processing_line
if processing_line is not None:
self._lines.append(processing_line)
self.process_line(processing_line_num, processing_line)
for line_num, line in enumerate(file_handle, 1):
self._next_line = line
do_process_line()
processing_line_num = line_num
processing_line = line
# Finally process the left-over line
self._next_line = None
do_process_line()
def process_file(self, filename, file_handle=None):
"""Main entry point - call with a filename and optionally the file handle to read from."""
if isinstance(filename, str):
filename = Path(filename).resolve()
self._filename = filename
if file_handle:
self._process_file_handle(file_handle)
else:
with self._filename.open('r', encoding='utf-8') as f:
self._process_file_handle(f)