Skip to content

Commit

Permalink
Merge pull request #65 from GuardKenzie/v1.2.0-dev
Browse files Browse the repository at this point in the history
Bindings for chafa v1.14
  • Loading branch information
GuardKenzie authored Sep 20, 2024
2 parents 8769e24 + 8766685 commit e1bd148
Show file tree
Hide file tree
Showing 44 changed files with 4,559 additions and 3,406 deletions.
18 changes: 4 additions & 14 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
env:
CHAFA_VERSION: master

build_and_store_wheels: &BUILD_AND_STORE_WHEELS
install_cibuildwheel_script:
- python -m pip install cibuildwheel==2.12.0
- python -m pip install cibuildwheel==2.21.1
run_cibuildwheel_script:
- cibuildwheel
wheels_artifacts:
path: "wheelhouse/*"

macos_arm64_task:
name: 💪🍎 Build MacOS arm wheels.
alias: macos_arm_wheels
macos_instance:
image: ghcr.io/cirruslabs/macos-monterey-xcode

env:
PATH: /opt/homebrew/opt/[email protected]/bin:$PATH
install_pre_requirements_script:
- brew install [email protected]
- ln -s python3 /opt/homebrew/opt/[email protected]/bin/python
<<: *BUILD_AND_STORE_WHEELS

linux_aarch64_task:
name: 💪🐧 Build Linux arm wheels.
alias: linux_arm_wheels
Expand Down
26 changes: 15 additions & 11 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ jobs:
build_wheels:
name: 🎡 ${{ matrix.os }} wheels
runs-on: ${{ matrix.os }}
env:
CHAFA_VERSION: master
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
# os: [ubuntu-20.04, windows-2019, macos-11]

steps:
- uses: actions/checkout@v4

- name: Setup UCRT64
uses: msys2/setup-msys2@v2
if: matrix.os == 'windows-2019'
if: matrix.os == 'windows-latest'
with:
msystem: ucrt64
install: >-
Expand All @@ -35,31 +38,33 @@ jobs:
make
- name: Build Windows DLLs
if: matrix.os == 'windows-2019'
if: matrix.os == 'windows-latest'
shell: msys2 {0}
run: |
git clone --branch 1.12.5 https://github.com/hpjansson/chafa libchafa_src
git clone --branch $CHAFA_VERSION https://github.com/hpjansson/chafa libchafa_src
cd libchafa_src
./autogen.sh --without-tools --host=mingw64 && make
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
uses: pypa/cibuildwheel@v2.21.1

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl

make_sdist:
name: 💽 Make SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Build SDist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz

upload_all:
Expand All @@ -68,12 +73,11 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@v1.8.10
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
6 changes: 2 additions & 4 deletions .github/workflows/deliver_cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 📬 Deliver from Cirrus

on:
check_suite:
type: ['completed']
types: ['completed']

jobs:
upload_all_cirrus:
Expand All @@ -17,13 +17,11 @@ jobs:
steps:
- name: Downloading artifacts
run: |
wget -O macos.zip https://api.cirrus-ci.com/v1/artifact/github/GuardKenzie/chafa.py/macos_arm_wheels/wheels.zip
wget -O linux.zip https://api.cirrus-ci.com/v1/artifact/github/GuardKenzie/chafa.py/linux_arm_wheels/wheels.zip
unzip macos.zip
unzip linux.zip
- name: Uploading to test PyPi
uses: pypa/gh-action-pypi-publish@v1.8.10
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: wheelhouse/
user: __token__
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
pip install sphinx sphinxemoji sphinxcontrib-prettyspecialmethods sphinx-toolbox
Expand All @@ -17,7 +17,7 @@ jobs:
# - name: Setup Pages
# uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: './docs/_build/html'

