Skip to content

Commit

Permalink
🚨 clean up import guards
Browse files Browse the repository at this point in the history
Signed-off-by: rjdbcm <[email protected]>
  • Loading branch information
rjdbcm committed Jun 9, 2024
1 parent 2804a02 commit cc78500
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
3 changes: 1 addition & 2 deletions ozi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

def main() -> None: # pragma: no cover
"""``ozi`` script entrypoint."""
ozi, args = parser.parse_known_args()
ozi, _ = parser.parse_known_args()
ozi.version()
ozi.check_version()
ozi.info()
Expand All @@ -133,5 +133,4 @@ def main() -> None: # pragma: no cover


if __name__ == '__main__':
"""Main ozi entrypoint."""
main()
22 changes: 11 additions & 11 deletions ozi/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
from typing import NoReturn
from warnings import warn

if TYPE_CHECKING:
from argparse import ArgumentParser
from argparse import Namespace
from collections.abc import Sequence

if sys.version_info >= (3, 11):
from typing import Self
elif sys.version_info < (3, 11):
from typing_extensions import Self

import requests
from packaging.version import Version
from packaging.version import parse
Expand All @@ -38,6 +28,16 @@
from ozi.trove import Prefix
from ozi.trove import from_prefix

if TYPE_CHECKING:
from argparse import ArgumentParser
from argparse import Namespace
from collections.abc import Sequence

if sys.version_info >= (3, 11):
from typing import Self
elif sys.version_info < (3, 11):
from typing_extensions import Self

_prefix = Prefix()


Expand Down Expand Up @@ -98,7 +98,7 @@ def close_matches(
if hasattr(self.exact_match, key):
matches = get_close_matches(
value,
self.exact_match.__getattribute__(key),
getattr(self.exact_match, key),
cutoff=0.40,
)
no_match = False if len(matches) else True
Expand Down
2 changes: 0 additions & 2 deletions ozi/fix/rewrite_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
elif sys.version_info < (3, 11):
from typing_extensions import Self

from ozi.spec import METADATA


@dataclass
class RewriteCommand: # pragma: defer to meson
Expand Down
20 changes: 10 additions & 10 deletions ozi/new/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from argparse import Namespace
from typing import Callable
from typing import TypeAlias

from jinja2 import Environment

Composable: TypeAlias = Callable[[Namespace], Namespace]

from blastpipe.ozi_templates import load_environment

from ozi.new.parser import parser
Expand All @@ -35,6 +26,15 @@
from ozi.spec import METADATA
from ozi.tap import TAP

if TYPE_CHECKING:
from argparse import Namespace
from typing import Callable
from typing import TypeAlias

from jinja2 import Environment

Composable: TypeAlias = Callable[[Namespace], Namespace]


def create_project_files(
project: Namespace,
Expand Down Expand Up @@ -119,7 +119,7 @@ def wrap(project: Namespace) -> None: # pragma: no cover
"""Create a new wrap file for publishing. Not a public function."""
env = load_environment(vars(project), METADATA.asdict())
template = env.get_template('ozi.wrap.j2')
with open('ozi.wrap', 'w') as f:
with open('ozi.wrap', 'w', encoding='UTF-8') as f:
f.write(template.render())


Expand Down
20 changes: 12 additions & 8 deletions ozi/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
from git import InvalidGitRepositoryError
from git import Repo

if TYPE_CHECKING:
from jinja2 import Environment

from ozi.spec import METADATA
from ozi.tap import TAP

if TYPE_CHECKING:
from jinja2 import Environment


def find_user_template(target: str, file: str, fix: str) -> str | None:
"""Find a user-defined project template file e.g. :file:`{target}/templates/{fix}/{file}`.
Expand All @@ -37,7 +37,7 @@ def find_user_template(target: str, file: str, fix: str) -> str | None:
"""
fp = Path(target, 'templates', fix, file)
if fp.exists():
with open(fp) as template:
with open(fp, encoding='UTF-8') as template:
user_template = template.read()
else:
TAP.diagnostic('User tempate not found', str(fp))
Expand Down Expand Up @@ -126,7 +126,7 @@ def build_child(env: Environment, parent: str, child: Path) -> None:
stacklevel=0,
)
else:
with open((child / 'meson.build'), 'x') as f:
with open((child / 'meson.build'), 'x', encoding='UTF-8') as f:
f.write(env.get_template('new_child.j2').render(parent=parent))


Expand All @@ -150,7 +150,11 @@ def render_ci_files_set_user(env: Environment, target: Path, ci_provider: str) -
ci_user = ''
Path(target, '.github', 'workflows').mkdir(parents=True)
template = env.get_template('github_workflows/ozi.yml.j2')
with open(Path(target, '.github', 'workflows', 'ozi.yml'), 'w') as f:
with open(
Path(target, '.github', 'workflows', 'ozi.yml'),
'w',
encoding='UTF-8',
) as f:
f.write(template.render())
case _: # pragma: no cover
ci_user = ''
Expand Down Expand Up @@ -178,7 +182,7 @@ def render_project_files(env: Environment, target: Path, name: str) -> None:
except LookupError: # pragma: defer to good-first-issue
content = f'template "{filename}" failed to render.'
warn(content, RuntimeWarning, stacklevel=0)
with open(target / filename, 'w') as f:
with open(target / filename, 'w', encoding='UTF-8') as f:
f.write(content)

for filename in templates.source:
Expand All @@ -199,5 +203,5 @@ def render_project_files(env: Environment, target: Path, name: str) -> None:
)

template = env.get_template('project.ozi.wrap.j2')
with open(target / 'subprojects' / 'ozi.wrap', 'w') as f:
with open(target / 'subprojects' / 'ozi.wrap', 'w', encoding='UTF-8') as f:
f.write(template.render())
7 changes: 3 additions & 4 deletions ozi/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from contextlib import redirect_stdout
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Generator
from typing import NoReturn
from typing import TextIO

if TYPE_CHECKING:
from typing import Any
Expand All @@ -24,10 +27,6 @@
elif sys.version_info < (3, 11):
from typing_extensions import Self

from typing import Generator
from typing import NoReturn
from typing import TextIO

OK = 'ok'
NOT_OK = 'not_ok'
SKIP = 'skip'
Expand Down
6 changes: 4 additions & 2 deletions ozi/trove.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from typing import TYPE_CHECKING
from warnings import warn

from trove_classifiers import classifiers

if TYPE_CHECKING:
import sys

Expand All @@ -19,8 +21,6 @@
elif sys.version_info < (3, 11):
from typing_extensions import Self

from trove_classifiers import classifiers


@lru_cache
def get_trove_prefix(text: str) -> str | None:
Expand All @@ -42,6 +42,8 @@ def get_trove_prefix(text: str) -> str | None:

@dataclass(frozen=True, slots=True, eq=True)
class Prefix:
"""Trove :term:`classifier` prefix literals for :term:`PyPI`"""

audience: str = 'Intended Audience :: '
environment: str = 'Environment :: '
framework: str = 'Framework :: '
Expand Down

0 comments on commit cc78500

Please sign in to comment.