Skip to content

Commit

Permalink
perf: add type safety
Browse files Browse the repository at this point in the history
ci: add concurrency
  • Loading branch information
KnownBlackHat committed May 12, 2023
1 parent fdb8d19 commit 19577ad
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 113 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Lint & Test

on:
push:
branches:
- 'master'
pull_request:
merge_group:
types: [checks_requested]

permissions:
read-all

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Run pre-commit
id: pre-commit
uses: pre-commit/[email protected]

pyright:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
experimental: [false]
fail-fast: false
continue-on-error: ${{ matrix.experimental }}

steps:
- uses: actions/checkout@v3


- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install .
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 ./easy_pil --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 ./easy_pil --count --exit-zero --max-complexity=10 --max-line-length=79 --statistics
- name: Test with pytest
run: |
pytest
- name: Run pyright (Linux)
uses: jakebailey/[email protected]
id: pyright-linux
with:
version: ${{ env.PYRIGHT_VERSION }}
python-version: ${{ steps.setup-env.outputs.python-version }}
python-platform: "Linux"
no-comments: ${{ matrix.python-version != '3.8' }} # only add comments for one version
warnings: true

- name: Run pyright (Windows)
uses: jakebailey/[email protected]
if: always() && (steps.pyright-linux.outcome == 'success' || steps.pyright-linux.outcome == 'failure')
with:
version: ${{ env.PYRIGHT_VERSION }}
python-version: ${{ steps.setup-env.outputs.python-version }}
python-platform: "Windows"
no-comments: true # only add comments for one platform (see above)
warnings: true
39 changes: 0 additions & 39 deletions .github/workflows/python-package.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ dmypy.json
.pytype/

# Cython debug symbols
cython_debug/
cython_debug/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include requirements.txt
include setup.py
include LICENSE
include *.md
include *.ttf
include *.ttf
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Easy PIL
A Python library built on top of [PIL](https://github.com/python-pillow/Pillow) to easily edit/modify images.
![Lint-Test](https://github.com/shahriyardx/easy-pil/actions/workflows/lint-test.yml/badge.svg)
A Python library built on top of [PIL](https://github.com/python-pillow/Pillow) to easily edit/modify images.

## Getting Started
Using this for the first time? Here are some links to help you get started.
Expand All @@ -12,4 +13,4 @@ Using this for the first time? Here are some links to help you get started.

## Get help
- Ask us in our [Discord server](https://discord.gg/fVzt5THTNb)
- Watch [Youtube Tutorials](https://www.youtube.com/playlist?list=PLb_oBhGqAlbT4yVqV0TSXggA8b0lZhGhn)
- Watch [Youtube Tutorials](https://www.youtube.com/playlist?list=PLb_oBhGqAlbT4yVqV0TSXggA8b0lZhGhn)
4 changes: 2 additions & 2 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Here are some examples made using easy-pil
welcome_image
welcome_image_two

.. note::
More examples will be added in future.
.. note::
More examples will be added in future.
2 changes: 1 addition & 1 deletion docs/examples/owo_level.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ Example of owo leveling card made using easy-pil
Output
---------
.. image:: /_static/examples/owo_level.png
.. image:: /_static/examples/owo_level.png
2 changes: 1 addition & 1 deletion docs/examples/rank_card.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ Example of a rank card made using easy-pil
Output
---------
.. image:: /_static/examples/rank_card1.png
.. image:: /_static/examples/rank_card1.png
2 changes: 1 addition & 1 deletion docs/examples/rank_card_two.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ Example of a rank card card made using easy-pil
Output
---------
.. image:: /_static/examples/rank_card2.png
.. image:: /_static/examples/rank_card2.png
2 changes: 1 addition & 1 deletion docs/examples/welcome_image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ Example of a welcome image made using easy-pil
Output
---------
.. image:: /_static/examples/welcome_image1.png
.. image:: /_static/examples/welcome_image1.png
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A python library built on top of PIL to easily edit images.
:maxdepth: 2
:hidden:
:caption: Contents

pages/intro
pages/discordbot
easy_pil/modules
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/discordbot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This will make command author's avatar circular and send it
# Creating nextcord.File object from image_bytes from editor
file = File(fp=editor.image_bytes, filename='circle.png')
await ctx.send(file=file)
bot.run("TOKEN")
bot.run("TOKEN")
6 changes: 3 additions & 3 deletions docs/pages/intro.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Introduction
============
This is the documentation for easy-pil, A python library built on top of PIL to easily edit images.
This is the documentation for easy-pil, A python library built on top of PIL to easily edit images.

Prerequisties
-------------
easy-pil requires python 3.7 or higher. Support for previous version is not guranteed.
easy-pil requires python 3.7 or higher. Support for previous version is not guranteed.

Installing
-----------
Expand All @@ -29,4 +29,4 @@ A quick example of how easy-pil works
editor = Editor(board)
editor.text((10, 10), "Hello World")
editor.show() # .save() to save the image
editor.show() # .save() to save the image
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Pillow>=9.5.0
requests>=2.28.2
typing-extensions>=4.5.0
aiohttp>=3.6.0
memoization>=0.4.0
memoization>=0.4.0
2 changes: 1 addition & 1 deletion easy_pil/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

VersionInfo = namedtuple("VersionInfo", "major minor macro release")

version_info = VersionInfo(*map(int, __version__.split(".")), "stable")
version_info = VersionInfo(*map(int, __version__.split(".")), release="stable")
20 changes: 10 additions & 10 deletions easy_pil/canvas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple
from typing import Optional, Tuple

from PIL import Image

Expand All @@ -10,11 +10,11 @@ class Canvas:
Parameters
----------
size : Tuple[float, float], optional
size : Tuple[int, int], optional
Size of image, by default None
width : float, optional
width : int, optional
Width of image, by default None
height : float, optional
height : int, optional
Height of image, by default None
color : Color, optional
Color of image, by default None
Expand All @@ -27,15 +27,15 @@ class Canvas:

def __init__(
self,
size: Tuple[float, float] = None,
width: float = None,
height: float = None,
color: Color = None,
size: Optional[Tuple[int, int]] = None,
width: int = 0,
height: int = 0,
color: Color = 0,
) -> None:
if not size and not width and not height:
if not (size or (width and height)):
raise ValueError("size, width, and height cannot all be None")

if width and height:
else:
size = (width, height)

self.size = size
Expand Down
Loading

0 comments on commit 19577ad

Please sign in to comment.