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

Bump Click to 8.0.1 and fix compatibility #282

Merged
merged 2 commits into from
May 31, 2021
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
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@

#### 1.7 (UNRELEASED)

**Important**: for a normal installation, *vpype* must now be installed/updated with the following command:
```
pip install -U vpype[all]
```


New features and improvements:
* ...
* The viewer (`show` command) and its dependencies is no longer required and is installed only if the `all` extra is provided to `pip`:
```
pip install -U vpype[all] # the viewer is fully installed
pip install -U vpype # the viewer and its dependencies is NOT installed
```
Forgoing the viewer considerably reduces the number of required dependencies and may be useful for embedded (e.g. Raspberry Pi) and server installs of *vpype*, when the `show` command is not necessary.

Bug fixes:
* Fixed an issue where `read` would crash with empty `<polygon>` tags and similar degenerate geometries (#260)

Other changes:
* Updated to Click 8.0.1 (#282)

#### 1.6 (2021-03-10)

New features and improvements:
Expand Down
213 changes: 106 additions & 107 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ vpype = "vpype_cli.cli:cli"
python = ">=3.7, !=3.9.0, <3.10"
attrs = "~21.2.0"
cachetools = "^4.2.0"
click = "~7.1.2"
click = "~8.0.1"
click-plugins = "~1.1.1"
multiprocess = "^0.70.11"
numpy = "^1.20"
pnoise = "^0.1.0"
Shapely = {extras = ["vectorized"], version = "~1.7.1"}
scipy = "^1.6"
setuptools = "^51.0.0"
svgelements = "1.5.2"
svgelements = "1.5.3"
svgwrite = "~1.4"
toml = "~0.10.2"

Expand All @@ -56,7 +56,7 @@ Pillow = { version = "^8.1.0", optional = true }
PySide2 = { version = "^5.15.2", optional = true }

# these needs to be there because of https://github.com/python-poetry/poetry/issues/1145
Sphinx = { version = "^3.5.0", optional = true }
Sphinx = { version = "^4.0.1", optional = true }
sphinx-click = { version = ">=2.5.0", optional = true }
sphinx-autodoc-typehints = { version = "^1.12.0", optional = true }
sphinx-rtd-theme = { version = "^0.5.0", optional = true }
Expand All @@ -67,7 +67,7 @@ coverage = {extras = ["toml"], version = "^5.4"}
pytest = "^6.2.3"
pytest-cov = "^2.11.0"
pytest-benchmark = "^3.2.3"
black = "^20.8b1"
black = "^21.5b1"
isort = "^5.8.0"
mypy = "^0.812"
pyinstaller = "^4.3"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@

@pytest.mark.parametrize("args", MINIMAL_COMMANDS)
def test_commands_empty_geometry(runner, args):
result = runner.invoke(cli, args)
result = runner.invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0


@pytest.mark.parametrize("args", MINIMAL_COMMANDS)
def test_commands_single_line(runner, args):
result = runner.invoke(cli, "line 0 0 10 10 " + args)
result = runner.invoke(cli, "line 0 0 10 10 " + args, catch_exceptions=False)
assert result.exit_code == 0


Expand Down
12 changes: 9 additions & 3 deletions vpype/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class LayerType(click.ParamType):
None is passed through, which typically means to use the default behaviour.
"""

name = "layer ID"

NEW = -1
ALL = -2

Expand All @@ -99,10 +101,14 @@ def __init__(self, accept_multiple: bool = False, accept_new: bool = False):
self.name = "layer"

def convert(self, value, param, ctx):
# comply with ParamType requirements
if value is None:
return None
# accept value when already converted to final type
if isinstance(value, int):
if value > 0 or value in [self.ALL, self.NEW]:
return value
else:
self.fail(f"inconsistent converted value {value}")

value = str(value)
if value.lower() == "all":
if self.accept_multiple:
return LayerType.ALL
Expand Down
28 changes: 19 additions & 9 deletions vpype/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import math
import re
from typing import Callable, Dict, List, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

import click
import numpy as np
Expand Down Expand Up @@ -196,10 +196,13 @@ class LengthType(click.ParamType):
name = "length"

def convert(self, value, param, ctx):
try:
return convert_length(value)
except ValueError:
self.fail(f"parameter {value} is an incorrect length")
if isinstance(value, str):
try:
return convert_length(value)
except ValueError:
self.fail(f"parameter {value} is an incorrect length")
else:
return super().convert(value, param, ctx)


class Length(LengthType): # pragma: no cover
Expand Down Expand Up @@ -231,7 +234,10 @@ class AngleType(click.ParamType):

def convert(self, value, param, ctx):
try:
return convert_angle(value)
if isinstance(value, str):
return convert_angle(value)
else:
return super().convert(value, param, ctx)
except ValueError:
self.fail(f"parameter {value} is an incorrect angle")

Expand All @@ -253,11 +259,15 @@ class PageSizeType(click.ParamType):
... pass
"""

name = "PAGESIZE"
name = "pagesize"

def convert(self, value, param, ctx) -> Tuple[float, float]:
def convert(self, value: Any, param, ctx) -> Optional[Tuple[float, float]]:
try:
return convert_page_size(value)
if isinstance(value, str):
return convert_page_size(value)
else:
return super().convert(value, param, ctx)

except ValueError:
self.fail(f"parameter {value} is not a valid page size")

Expand Down
8 changes: 4 additions & 4 deletions vpype_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os
import random
import shlex
import sys
from typing import Any, List, Optional, TextIO, Union

import click
import numpy as np
from click import get_os_args
from click_plugins import with_plugins
from pkg_resources import iter_entry_points
from shapely.geometry import MultiLineString
Expand Down Expand Up @@ -70,7 +70,7 @@ def format_commands(self, ctx, formatter):
def main(self, args=None, **extra):
"""Let's get a chance to pre-process the argument list for include options."""
if args is None:
args = get_os_args()
args = sys.argv[1:]
return super().main(args=preprocess_argument_list(args), **extra)


Expand Down Expand Up @@ -105,7 +105,7 @@ def cli(ctx, verbose, include, history, seed, config):
# We use the command string as context object, mainly for the purpose of the `write`
# command. This is a bit of a hack, and will need to be updated if we ever need more state
# to be passed around (probably VpypeState should go in there!)
cmd_string = "vpype " + " ".join(shlex.quote(arg) for arg in get_os_args()) + "\n"
cmd_string = "vpype " + " ".join(shlex.quote(arg) for arg in sys.argv[1:]) + "\n"
ctx.obj = cmd_string

if history:
Expand All @@ -123,7 +123,7 @@ def cli(ctx, verbose, include, history, seed, config):


# noinspection PyShadowingNames,PyUnusedLocal
@cli.resultcallback()
@cli.result_callback()
def process_pipeline(processors, verbose, include, history, seed, config):
execute_processors(processors)

Expand Down
4 changes: 2 additions & 2 deletions vpype_cli/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def _compute_origin(
document: vp.Document,
layer: Optional[Union[int, List[int]]],
origin_coords: Union[Tuple[()], Tuple[float, float]],
origin_coords: Optional[Union[Tuple[()], Tuple[float, float]]],
) -> Tuple[Tuple[float, float], List[int], Tuple[float, float, float, float]]:
layer_ids = vp.multiple_to_layer_ids(layer, document)
bounds = document.bounds(layer_ids)
Expand All @@ -23,7 +23,7 @@ def _compute_origin(
logging.warning("no geometry available, cannot compute origin")
raise ValueError

if len(origin_coords) == 2:
if origin_coords is not None and len(origin_coords) == 2:
origin = origin_coords
else:
origin = (
Expand Down