Skip to content

Commit ec8b29a

Browse files
committed
Fix type checking issue in Python 3.9
1 parent f947eeb commit ec8b29a

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

hooks/post_gen_project.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
1-
import logging
21
import os
3-
from pathlib import Path, PurePath
42
import shutil
53
import subprocess
64
import sys
75

8-
from cookiecutter.config import get_user_config
9-
10-
11-
logger = logging.getLogger(__name__)
12-
13-
logger.info('Saving replay file for red-port')
14-
config_dict = get_user_config()
15-
template_name = '{{ cookiecutter._repo_dir.split('/')[-1] }}'
16-
target_replay_path = Path('.redport') / 'cookiecutter_replay'
17-
target_replay_path.mkdir(exist_ok=True)
18-
shutil.copy(
19-
(PurePath(config_dict['replay_dir']) / template_name).with_suffix('.json'),
20-
target_replay_path,
21-
)
22-
236
shutil.rmtree('licenses')
247

258
{% if cookiecutter.include_executable != "y" -%}

{{ cookiecutter.pypi_package_name }}/{{ cookiecutter.python_package_name }}/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import json
44
import os
5+
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
56
from typing import Any
7+
{%- else -%}
8+
from typing import Any, Optional
9+
{%- endif %}
610

711
import xdg.BaseDirectory # type: ignore
812

@@ -12,7 +16,13 @@
1216
logger = get_logger(__name__)
1317

1418

19+
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
1520
def config_get(key: str, default: Any | None = None) -> Any | None:
21+
{%- else -%}
22+
def config_get(
23+
key: str, default: Optional[Any] = None
24+
) -> Optional[Any]:
25+
{%- endif %}
1626
"""Reads a config from the first level of a JSON file by key.
1727
1828
:param key: the name of the top-level JSON property.
@@ -74,7 +84,11 @@ def config_set(key: str, value: Any) -> None:
7484
logger.info('New value written')
7585

7686

87+
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
7788
def config_dir(subdir: str | None = None) -> str:
89+
{%- else -%}
90+
def config_dir(subdir: Optional[str] = None) -> str:
91+
{%- endif %}
7892
"""Returns the configuration directory for this package.
7993
8094
Respects the XDG settings. Also creates the directory if it does

0 commit comments

Comments
 (0)