Skip to content

Commit

Permalink
feat: re-implement cli with typer
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Oct 7, 2022
1 parent 5b977dd commit 5068fee
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 336 deletions.
26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ The following shows how to convert numpy and pytest, along with their dependenci
```sh
# Download (and build if needed) pytest, numpy and their requirements
pip3 wheel pytest numpy
# Convert all wheels to debian source packages
wheel2deb --map attrs=attr
# Call dpkg-buildpackages for each source package
wheel2deb build
# Convert all wheels to debian source packages, build them with dpkg-buildpackage
wheel2deb
ls -l output/*.deb
# Install generated packages
dpkg -i output/*.deb
Expand Down Expand Up @@ -95,23 +93,9 @@ pipx install wheel2deb
- handle entrypoints and scripts (those will be installed in /usr/bin with a proper shebang)
- try to locate licence files and to generate a debian/copyright file

## Options

Use `wheel2deb --help` and `wheel2deb build --help` to check all supported options

| Option | Description |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -v | Enable debug logs. |
| -x | List of search paths where to look for python wheels. Defaults to current directory. Not recursive. |
| -o | Output directory where debian source packages will be produced. Defaults to ./output |
| -i | List of wheel names to convert. By default all found wheels are included. |
| --python-version | cpython version on the target debian distribution. Defaults to platform version (example: 3.4). |
| --map | list of string pairs to explicitely map python dist names to debian package names. For instance: "--map foo:bar attrs:attr" will tell wheel2deb to map foo to python-bar and attrs to python-attr. |
| --depends | List of additional debian dependencies. |
| --epoch | Debian package epoch. Defaults to 0. |
| --revision | Debian package revision. Defaults to 1. |
| --ignore-entry-points | Don't include the wheel entrypoints in the debian package. |
| --ignore-upstream-version | Ignore version specifiers from wheel requirements. For instance, if foo requires bar>=3.0.0, using this option will produce a debian package simply depending on bar instead of "bar (>= 3.0.0)". |
## Usage

Use `wheel2deb convert --help` and `wheel2deb build --help` to check all supported options.

## Development

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pyinstaller = { version = "5.4.1", optional = true }
pyinstaller = ["pyinstaller"]

[tool.poetry.scripts]
wheel2deb = "wheel2deb:main"
wheel2deb = "wheel2deb.cli:main"

[tool.poetry.dev-dependencies]
pytest = "*"
Expand Down
35 changes: 31 additions & 4 deletions src/wheel2deb/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from threading import Event, Thread
from time import sleep

from wheel2deb.logger import logging
from wheel2deb import logger as logging
from wheel2deb.utils import shell

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,13 +48,15 @@ def build_package(cwd: Path) -> int:
return returncode


def build_packages(paths, threads: int = 4) -> None:
def build_packages(paths, threads: int, force_build: bool) -> None:
"""
Run several instances of dpkg-buildpackage in parallel.
:param paths: List of paths where dpkg-buildpackage will be called
:param threads: Number of threads to run in parallel
"""

logger.task(f"Building {len(paths)} source packages...")

paths = paths.copy()
workers = []
for i in range(threads):
Expand All @@ -63,8 +65,9 @@ def build_packages(paths, threads: int = 4) -> None:
workers.append(dict(done=event, path=None))

def build(done, path):
logger.info(f"building {path}")
build_package(path)
if force_build is True or Path(str(path) + ".deb").is_file() is False:
logger.info(f"building {path}")
build_package(path)
done.set()

while False in [w["done"].is_set() for w in workers] or paths:
Expand All @@ -74,3 +77,27 @@ def build(done, path):
w["path"] = paths.pop()
Thread(target=build, kwargs=w).start()
sleep(1)


def build_all_packages(output_directory: Path, workers: int, force_build: bool) -> None:
"""
Build debian source packages in parallel.
:param output_directory: path where to search for source packages
:param workers: Number of threads to run in parallel
:param force_build: Build packages even if .deb already exists
"""

if output_directory.exists() is False:
logger.error(f"Directory {output_directory} does not exist")
return

if output_directory.is_dir() is False:
logger.error(f"{output_directory} is not a directory")
return

paths = []
for output_directory in output_directory.iterdir():
if output_directory.is_dir() and (output_directory / "debian/control").is_file():
paths.append(output_directory)

build_packages(paths, workers, force_build)
Loading

0 comments on commit 5068fee

Please sign in to comment.