Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to pyproject.toml #66

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -e .[test]
- name: Lint
run: |
make lint
- name: Mypy
run: |
make mypy
build:
runs-on: ubuntu-latest
strategy:
Expand All @@ -27,10 +50,10 @@ jobs:
run: |
pip install setuptools
pip install .[all]
pip install .[test]
- name: Test
run: |
pip install pytest
pytest -vsx tests
make test
- name: Run examples
run: |
python getting_started.py
Expand All @@ -41,5 +64,6 @@ jobs:
done
- name: Install from dist
run: |
python setup.py sdist
make build
pip install dist/*.tar.gz
pip install dist/*.whl
34 changes: 0 additions & 34 deletions .github/workflows/lint.yml

This file was deleted.

22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@ all:
@echo
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

PACKAGE_DIR=imgviz

mypy:
mypy --package $(PACKAGE_DIR)

lint:
ruff format --check
ruff check
ruff format --check || ruff format --check --diff
ruff check || ruff check --diff

format:
ruff format
ruff check --fix

test:
pytest tests
python -m pytest -n auto -v tests

clean:
rm -rf build dist *.egg-info

build: clean
python -m build --sdist --wheel

upload: build
python -m twine upload dist/$(PACKAGE_DIR)-*

publish: build upload
27 changes: 13 additions & 14 deletions generate_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def tabulate(rows):
return html


def _get_github_image_url(relpath: str) -> str:
return f"https://github.com/wkentaro/imgviz/raw/main/{relpath}"


def main():
examples = []
for py_file in sorted(glob.glob("examples/*.py")):
Expand All @@ -28,24 +32,19 @@ def main():
width = 20.0 / img.height * img.width
examples.append(
(
'<pre><a href="{}">{}</a></pre>'.format(py_file, py_file),
'<img src="{}" width="{}%" />'.format(img_file, width),
f'<pre><a href="{py_file}">{py_file}</a></pre>',
f'<img src="{_get_github_image_url(relpath=img_file)}" width="{width}%" />', # NOQA: E501
)
)
examples = tabulate(examples)

# TODO: read from pyproject.toml
dependencies = []
with open("requirements.txt") as f:
for req in f:
if req.startswith("#"):
continue
req = req.strip()
pkg = req
for sep in "<=>":
pkg = pkg.split(sep)[0]
dependencies.append(
"- [{0}](https://pypi.org/project/{1})".format(req, pkg)
)
for req in ["matplotlib", "numpy", "Pillow>=5.3.0", "PyYAML"]:
pkg = req
for sep in "<=>":
pkg = pkg.split(sep)[0]
dependencies.append("- [{0}](https://pypi.org/project/{1})".format(req, pkg))
dependencies = "\n".join(dependencies)

py_file = "getting_started.py"
Expand Down Expand Up @@ -90,7 +89,7 @@ def main():
<br/>

<div align="center">
<img src=".readme/getting_started.jpg" width="95%">
<img src="https://github.com/wkentaro/imgviz/raw/main/.readme/getting_started.jpg" width="95%">
</div>

## Installation
Expand Down
2 changes: 1 addition & 1 deletion imgviz/_io/opencv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
try:
import cv2
except ImportError:
cv2 = None
cv2 = None # type: ignore
import numpy as np # NOQA


Expand Down
1 change: 0 additions & 1 deletion imgviz/depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Depth2RGB(object):

"""Convert depth array to rgb.

Parameters
Expand Down
1 change: 0 additions & 1 deletion imgviz/nchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Nchannel2RGB(object):

"""Convert nchannel array to rgb by PCA.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion imgviz/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
try:
import cv2
except ImportError:
cv2 = None
cv2 = None # type: ignore


def _resize_pillow(src, height, width, interpolation):
Expand Down
106 changes: 106 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[build-system]
requires = ["hatchling>=1.20.0", "hatch-vcs", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"

[project.urls]
Homepage = "https://github.com/wkentaro/imgviz"

[project]
name = "imgviz"
description = "Image Visualization Tools"
license = { text = "MIT" }
requires-python = ">=3.9"
authors = [
{ name = "Kentaro Wada", email = "[email protected]" },
]
keywords = []
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"matplotlib",
"numpy",
"Pillow>=5.3.0",
"PyYAML",
]
dynamic = ["readme", "version"]

[project.optional-dependencies]
all = [
"scikit-image",
"scikit-learn",
"opencv-python",
"pyglet",
]
test = [
"build",
"mypy",
"types-Pillow",
"types-PyYAML",
"pytest",
"pytest-xdist",
"ruff",
"twine",
]

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/markdown"
fragments = [
{ path = "README.md" },
]

[tool.hatch.version]
source = "vcs"

[tool.mypy]
ignore_missing_imports = true

[tool.ruff]
exclude = [
".conda",
".git",
"src",
]

line-length = 88
indent-width = 4

[tool.ruff.lint]
# Enable Pyflakes (`F`), pycodestyle (`E`), isort (`I`).
select = ["E", "F", "I"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

[tool.ruff.lint.isort]
force-single-line = true
5 changes: 0 additions & 5 deletions requirements-dev.txt

This file was deleted.

6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

33 changes: 0 additions & 33 deletions ruff.toml

This file was deleted.

10 changes: 0 additions & 10 deletions setup.cfg

This file was deleted.

Loading
Loading