Skip to content

Commit

Permalink
Refactor: modernize package config (#1)
Browse files Browse the repository at this point in the history
* Refactor: modernize package config

* Add step verifying main entrypoint

* Bump version to v0.2.0

Code or functionality has not changed, but lets bump version
just in case there are problems with the project modernization
refactoring.

* Switch to dynamic setuptools versioning

* Embed program version into --help output
  • Loading branch information
MawKKe committed Mar 9, 2024
1 parent 27f0166 commit 48949a8
Show file tree
Hide file tree
Showing 21 changed files with 523 additions and 227 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python app

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- uses: FedericoCarboni/setup-ffmpeg@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install environment
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements-dev.txt
- name: Run linter
run: |
make lint
- name: Run tests
run: |
make test
- name: Verify main entrypoint script works
run: |
python -m venv app-venv && ./app-venv/bin/pip install .
./app-venv/bin/audiobook-split-ffmpeg --help
./app-venv/bin/audiobook-split-ffmpeg --infile tests/beep.m4a --outdir _out --verbose
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache/

# Translations
*.mo
Expand Down Expand Up @@ -127,3 +128,6 @@ dmypy.json

# Pyre type checker
.pyre/

# vim crap
.*.sw[mnop]
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
VENV_DIR := .venv

sync-venv: requirements-dev.txt
python3 -m venv ${VENV_DIR}
./${VENV_DIR}/bin/pip install --upgrade pip
./${VENV_DIR}/bin/pip install -r requirements-dev.txt
@echo "---"
@echo "NOTE: Please run 'source ./${VENV_DIR}/bin/activate' to use the env"
@echo " or run 'Python: Select Interpreter' from VSCode command palette"

pin-requirements: requirements.txt requirements-dev.txt
@echo "---------------------------------------------"
@echo "Done.\n"
@echo "Remember to commit changes to pyproject.toml,"
@echo " requirements.txt, and requirements-dev.txt"
@echo "---------------------------------------------"

requirements.txt: pyproject.toml
pip-compile \
--generate-hashes \
--strip-extras \
--output-file=requirements.txt \
pyproject.toml

requirements-dev.txt: requirements.txt
pip-compile \
--strip-extras \
--constraint requirements.txt \
--output-file=requirements-dev.txt \
--extra dev \
pyproject.toml

# This is basically 'python3 -m build'
build:
pyproject-build

lint:
ruff check --output-format=full --statistics --exit-zero

test:
pytest --cov=audiobook_split_ffmpeg tests/

.PHONY: sync-venv pin-requirements build lint test
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ You may then play these files with your preferred application.

# Install

This package is not published in the PYPI, but you can install it directly from Github with

$ pip install --user git+https://github.com/MawKKe/audiobook-split-ffmpeg

This should place the main script into your user's PATH (`$HOME/.local/bin/` or
similar). Next, see `Usage` below.
**However**, I personally recommend using [pipx](https://github.com/pypa/pipx)
which simplifies installing python applications into isolated virtualenvs:

$ pipx install git+https://github.com/MawKKe/audiobook-split-ffmpeg

afterwards, the `audiobook-split-ffmpeg` command should be available via your `PATH`.

Next, see Usage below.

# Usage

Expand Down Expand Up @@ -100,6 +108,7 @@ then run tests with:

- The work is parallelized to speed up the processing.


# License

Copyright 2018 Markus Holmström (MawKKe)
Expand Down
52 changes: 48 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
requires = ['setuptools>=61']
build-backend = 'setuptools.build_meta'

[project]
name = 'audiobook-split-ffmpeg'
authors = [
{name='Markus H (MawKKe)', email='markus@mawkke.fi'}
]
description = 'Split audiobook file into per-chapter files using chapter metadata and ffmpeg'
dynamic = ["version"]
license = {text = 'Apache License 2.0'}
readme = 'README.md'
requires-python = '>=3.8'
dependencies = []

[tool.setuptools.dynamic]
version = {attr = "audiobook_split_ffmpeg.__version__"}

[project.optional-dependencies]
dev = [
'ruff>=0.3',
'pytest>=7',
'pytest-cov>=4.1',
]

build-backend = "setuptools.build_meta"
[project.urls]
homepage = 'https://github.com/MawKKe/audiobook-split-ffmpeg'
Issues = 'https://github.com/MawKKe/audiobook-split-ffmpeg/issues'

[project.scripts]
audiobook-split-ffmpeg = 'audiobook_split_ffmpeg.cli:main'

[tool.pytest.ini_options]
pythonpath = [
".", "src",
]

[tool.ruff]
line-length = 100

[tool.ruff.format]
# Use single quotes rather than double quotes.
quote-style = 'single'
skip-magic-trailing-comma = false

[tool.ruff.lint]
select = ['E4', 'E7', 'E9', 'F', 'C901']

[tool.ruff.lint.mccabe]
max-complexity = 10
6 changes: 0 additions & 6 deletions pytest.ini

This file was deleted.

25 changes: 22 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
pytest==6.2.5
pytest-cov==2.12.1
pytest-flake8==1.0.7
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --constraint=requirements.txt --extra=dev --output-file=requirements-dev.txt --strip-extras pyproject.toml
#
coverage==7.4.3
# via pytest-cov
iniconfig==2.0.0
# via pytest
packaging==23.2
# via pytest
pluggy==1.4.0
# via pytest
pytest==8.1.1
# via
# audiobook-split-ffmpeg (pyproject.toml)
# pytest-cov
pytest-cov==4.1.0
# via audiobook-split-ffmpeg (pyproject.toml)
ruff==0.3.2
# via audiobook-split-ffmpeg (pyproject.toml)
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --generate-hashes --output-file=requirements.txt --strip-extras pyproject.toml
#
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

41 changes: 0 additions & 41 deletions setup.py

This file was deleted.

16 changes: 14 additions & 2 deletions src/audiobook_split_ffmpeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@
More information in Github: https://github.com/MawKKe/audiobook-split-ffmpeg
"""

from .ffmpeg import ffprobe_read_chapters, workitem_to_ffmpeg_cmd, ffmpeg_split_chapter
from .ffmpeg import (
ffprobe_read_chapters,
workitem_to_ffmpeg_cmd,
ffmpeg_split_chapter,
)
from .workers import process_workitems
from .util import compute_workitems

__author__ = "Markus Holmström (MawKKe) - markus@mawkke.fi"
__all__ = [
ffprobe_read_chapters,
workitem_to_ffmpeg_cmd,
ffmpeg_split_chapter,
process_workitems,
compute_workitems,
]
__author__ = 'Markus Holmström (MawKKe) <markus@mawkke.fi>'
__version__ = '0.2.0'
Loading

0 comments on commit 48949a8

Please sign in to comment.