Skip to content

Commit

Permalink
Merge branch 'poetry' into fix/embedded-and-error-correction
Browse files Browse the repository at this point in the history
  • Loading branch information
maribedran committed Sep 27, 2024
2 parents f997fce + 39cf502 commit ffa2b4a
Show file tree
Hide file tree
Showing 36 changed files with 848 additions and 930 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.py]
indent_size = 4
max_line_length = 88

[*.{rst,md}]
indent_size = 4
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ruff format the entire project
5d60da17455607e9c8b7e7fef9940d20027894f2
23 changes: 23 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Code Quality Checks

on:
push:

jobs:
linting:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Install Dependencies
run: pip install ruff

- name: Code Linting
if: always()
run: ruff check qrcode

- name: Code Formatting
if: always()
run: ruff format --check qrcode
25 changes: 25 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Testsuite Run

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install --disable-pip-version-check tox tox-gh-actions
- name: Test with tox
run: tox
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
*.pyc
.tox
dist/
.coverage
.coverage.*
htmlcov/
build/
qrcode.egg-info/
.pytest_cache/
.idea/
.pytest_cache/
.tox
build/
cov.xml
dist/
htmlcov/
poetry.lock
qrcode.egg-info/
18 changes: 16 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ Change log
7.5 (unreleased)
================

- Nothing changed yet.
- Added support for Python 3.11 and 3.12.

- Drop support for Python <=3.8.

- Change local development setup to use Poetry_.

- Testsuite and code quality checks are done through Github Actions.

- Code quality and formatting utilises ruff_.

- Removed ``typing_extensions`` as a dependency, as it's no longer required with
having Python 3.9+ as a requirement.

.. _Poetry: https://python-poetry.org
.. _ruff: https://astral.sh/ruff


7.4.2 (6 February 2023)
=======================

- Allow ``pypng`` factory to allow for saving to a string (like
``qr.save("some_file.png")``) in addition to file-like objects.
``qr.save("some_file.png")``) in addition to file-like objects.


7.4.1 (3 February 2023)
Expand Down
7 changes: 0 additions & 7 deletions MANIFEST.in

This file was deleted.

4 changes: 2 additions & 2 deletions PACKAGING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Packaging quick reminder

Make sure maintainer dependencies are installed::

pip install -e .[maintainer,dev]
poetry install

Run release command and follow prompt instructions::

fullrelease
poetry run fullrelease
26 changes: 22 additions & 4 deletions TESTING.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Testing
=======

First, install tox into your virtualenv::
First, install dev dependencies::

pip install --upgrade tox
poetry install --with dev

To run all tests, you'll need to install multiple Python interpreters. On a
modern Ubuntu distribution you can use ``add-apt-repository
Expand All @@ -15,5 +15,23 @@ the libraries to build PIL, too. Here's the Ubuntu commands::
sudo apt-get install build-essential python-dev python3-dev
sudo apt-get install libjpeg8-dev zlib1g-dev

Finally, just run ``tox``!
If you want, you can test against a specific version like this: ``tox -e py36``
Here's the OSX Homebrew command:

brew install libjpeg libtiff little-cms2 openjpeg webp

Finally, just run ``tox``::

poetry run tox
# or
poetry shell
tox

If you want, you can test against a specific version like this: ``tox -e py312-pil``


Linting
-------

Run `ruff` to check formatting::

ruff format qrcode
73 changes: 71 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
[build-system]
requires = ["setuptools >= 48"]
build-backend = "setuptools.build_meta"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "qrcode"
version = "8.0.dev0"
packages = [{include = "qrcode"}]
description = "QR Code image generator"
authors = ["Lincoln Loop <[email protected]>"]
license = "BSD"
readme = ["README.rst", "CHANGES.rst"]
homepage = "https://github.com/lincolnloop/python-qrcode"
keywords = ["qr", "denso-wave", "IEC18004"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Multimedia :: Graphics",
"Topic :: Software Development :: Libraries :: Python Modules",
]

# There is no support for data files yet.
# https://github.com/python-poetry/poetry/issues/9519
#
# data_files = [
# { destination = "share/man/man1", from = [ "doc/qr.1" ] },
# ]

[tool.poetry.scripts]
qr = 'qrcode.console_scripts:main'


[tool.poetry.dependencies]
python = "^3.9"
colorama = {version = "*", platform = "win32"}
pypng = {version = "*", optional = true}
pillow = {version = ">=9.1.0", optional = true}

[tool.poetry.extras]
pil = ["pillow"]
png = ["pypng"]
all = ["pypng","pillow"]

[tool.poetry.group.dev.dependencies]
pytest = {version = "*"}
pytest-cov = {version = "*"}
tox = {version = "*"}
ruff = {version = "*"}
pypng = {version = "*"}
pillow = {version = ">=9.1.0"}
docutils = "^0.21.2"
zest-releaser = {extras = ["recommended"], version = "^9.2.0"}

