Skip to content

Code Cleanup#136

Merged
kaalleen merged 6 commits into
inkstitch:mainfrom
tcyrus:patch-1
Jun 17, 2026
Merged

Code Cleanup#136
kaalleen merged 6 commits into
inkstitch:mainfrom
tcyrus:patch-1

Conversation

@tcyrus

@tcyrus tcyrus commented May 31, 2026

Copy link
Copy Markdown
Contributor

Made a lot of changes while looking through the source code

  • replaced random.randint with random.getrandbits where appropriate
  • replace catch AttributeError with getattr where appropriate
  • pyproject.toml: fixed mixed indentation of classifiers
  • pyproject.toml: specified minimum setuptools version
  • EmbThread: created properties to replace getter + setter functions
  • EmbThread: fixed issue where color could be set to None
  • EmbPattern: replaced os.path with pathlib.PurePath
  • EmbPattern: fixed minor bug in add_stitch_absolute
  • EmbPattern: use type narrowing for stream argument (read_embroidery and write_embroidery)
  • EmbPattern: fixed bug where __iadd__ would sometimes return None
  • test: removed from __future__ import print_function
  • test: use tempfile with context manager instead of os.remove
  • test: avoid wildcard imports where possible
  • test: use unittest.skip for TestReadHus + test_generic_write_gcode

- fixed mixed indentation of classifiers
- specified minimum setuptools version
@tcyrus

tcyrus commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the issues and separated the commits. Passes all tests locally.

tcyrus added 4 commits June 10, 2026 14:59
- Simplified read + write + convert functions
- Handle PathLike and named streams
- replaced randint with getrandbits
- fixed issue where EmbThread.color could be None

color_hex returns None when the string length isn't as expected. This
can end up with color being set to None

color attribute + set_color was replaced with color property (other
getters / setters were replaced with properties where it made sense).

color.setter now throws a ValueError on types that aren't convertable to
an int (such as None)
- replaced os.path with pathlib
- fixed minor bug in add_stitch_absolute
- use type narrowing for stream argument
- fixed bug where __iadd__ would sometimes return None
- removed __future__.print_function
- replace randint with getrandbits
- use tempfile with context manager instead of os.remove
- avoid wildcard imports where possible
- use unittest.skip for TestReadHus
- use unittest.skip for test_generic_write_gcode
- fix typing for EmbThread.__init__
- handle invalid color strings in EmbThread.__eq__
- EmbThread.parse_string_color() no longer has a default value
@tcyrus

tcyrus commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

EmbThread.color can be set to None in some situations where color_hex can't parse a string. This causes errors in the EmbThread dunder methods since they depend on EmbThread.color being an integer. The EmbThread.color attribute has been replaced with a property, which means that the setter can stop this situation from happening. I've removed the fallback value (0x000000) for parse_string_color so that this behavior is consistent and not just for hex strings.

Also, io.TextIOWrapper can be used to read and write to a binary file-object as if it was a text file-object. This can be used to replace the READ_FILE_IN_TEXT_MODE and WRITE_FILE_IN_TEXT_MODE attributes.

@kaalleen

Copy link
Copy Markdown
Member

Thank you so much for all the work you've put into this. This package really needs someone to take the time and do this kind of work on it.

It's all looking good to me.

@kaalleen
kaalleen merged commit 26c9f7b into inkstitch:main Jun 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants