Skip to content

Commit

Permalink
migrate to poetry; initial linting
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Dec 15, 2024
1 parent 5eabc97 commit a2b566a
Show file tree
Hide file tree
Showing 18 changed files with 1,110 additions and 176 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build package and push to PyPi

on:
workflow_dispatch:
push:
tags:
- "v*.*.*"

jobs:
build:
runs-on: ubuntu-latest
env:
PYTHON: 3.12
POETRY_HOME: "~/poetry"

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Includes getting tags

- name: Set up python ${{ env.PYTHON }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON }}

- name: Cache Poetry Install
uses: actions/cache@v4
id: cached-poetry
with:
path: ${{ env.POETRY_HOME }}
key: poetry-cache-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.github/workflows/deploy.yaml') }}

- name: Install poetry
uses: snok/install-poetry@v1
if: steps.cached-poetry.outputs.cache-hit != 'true'

- name: Add Poetry to PATH # Needs to be separate from install-poetry because cache.
run: |
echo "$POETRY_HOME/bin" >> $GITHUB_PATH
- name: Configure Poetry # Needs to be separate from install-poetry because cache.
run: |
poetry self add poetry-dynamic-versioning[plugin]
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Cache venv
uses: actions/cache@v4
id: cached-venv
with:
path: .venv/
key: venv-cache-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.github/workflows/deploy.yaml') }}

- name: Install project
run: poetry install --no-interaction

- name: Build package
run: poetry build

- name: Publish package
if: github.event_name != 'workflow_dispatch'
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish
- uses: actions/upload-artifact@v4
if: always()
with:
name: dist
path: dist/
99 changes: 99 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Regular tests
#
# Use this to ensure your tests are passing on every push and PR (skipped on
# pushes which only affect documentation).
#
# You should make sure you run jobs on at least the *oldest* and the *newest*
# versions of python that your codebase is intended to support.

name: tests

on:
push:
branches:
- main
pull_request:

jobs:
test:
timeout-minutes: 10
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
POETRY_HOME: "~/poetry"

steps:
- name: Set OS Environment Variables (Windows)
if: runner.os == 'Windows'
run: |
echo 'ACTIVATE_PYTHON_VENV=.venv/scripts/activate' >> $GITHUB_ENV
- name: Set OS Environment Variables (not Windows)
if: runner.os != 'Windows'
run: |
echo 'ACTIVATE_PYTHON_VENV=.venv/bin/activate' >> $GITHUB_ENV
- name: Check out repository
uses: actions/checkout@v4

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

- name: Cache Poetry Install
uses: actions/cache@v4
id: cached-poetry
with:
path: ${{ env.POETRY_HOME }}
key: poetry-cache-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.github/workflows/tests.yaml') }}

- name: Install poetry
uses: snok/install-poetry@v1
if: steps.cached-poetry.outputs.cache-hit != 'true'

- name: Add Poetry to PATH # Needs to be separate from install-poetry because cache.
run: |
echo "$POETRY_HOME/bin" >> $GITHUB_PATH
- name: Configure Poetry # Needs to be separate from install-poetry because cache.
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
poetry config installer.parallel ${{ runner.os != 'Windows' }} # Currently there seems to be some race-condition in windows
- name: Cache venv
uses: actions/cache@v4
id: cached-venv
with:
path: .venv/
key: venv-cache-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.github/workflows/tests.yaml') }}

- name: Install library
run: poetry install --no-interaction

- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit/
key: pre-commit-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Pre-commit run
run: |
source ${{ env.ACTIVATE_PYTHON_VENV }}
pre-commit run --show-diff-on-failure --color=always --all-files
- name: Run tests
run: |
source ${{ env.ACTIVATE_PYTHON_VENV }}
python -m pytest
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
exclude: ^(poetry.lock|.idea/)
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.3"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
exclude: ^LICENSE|\.(html|csv|txt|svg|py)$
- id: pretty-format-json
args: ["--autofix", "--no-ensure-ascii", "--no-sort-keys"]
- id: requirements-txt-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
exclude: \.(html|svg)$

- repo: https://github.com/fredrikaverpil/creosote.git
rev: v3.2.0
hooks:
- id: creosote

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
- tomli

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.390
hooks:
- id: pyright
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
# py360convert

**A new library including more fuctionality for 360 is under contruction by my colleague. This repo will be depreciated then.**

Features of this project:
- Convertion between cubemap and equirectangular
- Conversion between cubemap and equirectangular
![](assert/teaser_convertion.png)
- Equirectangular to planar
![](assert/teaser_2planar.png)
- Pure python implementation and depend only on [numpy](http://www.numpy.org/) and [scipy](https://www.scipy.org/)
- Vectorization implementation (in most of the place)
- `c2e` takes 300ms and `e2c` takes 160ms on 1.6 GHz Intel Core i5 CPU

## Requirements
- numpy
- scipy
- pillow (for example code to load/save image)

## Install
```
pip install py360convert
Expand Down Expand Up @@ -61,7 +54,7 @@ Convert the given equirectangular to cubemap.
- `e_img`: Numpy array with shape [H, W, C].
- `face_w`: The width of each cube face.
- `mode`: `bilinear` or `nearest`.
- `cube_format`: See `c2e` explaination.
- `cube_format`: See `c2e` explanation.


#### `e2p(e_img, fov_deg, u_deg, v_deg, out_hw, in_rot_deg=0, mode='bilinear')`
Expand Down Expand Up @@ -100,7 +93,7 @@ import py360convert

cube_dice = np.array(Image.open('assert/demo_cube.png'))

# You can make convertion between supported cubemap format
# You can make conversion between supported cubemap format
cube_h = py360convert.cube_dice2h(cube_dice) # the inverse is cube_h2dice
cube_dict = py360convert.cube_h2dict(cube_h) # the inverse is cube_dict2h
cube_list = py360convert.cube_h2list(cube_h) # the inverse is cube_list2h
Expand Down
55 changes: 0 additions & 55 deletions convert360

This file was deleted.

Loading

0 comments on commit a2b566a

Please sign in to comment.