Skip to content

Commit

Permalink
#48: Avoid module load order issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed May 26, 2021
1 parent 10e4ef7 commit f438ef2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Unreleased

* Fixed:
* The plugin did not work on Fedora inside of Pip's isolated build
environment, because the plugin would be loaded before some of its
dependencies. Now, those imports are delayed until needed.

## v0.12.7 (2021-05-20)

* Fixed:
Expand Down
37 changes: 22 additions & 15 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@
import builtins
import copy
import functools
import jinja2
import os
import re
from importlib import import_module
from pathlib import Path
from typing import Mapping, MutableMapping, Optional, Sequence, Tuple
from typing import Any, Mapping, MutableMapping, Optional, Sequence, Tuple

import tomlkit
from dunamai import (
bump_version,
check_version,
serialize_pep440,
serialize_pvp,
serialize_semver,
Style,
Vcs,
Version,
)

_VERSION_PATTERN = r"""
(?x) (?# ignore whitespace)
Expand All @@ -30,13 +19,17 @@
(\+(?P<tagged_metadata>.+))?$ (?# +linux)
""".strip()

# This is a placeholder for type hint docs since the actual type can't be
# imported yet.
_DUNAMAI_VERSION_ANY = Any


class _ProjectState:
def __init__(
self,
path: Path = None,
original_version: str = None,
version: Tuple[Version, str] = None,
version: Tuple[_DUNAMAI_VERSION_ANY, str] = None,
substitutions: MutableMapping[Path, str] = None,
) -> None:
self.path = path
Expand Down Expand Up @@ -143,7 +136,9 @@ def get_config(start: Path = None) -> Mapping:
return result


def _bump_version_per_config(version: Version, bump: bool) -> Version:
def _bump_version_per_config(version: _DUNAMAI_VERSION_ANY, bump: bool) -> _DUNAMAI_VERSION_ANY:
from dunamai import bump_version

if not bump or version.distance == 0:
return version

Expand All @@ -160,7 +155,19 @@ def _bump_version_per_config(version: Version, bump: bool) -> Version:
return version


def _get_version(config: Mapping) -> Tuple[Version, str]:
def _get_version(config: Mapping) -> Tuple[_DUNAMAI_VERSION_ANY, str]:
import jinja2
from dunamai import (
bump_version,
check_version,
serialize_pep440,
serialize_pvp,
serialize_semver,
Style,
Vcs,
Version,
)

vcs = Vcs(config["vcs"])
style = config["style"]
if style is not None:
Expand Down

0 comments on commit f438ef2

Please sign in to comment.