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

Use type annotations and fix mypy errors #109

Merged
merged 46 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
809e730
Added callbacks
ftCLI Sep 26, 2023
a6b6a9e
Use type annotations
ftCLI Sep 26, 2023
720daa4
Use callbacks
ftCLI Sep 26, 2023
9920e37
Fix assignment errors
ftCLI Sep 26, 2023
d1d5aab
Fix return error
ftCLI Sep 26, 2023
353d6af
Fix return error
ftCLI Sep 26, 2023
8b8d7f8
Fix assignment errors and arg-type errors
ftCLI Sep 26, 2023
7e0a6ad
Fix arg-type errors
ftCLI Sep 26, 2023
ee4e09d
Use isinstance() rather than type()
ftCLI Sep 26, 2023
196e839
Fix incompatible default for argument "max_lines"
ftCLI Sep 26, 2023
39320ab
Replace 'namerecord' wit 'NameRecord' in docstring
ftCLI Sep 26, 2023
bf3b273
Remove unused function
ftCLI Sep 26, 2023
0676578
Add type annotations
ftCLI Sep 26, 2023
7995d72
Log SUCCESS instead of INFO when file is saved
ftCLI Sep 26, 2023
b9e9f72
Remove unused function, use Path in place of pathlib.Path, add type a…
ftCLI Sep 26, 2023
4d41076
Fix return error
ftCLI Sep 26, 2023
5b574a7
Fix assignment error
ftCLI Sep 26, 2023
870f589
Fix assignment errors
ftCLI Sep 26, 2023
4c028a8
Fix assignment error
ftCLI Sep 26, 2023
25810ad
Fix arg-type errors
ftCLI Sep 26, 2023
4e6d8d0
Fix assignment errors
ftCLI Sep 26, 2023
75e17d5
Add type annotations
ftCLI Sep 26, 2023
7a140cf
Add annotations for empty Tuple
ftCLI Sep 26, 2023
84298d0
Add type annotations
ftCLI Sep 26, 2023
a429da7
Add type annotations and fix wrong type declaration
ftCLI Sep 26, 2023
2b99039
Fix arg-type and assignment errors
ftCLI Sep 26, 2023
46c19e0
Use any() to check if at least one parameter has been passed
ftCLI Sep 26, 2023
2d7a604
Fix type declaration
ftCLI Sep 26, 2023
6f145d4
Fix assignment error
ftCLI Sep 26, 2023
f085757
Remove comment
ftCLI Sep 26, 2023
b9d03e2
Fix return error
ftCLI Sep 26, 2023
6b710ea
Add type annotations
ftCLI Sep 26, 2023
1e88f5c
Revert "Add type annotations"
ftCLI Sep 26, 2023
1088075
Add type annotations
ftCLI Sep 26, 2023
d71a9e8
Fix assignment error
ftCLI Sep 26, 2023
3a40c9c
Fix return error
ftCLI Sep 26, 2023
1d35a66
Fix incompatible defaults
ftCLI Sep 27, 2023
1be2246
Fix incompatible defaults
ftCLI Sep 27, 2023
606569d
Fix incompatible defaults
ftCLI Sep 27, 2023
f9b12a0
Fix incompatible type "Path" (expected: "str")
ftCLI Sep 27, 2023
2d2ce9f
Fix incompatible defaults
ftCLI Sep 27, 2023
d3435d6
Fix incompatible defaults
ftCLI Sep 27, 2023
54a404a
Fix incompatible defaults
ftCLI Sep 27, 2023
b6dc4a7
Fix incompatible type "Path" (expected: "str")
ftCLI Sep 27, 2023
7c9325e
Use enumerate instead of iterating with range and len
ftCLI Sep 27, 2023
1f3b8c4
Blacken code
ftCLI Sep 27, 2023
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
74 changes: 36 additions & 38 deletions foundryToolsCLI/CLI/ftcli_assistant.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing as t

from copy import copy, deepcopy
from pathlib import Path