[tool.zest-releaser]
less-zeros = "yes"
version-levels = 2
tag-format = "v{version}"
tag-message = "Version {version}"
tag-signing = "yes"
date-format =" %%-d %%B %%Y"
prereleaser.middle = [
"qrcode.release.update_manpage"
]
12 changes: 0 additions & 12 deletions qrcode/compat/pil.py

This file was deleted.

7 changes: 7 additions & 0 deletions qrcode/compat/png.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Try to import png library.
PngWriter = None

try:
from png import Writer as PngWriter # type: ignore # noqa: F401
except ImportError: # pragma: no cover
pass
5 changes: 3 additions & 2 deletions qrcode/console_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
When stdout is a tty the QR Code is printed to the terminal and when stdout is
a pipe to a file an image is written. The default image format is PNG.
"""

import optparse
import os
import sys
from typing import Dict, Iterable, NoReturn, Optional, Set, Type
from importlib import metadata

import qrcode
from qrcode.image.base import BaseImage, DrawerAliases
Expand Down Expand Up @@ -40,9 +42,8 @@
def main(args=None):
if args is None:
args = sys.argv[1:]
from pkg_resources import get_distribution

version = get_distribution("qrcode").version
version = metadata.version("qrcode")
parser = optparse.OptionParser(usage=(__doc__ or "").strip(), version=version)

# Wrap parser.error in a typed NoReturn method for better typing.
Expand Down
5 changes: 4 additions & 1 deletion qrcode/image/pil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import qrcode.image.base
from qrcode.compat.pil import Image, ImageDraw
from PIL import Image, ImageDraw


class PilImage(qrcode.image.base.BaseImage):
Expand All @@ -10,6 +10,9 @@ class PilImage(qrcode.image.base.BaseImage):
kind = "PNG"

def new_image(self, **kwargs):
if not Image:
raise ImportError("PIL library not found.")

back_color = kwargs.get("back_color", "white")
fill_color = kwargs.get("fill_color", "black")

Expand Down
12 changes: 7 additions & 5 deletions qrcode/image/pure.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from itertools import chain

import png
from qrcode.compat.png import PngWriter
from qrcode.image.base import BaseImage

import qrcode.image.base


class PyPNGImage(qrcode.image.base.BaseImage):
class PyPNGImage(BaseImage):
"""
pyPNG image builder.
"""
Expand All @@ -15,7 +14,10 @@ class PyPNGImage(qrcode.image.base.BaseImage):
needs_drawrect = False

def new_image(self, **kwargs):
return png.Writer(self.pixel_size, self.pixel_size, greyscale=True, bitdepth=1)
if not PngWriter:
raise ImportError("PyPNG library not installed.")

return PngWriter(self.pixel_size, self.pixel_size, greyscale=True, bitdepth=1)

def drawrect(self, row, col):
"""
Expand Down
5 changes: 1 addition & 4 deletions qrcode/image/styledpil.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Needed on case-insensitive filesystems
from __future__ import absolute_import

import qrcode.image.base
from qrcode.compat.pil import Image
from PIL import Image
from qrcode.image.styles.colormasks import QRColorMask, SolidFillColorMask
from qrcode.image.styles.moduledrawers import SquareModuleDrawer

Expand Down
5 changes: 1 addition & 4 deletions qrcode/image/styles/colormasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Needed on case-insensitive filesystems
from __future__ import absolute_import

import math

from qrcode.compat.pil import Image
from PIL import Image


class QRColorMask:
Expand Down
5 changes: 1 addition & 4 deletions qrcode/image/styles/moduledrawers/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import abc
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -32,5 +30,4 @@ def initialize(self, img: "BaseImage") -> None:
self.img = img

@abc.abstractmethod
def drawrect(self, box, is_active) -> None:
...
def drawrect(self, box, is_active) -> None: ...
9 changes: 4 additions & 5 deletions qrcode/image/styles/moduledrawers/pil.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Needed on case-insensitive filesystems
from __future__ import absolute_import

from typing import TYPE_CHECKING, List

from qrcode.compat.pil import Image, ImageDraw
from PIL import Image, ImageDraw
from qrcode.image.styles.moduledrawers.base import QRModuleDrawer

if TYPE_CHECKING:
Expand Down Expand Up @@ -249,7 +246,9 @@ def setup_edges(self):
base_draw = ImageDraw.Draw(base)
base_draw.ellipse((0, 0, fake_width * 2, fake_height), fill=front_color)

self.ROUND_LEFT = base.resize((width, shrunken_height), Image.Resampling.LANCZOS)
self.ROUND_LEFT = base.resize(
(width, shrunken_height), Image.Resampling.LANCZOS
)
self.ROUND_RIGHT = self.ROUND_LEFT.transpose(Image.Transpose.FLIP_LEFT_RIGHT)

def drawrect(self, box, is_active: "ActiveWithNeighbors"):
Expand Down
Loading

0 comments on commit ffa2b4a

Please sign in to comment.