partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
valid
ContentDumper._binary_file
Dump the ocntent into the `file` in binary mode.
knittingpattern/Dumper/file.py
def _binary_file(self, file): """Dump the ocntent into the `file` in binary mode. """ if self.__text_is_expected: file = TextWrapper(file, self.__encoding) self.__dump_to_file(file)
def _binary_file(self, file): """Dump the ocntent into the `file` in binary mode. """ if self.__text_is_expected: file = TextWrapper(file, self.__encoding) self.__dump_to_file(file)
[ "Dump", "the", "ocntent", "into", "the", "file", "in", "binary", "mode", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/file.py#L116-L121
[ "def", "_binary_file", "(", "self", ",", "file", ")", ":", "if", "self", ".", "__text_is_expected", ":", "file", "=", "TextWrapper", "(", "file", ",", "self", ".", "__encoding", ")", "self", ".", "__dump_to_file", "(", "file", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
ContentDumper._path
Saves the dump in a file named `path`.
knittingpattern/Dumper/file.py
def _path(self, path): """Saves the dump in a file named `path`.""" mode, encoding = self._mode_and_encoding_for_open() with open(path, mode, encoding=encoding) as file: self.__dump_to_file(file)
def _path(self, path): """Saves the dump in a file named `path`.""" mode, encoding = self._mode_and_encoding_for_open() with open(path, mode, encoding=encoding) as file: self.__dump_to_file(file)
[ "Saves", "the", "dump", "in", "a", "file", "named", "path", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/file.py#L136-L140
[ "def", "_path", "(", "self", ",", "path", ")", ":", "mode", ",", "encoding", "=", "self", ".", "_mode_and_encoding_for_open", "(", ")", "with", "open", "(", "path", ",", "mode", ",", "encoding", "=", "encoding", ")", "as", "file", ":", "self", ".", "__dump_to_file", "(", "file", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
ContentDumper._temporary_file
:return: a temporary file where the content is dumped to.
knittingpattern/Dumper/file.py
def _temporary_file(self, delete): """:return: a temporary file where the content is dumped to.""" file = NamedTemporaryFile("w+", delete=delete, encoding=self.__encoding) self._file(file) return file
def _temporary_file(self, delete): """:return: a temporary file where the content is dumped to.""" file = NamedTemporaryFile("w+", delete=delete, encoding=self.__encoding) self._file(file) return file
[ ":", "return", ":", "a", "temporary", "file", "where", "the", "content", "is", "dumped", "to", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/file.py#L142-L147
[ "def", "_temporary_file", "(", "self", ",", "delete", ")", ":", "file", "=", "NamedTemporaryFile", "(", "\"w+\"", ",", "delete", "=", "delete", ",", "encoding", "=", "self", ".", "__encoding", ")", "self", ".", "_file", "(", "file", ")", "return", "file" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
ContentDumper.temporary_path
Saves the dump in a temporary file and returns its path. .. warning:: The user of this method is responsible for deleting this file to save space on the hard drive. If you only need a file object for a short period of time you can use the method :meth:`temporary_file`. :param str extension: the ending ot the file name e.g. ``".png"`` :return: a path to the temporary file :rtype: str
knittingpattern/Dumper/file.py
def temporary_path(self, extension=""): """Saves the dump in a temporary file and returns its path. .. warning:: The user of this method is responsible for deleting this file to save space on the hard drive. If you only need a file object for a short period of time you can use the method :meth:`temporary_file`. :param str extension: the ending ot the file name e.g. ``".png"`` :return: a path to the temporary file :rtype: str """ path = NamedTemporaryFile(delete=False, suffix=extension).name self.path(path) return path
def temporary_path(self, extension=""): """Saves the dump in a temporary file and returns its path. .. warning:: The user of this method is responsible for deleting this file to save space on the hard drive. If you only need a file object for a short period of time you can use the method :meth:`temporary_file`. :param str extension: the ending ot the file name e.g. ``".png"`` :return: a path to the temporary file :rtype: str """ path = NamedTemporaryFile(delete=False, suffix=extension).name self.path(path) return path
[ "Saves", "the", "dump", "in", "a", "temporary", "file", "and", "returns", "its", "path", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/file.py#L149-L163
[ "def", "temporary_path", "(", "self", ",", "extension", "=", "\"\"", ")", ":", "path", "=", "NamedTemporaryFile", "(", "delete", "=", "False", ",", "suffix", "=", "extension", ")", ".", "name", "self", ".", "path", "(", "path", ")", "return", "path" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
ContentDumper._binary_temporary_file
:return: a binary temporary file where the content is dumped to.
knittingpattern/Dumper/file.py
def _binary_temporary_file(self, delete): """:return: a binary temporary file where the content is dumped to.""" file = NamedTemporaryFile("wb+", delete=delete) self._binary_file(file) return file
def _binary_temporary_file(self, delete): """:return: a binary temporary file where the content is dumped to.""" file = NamedTemporaryFile("wb+", delete=delete) self._binary_file(file) return file
[ ":", "return", ":", "a", "binary", "temporary", "file", "where", "the", "content", "is", "dumped", "to", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/file.py#L191-L195
[ "def", "_binary_temporary_file", "(", "self", ",", "delete", ")", ":", "file", "=", "NamedTemporaryFile", "(", "\"wb+\"", ",", "delete", "=", "delete", ")", "self", ".", "_binary_file", "(", "file", ")", "return", "file" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGBuilder._convert_to_image_color
:return: a color that can be used by the image
knittingpattern/convert/AYABPNGBuilder.py
def _convert_to_image_color(self, color): """:return: a color that can be used by the image""" rgb = self._convert_color_to_rrggbb(color) return self._convert_rrggbb_to_image_color(rgb)
def _convert_to_image_color(self, color): """:return: a color that can be used by the image""" rgb = self._convert_color_to_rrggbb(color) return self._convert_rrggbb_to_image_color(rgb)
[ ":", "return", ":", "a", "color", "that", "can", "be", "used", "by", "the", "image" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGBuilder.py#L70-L73
[ "def", "_convert_to_image_color", "(", "self", ",", "color", ")", ":", "rgb", "=", "self", ".", "_convert_color_to_rrggbb", "(", "color", ")", "return", "self", ".", "_convert_rrggbb_to_image_color", "(", "rgb", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGBuilder._set_pixel_and_convert_color
set the pixel but convert the color before.
knittingpattern/convert/AYABPNGBuilder.py
def _set_pixel_and_convert_color(self, x, y, color): """set the pixel but convert the color before.""" if color is None: return color = self._convert_color_to_rrggbb(color) self._set_pixel(x, y, color)
def _set_pixel_and_convert_color(self, x, y, color): """set the pixel but convert the color before.""" if color is None: return color = self._convert_color_to_rrggbb(color) self._set_pixel(x, y, color)
[ "set", "the", "pixel", "but", "convert", "the", "color", "before", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGBuilder.py#L75-L80
[ "def", "_set_pixel_and_convert_color", "(", "self", ",", "x", ",", "y", ",", "color", ")", ":", "if", "color", "is", "None", ":", "return", "color", "=", "self", ".", "_convert_color_to_rrggbb", "(", "color", ")", "self", ".", "_set_pixel", "(", "x", ",", "y", ",", "color", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGBuilder._set_pixel
set the color of the pixel. :param color: must be a valid color in the form of "#RRGGBB". If you need to convert color, use `_set_pixel_and_convert_color()`.
knittingpattern/convert/AYABPNGBuilder.py
def _set_pixel(self, x, y, color): """set the color of the pixel. :param color: must be a valid color in the form of "#RRGGBB". If you need to convert color, use `_set_pixel_and_convert_color()`. """ if not self.is_in_bounds(x, y): return rgb = self._convert_rrggbb_to_image_color(color) x -= self._min_x y -= self._min_y self._image.putpixel((x, y), rgb)
def _set_pixel(self, x, y, color): """set the color of the pixel. :param color: must be a valid color in the form of "#RRGGBB". If you need to convert color, use `_set_pixel_and_convert_color()`. """ if not self.is_in_bounds(x, y): return rgb = self._convert_rrggbb_to_image_color(color) x -= self._min_x y -= self._min_y self._image.putpixel((x, y), rgb)
[ "set", "the", "color", "of", "the", "pixel", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGBuilder.py#L82-L93
[ "def", "_set_pixel", "(", "self", ",", "x", ",", "y", ",", "color", ")", ":", "if", "not", "self", ".", "is_in_bounds", "(", "x", ",", "y", ")", ":", "return", "rgb", "=", "self", ".", "_convert_rrggbb_to_image_color", "(", "color", ")", "x", "-=", "self", ".", "_min_x", "y", "-=", "self", ".", "_min_y", "self", ".", "_image", ".", "putpixel", "(", "(", "x", ",", "y", ")", ",", "rgb", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGBuilder.set_pixel
set the pixel at ``(x, y)`` position to :paramref:`color` If ``(x, y)`` is out of the :ref:`bounds <png-builder-bounds>` this does not change the image. .. seealso:: :meth:`set_color_in_grid`
knittingpattern/convert/AYABPNGBuilder.py
def set_pixel(self, x, y, color): """set the pixel at ``(x, y)`` position to :paramref:`color` If ``(x, y)`` is out of the :ref:`bounds <png-builder-bounds>` this does not change the image. .. seealso:: :meth:`set_color_in_grid` """ self._set_pixel_and_convert_color(x, y, color)
def set_pixel(self, x, y, color): """set the pixel at ``(x, y)`` position to :paramref:`color` If ``(x, y)`` is out of the :ref:`bounds <png-builder-bounds>` this does not change the image. .. seealso:: :meth:`set_color_in_grid` """ self._set_pixel_and_convert_color(x, y, color)
[ "set", "the", "pixel", "at", "(", "x", "y", ")", "position", "to", ":", "paramref", ":", "color" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGBuilder.py#L95-L103
[ "def", "set_pixel", "(", "self", ",", "x", ",", "y", ",", "color", ")", ":", "self", ".", "_set_pixel_and_convert_color", "(", "x", ",", "y", ",", "color", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGBuilder.is_in_bounds
:return: whether ``(x, y)`` is inside the :ref:`bounds <png-builder-bounds>` :rtype: bool
knittingpattern/convert/AYABPNGBuilder.py
def is_in_bounds(self, x, y): """ :return: whether ``(x, y)`` is inside the :ref:`bounds <png-builder-bounds>` :rtype: bool """ lower = self._min_x <= x and self._min_y <= y upper = self._max_x > x and self._max_y > y return lower and upper
def is_in_bounds(self, x, y): """ :return: whether ``(x, y)`` is inside the :ref:`bounds <png-builder-bounds>` :rtype: bool """ lower = self._min_x <= x and self._min_y <= y upper = self._max_x > x and self._max_y > y return lower and upper
[ ":", "return", ":", "whether", "(", "x", "y", ")", "is", "inside", "the", ":", "ref", ":", "bounds", "<png", "-", "builder", "-", "bounds", ">", ":", "rtype", ":", "bool" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGBuilder.py#L105-L113
[ "def", "is_in_bounds", "(", "self", ",", "x", ",", "y", ")", ":", "lower", "=", "self", ".", "_min_x", "<=", "x", "and", "self", ".", "_min_y", "<=", "y", "upper", "=", "self", ".", "_max_x", ">", "x", "and", "self", ".", "_max_y", ">", "y", "return", "lower", "and", "upper" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGBuilder.set_color_in_grid
Set the pixel at the position of the :paramref:`color_in_grid` to its color. :param color_in_grid: must have the following attributes: - ``color`` is the :ref:`color <png-color>` to set the pixel to - ``x`` is the x position of the pixel - ``y`` is the y position of the pixel .. seealso:: :meth:`set_pixel`, :meth:`set_colors_in_grid`
knittingpattern/convert/AYABPNGBuilder.py
def set_color_in_grid(self, color_in_grid): """Set the pixel at the position of the :paramref:`color_in_grid` to its color. :param color_in_grid: must have the following attributes: - ``color`` is the :ref:`color <png-color>` to set the pixel to - ``x`` is the x position of the pixel - ``y`` is the y position of the pixel .. seealso:: :meth:`set_pixel`, :meth:`set_colors_in_grid` """ self._set_pixel_and_convert_color( color_in_grid.x, color_in_grid.y, color_in_grid.color)
def set_color_in_grid(self, color_in_grid): """Set the pixel at the position of the :paramref:`color_in_grid` to its color. :param color_in_grid: must have the following attributes: - ``color`` is the :ref:`color <png-color>` to set the pixel to - ``x`` is the x position of the pixel - ``y`` is the y position of the pixel .. seealso:: :meth:`set_pixel`, :meth:`set_colors_in_grid` """ self._set_pixel_and_convert_color( color_in_grid.x, color_in_grid.y, color_in_grid.color)
[ "Set", "the", "pixel", "at", "the", "position", "of", "the", ":", "paramref", ":", "color_in_grid", "to", "its", "color", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGBuilder.py#L115-L128
[ "def", "set_color_in_grid", "(", "self", ",", "color_in_grid", ")", ":", "self", ".", "_set_pixel_and_convert_color", "(", "color_in_grid", ".", "x", ",", "color_in_grid", ".", "y", ",", "color_in_grid", ".", "color", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGBuilder.set_colors_in_grid
Same as :meth:`set_color_in_grid` but with a collection of colors in grid. :param iterable some_colors_in_grid: a collection of colors in grid for :meth:`set_color_in_grid`
knittingpattern/convert/AYABPNGBuilder.py
def set_colors_in_grid(self, some_colors_in_grid): """Same as :meth:`set_color_in_grid` but with a collection of colors in grid. :param iterable some_colors_in_grid: a collection of colors in grid for :meth:`set_color_in_grid` """ for color_in_grid in some_colors_in_grid: self._set_pixel_and_convert_color( color_in_grid.x, color_in_grid.y, color_in_grid.color)
def set_colors_in_grid(self, some_colors_in_grid): """Same as :meth:`set_color_in_grid` but with a collection of colors in grid. :param iterable some_colors_in_grid: a collection of colors in grid for :meth:`set_color_in_grid` """ for color_in_grid in some_colors_in_grid: self._set_pixel_and_convert_color( color_in_grid.x, color_in_grid.y, color_in_grid.color)
[ "Same", "as", ":", "meth", ":", "set_color_in_grid", "but", "with", "a", "collection", "of", "colors", "in", "grid", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGBuilder.py#L130-L139
[ "def", "set_colors_in_grid", "(", "self", ",", "some_colors_in_grid", ")", ":", "for", "color_in_grid", "in", "some_colors_in_grid", ":", "self", ".", "_set_pixel_and_convert_color", "(", "color_in_grid", ".", "x", ",", "color_in_grid", ".", "y", ",", "color_in_grid", ".", "color", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionSVGCache.get_instruction_id
The id that identifies the instruction in this cache. :param instruction_or_id: an :class:`instruction <knittingpattern.Instruction.Instruction>` or an instruction id :return: a :func:`hashable <hash>` object :rtype: tuple
knittingpattern/convert/InstructionSVGCache.py
def get_instruction_id(self, instruction_or_id): """The id that identifies the instruction in this cache. :param instruction_or_id: an :class:`instruction <knittingpattern.Instruction.Instruction>` or an instruction id :return: a :func:`hashable <hash>` object :rtype: tuple """ if isinstance(instruction_or_id, tuple): return _InstructionId(instruction_or_id) return _InstructionId(instruction_or_id.type, instruction_or_id.hex_color)
def get_instruction_id(self, instruction_or_id): """The id that identifies the instruction in this cache. :param instruction_or_id: an :class:`instruction <knittingpattern.Instruction.Instruction>` or an instruction id :return: a :func:`hashable <hash>` object :rtype: tuple """ if isinstance(instruction_or_id, tuple): return _InstructionId(instruction_or_id) return _InstructionId(instruction_or_id.type, instruction_or_id.hex_color)
[ "The", "id", "that", "identifies", "the", "instruction", "in", "this", "cache", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionSVGCache.py#L36-L47
[ "def", "get_instruction_id", "(", "self", ",", "instruction_or_id", ")", ":", "if", "isinstance", "(", "instruction_or_id", ",", "tuple", ")", ":", "return", "_InstructionId", "(", "instruction_or_id", ")", "return", "_InstructionId", "(", "instruction_or_id", ".", "type", ",", "instruction_or_id", ".", "hex_color", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionSVGCache.to_svg
Return the SVG for an instruction. :param instruction_or_id: either an :class:`~knittingpattern.Instruction.Instruction` or an id returned by :meth:`get_instruction_id` :param bool i_promise_not_to_change_the_result: - :obj:`False`: the result is copied, you can alter it. - :obj:`True`: the result is directly from the cache. If you change the result, other calls of this function get the changed result. :return: an SVGDumper :rtype: knittingpattern.Dumper.SVGDumper
knittingpattern/convert/InstructionSVGCache.py
def to_svg(self, instruction_or_id, i_promise_not_to_change_the_result=False): """Return the SVG for an instruction. :param instruction_or_id: either an :class:`~knittingpattern.Instruction.Instruction` or an id returned by :meth:`get_instruction_id` :param bool i_promise_not_to_change_the_result: - :obj:`False`: the result is copied, you can alter it. - :obj:`True`: the result is directly from the cache. If you change the result, other calls of this function get the changed result. :return: an SVGDumper :rtype: knittingpattern.Dumper.SVGDumper """ return self._new_svg_dumper(lambda: self.instruction_to_svg_dict( instruction_or_id, not i_promise_not_to_change_the_result))
def to_svg(self, instruction_or_id, i_promise_not_to_change_the_result=False): """Return the SVG for an instruction. :param instruction_or_id: either an :class:`~knittingpattern.Instruction.Instruction` or an id returned by :meth:`get_instruction_id` :param bool i_promise_not_to_change_the_result: - :obj:`False`: the result is copied, you can alter it. - :obj:`True`: the result is directly from the cache. If you change the result, other calls of this function get the changed result. :return: an SVGDumper :rtype: knittingpattern.Dumper.SVGDumper """ return self._new_svg_dumper(lambda: self.instruction_to_svg_dict( instruction_or_id, not i_promise_not_to_change_the_result))
[ "Return", "the", "SVG", "for", "an", "instruction", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionSVGCache.py#L56-L73
[ "def", "to_svg", "(", "self", ",", "instruction_or_id", ",", "i_promise_not_to_change_the_result", "=", "False", ")", ":", "return", "self", ".", "_new_svg_dumper", "(", "lambda", ":", "self", ".", "instruction_to_svg_dict", "(", "instruction_or_id", ",", "not", "i_promise_not_to_change_the_result", ")", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionSVGCache.instruction_to_svg_dict
Return the SVG dict for the SVGBuilder. :param instruction_or_id: the instruction or id, see :meth:`get_instruction_id` :param bool copy_result: whether to copy the result :rtype: dict The result is cached.
knittingpattern/convert/InstructionSVGCache.py
def instruction_to_svg_dict(self, instruction_or_id, copy_result=True): """Return the SVG dict for the SVGBuilder. :param instruction_or_id: the instruction or id, see :meth:`get_instruction_id` :param bool copy_result: whether to copy the result :rtype: dict The result is cached. """ instruction_id = self.get_instruction_id(instruction_or_id) if instruction_id in self._cache: result = self._cache[instruction_id] else: result = self._instruction_to_svg_dict(instruction_id) self._cache[instruction_id] = result if copy_result: result = deepcopy(result) return result
def instruction_to_svg_dict(self, instruction_or_id, copy_result=True): """Return the SVG dict for the SVGBuilder. :param instruction_or_id: the instruction or id, see :meth:`get_instruction_id` :param bool copy_result: whether to copy the result :rtype: dict The result is cached. """ instruction_id = self.get_instruction_id(instruction_or_id) if instruction_id in self._cache: result = self._cache[instruction_id] else: result = self._instruction_to_svg_dict(instruction_id) self._cache[instruction_id] = result if copy_result: result = deepcopy(result) return result
[ "Return", "the", "SVG", "dict", "for", "the", "SVGBuilder", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionSVGCache.py#L75-L93
[ "def", "instruction_to_svg_dict", "(", "self", ",", "instruction_or_id", ",", "copy_result", "=", "True", ")", ":", "instruction_id", "=", "self", ".", "get_instruction_id", "(", "instruction_or_id", ")", "if", "instruction_id", "in", "self", ".", "_cache", ":", "result", "=", "self", ".", "_cache", "[", "instruction_id", "]", "else", ":", "result", "=", "self", ".", "_instruction_to_svg_dict", "(", "instruction_id", ")", "self", ".", "_cache", "[", "instruction_id", "]", "=", "result", "if", "copy_result", ":", "result", "=", "deepcopy", "(", "result", ")", "return", "result" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Row._instructions_changed
Call when there is a change in the instructions.
knittingpattern/Row.py
def _instructions_changed(self, change): """Call when there is a change in the instructions.""" if change.adds(): for index, instruction in change.items(): if isinstance(instruction, dict): in_row = self._parser.instruction_in_row(self, instruction) self.instructions[index] = in_row else: instruction.transfer_to_row(self)
def _instructions_changed(self, change): """Call when there is a change in the instructions.""" if change.adds(): for index, instruction in change.items(): if isinstance(instruction, dict): in_row = self._parser.instruction_in_row(self, instruction) self.instructions[index] = in_row else: instruction.transfer_to_row(self)
[ "Call", "when", "there", "is", "a", "change", "in", "the", "instructions", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Row.py#L46-L54
[ "def", "_instructions_changed", "(", "self", ",", "change", ")", ":", "if", "change", ".", "adds", "(", ")", ":", "for", "index", ",", "instruction", "in", "change", ".", "items", "(", ")", ":", "if", "isinstance", "(", "instruction", ",", "dict", ")", ":", "in_row", "=", "self", ".", "_parser", ".", "instruction_in_row", "(", "self", ",", "instruction", ")", "self", ".", "instructions", "[", "index", "]", "=", "in_row", "else", ":", "instruction", ".", "transfer_to_row", "(", "self", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Row.last_produced_mesh
The last produced mesh. :return: the last produced mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is produced .. seealso:: :attr:`number_of_produced_meshes`
knittingpattern/Row.py
def last_produced_mesh(self): """The last produced mesh. :return: the last produced mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is produced .. seealso:: :attr:`number_of_produced_meshes` """ for instruction in reversed(self.instructions): if instruction.produces_meshes(): return instruction.last_produced_mesh raise IndexError("{} produces no meshes".format(self))
def last_produced_mesh(self): """The last produced mesh. :return: the last produced mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is produced .. seealso:: :attr:`number_of_produced_meshes` """ for instruction in reversed(self.instructions): if instruction.produces_meshes(): return instruction.last_produced_mesh raise IndexError("{} produces no meshes".format(self))
[ "The", "last", "produced", "mesh", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Row.py#L148-L160
[ "def", "last_produced_mesh", "(", "self", ")", ":", "for", "instruction", "in", "reversed", "(", "self", ".", "instructions", ")", ":", "if", "instruction", ".", "produces_meshes", "(", ")", ":", "return", "instruction", ".", "last_produced_mesh", "raise", "IndexError", "(", "\"{} produces no meshes\"", ".", "format", "(", "self", ")", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Row.last_consumed_mesh
The last consumed mesh. :return: the last consumed mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is consumed .. seealso:: :attr:`number_of_consumed_meshes`
knittingpattern/Row.py
def last_consumed_mesh(self): """The last consumed mesh. :return: the last consumed mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is consumed .. seealso:: :attr:`number_of_consumed_meshes` """ for instruction in reversed(self.instructions): if instruction.consumes_meshes(): return instruction.last_consumed_mesh raise IndexError("{} consumes no meshes".format(self))
def last_consumed_mesh(self): """The last consumed mesh. :return: the last consumed mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is consumed .. seealso:: :attr:`number_of_consumed_meshes` """ for instruction in reversed(self.instructions): if instruction.consumes_meshes(): return instruction.last_consumed_mesh raise IndexError("{} consumes no meshes".format(self))
[ "The", "last", "consumed", "mesh", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Row.py#L163-L175
[ "def", "last_consumed_mesh", "(", "self", ")", ":", "for", "instruction", "in", "reversed", "(", "self", ".", "instructions", ")", ":", "if", "instruction", ".", "consumes_meshes", "(", ")", ":", "return", "instruction", ".", "last_consumed_mesh", "raise", "IndexError", "(", "\"{} consumes no meshes\"", ".", "format", "(", "self", ")", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Row.first_produced_mesh
The first produced mesh. :return: the first produced mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is produced .. seealso:: :attr:`number_of_produced_meshes`
knittingpattern/Row.py
def first_produced_mesh(self): """The first produced mesh. :return: the first produced mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is produced .. seealso:: :attr:`number_of_produced_meshes` """ for instruction in self.instructions: if instruction.produces_meshes(): return instruction.first_produced_mesh raise IndexError("{} produces no meshes".format(self))
def first_produced_mesh(self): """The first produced mesh. :return: the first produced mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is produced .. seealso:: :attr:`number_of_produced_meshes` """ for instruction in self.instructions: if instruction.produces_meshes(): return instruction.first_produced_mesh raise IndexError("{} produces no meshes".format(self))
[ "The", "first", "produced", "mesh", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Row.py#L178-L190
[ "def", "first_produced_mesh", "(", "self", ")", ":", "for", "instruction", "in", "self", ".", "instructions", ":", "if", "instruction", ".", "produces_meshes", "(", ")", ":", "return", "instruction", ".", "first_produced_mesh", "raise", "IndexError", "(", "\"{} produces no meshes\"", ".", "format", "(", "self", ")", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Row.first_consumed_mesh
The first consumed mesh. :return: the first consumed mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is consumed .. seealso:: :attr:`number_of_consumed_meshes`
knittingpattern/Row.py
def first_consumed_mesh(self): """The first consumed mesh. :return: the first consumed mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is consumed .. seealso:: :attr:`number_of_consumed_meshes` """ for instruction in self.instructions: if instruction.consumes_meshes(): return instruction.first_consumed_mesh raise IndexError("{} consumes no meshes".format(self))
def first_consumed_mesh(self): """The first consumed mesh. :return: the first consumed mesh :rtype: knittingpattern.Mesh.Mesh :raises IndexError: if no mesh is consumed .. seealso:: :attr:`number_of_consumed_meshes` """ for instruction in self.instructions: if instruction.consumes_meshes(): return instruction.first_consumed_mesh raise IndexError("{} consumes no meshes".format(self))
[ "The", "first", "consumed", "mesh", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Row.py#L193-L205
[ "def", "first_consumed_mesh", "(", "self", ")", ":", "for", "instruction", "in", "self", ".", "instructions", ":", "if", "instruction", ".", "consumes_meshes", "(", ")", ":", "return", "instruction", ".", "first_consumed_mesh", "raise", "IndexError", "(", "\"{} consumes no meshes\"", ".", "format", "(", "self", ")", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Row.rows_before
The rows that produce meshes for this row. :rtype: list :return: a list of rows that produce meshes for this row. Each row occurs only once. They are sorted by the first occurrence in the instructions.
knittingpattern/Row.py
def rows_before(self): """The rows that produce meshes for this row. :rtype: list :return: a list of rows that produce meshes for this row. Each row occurs only once. They are sorted by the first occurrence in the instructions. """ rows_before = [] for mesh in self.consumed_meshes: if mesh.is_produced(): row = mesh.producing_row if rows_before not in rows_before: rows_before.append(row) return rows_before
def rows_before(self): """The rows that produce meshes for this row. :rtype: list :return: a list of rows that produce meshes for this row. Each row occurs only once. They are sorted by the first occurrence in the instructions. """ rows_before = [] for mesh in self.consumed_meshes: if mesh.is_produced(): row = mesh.producing_row if rows_before not in rows_before: rows_before.append(row) return rows_before
[ "The", "rows", "that", "produce", "meshes", "for", "this", "row", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Row.py#L208-L222
[ "def", "rows_before", "(", "self", ")", ":", "rows_before", "=", "[", "]", "for", "mesh", "in", "self", ".", "consumed_meshes", ":", "if", "mesh", ".", "is_produced", "(", ")", ":", "row", "=", "mesh", ".", "producing_row", "if", "rows_before", "not", "in", "rows_before", ":", "rows_before", ".", "append", "(", "row", ")", "return", "rows_before" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Row.rows_after
The rows that consume meshes from this row. :rtype: list :return: a list of rows that consume meshes from this row. Each row occurs only once. They are sorted by the first occurrence in the instructions.
knittingpattern/Row.py
def rows_after(self): """The rows that consume meshes from this row. :rtype: list :return: a list of rows that consume meshes from this row. Each row occurs only once. They are sorted by the first occurrence in the instructions. """ rows_after = [] for mesh in self.produced_meshes: if mesh.is_consumed(): row = mesh.consuming_row if rows_after not in rows_after: rows_after.append(row) return rows_after
def rows_after(self): """The rows that consume meshes from this row. :rtype: list :return: a list of rows that consume meshes from this row. Each row occurs only once. They are sorted by the first occurrence in the instructions. """ rows_after = [] for mesh in self.produced_meshes: if mesh.is_consumed(): row = mesh.consuming_row if rows_after not in rows_after: rows_after.append(row) return rows_after
[ "The", "rows", "that", "consume", "meshes", "from", "this", "row", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Row.py#L225-L239
[ "def", "rows_after", "(", "self", ")", ":", "rows_after", "=", "[", "]", "for", "mesh", "in", "self", ".", "produced_meshes", ":", "if", "mesh", ".", "is_consumed", "(", ")", ":", "row", "=", "mesh", ".", "consuming_row", "if", "rows_after", "not", "in", "rows_after", ":", "rows_after", ".", "append", "(", "row", ")", "return", "rows_after" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
IdCollection.at
Get the object at an :paramref:`index`. :param int index: the index of the object :return: the object at :paramref:`index`
knittingpattern/IdCollection.py
def at(self, index): """Get the object at an :paramref:`index`. :param int index: the index of the object :return: the object at :paramref:`index` """ keys = list(self._items.keys()) key = keys[index] return self[key]
def at(self, index): """Get the object at an :paramref:`index`. :param int index: the index of the object :return: the object at :paramref:`index` """ keys = list(self._items.keys()) key = keys[index] return self[key]
[ "Get", "the", "object", "at", "an", ":", "paramref", ":", "index", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/IdCollection.py#L23-L31
[ "def", "at", "(", "self", ",", "index", ")", ":", "keys", "=", "list", "(", "self", ".", "_items", ".", "keys", "(", ")", ")", "key", "=", "keys", "[", "index", "]", "return", "self", "[", "key", "]" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
PathLoader.folder
Load all files from a folder recursively. Depending on :meth:`chooses_path` some paths may not be loaded. Every loaded path is processed and returned part of the returned list. :param str folder: the folder to load the files from :rtype: list :return: a list of the results of the processing steps of the loaded files
knittingpattern/Loader.py
def folder(self, folder): """Load all files from a folder recursively. Depending on :meth:`chooses_path` some paths may not be loaded. Every loaded path is processed and returned part of the returned list. :param str folder: the folder to load the files from :rtype: list :return: a list of the results of the processing steps of the loaded files """ result = [] for root, _, files in os.walk(folder): for file in files: path = os.path.join(root, file) if self._chooses_path(path): result.append(self.path(path)) return result
def folder(self, folder): """Load all files from a folder recursively. Depending on :meth:`chooses_path` some paths may not be loaded. Every loaded path is processed and returned part of the returned list. :param str folder: the folder to load the files from :rtype: list :return: a list of the results of the processing steps of the loaded files """ result = [] for root, _, files in os.walk(folder): for file in files: path = os.path.join(root, file) if self._chooses_path(path): result.append(self.path(path)) return result
[ "Load", "all", "files", "from", "a", "folder", "recursively", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Loader.py#L45-L62
[ "def", "folder", "(", "self", ",", "folder", ")", ":", "result", "=", "[", "]", "for", "root", ",", "_", ",", "files", "in", "os", ".", "walk", "(", "folder", ")", ":", "for", "file", "in", "files", ":", "path", "=", "os", ".", "path", ".", "join", "(", "root", ",", "file", ")", "if", "self", ".", "_chooses_path", "(", "path", ")", ":", "result", ".", "append", "(", "self", ".", "path", "(", "path", ")", ")", "return", "result" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
PathLoader._relative_to_absolute
:return: the absolute path for the `folder` relative to the module_location. :rtype: str
knittingpattern/Loader.py
def _relative_to_absolute(self, module_location, folder): """:return: the absolute path for the `folder` relative to the module_location. :rtype: str """ if os.path.isfile(module_location): path = os.path.dirname(module_location) elif os.path.isdir(module_location): path = module_location else: module_folder = os.path.dirname(module_location) if module_folder: path = module_folder else: __import__(module_location) module = sys.modules[module_location] path = os.path.dirname(module.__file__) absolute_path = os.path.join(path, folder) return absolute_path
def _relative_to_absolute(self, module_location, folder): """:return: the absolute path for the `folder` relative to the module_location. :rtype: str """ if os.path.isfile(module_location): path = os.path.dirname(module_location) elif os.path.isdir(module_location): path = module_location else: module_folder = os.path.dirname(module_location) if module_folder: path = module_folder else: __import__(module_location) module = sys.modules[module_location] path = os.path.dirname(module.__file__) absolute_path = os.path.join(path, folder) return absolute_path
[ ":", "return", ":", "the", "absolute", "path", "for", "the", "folder", "relative", "to", "the", "module_location", ".", ":", "rtype", ":", "str" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Loader.py#L80-L98
[ "def", "_relative_to_absolute", "(", "self", ",", "module_location", ",", "folder", ")", ":", "if", "os", ".", "path", ".", "isfile", "(", "module_location", ")", ":", "path", "=", "os", ".", "path", ".", "dirname", "(", "module_location", ")", "elif", "os", ".", "path", ".", "isdir", "(", "module_location", ")", ":", "path", "=", "module_location", "else", ":", "module_folder", "=", "os", ".", "path", ".", "dirname", "(", "module_location", ")", "if", "module_folder", ":", "path", "=", "module_folder", "else", ":", "__import__", "(", "module_location", ")", "module", "=", "sys", ".", "modules", "[", "module_location", "]", "path", "=", "os", ".", "path", ".", "dirname", "(", "module", ".", "__file__", ")", "absolute_path", "=", "os", ".", "path", ".", "join", "(", "path", ",", "folder", ")", "return", "absolute_path" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
PathLoader.relative_folder
Load a folder located relative to a module and return the processed result. :param str module: can be - a path to a folder - a path to a file - a module name :param str folder: the path of a folder relative to :paramref:`module` :return: a list of the results of the processing :rtype: list Depending on :meth:`chooses_path` some paths may not be loaded. Every loaded path is processed and returned part of the returned list. You can use :meth:`choose_paths` to find out which paths are chosen to load.
knittingpattern/Loader.py
def relative_folder(self, module, folder): """Load a folder located relative to a module and return the processed result. :param str module: can be - a path to a folder - a path to a file - a module name :param str folder: the path of a folder relative to :paramref:`module` :return: a list of the results of the processing :rtype: list Depending on :meth:`chooses_path` some paths may not be loaded. Every loaded path is processed and returned part of the returned list. You can use :meth:`choose_paths` to find out which paths are chosen to load. """ folder = self._relative_to_absolute(module, folder) return self.folder(folder)
def relative_folder(self, module, folder): """Load a folder located relative to a module and return the processed result. :param str module: can be - a path to a folder - a path to a file - a module name :param str folder: the path of a folder relative to :paramref:`module` :return: a list of the results of the processing :rtype: list Depending on :meth:`chooses_path` some paths may not be loaded. Every loaded path is processed and returned part of the returned list. You can use :meth:`choose_paths` to find out which paths are chosen to load. """ folder = self._relative_to_absolute(module, folder) return self.folder(folder)
[ "Load", "a", "folder", "located", "relative", "to", "a", "module", "and", "return", "the", "processed", "result", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Loader.py#L100-L120
[ "def", "relative_folder", "(", "self", ",", "module", ",", "folder", ")", ":", "folder", "=", "self", ".", "_relative_to_absolute", "(", "module", ",", "folder", ")", "return", "self", ".", "folder", "(", "folder", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
PathLoader.relative_file
Load a file relative to a module. :param str module: can be - a path to a folder - a path to a file - a module name :param str folder: the path of a folder relative to :paramref:`module` :return: the result of the processing
knittingpattern/Loader.py
def relative_file(self, module, file): """Load a file relative to a module. :param str module: can be - a path to a folder - a path to a file - a module name :param str folder: the path of a folder relative to :paramref:`module` :return: the result of the processing """ path = self._relative_to_absolute(module, file) return self.path(path)
def relative_file(self, module, file): """Load a file relative to a module. :param str module: can be - a path to a folder - a path to a file - a module name :param str folder: the path of a folder relative to :paramref:`module` :return: the result of the processing """ path = self._relative_to_absolute(module, file) return self.path(path)
[ "Load", "a", "file", "relative", "to", "a", "module", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Loader.py#L122-L136
[ "def", "relative_file", "(", "self", ",", "module", ",", "file", ")", ":", "path", "=", "self", ".", "_relative_to_absolute", "(", "module", ",", "file", ")", "return", "self", ".", "path", "(", "path", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
PathLoader.example
Load an example from the knitting pattern examples. :param str relative_path: the path to load :return: the result of the processing You can use :meth:`knittingpattern.Loader.PathLoader.examples` to find out the paths of all examples.
knittingpattern/Loader.py
def example(self, relative_path): """Load an example from the knitting pattern examples. :param str relative_path: the path to load :return: the result of the processing You can use :meth:`knittingpattern.Loader.PathLoader.examples` to find out the paths of all examples. """ example_path = os.path.join("examples", relative_path) return self.relative_file(__file__, example_path)
def example(self, relative_path): """Load an example from the knitting pattern examples. :param str relative_path: the path to load :return: the result of the processing You can use :meth:`knittingpattern.Loader.PathLoader.examples` to find out the paths of all examples. """ example_path = os.path.join("examples", relative_path) return self.relative_file(__file__, example_path)
[ "Load", "an", "example", "from", "the", "knitting", "pattern", "examples", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Loader.py#L144-L154
[ "def", "example", "(", "self", ",", "relative_path", ")", ":", "example_path", "=", "os", ".", "path", ".", "join", "(", "\"examples\"", ",", "relative_path", ")", "return", "self", ".", "relative_file", "(", "__file__", ",", "example_path", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
ContentLoader.url
load and process the content behind a url :return: the processed result of the :paramref:`url's <url>` content :param str url: the url to retrieve the content from :param str encoding: the encoding of the retrieved content. The default encoding is UTF-8.
knittingpattern/Loader.py
def url(self, url, encoding="UTF-8"): """load and process the content behind a url :return: the processed result of the :paramref:`url's <url>` content :param str url: the url to retrieve the content from :param str encoding: the encoding of the retrieved content. The default encoding is UTF-8. """ import urllib.request with urllib.request.urlopen(url) as file: webpage_content = file.read() webpage_content = webpage_content.decode(encoding) return self.string(webpage_content)
def url(self, url, encoding="UTF-8"): """load and process the content behind a url :return: the processed result of the :paramref:`url's <url>` content :param str url: the url to retrieve the content from :param str encoding: the encoding of the retrieved content. The default encoding is UTF-8. """ import urllib.request with urllib.request.urlopen(url) as file: webpage_content = file.read() webpage_content = webpage_content.decode(encoding) return self.string(webpage_content)
[ "load", "and", "process", "the", "content", "behind", "a", "url" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Loader.py#L198-L211
[ "def", "url", "(", "self", ",", "url", ",", "encoding", "=", "\"UTF-8\"", ")", ":", "import", "urllib", ".", "request", "with", "urllib", ".", "request", ".", "urlopen", "(", "url", ")", "as", "file", ":", "webpage_content", "=", "file", ".", "read", "(", ")", "webpage_content", "=", "webpage_content", ".", "decode", "(", "encoding", ")", "return", "self", ".", "string", "(", "webpage_content", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
JSONLoader.string
Load an object from a string and return the processed JSON content :return: the result of the processing step :param str string: the string to load the JSON from
knittingpattern/Loader.py
def string(self, string): """Load an object from a string and return the processed JSON content :return: the result of the processing step :param str string: the string to load the JSON from """ object_ = json.loads(string) return self.object(object_)
def string(self, string): """Load an object from a string and return the processed JSON content :return: the result of the processing step :param str string: the string to load the JSON from """ object_ = json.loads(string) return self.object(object_)
[ "Load", "an", "object", "from", "a", "string", "and", "return", "the", "processed", "JSON", "content" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Loader.py#L229-L236
[ "def", "string", "(", "self", ",", "string", ")", ":", "object_", "=", "json", ".", "loads", "(", "string", ")", "return", "self", ".", "object", "(", "object_", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Prototype.get
:return: the value behind :paramref:`key` in the specification. If no value was found, :paramref:`default` is returned. :param key: a :ref:`specification key <prototype-key>`
knittingpattern/Prototype.py
def get(self, key, default=None): """ :return: the value behind :paramref:`key` in the specification. If no value was found, :paramref:`default` is returned. :param key: a :ref:`specification key <prototype-key>` """ for base in self.__specification: if key in base: return base[key] return default
def get(self, key, default=None): """ :return: the value behind :paramref:`key` in the specification. If no value was found, :paramref:`default` is returned. :param key: a :ref:`specification key <prototype-key>` """ for base in self.__specification: if key in base: return base[key] return default
[ ":", "return", ":", "the", "value", "behind", ":", "paramref", ":", "key", "in", "the", "specification", ".", "If", "no", "value", "was", "found", ":", "paramref", ":", "default", "is", "returned", ".", ":", "param", "key", ":", "a", ":", "ref", ":", "specification", "key", "<prototype", "-", "key", ">" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Prototype.py#L36-L45
[ "def", "get", "(", "self", ",", "key", ",", "default", "=", "None", ")", ":", "for", "base", "in", "self", ".", "__specification", ":", "if", "key", "in", "base", ":", "return", "base", "[", "key", "]", "return", "default" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
AYABPNGDumper._dump_knitting_pattern
dump a knitting pattern to a file.
knittingpattern/convert/AYABPNGDumper.py
def _dump_knitting_pattern(self, file): """dump a knitting pattern to a file.""" knitting_pattern_set = self.__on_dump() knitting_pattern = knitting_pattern_set.patterns.at(0) layout = GridLayout(knitting_pattern) builder = AYABPNGBuilder(*layout.bounding_box) builder.set_colors_in_grid(layout.walk_instructions()) builder.write_to_file(file)
def _dump_knitting_pattern(self, file): """dump a knitting pattern to a file.""" knitting_pattern_set = self.__on_dump() knitting_pattern = knitting_pattern_set.patterns.at(0) layout = GridLayout(knitting_pattern) builder = AYABPNGBuilder(*layout.bounding_box) builder.set_colors_in_grid(layout.walk_instructions()) builder.write_to_file(file)
[ "dump", "a", "knitting", "pattern", "to", "a", "file", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/AYABPNGDumper.py#L30-L37
[ "def", "_dump_knitting_pattern", "(", "self", ",", "file", ")", ":", "knitting_pattern_set", "=", "self", ".", "__on_dump", "(", ")", "knitting_pattern", "=", "knitting_pattern_set", ".", "patterns", ".", "at", "(", "0", ")", "layout", "=", "GridLayout", "(", "knitting_pattern", ")", "builder", "=", "AYABPNGBuilder", "(", "*", "layout", ".", "bounding_box", ")", "builder", ".", "set_colors_in_grid", "(", "layout", ".", "walk_instructions", "(", ")", ")", "builder", ".", "write_to_file", "(", "file", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
unique
Create an iterable from the iterables that contains each element once. :return: an iterable over the iterables. Each element of the result appeared only once in the result. They are ordered by the first occurrence in the iterables.
knittingpattern/utils.py
def unique(iterables): """Create an iterable from the iterables that contains each element once. :return: an iterable over the iterables. Each element of the result appeared only once in the result. They are ordered by the first occurrence in the iterables. """ included_elements = set() def included(element): result = element in included_elements included_elements.add(element) return result return [element for elements in iterables for element in elements if not included(element)]
def unique(iterables): """Create an iterable from the iterables that contains each element once. :return: an iterable over the iterables. Each element of the result appeared only once in the result. They are ordered by the first occurrence in the iterables. """ included_elements = set() def included(element): result = element in included_elements included_elements.add(element) return result return [element for elements in iterables for element in elements if not included(element)]
[ "Create", "an", "iterable", "from", "the", "iterables", "that", "contains", "each", "element", "once", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/utils.py#L8-L22
[ "def", "unique", "(", "iterables", ")", ":", "included_elements", "=", "set", "(", ")", "def", "included", "(", "element", ")", ":", "result", "=", "element", "in", "included_elements", "included_elements", ".", "add", "(", "element", ")", "return", "result", "return", "[", "element", "for", "elements", "in", "iterables", "for", "element", "in", "elements", "if", "not", "included", "(", "element", ")", "]" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
KnittingPatternToSVG.build_SVG_dict
Go through the layout and build the SVG. :return: an xml dict that can be exported using a :class:`~knittingpattern.Dumper.XMLDumper` :rtype: dict
knittingpattern/convert/KnittingPatternToSVG.py
def build_SVG_dict(self): """Go through the layout and build the SVG. :return: an xml dict that can be exported using a :class:`~knittingpattern.Dumper.XMLDumper` :rtype: dict """ zoom = self._zoom layout = self._layout builder = self._builder bbox = list(map(lambda f: f * zoom, layout.bounding_box)) builder.bounding_box = bbox flip_x = bbox[2] + bbox[0] * 2 flip_y = bbox[3] + bbox[1] * 2 instructions = list(layout.walk_instructions( lambda i: (flip_x - (i.x + i.width) * zoom, flip_y - (i.y + i.height) * zoom, i.instruction))) instructions.sort(key=lambda x_y_i: x_y_i[2].render_z) for x, y, instruction in instructions: render_z = instruction.render_z z_id = ("" if not render_z else "-{}".format(render_z)) layer_id = "row-{}{}".format(instruction.row.id, z_id) def_id = self._register_instruction_in_defs(instruction) scale = self._symbol_id_to_scale[def_id] group = { "@class": "instruction", "@id": "instruction-{}".format(instruction.id), "@transform": "translate({},{}),scale({})".format( x, y, scale) } builder.place_svg_use(def_id, layer_id, group) builder.insert_defs(self._instruction_type_color_to_symbol.values()) return builder.get_svg_dict()
def build_SVG_dict(self): """Go through the layout and build the SVG. :return: an xml dict that can be exported using a :class:`~knittingpattern.Dumper.XMLDumper` :rtype: dict """ zoom = self._zoom layout = self._layout builder = self._builder bbox = list(map(lambda f: f * zoom, layout.bounding_box)) builder.bounding_box = bbox flip_x = bbox[2] + bbox[0] * 2 flip_y = bbox[3] + bbox[1] * 2 instructions = list(layout.walk_instructions( lambda i: (flip_x - (i.x + i.width) * zoom, flip_y - (i.y + i.height) * zoom, i.instruction))) instructions.sort(key=lambda x_y_i: x_y_i[2].render_z) for x, y, instruction in instructions: render_z = instruction.render_z z_id = ("" if not render_z else "-{}".format(render_z)) layer_id = "row-{}{}".format(instruction.row.id, z_id) def_id = self._register_instruction_in_defs(instruction) scale = self._symbol_id_to_scale[def_id] group = { "@class": "instruction", "@id": "instruction-{}".format(instruction.id), "@transform": "translate({},{}),scale({})".format( x, y, scale) } builder.place_svg_use(def_id, layer_id, group) builder.insert_defs(self._instruction_type_color_to_symbol.values()) return builder.get_svg_dict()
[ "Go", "through", "the", "layout", "and", "build", "the", "SVG", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/KnittingPatternToSVG.py#L39-L72
[ "def", "build_SVG_dict", "(", "self", ")", ":", "zoom", "=", "self", ".", "_zoom", "layout", "=", "self", ".", "_layout", "builder", "=", "self", ".", "_builder", "bbox", "=", "list", "(", "map", "(", "lambda", "f", ":", "f", "*", "zoom", ",", "layout", ".", "bounding_box", ")", ")", "builder", ".", "bounding_box", "=", "bbox", "flip_x", "=", "bbox", "[", "2", "]", "+", "bbox", "[", "0", "]", "*", "2", "flip_y", "=", "bbox", "[", "3", "]", "+", "bbox", "[", "1", "]", "*", "2", "instructions", "=", "list", "(", "layout", ".", "walk_instructions", "(", "lambda", "i", ":", "(", "flip_x", "-", "(", "i", ".", "x", "+", "i", ".", "width", ")", "*", "zoom", ",", "flip_y", "-", "(", "i", ".", "y", "+", "i", ".", "height", ")", "*", "zoom", ",", "i", ".", "instruction", ")", ")", ")", "instructions", ".", "sort", "(", "key", "=", "lambda", "x_y_i", ":", "x_y_i", "[", "2", "]", ".", "render_z", ")", "for", "x", ",", "y", ",", "instruction", "in", "instructions", ":", "render_z", "=", "instruction", ".", "render_z", "z_id", "=", "(", "\"\"", "if", "not", "render_z", "else", "\"-{}\"", ".", "format", "(", "render_z", ")", ")", "layer_id", "=", "\"row-{}{}\"", ".", "format", "(", "instruction", ".", "row", ".", "id", ",", "z_id", ")", "def_id", "=", "self", ".", "_register_instruction_in_defs", "(", "instruction", ")", "scale", "=", "self", ".", "_symbol_id_to_scale", "[", "def_id", "]", "group", "=", "{", "\"@class\"", ":", "\"instruction\"", ",", "\"@id\"", ":", "\"instruction-{}\"", ".", "format", "(", "instruction", ".", "id", ")", ",", "\"@transform\"", ":", "\"translate({},{}),scale({})\"", ".", "format", "(", "x", ",", "y", ",", "scale", ")", "}", "builder", ".", "place_svg_use", "(", "def_id", ",", "layer_id", ",", "group", ")", "builder", ".", "insert_defs", "(", "self", ".", "_instruction_type_color_to_symbol", ".", "values", "(", ")", ")", "return", "builder", ".", "get_svg_dict", "(", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
KnittingPatternToSVG._register_instruction_in_defs
Create a definition for the instruction. :return: the id of a symbol in the defs for the specified :paramref:`instruction` :rtype: str If no symbol yet exists in the defs for the :paramref:`instruction` a symbol is created and saved using :meth:`_make_symbol`.
knittingpattern/convert/KnittingPatternToSVG.py
def _register_instruction_in_defs(self, instruction): """Create a definition for the instruction. :return: the id of a symbol in the defs for the specified :paramref:`instruction` :rtype: str If no symbol yet exists in the defs for the :paramref:`instruction` a symbol is created and saved using :meth:`_make_symbol`. """ type_ = instruction.type color_ = instruction.color instruction_to_svg_dict = \ self._instruction_to_svg.instruction_to_svg_dict instruction_id = "{}:{}".format(type_, color_) defs_id = instruction_id + ":defs" if instruction_id not in self._instruction_type_color_to_symbol: svg_dict = instruction_to_svg_dict(instruction) self._compute_scale(instruction_id, svg_dict) symbol = self._make_definition(svg_dict, instruction_id) self._instruction_type_color_to_symbol[defs_id] = \ symbol[DEFINITION_HOLDER].pop("defs", {}) self._instruction_type_color_to_symbol[instruction_id] = symbol return instruction_id
def _register_instruction_in_defs(self, instruction): """Create a definition for the instruction. :return: the id of a symbol in the defs for the specified :paramref:`instruction` :rtype: str If no symbol yet exists in the defs for the :paramref:`instruction` a symbol is created and saved using :meth:`_make_symbol`. """ type_ = instruction.type color_ = instruction.color instruction_to_svg_dict = \ self._instruction_to_svg.instruction_to_svg_dict instruction_id = "{}:{}".format(type_, color_) defs_id = instruction_id + ":defs" if instruction_id not in self._instruction_type_color_to_symbol: svg_dict = instruction_to_svg_dict(instruction) self._compute_scale(instruction_id, svg_dict) symbol = self._make_definition(svg_dict, instruction_id) self._instruction_type_color_to_symbol[defs_id] = \ symbol[DEFINITION_HOLDER].pop("defs", {}) self._instruction_type_color_to_symbol[instruction_id] = symbol return instruction_id
[ "Create", "a", "definition", "for", "the", "instruction", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/KnittingPatternToSVG.py#L74-L97
[ "def", "_register_instruction_in_defs", "(", "self", ",", "instruction", ")", ":", "type_", "=", "instruction", ".", "type", "color_", "=", "instruction", ".", "color", "instruction_to_svg_dict", "=", "self", ".", "_instruction_to_svg", ".", "instruction_to_svg_dict", "instruction_id", "=", "\"{}:{}\"", ".", "format", "(", "type_", ",", "color_", ")", "defs_id", "=", "instruction_id", "+", "\":defs\"", "if", "instruction_id", "not", "in", "self", ".", "_instruction_type_color_to_symbol", ":", "svg_dict", "=", "instruction_to_svg_dict", "(", "instruction", ")", "self", ".", "_compute_scale", "(", "instruction_id", ",", "svg_dict", ")", "symbol", "=", "self", ".", "_make_definition", "(", "svg_dict", ",", "instruction_id", ")", "self", ".", "_instruction_type_color_to_symbol", "[", "defs_id", "]", "=", "symbol", "[", "DEFINITION_HOLDER", "]", ".", "pop", "(", "\"defs\"", ",", "{", "}", ")", "self", ".", "_instruction_type_color_to_symbol", "[", "instruction_id", "]", "=", "symbol", "return", "instruction_id" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
KnittingPatternToSVG._make_definition
Create a symbol out of the supplied :paramref:`svg_dict`. :param dict svg_dict: dictionary containing the SVG for the instruction currently processed :param str instruction_id: id that will be assigned to the symbol
knittingpattern/convert/KnittingPatternToSVG.py
def _make_definition(self, svg_dict, instruction_id): """Create a symbol out of the supplied :paramref:`svg_dict`. :param dict svg_dict: dictionary containing the SVG for the instruction currently processed :param str instruction_id: id that will be assigned to the symbol """ instruction_def = svg_dict["svg"] blacklisted_elements = ["sodipodi:namedview", "metadata"] whitelisted_attributes = ["@sodipodi:docname"] symbol = OrderedDict({"@id": instruction_id}) for content, value in instruction_def.items(): if content.startswith('@'): if content in whitelisted_attributes: symbol[content] = value elif content not in blacklisted_elements: symbol[content] = value return {DEFINITION_HOLDER: symbol}
def _make_definition(self, svg_dict, instruction_id): """Create a symbol out of the supplied :paramref:`svg_dict`. :param dict svg_dict: dictionary containing the SVG for the instruction currently processed :param str instruction_id: id that will be assigned to the symbol """ instruction_def = svg_dict["svg"] blacklisted_elements = ["sodipodi:namedview", "metadata"] whitelisted_attributes = ["@sodipodi:docname"] symbol = OrderedDict({"@id": instruction_id}) for content, value in instruction_def.items(): if content.startswith('@'): if content in whitelisted_attributes: symbol[content] = value elif content not in blacklisted_elements: symbol[content] = value return {DEFINITION_HOLDER: symbol}
[ "Create", "a", "symbol", "out", "of", "the", "supplied", ":", "paramref", ":", "svg_dict", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/KnittingPatternToSVG.py#L99-L116
[ "def", "_make_definition", "(", "self", ",", "svg_dict", ",", "instruction_id", ")", ":", "instruction_def", "=", "svg_dict", "[", "\"svg\"", "]", "blacklisted_elements", "=", "[", "\"sodipodi:namedview\"", ",", "\"metadata\"", "]", "whitelisted_attributes", "=", "[", "\"@sodipodi:docname\"", "]", "symbol", "=", "OrderedDict", "(", "{", "\"@id\"", ":", "instruction_id", "}", ")", "for", "content", ",", "value", "in", "instruction_def", ".", "items", "(", ")", ":", "if", "content", ".", "startswith", "(", "'@'", ")", ":", "if", "content", "in", "whitelisted_attributes", ":", "symbol", "[", "content", "]", "=", "value", "elif", "content", "not", "in", "blacklisted_elements", ":", "symbol", "[", "content", "]", "=", "value", "return", "{", "DEFINITION_HOLDER", ":", "symbol", "}" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
KnittingPatternToSVG._compute_scale
Compute the scale of an instruction svg. Compute the scale using the bounding box stored in the :paramref:`svg_dict`. The scale is saved in a dictionary using :paramref:`instruction_id` as key. :param str instruction_id: id identifying a symbol in the defs :param dict svg_dict: dictionary containing the SVG for the instruction currently processed
knittingpattern/convert/KnittingPatternToSVG.py
def _compute_scale(self, instruction_id, svg_dict): """Compute the scale of an instruction svg. Compute the scale using the bounding box stored in the :paramref:`svg_dict`. The scale is saved in a dictionary using :paramref:`instruction_id` as key. :param str instruction_id: id identifying a symbol in the defs :param dict svg_dict: dictionary containing the SVG for the instruction currently processed """ bbox = list(map(float, svg_dict["svg"]["@viewBox"].split())) scale = self._zoom / (bbox[3] - bbox[1]) self._symbol_id_to_scale[instruction_id] = scale
def _compute_scale(self, instruction_id, svg_dict): """Compute the scale of an instruction svg. Compute the scale using the bounding box stored in the :paramref:`svg_dict`. The scale is saved in a dictionary using :paramref:`instruction_id` as key. :param str instruction_id: id identifying a symbol in the defs :param dict svg_dict: dictionary containing the SVG for the instruction currently processed """ bbox = list(map(float, svg_dict["svg"]["@viewBox"].split())) scale = self._zoom / (bbox[3] - bbox[1]) self._symbol_id_to_scale[instruction_id] = scale
[ "Compute", "the", "scale", "of", "an", "instruction", "svg", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/KnittingPatternToSVG.py#L118-L131
[ "def", "_compute_scale", "(", "self", ",", "instruction_id", ",", "svg_dict", ")", ":", "bbox", "=", "list", "(", "map", "(", "float", ",", "svg_dict", "[", "\"svg\"", "]", "[", "\"@viewBox\"", "]", ".", "split", "(", ")", ")", ")", "scale", "=", "self", ".", "_zoom", "/", "(", "bbox", "[", "3", "]", "-", "bbox", "[", "1", "]", ")", "self", ".", "_symbol_id_to_scale", "[", "instruction_id", "]", "=", "scale" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
KnittingPatternSet.to_svg
Create an SVG from the knitting pattern set. :param float zoom: the height and width of a knit instruction :return: a dumper to save the svg to :rtype: knittingpattern.Dumper.XMLDumper Example: .. code:: python >>> knitting_pattern_set.to_svg(25).temporary_path(".svg") "/the/path/to/the/file.svg"
knittingpattern/KnittingPatternSet.py
def to_svg(self, zoom): """Create an SVG from the knitting pattern set. :param float zoom: the height and width of a knit instruction :return: a dumper to save the svg to :rtype: knittingpattern.Dumper.XMLDumper Example: .. code:: python >>> knitting_pattern_set.to_svg(25).temporary_path(".svg") "/the/path/to/the/file.svg" """ def on_dump(): """Dump the knitting pattern to the file. :return: the SVG XML structure as dictionary. """ knitting_pattern = self.patterns.at(0) layout = GridLayout(knitting_pattern) instruction_to_svg = default_instruction_svg_cache() builder = SVGBuilder() kp_to_svg = KnittingPatternToSVG(knitting_pattern, layout, instruction_to_svg, builder, zoom) return kp_to_svg.build_SVG_dict() return XMLDumper(on_dump)
def to_svg(self, zoom): """Create an SVG from the knitting pattern set. :param float zoom: the height and width of a knit instruction :return: a dumper to save the svg to :rtype: knittingpattern.Dumper.XMLDumper Example: .. code:: python >>> knitting_pattern_set.to_svg(25).temporary_path(".svg") "/the/path/to/the/file.svg" """ def on_dump(): """Dump the knitting pattern to the file. :return: the SVG XML structure as dictionary. """ knitting_pattern = self.patterns.at(0) layout = GridLayout(knitting_pattern) instruction_to_svg = default_instruction_svg_cache() builder = SVGBuilder() kp_to_svg = KnittingPatternToSVG(knitting_pattern, layout, instruction_to_svg, builder, zoom) return kp_to_svg.build_SVG_dict() return XMLDumper(on_dump)
[ "Create", "an", "SVG", "from", "the", "knitting", "pattern", "set", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/KnittingPatternSet.py#L105-L131
[ "def", "to_svg", "(", "self", ",", "zoom", ")", ":", "def", "on_dump", "(", ")", ":", "\"\"\"Dump the knitting pattern to the file.\n\n :return: the SVG XML structure as dictionary.\n \"\"\"", "knitting_pattern", "=", "self", ".", "patterns", ".", "at", "(", "0", ")", "layout", "=", "GridLayout", "(", "knitting_pattern", ")", "instruction_to_svg", "=", "default_instruction_svg_cache", "(", ")", "builder", "=", "SVGBuilder", "(", ")", "kp_to_svg", "=", "KnittingPatternToSVG", "(", "knitting_pattern", ",", "layout", ",", "instruction_to_svg", ",", "builder", ",", "zoom", ")", "return", "kp_to_svg", ".", "build_SVG_dict", "(", ")", "return", "XMLDumper", "(", "on_dump", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
KnittingPatternSet.add_new_pattern
Add a new, empty knitting pattern to the set. :param id_: the id of the pattern :param name: the name of the pattern to add or if :obj:`None`, the :paramref:`id_` is used :return: a new, empty knitting pattern :rtype: knittingpattern.KnittingPattern.KnittingPattern
knittingpattern/KnittingPatternSet.py
def add_new_pattern(self, id_, name=None): """Add a new, empty knitting pattern to the set. :param id_: the id of the pattern :param name: the name of the pattern to add or if :obj:`None`, the :paramref:`id_` is used :return: a new, empty knitting pattern :rtype: knittingpattern.KnittingPattern.KnittingPattern """ if name is None: name = id_ pattern = self._parser.new_pattern(id_, name) self._patterns.append(pattern) return pattern
def add_new_pattern(self, id_, name=None): """Add a new, empty knitting pattern to the set. :param id_: the id of the pattern :param name: the name of the pattern to add or if :obj:`None`, the :paramref:`id_` is used :return: a new, empty knitting pattern :rtype: knittingpattern.KnittingPattern.KnittingPattern """ if name is None: name = id_ pattern = self._parser.new_pattern(id_, name) self._patterns.append(pattern) return pattern
[ "Add", "a", "new", "empty", "knitting", "pattern", "to", "the", "set", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/KnittingPatternSet.py#L133-L146
[ "def", "add_new_pattern", "(", "self", ",", "id_", ",", "name", "=", "None", ")", ":", "if", "name", "is", "None", ":", "name", "=", "id_", "pattern", "=", "self", ".", "_parser", ".", "new_pattern", "(", "id_", ",", "name", ")", "self", ".", "_patterns", ".", "append", "(", "pattern", ")", "return", "pattern" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Instruction.to_svg
Return a SVGDumper for this instruction. :param converter: a :class:` knittingpattern.convert.InstructionSVGCache.InstructionSVGCache` or :obj:`None`. If :obj:`None` is given, the :func:` knittingpattern.convert.InstructionSVGCache.default_svg_cache` is used. :rtype: knittingpattern.Dumper.SVGDumper
knittingpattern/Instruction.py
def to_svg(self, converter=None): """Return a SVGDumper for this instruction. :param converter: a :class:` knittingpattern.convert.InstructionSVGCache.InstructionSVGCache` or :obj:`None`. If :obj:`None` is given, the :func:` knittingpattern.convert.InstructionSVGCache.default_svg_cache` is used. :rtype: knittingpattern.Dumper.SVGDumper """ if converter is None: from knittingpattern.convert.InstructionSVGCache import \ default_svg_cache converter = default_svg_cache() return converter.to_svg(self)
def to_svg(self, converter=None): """Return a SVGDumper for this instruction. :param converter: a :class:` knittingpattern.convert.InstructionSVGCache.InstructionSVGCache` or :obj:`None`. If :obj:`None` is given, the :func:` knittingpattern.convert.InstructionSVGCache.default_svg_cache` is used. :rtype: knittingpattern.Dumper.SVGDumper """ if converter is None: from knittingpattern.convert.InstructionSVGCache import \ default_svg_cache converter = default_svg_cache() return converter.to_svg(self)
[ "Return", "a", "SVGDumper", "for", "this", "instruction", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Instruction.py#L217-L231
[ "def", "to_svg", "(", "self", ",", "converter", "=", "None", ")", ":", "if", "converter", "is", "None", ":", "from", "knittingpattern", ".", "convert", ".", "InstructionSVGCache", "import", "default_svg_cache", "converter", "=", "default_svg_cache", "(", ")", "return", "converter", ".", "to_svg", "(", "self", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionInRow.transfer_to_row
Transfer this instruction to a new row. :param knittingpattern.Row.Row new_row: the new row the instruction is in.
knittingpattern/Instruction.py
def transfer_to_row(self, new_row): """Transfer this instruction to a new row. :param knittingpattern.Row.Row new_row: the new row the instruction is in. """ if new_row != self._row: index = self.get_index_in_row() if index is not None: self._row.instructions.pop(index) self._row = new_row
def transfer_to_row(self, new_row): """Transfer this instruction to a new row. :param knittingpattern.Row.Row new_row: the new row the instruction is in. """ if new_row != self._row: index = self.get_index_in_row() if index is not None: self._row.instructions.pop(index) self._row = new_row
[ "Transfer", "this", "instruction", "to", "a", "new", "row", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Instruction.py#L260-L270
[ "def", "transfer_to_row", "(", "self", ",", "new_row", ")", ":", "if", "new_row", "!=", "self", ".", "_row", ":", "index", "=", "self", ".", "get_index_in_row", "(", ")", "if", "index", "is", "not", "None", ":", "self", ".", "_row", ".", "instructions", ".", "pop", "(", "index", ")", "self", ".", "_row", "=", "new_row" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionInRow.get_index_in_row
Index of the instruction in the instructions of the row or None. :return: index in the :attr:`row`'s instructions or None, if the instruction is not in the row :rtype: int .. seealso:: :attr:`row_instructions`, :attr:`index_in_row`, :meth:`is_in_row`
knittingpattern/Instruction.py
def get_index_in_row(self): """Index of the instruction in the instructions of the row or None. :return: index in the :attr:`row`'s instructions or None, if the instruction is not in the row :rtype: int .. seealso:: :attr:`row_instructions`, :attr:`index_in_row`, :meth:`is_in_row` """ expected_index = self._cached_index_in_row instructions = self._row.instructions if expected_index is not None and \ 0 <= expected_index < len(instructions) and \ instructions[expected_index] is self: return expected_index for index, instruction_in_row in enumerate(instructions): if instruction_in_row is self: self._cached_index_in_row = index return index return None
def get_index_in_row(self): """Index of the instruction in the instructions of the row or None. :return: index in the :attr:`row`'s instructions or None, if the instruction is not in the row :rtype: int .. seealso:: :attr:`row_instructions`, :attr:`index_in_row`, :meth:`is_in_row` """ expected_index = self._cached_index_in_row instructions = self._row.instructions if expected_index is not None and \ 0 <= expected_index < len(instructions) and \ instructions[expected_index] is self: return expected_index for index, instruction_in_row in enumerate(instructions): if instruction_in_row is self: self._cached_index_in_row = index return index return None
[ "Index", "of", "the", "instruction", "in", "the", "instructions", "of", "the", "row", "or", "None", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Instruction.py#L301-L321
[ "def", "get_index_in_row", "(", "self", ")", ":", "expected_index", "=", "self", ".", "_cached_index_in_row", "instructions", "=", "self", ".", "_row", ".", "instructions", "if", "expected_index", "is", "not", "None", "and", "0", "<=", "expected_index", "<", "len", "(", "instructions", ")", "and", "instructions", "[", "expected_index", "]", "is", "self", ":", "return", "expected_index", "for", "index", ",", "instruction_in_row", "in", "enumerate", "(", "instructions", ")", ":", "if", "instruction_in_row", "is", "self", ":", "self", ".", "_cached_index_in_row", "=", "index", "return", "index", "return", "None" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionInRow.next_instruction_in_row
The instruction after this one or None. :return: the instruction in :attr:`row_instructions` after this or :obj:`None` if this is the last :rtype: knittingpattern.Instruction.InstructionInRow This can be used to traverse the instructions. .. seealso:: :attr:`previous_instruction_in_row`
knittingpattern/Instruction.py
def next_instruction_in_row(self): """The instruction after this one or None. :return: the instruction in :attr:`row_instructions` after this or :obj:`None` if this is the last :rtype: knittingpattern.Instruction.InstructionInRow This can be used to traverse the instructions. .. seealso:: :attr:`previous_instruction_in_row` """ index = self.index_in_row + 1 if index >= len(self.row_instructions): return None return self.row_instructions[index]
def next_instruction_in_row(self): """The instruction after this one or None. :return: the instruction in :attr:`row_instructions` after this or :obj:`None` if this is the last :rtype: knittingpattern.Instruction.InstructionInRow This can be used to traverse the instructions. .. seealso:: :attr:`previous_instruction_in_row` """ index = self.index_in_row + 1 if index >= len(self.row_instructions): return None return self.row_instructions[index]
[ "The", "instruction", "after", "this", "one", "or", "None", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Instruction.py#L356-L370
[ "def", "next_instruction_in_row", "(", "self", ")", ":", "index", "=", "self", ".", "index_in_row", "+", "1", "if", "index", ">=", "len", "(", "self", ".", "row_instructions", ")", ":", "return", "None", "return", "self", ".", "row_instructions", "[", "index", "]" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionInRow.index_of_first_produced_mesh_in_row
Index of the first produced mesh in the row that consumes it. :return: an index of the first produced mesh of rows produced meshes :rtype: int .. note:: If the instruction :meth:`produces meshes <Instruction.produces_meshes>`, this is the index of the first mesh the instruction produces in all the meshes of the row. If the instruction does not produce meshes, the index of the mesh is returned as if the instruction had produced a mesh. .. code:: if instruction.produces_meshes(): index = instruction.index_of_first_produced_mesh_in_row
knittingpattern/Instruction.py
def index_of_first_produced_mesh_in_row(self): """Index of the first produced mesh in the row that consumes it. :return: an index of the first produced mesh of rows produced meshes :rtype: int .. note:: If the instruction :meth:`produces meshes <Instruction.produces_meshes>`, this is the index of the first mesh the instruction produces in all the meshes of the row. If the instruction does not produce meshes, the index of the mesh is returned as if the instruction had produced a mesh. .. code:: if instruction.produces_meshes(): index = instruction.index_of_first_produced_mesh_in_row """ index = 0 for instruction in self.row_instructions: if instruction is self: break index += instruction.number_of_produced_meshes else: self._raise_not_found_error() return index
def index_of_first_produced_mesh_in_row(self): """Index of the first produced mesh in the row that consumes it. :return: an index of the first produced mesh of rows produced meshes :rtype: int .. note:: If the instruction :meth:`produces meshes <Instruction.produces_meshes>`, this is the index of the first mesh the instruction produces in all the meshes of the row. If the instruction does not produce meshes, the index of the mesh is returned as if the instruction had produced a mesh. .. code:: if instruction.produces_meshes(): index = instruction.index_of_first_produced_mesh_in_row """ index = 0 for instruction in self.row_instructions: if instruction is self: break index += instruction.number_of_produced_meshes else: self._raise_not_found_error() return index
[ "Index", "of", "the", "first", "produced", "mesh", "in", "the", "row", "that", "consumes", "it", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Instruction.py#L413-L438
[ "def", "index_of_first_produced_mesh_in_row", "(", "self", ")", ":", "index", "=", "0", "for", "instruction", "in", "self", ".", "row_instructions", ":", "if", "instruction", "is", "self", ":", "break", "index", "+=", "instruction", ".", "number_of_produced_meshes", "else", ":", "self", ".", "_raise_not_found_error", "(", ")", "return", "index" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionInRow.index_of_first_consumed_mesh_in_row
The index of the first consumed mesh of this instruction in its row. Same as :attr:`index_of_first_produced_mesh_in_row` but for consumed meshes.
knittingpattern/Instruction.py
def index_of_first_consumed_mesh_in_row(self): """The index of the first consumed mesh of this instruction in its row. Same as :attr:`index_of_first_produced_mesh_in_row` but for consumed meshes. """ index = 0 for instruction in self.row_instructions: if instruction is self: break index += instruction.number_of_consumed_meshes else: self._raise_not_found_error() return index
def index_of_first_consumed_mesh_in_row(self): """The index of the first consumed mesh of this instruction in its row. Same as :attr:`index_of_first_produced_mesh_in_row` but for consumed meshes. """ index = 0 for instruction in self.row_instructions: if instruction is self: break index += instruction.number_of_consumed_meshes else: self._raise_not_found_error() return index
[ "The", "index", "of", "the", "first", "consumed", "mesh", "of", "this", "instruction", "in", "its", "row", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Instruction.py#L459-L472
[ "def", "index_of_first_consumed_mesh_in_row", "(", "self", ")", ":", "index", "=", "0", "for", "instruction", "in", "self", ".", "row_instructions", ":", "if", "instruction", "is", "self", ":", "break", "index", "+=", "instruction", ".", "number_of_consumed_meshes", "else", ":", "self", ".", "_raise_not_found_error", "(", ")", "return", "index" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
convert_color_to_rrggbb
The color in "#RRGGBB" format. :return: the :attr:`color` in "#RRGGBB" format
knittingpattern/convert/color.py
def convert_color_to_rrggbb(color): """The color in "#RRGGBB" format. :return: the :attr:`color` in "#RRGGBB" format """ if not color.startswith("#"): rgb = webcolors.html5_parse_legacy_color(color) hex_color = webcolors.html5_serialize_simple_color(rgb) else: hex_color = color return webcolors.normalize_hex(hex_color)
def convert_color_to_rrggbb(color): """The color in "#RRGGBB" format. :return: the :attr:`color` in "#RRGGBB" format """ if not color.startswith("#"): rgb = webcolors.html5_parse_legacy_color(color) hex_color = webcolors.html5_serialize_simple_color(rgb) else: hex_color = color return webcolors.normalize_hex(hex_color)
[ "The", "color", "in", "#RRGGBB", "format", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/color.py#L5-L15
[ "def", "convert_color_to_rrggbb", "(", "color", ")", ":", "if", "not", "color", ".", "startswith", "(", "\"#\"", ")", ":", "rgb", "=", "webcolors", ".", "html5_parse_legacy_color", "(", "color", ")", "hex_color", "=", "webcolors", ".", "html5_serialize_simple_color", "(", "rgb", ")", "else", ":", "hex_color", "=", "color", "return", "webcolors", ".", "normalize_hex", "(", "hex_color", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._start
Initialize the parsing process.
knittingpattern/Parser.py
def _start(self): """Initialize the parsing process.""" self._instruction_library = self._spec.new_default_instructions() self._as_instruction = self._instruction_library.as_instruction self._id_cache = {} self._pattern_set = None self._inheritance_todos = [] self._instruction_todos = []
def _start(self): """Initialize the parsing process.""" self._instruction_library = self._spec.new_default_instructions() self._as_instruction = self._instruction_library.as_instruction self._id_cache = {} self._pattern_set = None self._inheritance_todos = [] self._instruction_todos = []
[ "Initialize", "the", "parsing", "process", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L51-L58
[ "def", "_start", "(", "self", ")", ":", "self", ".", "_instruction_library", "=", "self", ".", "_spec", ".", "new_default_instructions", "(", ")", "self", ".", "_as_instruction", "=", "self", ".", "_instruction_library", ".", "as_instruction", "self", ".", "_id_cache", "=", "{", "}", "self", ".", "_pattern_set", "=", "None", "self", ".", "_inheritance_todos", "=", "[", "]", "self", ".", "_instruction_todos", "=", "[", "]" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser.knitting_pattern_set
Parse a knitting pattern set. :param dict value: the specification of the knitting pattern set :rtype: knittingpattern.KnittingPatternSet.KnittingPatternSet :raises knittingpattern.KnittingPatternSet.ParsingError: if :paramref:`value` does not fulfill the :ref:`specification <FileFormatSpecification>`.
knittingpattern/Parser.py
def knitting_pattern_set(self, values): """Parse a knitting pattern set. :param dict value: the specification of the knitting pattern set :rtype: knittingpattern.KnittingPatternSet.KnittingPatternSet :raises knittingpattern.KnittingPatternSet.ParsingError: if :paramref:`value` does not fulfill the :ref:`specification <FileFormatSpecification>`. """ self._start() pattern_collection = self._new_pattern_collection() self._fill_pattern_collection(pattern_collection, values) self._create_pattern_set(pattern_collection, values) return self._pattern_set
def knitting_pattern_set(self, values): """Parse a knitting pattern set. :param dict value: the specification of the knitting pattern set :rtype: knittingpattern.KnittingPatternSet.KnittingPatternSet :raises knittingpattern.KnittingPatternSet.ParsingError: if :paramref:`value` does not fulfill the :ref:`specification <FileFormatSpecification>`. """ self._start() pattern_collection = self._new_pattern_collection() self._fill_pattern_collection(pattern_collection, values) self._create_pattern_set(pattern_collection, values) return self._pattern_set
[ "Parse", "a", "knitting", "pattern", "set", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L76-L90
[ "def", "knitting_pattern_set", "(", "self", ",", "values", ")", ":", "self", ".", "_start", "(", ")", "pattern_collection", "=", "self", ".", "_new_pattern_collection", "(", ")", "self", ".", "_fill_pattern_collection", "(", "pattern_collection", ",", "values", ")", "self", ".", "_create_pattern_set", "(", "pattern_collection", ",", "values", ")", "return", "self", ".", "_pattern_set" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._finish_inheritance
Finish those who still need to inherit.
knittingpattern/Parser.py
def _finish_inheritance(self): """Finish those who still need to inherit.""" while self._inheritance_todos: prototype, parent_id = self._inheritance_todos.pop() parent = self._id_cache[parent_id] prototype.inherit_from(parent)
def _finish_inheritance(self): """Finish those who still need to inherit.""" while self._inheritance_todos: prototype, parent_id = self._inheritance_todos.pop() parent = self._id_cache[parent_id] prototype.inherit_from(parent)
[ "Finish", "those", "who", "still", "need", "to", "inherit", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L92-L97
[ "def", "_finish_inheritance", "(", "self", ")", ":", "while", "self", ".", "_inheritance_todos", ":", "prototype", ",", "parent_id", "=", "self", ".", "_inheritance_todos", ".", "pop", "(", ")", "parent", "=", "self", ".", "_id_cache", "[", "parent_id", "]", "prototype", ".", "inherit_from", "(", "parent", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._finish_instructions
Finish those who still need to inherit.
knittingpattern/Parser.py
def _finish_instructions(self): """Finish those who still need to inherit.""" while self._instruction_todos: row = self._instruction_todos.pop() instructions = row.get(INSTRUCTIONS, []) row.instructions.extend(instructions)
def _finish_instructions(self): """Finish those who still need to inherit.""" while self._instruction_todos: row = self._instruction_todos.pop() instructions = row.get(INSTRUCTIONS, []) row.instructions.extend(instructions)
[ "Finish", "those", "who", "still", "need", "to", "inherit", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L107-L112
[ "def", "_finish_instructions", "(", "self", ")", ":", "while", "self", ".", "_instruction_todos", ":", "row", "=", "self", ".", "_instruction_todos", ".", "pop", "(", ")", "instructions", "=", "row", ".", "get", "(", "INSTRUCTIONS", ",", "[", "]", ")", "row", ".", "instructions", ".", "extend", "(", "instructions", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._fill_pattern_collection
Fill a pattern collection.
knittingpattern/Parser.py
def _fill_pattern_collection(self, pattern_collection, values): """Fill a pattern collection.""" pattern = values.get(PATTERNS, []) for pattern_to_parse in pattern: parsed_pattern = self._pattern(pattern_to_parse) pattern_collection.append(parsed_pattern)
def _fill_pattern_collection(self, pattern_collection, values): """Fill a pattern collection.""" pattern = values.get(PATTERNS, []) for pattern_to_parse in pattern: parsed_pattern = self._pattern(pattern_to_parse) pattern_collection.append(parsed_pattern)
[ "Fill", "a", "pattern", "collection", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L138-L143
[ "def", "_fill_pattern_collection", "(", "self", ",", "pattern_collection", ",", "values", ")", ":", "pattern", "=", "values", ".", "get", "(", "PATTERNS", ",", "[", "]", ")", "for", "pattern_to_parse", "in", "pattern", ":", "parsed_pattern", "=", "self", ".", "_pattern", "(", "pattern_to_parse", ")", "pattern_collection", ".", "append", "(", "parsed_pattern", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._row
Parse a row.
knittingpattern/Parser.py
def _row(self, values): """Parse a row.""" row_id = self._to_id(values[ID]) row = self._spec.new_row(row_id, values, self) if SAME_AS in values: self._delay_inheritance(row, self._to_id(values[SAME_AS])) self._delay_instructions(row) self._id_cache[row_id] = row return row
def _row(self, values): """Parse a row.""" row_id = self._to_id(values[ID]) row = self._spec.new_row(row_id, values, self) if SAME_AS in values: self._delay_inheritance(row, self._to_id(values[SAME_AS])) self._delay_instructions(row) self._id_cache[row_id] = row return row
[ "Parse", "a", "row", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L145-L153
[ "def", "_row", "(", "self", ",", "values", ")", ":", "row_id", "=", "self", ".", "_to_id", "(", "values", "[", "ID", "]", ")", "row", "=", "self", ".", "_spec", ".", "new_row", "(", "row_id", ",", "values", ",", "self", ")", "if", "SAME_AS", "in", "values", ":", "self", ".", "_delay_inheritance", "(", "row", ",", "self", ".", "_to_id", "(", "values", "[", "SAME_AS", "]", ")", ")", "self", ".", "_delay_instructions", "(", "row", ")", "self", ".", "_id_cache", "[", "row_id", "]", "=", "row", "return", "row" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser.instruction_in_row
Parse an instruction. :param row: the row of the instruction :param specification: the specification of the instruction :return: the instruction in the row
knittingpattern/Parser.py
def instruction_in_row(self, row, specification): """Parse an instruction. :param row: the row of the instruction :param specification: the specification of the instruction :return: the instruction in the row """ whole_instruction_ = self._as_instruction(specification) return self._spec.new_instruction_in_row(row, whole_instruction_)
def instruction_in_row(self, row, specification): """Parse an instruction. :param row: the row of the instruction :param specification: the specification of the instruction :return: the instruction in the row """ whole_instruction_ = self._as_instruction(specification) return self._spec.new_instruction_in_row(row, whole_instruction_)
[ "Parse", "an", "instruction", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L164-L172
[ "def", "instruction_in_row", "(", "self", ",", "row", ",", "specification", ")", ":", "whole_instruction_", "=", "self", ".", "_as_instruction", "(", "specification", ")", "return", "self", ".", "_spec", ".", "new_instruction_in_row", "(", "row", ",", "whole_instruction_", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._pattern
Parse a pattern.
knittingpattern/Parser.py
def _pattern(self, base): """Parse a pattern.""" rows = self._rows(base.get(ROWS, [])) self._finish_inheritance() self._finish_instructions() self._connect_rows(base.get(CONNECTIONS, [])) id_ = self._to_id(base[ID]) name = base[NAME] return self.new_pattern(id_, name, rows)
def _pattern(self, base): """Parse a pattern.""" rows = self._rows(base.get(ROWS, [])) self._finish_inheritance() self._finish_instructions() self._connect_rows(base.get(CONNECTIONS, [])) id_ = self._to_id(base[ID]) name = base[NAME] return self.new_pattern(id_, name, rows)
[ "Parse", "a", "pattern", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L174-L182
[ "def", "_pattern", "(", "self", ",", "base", ")", ":", "rows", "=", "self", ".", "_rows", "(", "base", ".", "get", "(", "ROWS", ",", "[", "]", ")", ")", "self", ".", "_finish_inheritance", "(", ")", "self", ".", "_finish_instructions", "(", ")", "self", ".", "_connect_rows", "(", "base", ".", "get", "(", "CONNECTIONS", ",", "[", "]", ")", ")", "id_", "=", "self", ".", "_to_id", "(", "base", "[", "ID", "]", ")", "name", "=", "base", "[", "NAME", "]", "return", "self", ".", "new_pattern", "(", "id_", ",", "name", ",", "rows", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser.new_pattern
Create a new knitting pattern. If rows is :obj:`None` it is replaced with the :meth:`new_row_collection`.
knittingpattern/Parser.py
def new_pattern(self, id_, name, rows=None): """Create a new knitting pattern. If rows is :obj:`None` it is replaced with the :meth:`new_row_collection`. """ if rows is None: rows = self.new_row_collection() return self._spec.new_pattern(id_, name, rows, self)
def new_pattern(self, id_, name, rows=None): """Create a new knitting pattern. If rows is :obj:`None` it is replaced with the :meth:`new_row_collection`. """ if rows is None: rows = self.new_row_collection() return self._spec.new_pattern(id_, name, rows, self)
[ "Create", "a", "new", "knitting", "pattern", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L184-L192
[ "def", "new_pattern", "(", "self", ",", "id_", ",", "name", ",", "rows", "=", "None", ")", ":", "if", "rows", "is", "None", ":", "rows", "=", "self", ".", "new_row_collection", "(", ")", "return", "self", ".", "_spec", ".", "new_pattern", "(", "id_", ",", "name", ",", "rows", ",", "self", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._rows
Parse a collection of rows.
knittingpattern/Parser.py
def _rows(self, spec): """Parse a collection of rows.""" rows = self.new_row_collection() for row in spec: rows.append(self._row(row)) return rows
def _rows(self, spec): """Parse a collection of rows.""" rows = self.new_row_collection() for row in spec: rows.append(self._row(row)) return rows
[ "Parse", "a", "collection", "of", "rows", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L194-L199
[ "def", "_rows", "(", "self", ",", "spec", ")", ":", "rows", "=", "self", ".", "new_row_collection", "(", ")", "for", "row", "in", "spec", ":", "rows", ".", "append", "(", "self", ".", "_row", "(", "row", ")", ")", "return", "rows" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._connect_rows
Connect the parsed rows.
knittingpattern/Parser.py
def _connect_rows(self, connections): """Connect the parsed rows.""" for connection in connections: from_row_id = self._to_id(connection[FROM][ID]) from_row = self._id_cache[from_row_id] from_row_start_index = connection[FROM].get(START, DEFAULT_START) from_row_number_of_possible_meshes = \ from_row.number_of_produced_meshes - from_row_start_index to_row_id = self._to_id(connection[TO][ID]) to_row = self._id_cache[to_row_id] to_row_start_index = connection[TO].get(START, DEFAULT_START) to_row_number_of_possible_meshes = \ to_row.number_of_consumed_meshes - to_row_start_index meshes = min(from_row_number_of_possible_meshes, to_row_number_of_possible_meshes) # TODO: test all kinds of connections number_of_meshes = connection.get(MESHES, meshes) from_row_stop_index = from_row_start_index + number_of_meshes to_row_stop_index = to_row_start_index + number_of_meshes assert 0 <= from_row_start_index <= from_row_stop_index produced_meshes = from_row.produced_meshes[ from_row_start_index:from_row_stop_index] assert 0 <= to_row_start_index <= to_row_stop_index consumed_meshes = to_row.consumed_meshes[ to_row_start_index:to_row_stop_index] assert len(produced_meshes) == len(consumed_meshes) mesh_pairs = zip(produced_meshes, consumed_meshes) for produced_mesh, consumed_mesh in mesh_pairs: produced_mesh.connect_to(consumed_mesh)
def _connect_rows(self, connections): """Connect the parsed rows.""" for connection in connections: from_row_id = self._to_id(connection[FROM][ID]) from_row = self._id_cache[from_row_id] from_row_start_index = connection[FROM].get(START, DEFAULT_START) from_row_number_of_possible_meshes = \ from_row.number_of_produced_meshes - from_row_start_index to_row_id = self._to_id(connection[TO][ID]) to_row = self._id_cache[to_row_id] to_row_start_index = connection[TO].get(START, DEFAULT_START) to_row_number_of_possible_meshes = \ to_row.number_of_consumed_meshes - to_row_start_index meshes = min(from_row_number_of_possible_meshes, to_row_number_of_possible_meshes) # TODO: test all kinds of connections number_of_meshes = connection.get(MESHES, meshes) from_row_stop_index = from_row_start_index + number_of_meshes to_row_stop_index = to_row_start_index + number_of_meshes assert 0 <= from_row_start_index <= from_row_stop_index produced_meshes = from_row.produced_meshes[ from_row_start_index:from_row_stop_index] assert 0 <= to_row_start_index <= to_row_stop_index consumed_meshes = to_row.consumed_meshes[ to_row_start_index:to_row_stop_index] assert len(produced_meshes) == len(consumed_meshes) mesh_pairs = zip(produced_meshes, consumed_meshes) for produced_mesh, consumed_mesh in mesh_pairs: produced_mesh.connect_to(consumed_mesh)
[ "Connect", "the", "parsed", "rows", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L201-L229
[ "def", "_connect_rows", "(", "self", ",", "connections", ")", ":", "for", "connection", "in", "connections", ":", "from_row_id", "=", "self", ".", "_to_id", "(", "connection", "[", "FROM", "]", "[", "ID", "]", ")", "from_row", "=", "self", ".", "_id_cache", "[", "from_row_id", "]", "from_row_start_index", "=", "connection", "[", "FROM", "]", ".", "get", "(", "START", ",", "DEFAULT_START", ")", "from_row_number_of_possible_meshes", "=", "from_row", ".", "number_of_produced_meshes", "-", "from_row_start_index", "to_row_id", "=", "self", ".", "_to_id", "(", "connection", "[", "TO", "]", "[", "ID", "]", ")", "to_row", "=", "self", ".", "_id_cache", "[", "to_row_id", "]", "to_row_start_index", "=", "connection", "[", "TO", "]", ".", "get", "(", "START", ",", "DEFAULT_START", ")", "to_row_number_of_possible_meshes", "=", "to_row", ".", "number_of_consumed_meshes", "-", "to_row_start_index", "meshes", "=", "min", "(", "from_row_number_of_possible_meshes", ",", "to_row_number_of_possible_meshes", ")", "# TODO: test all kinds of connections", "number_of_meshes", "=", "connection", ".", "get", "(", "MESHES", ",", "meshes", ")", "from_row_stop_index", "=", "from_row_start_index", "+", "number_of_meshes", "to_row_stop_index", "=", "to_row_start_index", "+", "number_of_meshes", "assert", "0", "<=", "from_row_start_index", "<=", "from_row_stop_index", "produced_meshes", "=", "from_row", ".", "produced_meshes", "[", "from_row_start_index", ":", "from_row_stop_index", "]", "assert", "0", "<=", "to_row_start_index", "<=", "to_row_stop_index", "consumed_meshes", "=", "to_row", ".", "consumed_meshes", "[", "to_row_start_index", ":", "to_row_stop_index", "]", "assert", "len", "(", "produced_meshes", ")", "==", "len", "(", "consumed_meshes", ")", "mesh_pairs", "=", "zip", "(", "produced_meshes", ",", "consumed_meshes", ")", "for", "produced_mesh", ",", "consumed_mesh", "in", "mesh_pairs", ":", "produced_mesh", ".", "connect_to", "(", "consumed_mesh", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._get_type
:return: the type of a knitting pattern set.
knittingpattern/Parser.py
def _get_type(self, values): """:return: the type of a knitting pattern set.""" if TYPE not in values: self._error("No pattern type given but should be " "\"{}\"".format(KNITTING_PATTERN_TYPE)) type_ = values[TYPE] if type_ != KNITTING_PATTERN_TYPE: self._error("Wrong pattern type. Type is \"{}\" " "but should be \"{}\"" "".format(type_, KNITTING_PATTERN_TYPE)) return type_
def _get_type(self, values): """:return: the type of a knitting pattern set.""" if TYPE not in values: self._error("No pattern type given but should be " "\"{}\"".format(KNITTING_PATTERN_TYPE)) type_ = values[TYPE] if type_ != KNITTING_PATTERN_TYPE: self._error("Wrong pattern type. Type is \"{}\" " "but should be \"{}\"" "".format(type_, KNITTING_PATTERN_TYPE)) return type_
[ ":", "return", ":", "the", "type", "of", "a", "knitting", "pattern", "set", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L231-L241
[ "def", "_get_type", "(", "self", ",", "values", ")", ":", "if", "TYPE", "not", "in", "values", ":", "self", ".", "_error", "(", "\"No pattern type given but should be \"", "\"\\\"{}\\\"\"", ".", "format", "(", "KNITTING_PATTERN_TYPE", ")", ")", "type_", "=", "values", "[", "TYPE", "]", "if", "type_", "!=", "KNITTING_PATTERN_TYPE", ":", "self", ".", "_error", "(", "\"Wrong pattern type. Type is \\\"{}\\\" \"", "\"but should be \\\"{}\\\"\"", "\"\"", ".", "format", "(", "type_", ",", "KNITTING_PATTERN_TYPE", ")", ")", "return", "type_" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Parser._create_pattern_set
Create a new pattern set.
knittingpattern/Parser.py
def _create_pattern_set(self, pattern, values): """Create a new pattern set.""" type_ = self._get_type(values) version = self._get_version(values) comment = values.get(COMMENT) self._pattern_set = self._spec.new_pattern_set( type_, version, pattern, self, comment )
def _create_pattern_set(self, pattern, values): """Create a new pattern set.""" type_ = self._get_type(values) version = self._get_version(values) comment = values.get(COMMENT) self._pattern_set = self._spec.new_pattern_set( type_, version, pattern, self, comment )
[ "Create", "a", "new", "pattern", "set", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Parser.py#L247-L254
[ "def", "_create_pattern_set", "(", "self", ",", "pattern", ",", "values", ")", ":", "type_", "=", "self", ".", "_get_type", "(", "values", ")", "version", "=", "self", ".", "_get_version", "(", "values", ")", "comment", "=", "values", ".", "get", "(", "COMMENT", ")", "self", ".", "_pattern_set", "=", "self", ".", "_spec", ".", "new_pattern_set", "(", "type_", ",", "version", ",", "pattern", ",", "self", ",", "comment", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
KnittingPattern.add_row
Add a new row to the pattern. :param id_: the id of the row
knittingpattern/KnittingPattern.py
def add_row(self, id_): """Add a new row to the pattern. :param id_: the id of the row """ row = self._parser.new_row(id_) self._rows.append(row) return row
def add_row(self, id_): """Add a new row to the pattern. :param id_: the id of the row """ row = self._parser.new_row(id_) self._rows.append(row) return row
[ "Add", "a", "new", "row", "to", "the", "pattern", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/KnittingPattern.py#L58-L65
[ "def", "add_row", "(", "self", ",", "id_", ")", ":", "row", "=", "self", ".", "_parser", ".", "new_row", "(", "id_", ")", "self", ".", "_rows", ".", "append", "(", "row", ")", "return", "row" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
BytesWrapper.write
Write bytes to the file.
knittingpattern/Dumper/FileWrapper.py
def write(self, bytes_): """Write bytes to the file.""" string = bytes_.decode(self._encoding) self._file.write(string)
def write(self, bytes_): """Write bytes to the file.""" string = bytes_.decode(self._encoding) self._file.write(string)
[ "Write", "bytes", "to", "the", "file", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/FileWrapper.py#L24-L27
[ "def", "write", "(", "self", ",", "bytes_", ")", ":", "string", "=", "bytes_", ".", "decode", "(", "self", ".", "_encoding", ")", "self", ".", "_file", ".", "write", "(", "string", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
TextWrapper.write
Write a string to the file.
knittingpattern/Dumper/FileWrapper.py
def write(self, string): """Write a string to the file.""" bytes_ = string.encode(self._encoding) self._file.write(bytes_)
def write(self, string): """Write a string to the file.""" bytes_ = string.encode(self._encoding) self._file.write(bytes_)
[ "Write", "a", "string", "to", "the", "file", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/FileWrapper.py#L47-L50
[ "def", "write", "(", "self", ",", "string", ")", ":", "bytes_", "=", "string", ".", "encode", "(", "self", ".", "_encoding", ")", "self", ".", "_file", ".", "write", "(", "bytes_", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGDumper.kivy_svg
An SVG object. :return: an SVG object :rtype: kivy.graphics.svg.Svg :raises ImportError: if the module was not found
knittingpattern/Dumper/svg.py
def kivy_svg(self): """An SVG object. :return: an SVG object :rtype: kivy.graphics.svg.Svg :raises ImportError: if the module was not found """ from kivy.graphics.svg import Svg path = self.temporary_path(".svg") try: return Svg(path) finally: remove_file(path)
def kivy_svg(self): """An SVG object. :return: an SVG object :rtype: kivy.graphics.svg.Svg :raises ImportError: if the module was not found """ from kivy.graphics.svg import Svg path = self.temporary_path(".svg") try: return Svg(path) finally: remove_file(path)
[ "An", "SVG", "object", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/svg.py#L10-L22
[ "def", "kivy_svg", "(", "self", ")", ":", "from", "kivy", ".", "graphics", ".", "svg", "import", "Svg", "path", "=", "self", ".", "temporary_path", "(", "\".svg\"", ")", "try", ":", "return", "Svg", "(", "path", ")", "finally", ":", "remove_file", "(", "path", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder.bounding_box
the bounding box of this SVG ``(min_x, min_y, max_x, max_y)``. .. code:: python svg_builder10x10.bounding_box = (0, 0, 10, 10) assert svg_builder10x10.bounding_box == (0, 0, 10, 10) ``viewBox``, ``width`` and ``height`` are computed from this. If the bounding box was never set, the result is a tuple of four :obj:`None`.
knittingpattern/convert/SVGBuilder.py
def bounding_box(self): """the bounding box of this SVG ``(min_x, min_y, max_x, max_y)``. .. code:: python svg_builder10x10.bounding_box = (0, 0, 10, 10) assert svg_builder10x10.bounding_box == (0, 0, 10, 10) ``viewBox``, ``width`` and ``height`` are computed from this. If the bounding box was never set, the result is a tuple of four :obj:`None`. """ return (self._min_x, self._min_y, self._max_x, self._max_y)
def bounding_box(self): """the bounding box of this SVG ``(min_x, min_y, max_x, max_y)``. .. code:: python svg_builder10x10.bounding_box = (0, 0, 10, 10) assert svg_builder10x10.bounding_box == (0, 0, 10, 10) ``viewBox``, ``width`` and ``height`` are computed from this. If the bounding box was never set, the result is a tuple of four :obj:`None`. """ return (self._min_x, self._min_y, self._max_x, self._max_y)
[ "the", "bounding", "box", "of", "this", "SVG", "(", "min_x", "min_y", "max_x", "max_y", ")", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L43-L57
[ "def", "bounding_box", "(", "self", ")", ":", "return", "(", "self", ".", "_min_x", ",", "self", ".", "_min_y", ",", "self", ".", "_max_x", ",", "self", ".", "_max_y", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder.place
Place the :paramref:`svg` content at ``(x, y)`` position in the SVG, in a layer with the id :paramref:`layer_id`. :param float x: the x position of the svg :param float y: the y position of the svg :param str svg: the SVG to place at ``(x, y)`` :param str layer_id: the id of the layer that this :paramref:`svg` should be placed inside
knittingpattern/convert/SVGBuilder.py
def place(self, x, y, svg, layer_id): """Place the :paramref:`svg` content at ``(x, y)`` position in the SVG, in a layer with the id :paramref:`layer_id`. :param float x: the x position of the svg :param float y: the y position of the svg :param str svg: the SVG to place at ``(x, y)`` :param str layer_id: the id of the layer that this :paramref:`svg` should be placed inside """ content = xmltodict.parse(svg) self.place_svg_dict(x, y, content, layer_id)
def place(self, x, y, svg, layer_id): """Place the :paramref:`svg` content at ``(x, y)`` position in the SVG, in a layer with the id :paramref:`layer_id`. :param float x: the x position of the svg :param float y: the y position of the svg :param str svg: the SVG to place at ``(x, y)`` :param str layer_id: the id of the layer that this :paramref:`svg` should be placed inside """ content = xmltodict.parse(svg) self.place_svg_dict(x, y, content, layer_id)
[ "Place", "the", ":", "paramref", ":", "svg", "content", "at", "(", "x", "y", ")", "position", "in", "the", "SVG", "in", "a", "layer", "with", "the", "id", ":", "paramref", ":", "layer_id", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L71-L83
[ "def", "place", "(", "self", ",", "x", ",", "y", ",", "svg", ",", "layer_id", ")", ":", "content", "=", "xmltodict", ".", "parse", "(", "svg", ")", "self", ".", "place_svg_dict", "(", "x", ",", "y", ",", "content", ",", "layer_id", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder.place_svg_dict
Same as :meth:`place` but with a dictionary as :paramref:`svg_dict`. :param dict svg_dict: a dictionary returned by `xmltodict.parse() <https://github.com/martinblech/xmltodict>`__ :param dict group: a dictionary of values to add to the group the :paramref:`svg_dict` will be added to or :obj:`None` if nothing should be added
knittingpattern/convert/SVGBuilder.py
def place_svg_dict(self, x, y, svg_dict, layer_id, group=None): """Same as :meth:`place` but with a dictionary as :paramref:`svg_dict`. :param dict svg_dict: a dictionary returned by `xmltodict.parse() <https://github.com/martinblech/xmltodict>`__ :param dict group: a dictionary of values to add to the group the :paramref:`svg_dict` will be added to or :obj:`None` if nothing should be added """ if group is None: group = {} group_ = { "@transform": "translate({},{})".format(x, y), "g": list(svg_dict.values()) } group_.update(group) layer = self._get_layer(layer_id) layer["g"].append(group_)
def place_svg_dict(self, x, y, svg_dict, layer_id, group=None): """Same as :meth:`place` but with a dictionary as :paramref:`svg_dict`. :param dict svg_dict: a dictionary returned by `xmltodict.parse() <https://github.com/martinblech/xmltodict>`__ :param dict group: a dictionary of values to add to the group the :paramref:`svg_dict` will be added to or :obj:`None` if nothing should be added """ if group is None: group = {} group_ = { "@transform": "translate({},{})".format(x, y), "g": list(svg_dict.values()) } group_.update(group) layer = self._get_layer(layer_id) layer["g"].append(group_)
[ "Same", "as", ":", "meth", ":", "place", "but", "with", "a", "dictionary", "as", ":", "paramref", ":", "svg_dict", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L85-L102
[ "def", "place_svg_dict", "(", "self", ",", "x", ",", "y", ",", "svg_dict", ",", "layer_id", ",", "group", "=", "None", ")", ":", "if", "group", "is", "None", ":", "group", "=", "{", "}", "group_", "=", "{", "\"@transform\"", ":", "\"translate({},{})\"", ".", "format", "(", "x", ",", "y", ")", ",", "\"g\"", ":", "list", "(", "svg_dict", ".", "values", "(", ")", ")", "}", "group_", ".", "update", "(", "group", ")", "layer", "=", "self", ".", "_get_layer", "(", "layer_id", ")", "layer", "[", "\"g\"", "]", ".", "append", "(", "group_", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder.place_svg_use_coords
Similar to :meth:`place` but with an id as :paramref:`symbol_id`. :param str symbol_id: an id which identifies an svg object defined in the defs :param dict group: a dictionary of values to add to the group the use statement will be added to or :obj:`None` if nothing should be added
knittingpattern/convert/SVGBuilder.py
def place_svg_use_coords(self, x, y, symbol_id, layer_id, group=None): """Similar to :meth:`place` but with an id as :paramref:`symbol_id`. :param str symbol_id: an id which identifies an svg object defined in the defs :param dict group: a dictionary of values to add to the group the use statement will be added to or :obj:`None` if nothing should be added """ if group is None: group = {} use = {"@x": x, "@y": y, "@xlink:href": "#{}".format(symbol_id)} group_ = {"use": use} group_.update(group) layer = self._get_layer(layer_id) layer["g"].append(group_)
def place_svg_use_coords(self, x, y, symbol_id, layer_id, group=None): """Similar to :meth:`place` but with an id as :paramref:`symbol_id`. :param str symbol_id: an id which identifies an svg object defined in the defs :param dict group: a dictionary of values to add to the group the use statement will be added to or :obj:`None` if nothing should be added """ if group is None: group = {} use = {"@x": x, "@y": y, "@xlink:href": "#{}".format(symbol_id)} group_ = {"use": use} group_.update(group) layer = self._get_layer(layer_id) layer["g"].append(group_)
[ "Similar", "to", ":", "meth", ":", "place", "but", "with", "an", "id", "as", ":", "paramref", ":", "symbol_id", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L104-L119
[ "def", "place_svg_use_coords", "(", "self", ",", "x", ",", "y", ",", "symbol_id", ",", "layer_id", ",", "group", "=", "None", ")", ":", "if", "group", "is", "None", ":", "group", "=", "{", "}", "use", "=", "{", "\"@x\"", ":", "x", ",", "\"@y\"", ":", "y", ",", "\"@xlink:href\"", ":", "\"#{}\"", ".", "format", "(", "symbol_id", ")", "}", "group_", "=", "{", "\"use\"", ":", "use", "}", "group_", ".", "update", "(", "group", ")", "layer", "=", "self", ".", "_get_layer", "(", "layer_id", ")", "layer", "[", "\"g\"", "]", ".", "append", "(", "group_", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder.place_svg_use
Same as :meth:`place_svg_use_coords`. With implicit `x` and `y` which are set to `0` in this method and then :meth:`place_svg_use_coords` is called.
knittingpattern/convert/SVGBuilder.py
def place_svg_use(self, symbol_id, layer_id, group=None): """Same as :meth:`place_svg_use_coords`. With implicit `x` and `y` which are set to `0` in this method and then :meth:`place_svg_use_coords` is called. """ self.place_svg_use_coords(0, 0, symbol_id, layer_id, group)
def place_svg_use(self, symbol_id, layer_id, group=None): """Same as :meth:`place_svg_use_coords`. With implicit `x` and `y` which are set to `0` in this method and then :meth:`place_svg_use_coords` is called. """ self.place_svg_use_coords(0, 0, symbol_id, layer_id, group)
[ "Same", "as", ":", "meth", ":", "place_svg_use_coords", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L121-L127
[ "def", "place_svg_use", "(", "self", ",", "symbol_id", ",", "layer_id", ",", "group", "=", "None", ")", ":", "self", ".", "place_svg_use_coords", "(", "0", ",", "0", ",", "symbol_id", ",", "layer_id", ",", "group", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder._get_layer
:return: the layer with the :paramref:`layer_id`. If the layer does not exist, it is created. :param str layer_id: the id of the layer
knittingpattern/convert/SVGBuilder.py
def _get_layer(self, layer_id): """ :return: the layer with the :paramref:`layer_id`. If the layer does not exist, it is created. :param str layer_id: the id of the layer """ if layer_id not in self._layer_id_to_layer: self._svg.setdefault("g", []) layer = { "g": [], "@inkscape:label": layer_id, "@id": layer_id, "@inkscape:groupmode": "layer", "@class": "row" } self._layer_id_to_layer[layer_id] = layer self._svg["g"].append(layer) return self._layer_id_to_layer[layer_id]
def _get_layer(self, layer_id): """ :return: the layer with the :paramref:`layer_id`. If the layer does not exist, it is created. :param str layer_id: the id of the layer """ if layer_id not in self._layer_id_to_layer: self._svg.setdefault("g", []) layer = { "g": [], "@inkscape:label": layer_id, "@id": layer_id, "@inkscape:groupmode": "layer", "@class": "row" } self._layer_id_to_layer[layer_id] = layer self._svg["g"].append(layer) return self._layer_id_to_layer[layer_id]
[ ":", "return", ":", "the", "layer", "with", "the", ":", "paramref", ":", "layer_id", ".", "If", "the", "layer", "does", "not", "exist", "it", "is", "created", ".", ":", "param", "str", "layer_id", ":", "the", "id", "of", "the", "layer" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L129-L146
[ "def", "_get_layer", "(", "self", ",", "layer_id", ")", ":", "if", "layer_id", "not", "in", "self", ".", "_layer_id_to_layer", ":", "self", ".", "_svg", ".", "setdefault", "(", "\"g\"", ",", "[", "]", ")", "layer", "=", "{", "\"g\"", ":", "[", "]", ",", "\"@inkscape:label\"", ":", "layer_id", ",", "\"@id\"", ":", "layer_id", ",", "\"@inkscape:groupmode\"", ":", "\"layer\"", ",", "\"@class\"", ":", "\"row\"", "}", "self", ".", "_layer_id_to_layer", "[", "layer_id", "]", "=", "layer", "self", ".", "_svg", "[", "\"g\"", "]", ".", "append", "(", "layer", ")", "return", "self", ".", "_layer_id_to_layer", "[", "layer_id", "]" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder.insert_defs
Adds the defs to the SVG structure. :param defs: a list of SVG dictionaries, which contain the defs, which should be added to the SVG structure.
knittingpattern/convert/SVGBuilder.py
def insert_defs(self, defs): """Adds the defs to the SVG structure. :param defs: a list of SVG dictionaries, which contain the defs, which should be added to the SVG structure. """ if self._svg["defs"] is None: self._svg["defs"] = {} for def_ in defs: for key, value in def_.items(): if key.startswith("@"): continue if key not in self._svg["defs"]: self._svg["defs"][key] = [] if not isinstance(value, list): value = [value] self._svg["defs"][key].extend(value)
def insert_defs(self, defs): """Adds the defs to the SVG structure. :param defs: a list of SVG dictionaries, which contain the defs, which should be added to the SVG structure. """ if self._svg["defs"] is None: self._svg["defs"] = {} for def_ in defs: for key, value in def_.items(): if key.startswith("@"): continue if key not in self._svg["defs"]: self._svg["defs"][key] = [] if not isinstance(value, list): value = [value] self._svg["defs"][key].extend(value)
[ "Adds", "the", "defs", "to", "the", "SVG", "structure", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L148-L164
[ "def", "insert_defs", "(", "self", ",", "defs", ")", ":", "if", "self", ".", "_svg", "[", "\"defs\"", "]", "is", "None", ":", "self", ".", "_svg", "[", "\"defs\"", "]", "=", "{", "}", "for", "def_", "in", "defs", ":", "for", "key", ",", "value", "in", "def_", ".", "items", "(", ")", ":", "if", "key", ".", "startswith", "(", "\"@\"", ")", ":", "continue", "if", "key", "not", "in", "self", ".", "_svg", "[", "\"defs\"", "]", ":", "self", ".", "_svg", "[", "\"defs\"", "]", "[", "key", "]", "=", "[", "]", "if", "not", "isinstance", "(", "value", ",", "list", ")", ":", "value", "=", "[", "value", "]", "self", ".", "_svg", "[", "\"defs\"", "]", "[", "key", "]", ".", "extend", "(", "value", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
SVGBuilder.write_to_file
Writes the current SVG to the :paramref:`file`. :param file: a file-like object
knittingpattern/convert/SVGBuilder.py
def write_to_file(self, file): """Writes the current SVG to the :paramref:`file`. :param file: a file-like object """ xmltodict.unparse(self._structure, file, pretty=True)
def write_to_file(self, file): """Writes the current SVG to the :paramref:`file`. :param file: a file-like object """ xmltodict.unparse(self._structure, file, pretty=True)
[ "Writes", "the", "current", "SVG", "to", "the", ":", "paramref", ":", "file", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/SVGBuilder.py#L170-L175
[ "def", "write_to_file", "(", "self", ",", "file", ")", ":", "xmltodict", ".", "unparse", "(", "self", ".", "_structure", ",", "file", ",", "pretty", "=", "True", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionInGrid._width
For ``self.width``.
knittingpattern/convert/Layout.py
def _width(self): """For ``self.width``.""" layout = self._instruction.get(GRID_LAYOUT) if layout is not None: width = layout.get(WIDTH) if width is not None: return width return self._instruction.number_of_consumed_meshes
def _width(self): """For ``self.width``.""" layout = self._instruction.get(GRID_LAYOUT) if layout is not None: width = layout.get(WIDTH) if width is not None: return width return self._instruction.number_of_consumed_meshes
[ "For", "self", ".", "width", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L115-L122
[ "def", "_width", "(", "self", ")", ":", "layout", "=", "self", ".", "_instruction", ".", "get", "(", "GRID_LAYOUT", ")", "if", "layout", "is", "not", "None", ":", "width", "=", "layout", ".", "get", "(", "WIDTH", ")", "if", "width", "is", "not", "None", ":", "return", "width", "return", "self", ".", "_instruction", ".", "number_of_consumed_meshes" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
RowInGrid.instructions
The instructions in a grid. :return: the :class:`instructions in a grid <InstructionInGrid>` of this row :rtype: list
knittingpattern/convert/Layout.py
def instructions(self): """The instructions in a grid. :return: the :class:`instructions in a grid <InstructionInGrid>` of this row :rtype: list """ x = self.x y = self.y result = [] for instruction in self._row.instructions: instruction_in_grid = InstructionInGrid(instruction, Point(x, y)) x += instruction_in_grid.width result.append(instruction_in_grid) return result
def instructions(self): """The instructions in a grid. :return: the :class:`instructions in a grid <InstructionInGrid>` of this row :rtype: list """ x = self.x y = self.y result = [] for instruction in self._row.instructions: instruction_in_grid = InstructionInGrid(instruction, Point(x, y)) x += instruction_in_grid.width result.append(instruction_in_grid) return result
[ "The", "instructions", "in", "a", "grid", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L160-L174
[ "def", "instructions", "(", "self", ")", ":", "x", "=", "self", ".", "x", "y", "=", "self", ".", "y", "result", "=", "[", "]", "for", "instruction", "in", "self", ".", "_row", ".", "instructions", ":", "instruction_in_grid", "=", "InstructionInGrid", "(", "instruction", ",", "Point", "(", "x", ",", "y", ")", ")", "x", "+=", "instruction_in_grid", ".", "width", "result", ".", "append", "(", "instruction_in_grid", ")", "return", "result" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk._expand
Add the arguments `(args, kw)` to `_walk` to the todo list.
knittingpattern/convert/Layout.py
def _expand(self, row, consumed_position, passed): """Add the arguments `(args, kw)` to `_walk` to the todo list.""" self._todo.append((row, consumed_position, passed))
def _expand(self, row, consumed_position, passed): """Add the arguments `(args, kw)` to `_walk` to the todo list.""" self._todo.append((row, consumed_position, passed))
[ "Add", "the", "arguments", "(", "args", "kw", ")", "to", "_walk", "to", "the", "todo", "list", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L207-L209
[ "def", "_expand", "(", "self", ",", "row", ",", "consumed_position", ",", "passed", ")", ":", "self", ".", "_todo", ".", "append", "(", "(", "row", ",", "consumed_position", ",", "passed", ")", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk._step
Walk through the knitting pattern by expanding an row.
knittingpattern/convert/Layout.py
def _step(self, row, position, passed): """Walk through the knitting pattern by expanding an row.""" if row in passed or not self._row_should_be_placed(row, position): return self._place_row(row, position) passed = [row] + passed # print("{}{} at\t{} {}".format(" " * len(passed), row, position, # passed)) for i, produced_mesh in enumerate(row.produced_meshes): self._expand_produced_mesh(produced_mesh, i, position, passed) for i, consumed_mesh in enumerate(row.consumed_meshes): self._expand_consumed_mesh(consumed_mesh, i, position, passed)
def _step(self, row, position, passed): """Walk through the knitting pattern by expanding an row.""" if row in passed or not self._row_should_be_placed(row, position): return self._place_row(row, position) passed = [row] + passed # print("{}{} at\t{} {}".format(" " * len(passed), row, position, # passed)) for i, produced_mesh in enumerate(row.produced_meshes): self._expand_produced_mesh(produced_mesh, i, position, passed) for i, consumed_mesh in enumerate(row.consumed_meshes): self._expand_consumed_mesh(consumed_mesh, i, position, passed)
[ "Walk", "through", "the", "knitting", "pattern", "by", "expanding", "an", "row", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L211-L222
[ "def", "_step", "(", "self", ",", "row", ",", "position", ",", "passed", ")", ":", "if", "row", "in", "passed", "or", "not", "self", ".", "_row_should_be_placed", "(", "row", ",", "position", ")", ":", "return", "self", ".", "_place_row", "(", "row", ",", "position", ")", "passed", "=", "[", "row", "]", "+", "passed", "# print(\"{}{} at\\t{} {}\".format(\" \" * len(passed), row, position,", "# passed))", "for", "i", ",", "produced_mesh", "in", "enumerate", "(", "row", ".", "produced_meshes", ")", ":", "self", ".", "_expand_produced_mesh", "(", "produced_mesh", ",", "i", ",", "position", ",", "passed", ")", "for", "i", ",", "consumed_mesh", "in", "enumerate", "(", "row", ".", "consumed_meshes", ")", ":", "self", ".", "_expand_consumed_mesh", "(", "consumed_mesh", ",", "i", ",", "position", ",", "passed", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk._expand_consumed_mesh
expand the consumed meshes
knittingpattern/convert/Layout.py
def _expand_consumed_mesh(self, mesh, mesh_index, row_position, passed): """expand the consumed meshes""" if not mesh.is_produced(): return row = mesh.producing_row position = Point( row_position.x + mesh.index_in_producing_row - mesh_index, row_position.y - INSTRUCTION_HEIGHT ) self._expand(row, position, passed)
def _expand_consumed_mesh(self, mesh, mesh_index, row_position, passed): """expand the consumed meshes""" if not mesh.is_produced(): return row = mesh.producing_row position = Point( row_position.x + mesh.index_in_producing_row - mesh_index, row_position.y - INSTRUCTION_HEIGHT ) self._expand(row, position, passed)
[ "expand", "the", "consumed", "meshes" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L224-L233
[ "def", "_expand_consumed_mesh", "(", "self", ",", "mesh", ",", "mesh_index", ",", "row_position", ",", "passed", ")", ":", "if", "not", "mesh", ".", "is_produced", "(", ")", ":", "return", "row", "=", "mesh", ".", "producing_row", "position", "=", "Point", "(", "row_position", ".", "x", "+", "mesh", ".", "index_in_producing_row", "-", "mesh_index", ",", "row_position", ".", "y", "-", "INSTRUCTION_HEIGHT", ")", "self", ".", "_expand", "(", "row", ",", "position", ",", "passed", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk._expand_produced_mesh
expand the produced meshes
knittingpattern/convert/Layout.py
def _expand_produced_mesh(self, mesh, mesh_index, row_position, passed): """expand the produced meshes""" if not mesh.is_consumed(): return row = mesh.consuming_row position = Point( row_position.x - mesh.index_in_consuming_row + mesh_index, row_position.y + INSTRUCTION_HEIGHT ) self._expand(row, position, passed)
def _expand_produced_mesh(self, mesh, mesh_index, row_position, passed): """expand the produced meshes""" if not mesh.is_consumed(): return row = mesh.consuming_row position = Point( row_position.x - mesh.index_in_consuming_row + mesh_index, row_position.y + INSTRUCTION_HEIGHT ) self._expand(row, position, passed)
[ "expand", "the", "produced", "meshes" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L235-L244
[ "def", "_expand_produced_mesh", "(", "self", ",", "mesh", ",", "mesh_index", ",", "row_position", ",", "passed", ")", ":", "if", "not", "mesh", ".", "is_consumed", "(", ")", ":", "return", "row", "=", "mesh", ".", "consuming_row", "position", "=", "Point", "(", "row_position", ".", "x", "-", "mesh", ".", "index_in_consuming_row", "+", "mesh_index", ",", "row_position", ".", "y", "+", "INSTRUCTION_HEIGHT", ")", "self", ".", "_expand", "(", "row", ",", "position", ",", "passed", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk._row_should_be_placed
:return: whether to place this instruction
knittingpattern/convert/Layout.py
def _row_should_be_placed(self, row, position): """:return: whether to place this instruction""" placed_row = self._rows_in_grid.get(row) return placed_row is None or placed_row.y < position.y
def _row_should_be_placed(self, row, position): """:return: whether to place this instruction""" placed_row = self._rows_in_grid.get(row) return placed_row is None or placed_row.y < position.y
[ ":", "return", ":", "whether", "to", "place", "this", "instruction" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L246-L249
[ "def", "_row_should_be_placed", "(", "self", ",", "row", ",", "position", ")", ":", "placed_row", "=", "self", ".", "_rows_in_grid", ".", "get", "(", "row", ")", "return", "placed_row", "is", "None", "or", "placed_row", ".", "y", "<", "position", ".", "y" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk._place_row
place the instruction on a grid
knittingpattern/convert/Layout.py
def _place_row(self, row, position): """place the instruction on a grid""" self._rows_in_grid[row] = RowInGrid(row, position)
def _place_row(self, row, position): """place the instruction on a grid""" self._rows_in_grid[row] = RowInGrid(row, position)
[ "place", "the", "instruction", "on", "a", "grid" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L251-L253
[ "def", "_place_row", "(", "self", ",", "row", ",", "position", ")", ":", "self", ".", "_rows_in_grid", "[", "row", "]", "=", "RowInGrid", "(", "row", ",", "position", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk._walk
Loop through all the instructions that are `_todo`.
knittingpattern/convert/Layout.py
def _walk(self): """Loop through all the instructions that are `_todo`.""" while self._todo: args = self._todo.pop(0) self._step(*args)
def _walk(self): """Loop through all the instructions that are `_todo`.""" while self._todo: args = self._todo.pop(0) self._step(*args)
[ "Loop", "through", "all", "the", "instructions", "that", "are", "_todo", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L255-L259
[ "def", "_walk", "(", "self", ")", ":", "while", "self", ".", "_todo", ":", "args", "=", "self", ".", "_todo", ".", "pop", "(", "0", ")", "self", ".", "_step", "(", "*", "args", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
_RecursiveWalk.instruction_in_grid
Returns an `InstructionInGrid` object for the `instruction`
knittingpattern/convert/Layout.py
def instruction_in_grid(self, instruction): """Returns an `InstructionInGrid` object for the `instruction`""" row_position = self._rows_in_grid[instruction.row].xy x = instruction.index_of_first_consumed_mesh_in_row position = Point(row_position.x + x, row_position.y) return InstructionInGrid(instruction, position)
def instruction_in_grid(self, instruction): """Returns an `InstructionInGrid` object for the `instruction`""" row_position = self._rows_in_grid[instruction.row].xy x = instruction.index_of_first_consumed_mesh_in_row position = Point(row_position.x + x, row_position.y) return InstructionInGrid(instruction, position)
[ "Returns", "an", "InstructionInGrid", "object", "for", "the", "instruction" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L261-L266
[ "def", "instruction_in_grid", "(", "self", ",", "instruction", ")", ":", "row_position", "=", "self", ".", "_rows_in_grid", "[", "instruction", ".", "row", "]", ".", "xy", "x", "=", "instruction", ".", "index_of_first_consumed_mesh_in_row", "position", "=", "Point", "(", "row_position", ".", "x", "+", "x", ",", "row_position", ".", "y", ")", "return", "InstructionInGrid", "(", "instruction", ",", "position", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
Connection.is_visible
:return: is this connection is visible :rtype: bool A connection is visible if it is longer that 0.
knittingpattern/convert/Layout.py
def is_visible(self): """:return: is this connection is visible :rtype: bool A connection is visible if it is longer that 0.""" if self._start.y + 1 < self._stop.y: return True return False
def is_visible(self): """:return: is this connection is visible :rtype: bool A connection is visible if it is longer that 0.""" if self._start.y + 1 < self._stop.y: return True return False
[ ":", "return", ":", "is", "this", "connection", "is", "visible", ":", "rtype", ":", "bool" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L298-L305
[ "def", "is_visible", "(", "self", ")", ":", "if", "self", ".", "_start", ".", "y", "+", "1", "<", "self", ".", "_stop", ".", "y", ":", "return", "True", "return", "False" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
GridLayout.walk_instructions
Iterate over instructions. :return: an iterator over :class:`instructions in grid <InstructionInGrid>` :param mapping: funcion to map the result .. code:: python for pos, c in layout.walk_instructions(lambda i: (i.xy, i.color)): print("color {} at {}".format(c, pos))
knittingpattern/convert/Layout.py
def walk_instructions(self, mapping=identity): """Iterate over instructions. :return: an iterator over :class:`instructions in grid <InstructionInGrid>` :param mapping: funcion to map the result .. code:: python for pos, c in layout.walk_instructions(lambda i: (i.xy, i.color)): print("color {} at {}".format(c, pos)) """ instructions = chain(*self.walk_rows(lambda row: row.instructions)) return map(mapping, instructions)
def walk_instructions(self, mapping=identity): """Iterate over instructions. :return: an iterator over :class:`instructions in grid <InstructionInGrid>` :param mapping: funcion to map the result .. code:: python for pos, c in layout.walk_instructions(lambda i: (i.xy, i.color)): print("color {} at {}".format(c, pos)) """ instructions = chain(*self.walk_rows(lambda row: row.instructions)) return map(mapping, instructions)
[ "Iterate", "over", "instructions", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L322-L336
[ "def", "walk_instructions", "(", "self", ",", "mapping", "=", "identity", ")", ":", "instructions", "=", "chain", "(", "*", "self", ".", "walk_rows", "(", "lambda", "row", ":", "row", ".", "instructions", ")", ")", "return", "map", "(", "mapping", ",", "instructions", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
GridLayout.walk_rows
Iterate over rows. :return: an iterator over :class:`rows <RowsInGrid>` :param mapping: funcion to map the result, see :meth:`walk_instructions` for an example usage
knittingpattern/convert/Layout.py
def walk_rows(self, mapping=identity): """Iterate over rows. :return: an iterator over :class:`rows <RowsInGrid>` :param mapping: funcion to map the result, see :meth:`walk_instructions` for an example usage """ row_in_grid = self._walk.row_in_grid return map(lambda row: mapping(row_in_grid(row)), self._rows)
def walk_rows(self, mapping=identity): """Iterate over rows. :return: an iterator over :class:`rows <RowsInGrid>` :param mapping: funcion to map the result, see :meth:`walk_instructions` for an example usage """ row_in_grid = self._walk.row_in_grid return map(lambda row: mapping(row_in_grid(row)), self._rows)
[ "Iterate", "over", "rows", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L338-L346
[ "def", "walk_rows", "(", "self", ",", "mapping", "=", "identity", ")", ":", "row_in_grid", "=", "self", ".", "_walk", ".", "row_in_grid", "return", "map", "(", "lambda", "row", ":", "mapping", "(", "row_in_grid", "(", "row", ")", ")", ",", "self", ".", "_rows", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
GridLayout.walk_connections
Iterate over connections between instructions. :return: an iterator over :class:`connections <Connection>` between :class:`instructions in grid <InstructionInGrid>` :param mapping: funcion to map the result, see :meth:`walk_instructions` for an example usage
knittingpattern/convert/Layout.py
def walk_connections(self, mapping=identity): """Iterate over connections between instructions. :return: an iterator over :class:`connections <Connection>` between :class:`instructions in grid <InstructionInGrid>` :param mapping: funcion to map the result, see :meth:`walk_instructions` for an example usage """ for start in self.walk_instructions(): for stop_instruction in start.instruction.consuming_instructions: if stop_instruction is None: continue stop = self._walk.instruction_in_grid(stop_instruction) connection = Connection(start, stop) if connection.is_visible(): # print("connection:", # connection.start.instruction, # connection.stop.instruction) yield mapping(connection)
def walk_connections(self, mapping=identity): """Iterate over connections between instructions. :return: an iterator over :class:`connections <Connection>` between :class:`instructions in grid <InstructionInGrid>` :param mapping: funcion to map the result, see :meth:`walk_instructions` for an example usage """ for start in self.walk_instructions(): for stop_instruction in start.instruction.consuming_instructions: if stop_instruction is None: continue stop = self._walk.instruction_in_grid(stop_instruction) connection = Connection(start, stop) if connection.is_visible(): # print("connection:", # connection.start.instruction, # connection.stop.instruction) yield mapping(connection)
[ "Iterate", "over", "connections", "between", "instructions", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L348-L366
[ "def", "walk_connections", "(", "self", ",", "mapping", "=", "identity", ")", ":", "for", "start", "in", "self", ".", "walk_instructions", "(", ")", ":", "for", "stop_instruction", "in", "start", ".", "instruction", ".", "consuming_instructions", ":", "if", "stop_instruction", "is", "None", ":", "continue", "stop", "=", "self", ".", "_walk", ".", "instruction_in_grid", "(", "stop_instruction", ")", "connection", "=", "Connection", "(", "start", ",", "stop", ")", "if", "connection", ".", "is_visible", "(", ")", ":", "# print(\"connection:\",", "# connection.start.instruction,", "# connection.stop.instruction)", "yield", "mapping", "(", "connection", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
GridLayout.bounding_box
The minimum and maximum bounds of this layout. :return: ``(min_x, min_y, max_x, max_y)`` the bounding box of this layout :rtype: tuple
knittingpattern/convert/Layout.py
def bounding_box(self): """The minimum and maximum bounds of this layout. :return: ``(min_x, min_y, max_x, max_y)`` the bounding box of this layout :rtype: tuple """ min_x, min_y, max_x, max_y = zip(*list(self.walk_rows( lambda row: row.bounding_box))) return min(min_x), min(min_y), max(max_x), max(max_y)
def bounding_box(self): """The minimum and maximum bounds of this layout. :return: ``(min_x, min_y, max_x, max_y)`` the bounding box of this layout :rtype: tuple """ min_x, min_y, max_x, max_y = zip(*list(self.walk_rows( lambda row: row.bounding_box))) return min(min_x), min(min_y), max(max_x), max(max_y)
[ "The", "minimum", "and", "maximum", "bounds", "of", "this", "layout", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/Layout.py#L369-L378
[ "def", "bounding_box", "(", "self", ")", ":", "min_x", ",", "min_y", ",", "max_x", ",", "max_y", "=", "zip", "(", "*", "list", "(", "self", ".", "walk_rows", "(", "lambda", "row", ":", "row", ".", "bounding_box", ")", ")", ")", "return", "min", "(", "min_x", ")", ",", "min", "(", "min_y", ")", ",", "max", "(", "max_x", ")", ",", "max", "(", "max_y", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionToSVG._process_loaded_object
process the :paramref:`path`. :param str path: the path to load an svg from
knittingpattern/convert/InstructionToSVG.py
def _process_loaded_object(self, path): """process the :paramref:`path`. :param str path: the path to load an svg from """ file_name = os.path.basename(path) name = os.path.splitext(file_name)[0] with open(path) as file: string = file.read() self._instruction_type_to_file_content[name] = string
def _process_loaded_object(self, path): """process the :paramref:`path`. :param str path: the path to load an svg from """ file_name = os.path.basename(path) name = os.path.splitext(file_name)[0] with open(path) as file: string = file.read() self._instruction_type_to_file_content[name] = string
[ "process", "the", ":", "paramref", ":", "path", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionToSVG.py#L44-L53
[ "def", "_process_loaded_object", "(", "self", ",", "path", ")", ":", "file_name", "=", "os", ".", "path", ".", "basename", "(", "path", ")", "name", "=", "os", ".", "path", ".", "splitext", "(", "file_name", ")", "[", "0", "]", "with", "open", "(", "path", ")", "as", "file", ":", "string", "=", "file", ".", "read", "(", ")", "self", ".", "_instruction_type_to_file_content", "[", "name", "]", "=", "string" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionToSVG.instruction_to_svg_dict
:return: an xml-dictionary with the same content as :meth:`instruction_to_svg`.
knittingpattern/convert/InstructionToSVG.py
def instruction_to_svg_dict(self, instruction): """ :return: an xml-dictionary with the same content as :meth:`instruction_to_svg`. """ instruction_type = instruction.type if instruction_type in self._instruction_type_to_file_content: svg = self._instruction_type_to_file_content[instruction_type] return self._set_fills_in_color_layer(svg, instruction.hex_color) return self.default_instruction_to_svg_dict(instruction)
def instruction_to_svg_dict(self, instruction): """ :return: an xml-dictionary with the same content as :meth:`instruction_to_svg`. """ instruction_type = instruction.type if instruction_type in self._instruction_type_to_file_content: svg = self._instruction_type_to_file_content[instruction_type] return self._set_fills_in_color_layer(svg, instruction.hex_color) return self.default_instruction_to_svg_dict(instruction)
[ ":", "return", ":", "an", "xml", "-", "dictionary", "with", "the", "same", "content", "as", ":", "meth", ":", "instruction_to_svg", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionToSVG.py#L55-L64
[ "def", "instruction_to_svg_dict", "(", "self", ",", "instruction", ")", ":", "instruction_type", "=", "instruction", ".", "type", "if", "instruction_type", "in", "self", ".", "_instruction_type_to_file_content", ":", "svg", "=", "self", ".", "_instruction_type_to_file_content", "[", "instruction_type", "]", "return", "self", ".", "_set_fills_in_color_layer", "(", "svg", ",", "instruction", ".", "hex_color", ")", "return", "self", ".", "default_instruction_to_svg_dict", "(", "instruction", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionToSVG._set_fills_in_color_layer
replaces fill colors in ``<g inkscape:label="color" inkscape:groupmode="layer">`` with :paramref:`color` :param color: a color fill the objects in the layer with
knittingpattern/convert/InstructionToSVG.py
def _set_fills_in_color_layer(self, svg_string, color): """replaces fill colors in ``<g inkscape:label="color" inkscape:groupmode="layer">`` with :paramref:`color` :param color: a color fill the objects in the layer with """ structure = xmltodict.parse(svg_string) if color is None: return structure layers = structure["svg"]["g"] if not isinstance(layers, list): layers = [layers] for layer in layers: if not isinstance(layer, dict): continue if layer.get("@inkscape:label") == "color" and \ layer.get("@inkscape:groupmode") == "layer": for key, elements in layer.items(): if key.startswith("@") or key.startswith("#"): continue if not isinstance(elements, list): elements = [elements] for element in elements: style = element.get("@style", None) if style: style = style.split(";") processed_style = [] for style_element in style: if style_element.startswith("fill:"): style_element = "fill:" + color processed_style.append(style_element) style = ";".join(processed_style) element["@style"] = style return structure
def _set_fills_in_color_layer(self, svg_string, color): """replaces fill colors in ``<g inkscape:label="color" inkscape:groupmode="layer">`` with :paramref:`color` :param color: a color fill the objects in the layer with """ structure = xmltodict.parse(svg_string) if color is None: return structure layers = structure["svg"]["g"] if not isinstance(layers, list): layers = [layers] for layer in layers: if not isinstance(layer, dict): continue if layer.get("@inkscape:label") == "color" and \ layer.get("@inkscape:groupmode") == "layer": for key, elements in layer.items(): if key.startswith("@") or key.startswith("#"): continue if not isinstance(elements, list): elements = [elements] for element in elements: style = element.get("@style", None) if style: style = style.split(";") processed_style = [] for style_element in style: if style_element.startswith("fill:"): style_element = "fill:" + color processed_style.append(style_element) style = ";".join(processed_style) element["@style"] = style return structure
[ "replaces", "fill", "colors", "in", "<g", "inkscape", ":", "label", "=", "color", "inkscape", ":", "groupmode", "=", "layer", ">", "with", ":", "paramref", ":", "color" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionToSVG.py#L90-L123
[ "def", "_set_fills_in_color_layer", "(", "self", ",", "svg_string", ",", "color", ")", ":", "structure", "=", "xmltodict", ".", "parse", "(", "svg_string", ")", "if", "color", "is", "None", ":", "return", "structure", "layers", "=", "structure", "[", "\"svg\"", "]", "[", "\"g\"", "]", "if", "not", "isinstance", "(", "layers", ",", "list", ")", ":", "layers", "=", "[", "layers", "]", "for", "layer", "in", "layers", ":", "if", "not", "isinstance", "(", "layer", ",", "dict", ")", ":", "continue", "if", "layer", ".", "get", "(", "\"@inkscape:label\"", ")", "==", "\"color\"", "and", "layer", ".", "get", "(", "\"@inkscape:groupmode\"", ")", "==", "\"layer\"", ":", "for", "key", ",", "elements", "in", "layer", ".", "items", "(", ")", ":", "if", "key", ".", "startswith", "(", "\"@\"", ")", "or", "key", ".", "startswith", "(", "\"#\"", ")", ":", "continue", "if", "not", "isinstance", "(", "elements", ",", "list", ")", ":", "elements", "=", "[", "elements", "]", "for", "element", "in", "elements", ":", "style", "=", "element", ".", "get", "(", "\"@style\"", ",", "None", ")", "if", "style", ":", "style", "=", "style", ".", "split", "(", "\";\"", ")", "processed_style", "=", "[", "]", "for", "style_element", "in", "style", ":", "if", "style_element", ".", "startswith", "(", "\"fill:\"", ")", ":", "style_element", "=", "\"fill:\"", "+", "color", "processed_style", ".", "append", "(", "style_element", ")", "style", "=", "\";\"", ".", "join", "(", "processed_style", ")", "element", "[", "\"@style\"", "]", "=", "style", "return", "structure" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionToSVG.default_instruction_to_svg
As :meth:`instruction_to_svg` but it only takes the ``default.svg`` file into account. In case no file is found for an instruction in :meth:`instruction_to_svg`, this method is used to determine the default svg for it. The content is created by replacing the text ``{instruction.type}`` in the whole svg file named ``default.svg``. If no file ``default.svg`` was loaded, an empty string is returned.
knittingpattern/convert/InstructionToSVG.py
def default_instruction_to_svg(self, instruction): """As :meth:`instruction_to_svg` but it only takes the ``default.svg`` file into account. In case no file is found for an instruction in :meth:`instruction_to_svg`, this method is used to determine the default svg for it. The content is created by replacing the text ``{instruction.type}`` in the whole svg file named ``default.svg``. If no file ``default.svg`` was loaded, an empty string is returned. """ svg_dict = self.default_instruction_to_svg_dict(instruction) return xmltodict.unparse(svg_dict)
def default_instruction_to_svg(self, instruction): """As :meth:`instruction_to_svg` but it only takes the ``default.svg`` file into account. In case no file is found for an instruction in :meth:`instruction_to_svg`, this method is used to determine the default svg for it. The content is created by replacing the text ``{instruction.type}`` in the whole svg file named ``default.svg``. If no file ``default.svg`` was loaded, an empty string is returned. """ svg_dict = self.default_instruction_to_svg_dict(instruction) return xmltodict.unparse(svg_dict)
[ "As", ":", "meth", ":", "instruction_to_svg", "but", "it", "only", "takes", "the", "default", ".", "svg", "file", "into", "account", "." ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionToSVG.py#L139-L153
[ "def", "default_instruction_to_svg", "(", "self", ",", "instruction", ")", ":", "svg_dict", "=", "self", ".", "default_instruction_to_svg_dict", "(", "instruction", ")", "return", "xmltodict", ".", "unparse", "(", "svg_dict", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionToSVG.default_instruction_to_svg_dict
Returns an xml-dictionary with the same content as :meth:`default_instruction_to_svg` If no file ``default.svg`` was loaded, an empty svg-dict is returned.
knittingpattern/convert/InstructionToSVG.py
def default_instruction_to_svg_dict(self, instruction): """Returns an xml-dictionary with the same content as :meth:`default_instruction_to_svg` If no file ``default.svg`` was loaded, an empty svg-dict is returned. """ instruction_type = instruction.type default_type = "default" rep_str = "{instruction.type}" if default_type not in self._instruction_type_to_file_content: return {"svg": ""} default_svg = self._instruction_type_to_file_content[default_type] default_svg = default_svg.replace(rep_str, instruction_type) colored_svg = self._set_fills_in_color_layer(default_svg, instruction.hex_color) return colored_svg
def default_instruction_to_svg_dict(self, instruction): """Returns an xml-dictionary with the same content as :meth:`default_instruction_to_svg` If no file ``default.svg`` was loaded, an empty svg-dict is returned. """ instruction_type = instruction.type default_type = "default" rep_str = "{instruction.type}" if default_type not in self._instruction_type_to_file_content: return {"svg": ""} default_svg = self._instruction_type_to_file_content[default_type] default_svg = default_svg.replace(rep_str, instruction_type) colored_svg = self._set_fills_in_color_layer(default_svg, instruction.hex_color) return colored_svg
[ "Returns", "an", "xml", "-", "dictionary", "with", "the", "same", "content", "as", ":", "meth", ":", "default_instruction_to_svg" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/convert/InstructionToSVG.py#L155-L170
[ "def", "default_instruction_to_svg_dict", "(", "self", ",", "instruction", ")", ":", "instruction_type", "=", "instruction", ".", "type", "default_type", "=", "\"default\"", "rep_str", "=", "\"{instruction.type}\"", "if", "default_type", "not", "in", "self", ".", "_instruction_type_to_file_content", ":", "return", "{", "\"svg\"", ":", "\"\"", "}", "default_svg", "=", "self", ".", "_instruction_type_to_file_content", "[", "default_type", "]", "default_svg", "=", "default_svg", ".", "replace", "(", "rep_str", ",", "instruction_type", ")", "colored_svg", "=", "self", ".", "_set_fills_in_color_layer", "(", "default_svg", ",", "instruction", ".", "hex_color", ")", "return", "colored_svg" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
XMLDumper._dump_to_file
dump to the file
knittingpattern/Dumper/xml.py
def _dump_to_file(self, file): """dump to the file""" xmltodict.unparse(self.object(), file, pretty=True)
def _dump_to_file(self, file): """dump to the file""" xmltodict.unparse(self.object(), file, pretty=True)
[ "dump", "to", "the", "file" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/Dumper/xml.py#L22-L24
[ "def", "_dump_to_file", "(", "self", ",", "file", ")", ":", "xmltodict", ".", "unparse", "(", "self", ".", "object", "(", ")", ",", "file", ",", "pretty", "=", "True", ")" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionLibrary.add_instruction
Add an instruction specification :param specification: a specification with a key :data:`knittingpattern.Instruction.TYPE` .. seealso:: :meth:`as_instruction`
knittingpattern/InstructionLibrary.py
def add_instruction(self, specification): """Add an instruction specification :param specification: a specification with a key :data:`knittingpattern.Instruction.TYPE` .. seealso:: :meth:`as_instruction` """ instruction = self.as_instruction(specification) self._type_to_instruction[instruction.type] = instruction
def add_instruction(self, specification): """Add an instruction specification :param specification: a specification with a key :data:`knittingpattern.Instruction.TYPE` .. seealso:: :meth:`as_instruction` """ instruction = self.as_instruction(specification) self._type_to_instruction[instruction.type] = instruction
[ "Add", "an", "instruction", "specification" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/InstructionLibrary.py#L71-L80
[ "def", "add_instruction", "(", "self", ",", "specification", ")", ":", "instruction", "=", "self", ".", "as_instruction", "(", "specification", ")", "self", ".", "_type_to_instruction", "[", "instruction", ".", "type", "]", "=", "instruction" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
InstructionLibrary.as_instruction
Convert the specification into an instruction :param specification: a specification with a key :data:`knittingpattern.Instruction.TYPE` The instruction is not added. .. seealso:: :meth:`add_instruction`
knittingpattern/InstructionLibrary.py
def as_instruction(self, specification): """Convert the specification into an instruction :param specification: a specification with a key :data:`knittingpattern.Instruction.TYPE` The instruction is not added. .. seealso:: :meth:`add_instruction` """ instruction = self._instruction_class(specification) type_ = instruction.type if type_ in self._type_to_instruction: instruction.inherit_from(self._type_to_instruction[type_]) return instruction
def as_instruction(self, specification): """Convert the specification into an instruction :param specification: a specification with a key :data:`knittingpattern.Instruction.TYPE` The instruction is not added. .. seealso:: :meth:`add_instruction` """ instruction = self._instruction_class(specification) type_ = instruction.type if type_ in self._type_to_instruction: instruction.inherit_from(self._type_to_instruction[type_]) return instruction
[ "Convert", "the", "specification", "into", "an", "instruction" ]
fossasia/knittingpattern
python
https://github.com/fossasia/knittingpattern/blob/8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027/knittingpattern/InstructionLibrary.py#L82-L96
[ "def", "as_instruction", "(", "self", ",", "specification", ")", ":", "instruction", "=", "self", ".", "_instruction_class", "(", "specification", ")", "type_", "=", "instruction", ".", "type", "if", "type_", "in", "self", ".", "_type_to_instruction", ":", "instruction", ".", "inherit_from", "(", "self", ".", "_type_to_instruction", "[", "type_", "]", ")", "return", "instruction" ]
8e608896b0ab82fea1ca9fbfa2b4ee023d8c8027
valid
FreeFormCov.eigh
Eigen decomposition of K. Returns ------- S : ndarray The eigenvalues in ascending order, each repeated according to its multiplicity. U : ndarray Normalized eigenvectors.
glimix_core/cov/_free.py
def eigh(self): """ Eigen decomposition of K. Returns ------- S : ndarray The eigenvalues in ascending order, each repeated according to its multiplicity. U : ndarray Normalized eigenvectors. """ from numpy.linalg import svd if self._cache["eig"] is not None: return self._cache["eig"] U, S = svd(self.L)[:2] S *= S S += self._epsilon self._cache["eig"] = S, U return self._cache["eig"]
def eigh(self): """ Eigen decomposition of K. Returns ------- S : ndarray The eigenvalues in ascending order, each repeated according to its multiplicity. U : ndarray Normalized eigenvectors. """ from numpy.linalg import svd if self._cache["eig"] is not None: return self._cache["eig"] U, S = svd(self.L)[:2] S *= S S += self._epsilon self._cache["eig"] = S, U return self._cache["eig"]
[ "Eigen", "decomposition", "of", "K", "." ]
limix/glimix-core
python
https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/cov/_free.py#L113-L135
[ "def", "eigh", "(", "self", ")", ":", "from", "numpy", ".", "linalg", "import", "svd", "if", "self", ".", "_cache", "[", "\"eig\"", "]", "is", "not", "None", ":", "return", "self", ".", "_cache", "[", "\"eig\"", "]", "U", ",", "S", "=", "svd", "(", "self", ".", "L", ")", "[", ":", "2", "]", "S", "*=", "S", "S", "+=", "self", ".", "_epsilon", "self", ".", "_cache", "[", "\"eig\"", "]", "=", "S", ",", "U", "return", "self", ".", "_cache", "[", "\"eig\"", "]" ]
cddd0994591d100499cc41c1f480ddd575e7a980
valid
FreeFormCov.L
Lower-triangular matrix L such that K = LLᵀ + ϵI. Returns ------- L : (d, d) ndarray Lower-triangular matrix.
glimix_core/cov/_free.py
def L(self): """ Lower-triangular matrix L such that K = LLᵀ + ϵI. Returns ------- L : (d, d) ndarray Lower-triangular matrix. """ m = len(self._tril1[0]) self._L[self._tril1] = self._Lu.value[:m] self._L[self._diag] = exp(self._Lu.value[m:]) return self._L
def L(self): """ Lower-triangular matrix L such that K = LLᵀ + ϵI. Returns ------- L : (d, d) ndarray Lower-triangular matrix. """ m = len(self._tril1[0]) self._L[self._tril1] = self._Lu.value[:m] self._L[self._diag] = exp(self._Lu.value[m:]) return self._L
[ "Lower", "-", "triangular", "matrix", "L", "such", "that", "K", "=", "LLᵀ", "+", "ϵI", "." ]
limix/glimix-core
python
https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/cov/_free.py#L149-L161
[ "def", "L", "(", "self", ")", ":", "m", "=", "len", "(", "self", ".", "_tril1", "[", "0", "]", ")", "self", ".", "_L", "[", "self", ".", "_tril1", "]", "=", "self", ".", "_Lu", ".", "value", "[", ":", "m", "]", "self", ".", "_L", "[", "self", ".", "_diag", "]", "=", "exp", "(", "self", ".", "_Lu", ".", "value", "[", "m", ":", "]", ")", "return", "self", ".", "_L" ]
cddd0994591d100499cc41c1f480ddd575e7a980
valid
FreeFormCov.logdet
Log of |K|. Returns ------- float Log-determinant of K.
glimix_core/cov/_free.py
def logdet(self): """ Log of |K|. Returns ------- float Log-determinant of K. """ from numpy.linalg import slogdet K = self.value() sign, logdet = slogdet(K) if sign != 1.0: msg = "The estimated determinant of K is not positive: " msg += f" ({sign}, {logdet})." raise RuntimeError(msg) return logdet
def logdet(self): """ Log of |K|. Returns ------- float Log-determinant of K. """ from numpy.linalg import slogdet K = self.value() sign, logdet = slogdet(K) if sign != 1.0: msg = "The estimated determinant of K is not positive: " msg += f" ({sign}, {logdet})." raise RuntimeError(msg) return logdet
[ "Log", "of", "|K|", "." ]
limix/glimix-core
python
https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/cov/_free.py#L170-L189
[ "def", "logdet", "(", "self", ")", ":", "from", "numpy", ".", "linalg", "import", "slogdet", "K", "=", "self", ".", "value", "(", ")", "sign", ",", "logdet", "=", "slogdet", "(", "K", ")", "if", "sign", "!=", "1.0", ":", "msg", "=", "\"The estimated determinant of K is not positive: \"", "msg", "+=", "f\" ({sign}, {logdet}).\"", "raise", "RuntimeError", "(", "msg", ")", "return", "logdet" ]
cddd0994591d100499cc41c1f480ddd575e7a980
valid
FreeFormCov.value
Covariance matrix. Returns ------- K : ndarray Matrix K = LLᵀ + ϵI, for a very small positive number ϵ.
glimix_core/cov/_free.py
def value(self): """ Covariance matrix. Returns ------- K : ndarray Matrix K = LLᵀ + ϵI, for a very small positive number ϵ. """ K = dot(self.L, self.L.T) return K + self._epsilon * eye(K.shape[0])
def value(self): """ Covariance matrix. Returns ------- K : ndarray Matrix K = LLᵀ + ϵI, for a very small positive number ϵ. """ K = dot(self.L, self.L.T) return K + self._epsilon * eye(K.shape[0])
[ "Covariance", "matrix", "." ]
limix/glimix-core
python
https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/cov/_free.py#L191-L201
[ "def", "value", "(", "self", ")", ":", "K", "=", "dot", "(", "self", ".", "L", ",", "self", ".", "L", ".", "T", ")", "return", "K", "+", "self", ".", "_epsilon", "*", "eye", "(", "K", ".", "shape", "[", "0", "]", ")" ]
cddd0994591d100499cc41c1f480ddd575e7a980
valid
FreeFormCov.gradient
Derivative of the covariance matrix over the parameters of L. Returns ------- Lu : ndarray Derivative of K over the lower triangular part of L.
glimix_core/cov/_free.py
def gradient(self): """ Derivative of the covariance matrix over the parameters of L. Returns ------- Lu : ndarray Derivative of K over the lower triangular part of L. """ L = self.L self._grad_Lu[:] = 0 for i in range(len(self._tril1[0])): row = self._tril1[0][i] col = self._tril1[1][i] self._grad_Lu[row, :, i] = L[:, col] self._grad_Lu[:, row, i] += L[:, col] m = len(self._tril1[0]) for i in range(len(self._diag[0])): row = self._diag[0][i] col = self._diag[1][i] self._grad_Lu[row, :, m + i] = L[row, col] * L[:, col] self._grad_Lu[:, row, m + i] += L[row, col] * L[:, col] return {"Lu": self._grad_Lu}
def gradient(self): """ Derivative of the covariance matrix over the parameters of L. Returns ------- Lu : ndarray Derivative of K over the lower triangular part of L. """ L = self.L self._grad_Lu[:] = 0 for i in range(len(self._tril1[0])): row = self._tril1[0][i] col = self._tril1[1][i] self._grad_Lu[row, :, i] = L[:, col] self._grad_Lu[:, row, i] += L[:, col] m = len(self._tril1[0]) for i in range(len(self._diag[0])): row = self._diag[0][i] col = self._diag[1][i] self._grad_Lu[row, :, m + i] = L[row, col] * L[:, col] self._grad_Lu[:, row, m + i] += L[row, col] * L[:, col] return {"Lu": self._grad_Lu}
[ "Derivative", "of", "the", "covariance", "matrix", "over", "the", "parameters", "of", "L", "." ]
limix/glimix-core
python
https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/cov/_free.py#L203-L228
[ "def", "gradient", "(", "self", ")", ":", "L", "=", "self", ".", "L", "self", ".", "_grad_Lu", "[", ":", "]", "=", "0", "for", "i", "in", "range", "(", "len", "(", "self", ".", "_tril1", "[", "0", "]", ")", ")", ":", "row", "=", "self", ".", "_tril1", "[", "0", "]", "[", "i", "]", "col", "=", "self", ".", "_tril1", "[", "1", "]", "[", "i", "]", "self", ".", "_grad_Lu", "[", "row", ",", ":", ",", "i", "]", "=", "L", "[", ":", ",", "col", "]", "self", ".", "_grad_Lu", "[", ":", ",", "row", ",", "i", "]", "+=", "L", "[", ":", ",", "col", "]", "m", "=", "len", "(", "self", ".", "_tril1", "[", "0", "]", ")", "for", "i", "in", "range", "(", "len", "(", "self", ".", "_diag", "[", "0", "]", ")", ")", ":", "row", "=", "self", ".", "_diag", "[", "0", "]", "[", "i", "]", "col", "=", "self", ".", "_diag", "[", "1", "]", "[", "i", "]", "self", ".", "_grad_Lu", "[", "row", ",", ":", ",", "m", "+", "i", "]", "=", "L", "[", "row", ",", "col", "]", "*", "L", "[", ":", ",", "col", "]", "self", ".", "_grad_Lu", "[", ":", ",", "row", ",", "m", "+", "i", "]", "+=", "L", "[", "row", ",", "col", "]", "*", "L", "[", ":", ",", "col", "]", "return", "{", "\"Lu\"", ":", "self", ".", "_grad_Lu", "}" ]
cddd0994591d100499cc41c1f480ddd575e7a980
valid
Kron2SumCov.Ge
Result of US from the SVD decomposition G = USVᵀ.
glimix_core/cov/_kron2sum.py
def Ge(self): """ Result of US from the SVD decomposition G = USVᵀ. """ from scipy.linalg import svd from numpy_sugar.linalg import ddot U, S, _ = svd(self._G, full_matrices=False, check_finite=False) if U.shape[1] < self._G.shape[1]: return ddot(U, S) return self._G
def Ge(self): """ Result of US from the SVD decomposition G = USVᵀ. """ from scipy.linalg import svd from numpy_sugar.linalg import ddot U, S, _ = svd(self._G, full_matrices=False, check_finite=False) if U.shape[1] < self._G.shape[1]: return ddot(U, S) return self._G
[ "Result", "of", "US", "from", "the", "SVD", "decomposition", "G", "=", "USVᵀ", "." ]
limix/glimix-core
python
https://github.com/limix/glimix-core/blob/cddd0994591d100499cc41c1f480ddd575e7a980/glimix_core/cov/_kron2sum.py#L135-L146
[ "def", "Ge", "(", "self", ")", ":", "from", "scipy", ".", "linalg", "import", "svd", "from", "numpy_sugar", ".", "linalg", "import", "ddot", "U", ",", "S", ",", "_", "=", "svd", "(", "self", ".", "_G", ",", "full_matrices", "=", "False", ",", "check_finite", "=", "False", ")", "if", "U", ".", "shape", "[", "1", "]", "<", "self", ".", "_G", ".", "shape", "[", "1", "]", ":", "return", "ddot", "(", "U", ",", "S", ")", "return", "self", ".", "_G" ]
cddd0994591d100499cc41c1f480ddd575e7a980