Expand All @@ -35,6 +35,6 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ dmypy.json
# Build stuff to ignore
libs/**.dll
libs/**.so
wheelhouse/*
wheelhouse/*

# Testing
src/snake.jpg
81 changes: 4 additions & 77 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,4 @@
# CanvasConfig

- [x] Peaking at symbol maps?

- [x] fill_symbol_map
- [x] transparency_threshold
- [x] fg_only
- [x] fg and bg color
- [x] work factor
- [x] dithering
- [x] mode
- [x] intensity
- [x] optimizations
- [x] **DOCS**

# Canvas

- [ ] new_similar
- [x] Peeking at config
- [x] inspect characters at (x, y)
- [x] inspect color at (x, y)
- [x] raw color
- [x] **DOCS**
- [x] What argument type should `draw_pixels` accept for the pixel array? <- This is pretty much done
1. array (pretty fast)
2. python list and convert to array (slower than array)
3. Look into `from_buffer` for use with pyvips (faster than array)
4. Only ctypes array and make user handle conversion (This would be bad)

# Symbol map

- [x] copy
- [x] adding
- [x] by tags
- [x] by range
- [x] removing
- [x] by tags
- [x] by range

- [x] selectors

- [ ] allow builtin glyphs
- [ ] get glyph
- [ ] add glyph
- [x] **DOCS**

# TermDb

- [x] copy
- [x] fallback info
- [x] **DOCS**

# TermInfo

- [x] copy
- [ ] sequences
- [ ] get
- [ ] set
- [x] supplement
- [ ] **emitters!!!**
- [x] **DOCS**

# Misc
- [x] Properly figure out how the loader should work (pretty happy with it for now but could be faster)
- [x] Error handling (I think this is done?)
- [ ] ~~Splitting classes into separate files?~~ (not for now)

# Docs
- [x] Add remaining enums
- [x] Dither mode
- [x] Pixel Type

- [x] Docs for the loader

- [x] Write a tutorial
- [x] Add some examples
- [x] Installation
## Canvas
- [ ] Bindings for print_rows
- [ ] Bindings for print_rows_strv
- [ ] **DOCS!!**
22 changes: 19 additions & 3 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
--rosewater: #f2d5cf;
--flamingo: #eebebe;
--pink: #f4b8e4;
--mauve: #ca9ee6;
--mauve: hsl(277, 59%, 76%);
--red: #e78284;
--peach: #ef9f76;
--maroon: #ea999c;
Expand All @@ -47,13 +47,29 @@
--property: var(--green);
--attribute: var(--green);

--links: var(--peach);
--links: hsl(277, 49%, 65%);;
}

a:visited {
color: var(--links);
}

div.sphinxsidebarwrapper p.blurb {
text-align: center;
}

div.sphinxsidebarwrapper code.xref.py-class:hover {
background-color: initial;
}

div.sphinxsidebar a:hover code {
background-color: inherit;
}

div.sphinxsidebar code {
color: inherit;
}

img {
border-radius: .5rem;
}
Expand All @@ -62,7 +78,7 @@ img {
display: inline-block;
}

div.body h1.blocked-header {
div.body h1 {
line-height: 1em;
margin: .6em 0;
}
Expand Down
27 changes: 24 additions & 3 deletions docs/api/Canvas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ A :py:class:`Canvas` is a canvas that can render its contents as text strings.

When you want to make a :py:class:`Canvas`, you can specify it's properties like the width, height, output pixel mode etc. by first creating a :py:class:`CanvasConfig` and then initialising :py:class:`Canvas` with that.

You can draw an image to the canvas using :py:meth:`Canvas.draw_all_pixels` and convert it to output bytes for printing with :py:meth:`Canvas.print`. *(pssst: check out the :py:class:`loader.Loader` to make drawing images easier)*.
You can draw an image to the canvas using :py:meth:`Canvas.draw_all_pixels` and convert it to output bytes for printing with :py:meth:`Canvas.print`. Check out :ref:`pillow-example` for an example on how to load an image using `Pillow`_.

Alternatively, you can assign the :py:class:`Canvas` a :py:class:`Placement` with the :py:attr:`Canvas.placement` property if you want to control the alignment of the image on the :py:class:`Canvas`. If you go this route, you do not need to use :py:meth:`Canvas.draw_all_pixels`, and can go straight to :py:meth:`Canvas.print`.

The :py:class:`Canvas` supports indexing (and slicing) with ``[]``! This will return a :py:class:`CanvasInspector` or a `generator`_ for the relevant :py:class:`CanvasInspector` objects.

Expand Down Expand Up @@ -78,7 +80,25 @@ The :py:class:`Canvas` supports indexing (and slicing) with ``[]``! This will re
:param int|slice|tuple pos: The position to index

:rtype: CanvasInspector



.. py:property:: placement
:type: Placement

The :py:class:`Placement` of an :py:class:`Image` containing a :py:class:`Frame` on the canvas. Use this as an alternative to :py:meth:`draw_all_pixels` and for control over the image's alignment with :py:class:`Align` and :py:class:`Tuck`.

.. versionadded:: 1.2.0


.. py:method:: new_similar()
Returns a new :py:class:`Canvas` configured similarly to this one.

:rtype: Canvas

.. versionadded:: 1.2.0


.. py:method:: peek_config()
Expand All @@ -97,7 +117,7 @@ The :py:class:`Canvas` supports indexing (and slicing) with ``[]``! This will re
To output the data after drawing, use the :py:meth:`print` method.

.. note::
Best performance is achieved by passing a :py:class:`ctypes.Array` for src_pixels. The :py:class:`chafa.loader.Loader` class provides convenient (and reasonably fast) methods for this using the `MagickWand`_ C-library.
Best performance is achieved by passing a :py:class:`ctypes.Array` for src_pixels. A fast way to do this is to use `Pillow`_; specifically the `` `Image.tobytes <https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.tobytes>`_ `` method.

:param PixelType src_pixel_type: The pixel type of src_pixels. This will determine what order the color channels will be read in and whether there is an alpha channel.
:param list|tuple|array.array|ctypes.Array src_pixels: The source pixel data. This is a one dimensional array where every block of 3 (or 4 depending on the :py:class:`PixelType`) values represents one pixel of the image. The order of the channels is determined by src_pixel_type.
Expand Down Expand Up @@ -216,3 +236,4 @@ You can think of the :py:class:`CanvasInspector` like a detective with a magnify

.. _`generator`: https://docs.python.org/3/glossary.html#term-generator
.. _`MagickWand`: https://imagemagick.org/script/magick-wand.php
.. _`Pillow`: https://python-pillow.org/
Loading

0 comments on commit e1bd148

Please sign in to comment.