Expand All @@ -16,6 +18,8 @@
add_file_or_path_argument,
add_common_options,
file_overwrite_prompt,
linked_styles_callback,
choice_to_int_callback,
)
from foundryToolsCLI.Lib.utils.logger import logger, Logs
from foundryToolsCLI.Lib.utils.timer import Timer
Expand Down Expand Up @@ -88,6 +92,7 @@ def init(input_path: Path, quiet: bool = False):
"-ls",
"--linked-styles",
type=(click.IntRange(1, 1000), click.IntRange(1, 1000)),
callback=linked_styles_callback,
help="""Use this option to activate linked styles. If this option is active, linked styles must be specified. For
example: -ls 400 700, or -ls 300 600.
""",
Expand All @@ -97,6 +102,7 @@ def init(input_path: Path, quiet: bool = False):
"--exclude-namerecords",
type=click.Choice(choices=["1", "2", "3", "4", "5", "6", "16", "17", "18"]),
multiple=True,
callback=choice_to_int_callback,
help="""
Name IDs to skip. The specified name IDs won't be recalculated. This option can be repeated (for example: -x 3 -x 5
-x 6...).
Expand All @@ -107,6 +113,7 @@ def init(input_path: Path, quiet: bool = False):
"--shorten-width",
type=click.Choice(choices=["1", "4", "6", "16", "17"]),
multiple=True,
callback=choice_to_int_callback,
help="""
Name IDs where to use the short word for width style name (for example, 'Cn' instead of 'Condensed'). This option
can be repeated (for example: -swdt 1 -swdt 5, -swdt 16...).
Expand All @@ -117,11 +124,23 @@ def init(input_path: Path, quiet: bool = False):
"--shorten-weight",
type=click.Choice(choices=["1", "4", "6", "17"]),
multiple=True,
callback=choice_to_int_callback,
help="""
Name IDs where to use the short word for weight style name (for example, 'Md' instead of 'Medium'). This option can
be repeated (for example: -swgt 1 -swgt 5 -swgt 6...).
""",
)
@click.option(
"-sslp",
"--shorten-slope",
type=click.Choice(choices=["4", "6", "16", "17"]),
multiple=True,
callback=choice_to_int_callback,
help="""
Name IDs where to use the short word for slope style name (for example, 'It' instead of 'Italic'). This option can
be repeated (for example: -sslp 3 -sslp 5 -sslp 6...).
""",
)
@click.option(
"-kwdt",
"--keep-width-elidable",
Expand All @@ -138,16 +157,6 @@ def init(input_path: Path, quiet: bool = False):
Doesn't remove the weight elidable words (by default, "Rg" and "Regular").
""",
)
@click.option(
"-sslp",
"--shorten-slope",
type=click.Choice(choices=["4", "6", "16", "17"]),
multiple=True,
help="""
Name IDs where to use the short word for slope style name (for example, 'It' instead of 'Italic'). This option can
be repeated (for example: -sslp 3 -sslp 5 -sslp 6...).
""",
)
@click.option(
"-sf",
"--super-family",
Expand Down Expand Up @@ -201,23 +210,23 @@ def init(input_path: Path, quiet: bool = False):
@Timer(logger=logger.info)
def commit(
input_path: Path,
width_elidable: str,
weight_elidable: str,
linked_styles: list = None,
exclude_namerecords=None,
shorten_width=None,
shorten_weight=None,
keep_width_elidable=False,
keep_weight_elidable=False,
shorten_slope=None,
super_family=False,
alt_uid=False,
oblique_not_italic=False,
auto_shorten=True,
cff=False,
output_dir=None,
recalc_timestamp=False,
overwrite=True,
linked_styles: t.Optional[t.Tuple[int, int]] = None,
exclude_namerecords: t.Union[t.Tuple[int], t.Tuple[()]] = (),
shorten_width: t.Union[t.Tuple[int], t.Tuple[()]] = (),
shorten_weight: t.Union[t.Tuple[int], t.Tuple[()]] = (),
shorten_slope: t.Union[t.Tuple[int], t.Tuple[()]] = (),
width_elidable: str = "Normal",
weight_elidable: str = "Regular",
keep_width_elidable: bool = False,
keep_weight_elidable: bool = False,
super_family: bool = False,
alt_uid: bool = False,
oblique_not_italic: bool = False,
auto_shorten: bool = True,
cff: bool = False,
output_dir: t.Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
"""
Writes data from CSV to fonts.
Expand All @@ -229,17 +238,6 @@ def commit(
except Exception as e:
logger.exception(e)

if linked_styles:
linked_styles = sorted(linked_styles)
if exclude_namerecords:
exclude_namerecords = sorted(set(int(i) for i in exclude_namerecords))
if shorten_width:
shorten_width = sorted(set(int(i) for i in shorten_width))
if shorten_weight:
shorten_weight = sorted(set(int(i) for i in shorten_weight))
if shorten_slope:
shorten_slope = sorted(set(int(i) for i in shorten_slope))

try:
fonts_data = FontsData(get_fonts_data_path(input_path))
data = fonts_data.get_data()
Expand Down
8 changes: 5 additions & 3 deletions foundryToolsCLI/CLI/ftcli_cff.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing as t

from copy import deepcopy
from pathlib import Path

Expand Down Expand Up @@ -32,7 +34,7 @@ def del_names(
input_path: Path,
recursive: bool = False,
recalc_timestamp: bool = False,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
overwrite: bool = True,
**kwargs
):
Expand Down Expand Up @@ -99,7 +101,7 @@ def set_names(
input_path: Path,
recursive: bool = False,
recalc_timestamp: bool = False,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
overwrite: bool = True,
**kwargs
):
Expand Down Expand Up @@ -163,7 +165,7 @@ def find_replace(
old_string: str,
new_string: str,
recursive: bool = False,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down
25 changes: 17 additions & 8 deletions foundryToolsCLI/CLI/ftcli_converter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing as t

from pathlib import Path

import click
Expand Down Expand Up @@ -42,11 +44,11 @@
def ttf2otf(
input_path: Path,
tolerance: float = 1.0,
scale_upm: int = None,
scale_upm: t.Optional[int] = None,
subroutinize: bool = True,
recalc_timestamp: bool = False,
recursive: bool = False,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
overwrite: bool = True,
verbose: bool = True,
):
Expand Down Expand Up @@ -92,7 +94,7 @@ def otf2ttf(
max_err: float = 1.0,
recalc_timestamp: bool = False,
recursive: bool = False,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
overwrite: bool = True,
):
"""
Expand Down Expand Up @@ -157,7 +159,7 @@ def vf2i(
cleanup: bool = True,
update_name_table: bool = True,
recursive: bool = False,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -228,9 +230,9 @@ def vf2i(
@Timer(logger=logger.info)
def wf2ft(
input_path: Path,
flavor: str = None,
flavor: t.Optional[str] = None,
recursive: bool = False,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -282,7 +284,14 @@ def wf2ft(
@add_recursive_option()
@add_common_options()
@Timer(logger=logger.info)
def ft2wf(input_path, flavor=None, recursive: bool = False, output_dir=None, recalc_timestamp=False, overwrite=True):
def ft2wf(
input_path: Path,
flavor: t.Optional[str] = None,
recursive: bool = False,
output_dir: t.Optional[Path] = None,
recalc_timestamp=False,
overwrite=True,
):
"""
Converts SFNT fonts (TTF or OTF) to web fonts (WOFF and/or WOFF2)
"""
Expand Down Expand Up @@ -315,7 +324,7 @@ def ft2wf(input_path, flavor=None, recursive: bool = False, output_dir=None, rec
@Timer(logger=logger.info)
def ttc2sfnt(
input_path: Path,
output_dir: Path = None,
output_dir: t.Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down
20 changes: 11 additions & 9 deletions foundryToolsCLI/CLI/ftcli_fix.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from copy import deepcopy
from pathlib import Path

Expand Down Expand Up @@ -28,7 +30,7 @@
def monospace(
input_path: Path,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -175,7 +177,7 @@ def monospace(
def nbsp_width(
input_path: Path,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -267,7 +269,7 @@ def italic_angle(
input_path: Path,
mode: int = 1,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
min_slant: float = 2.0,
Expand Down Expand Up @@ -442,7 +444,7 @@ def italic_angle(
def nbsp_missing(
input_path: Path,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -499,7 +501,7 @@ def nbsp_missing(
def decompose_transformed(
input_path: Path,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -605,7 +607,7 @@ def decompose_transformed(
def duplicate_components(
input_path: Path,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -681,7 +683,7 @@ def duplicate_components(
def kern_table(
input_path: Path,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -768,7 +770,7 @@ def kern_table(
def strip_names(
input_path: Path,
recursive: bool = False,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down Expand Up @@ -821,7 +823,7 @@ def strip_names(
@Timer(logger=logger.info)
def empty_names(
input_path: Path,
output_dir: Path = None,
output_dir: Optional[Path] = None,
recalc_timestamp: bool = False,
overwrite: bool = True,
):
Expand Down
Loading