Skip to content

Commit

Permalink
Version 0.7.0 release (#180)
Browse files Browse the repository at this point in the history
* Version 0.7.0 release

* Fix CI

* Fix flake8
  • Loading branch information
sobolevn authored Sep 26, 2022
1 parent 66a1444 commit abe734b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
We follow [Semantic Versions](https://semver.org/).


## Version 0.7.0

### Features

- Use `importlib` instead of `pkg_resources` to get package version


## Version 0.6.0

### Features
Expand Down
25 changes: 4 additions & 21 deletions coverage_conditional_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
import sys
import traceback
from importlib import import_module
from typing import ClassVar, Dict, Iterable, Optional, Tuple, Union
from typing import ClassVar, Dict, Iterable, Tuple, Union

try: # pragma: no cover
from importlib.metadata import version as metadata_version
except ImportError: # pragma: no cover
from importlib_metadata import version as metadata_version # type: ignore
from coverage import CoveragePlugin
from coverage.config import CoverageConfig
from packaging import version
from packaging.markers import default_environment

from coverage_conditional_plugin.version import package_version


def get_env_info() -> Dict[str, object]:
"""Public helper to get the same env we pass to the plugin."""
Expand All @@ -23,7 +20,7 @@ def get_env_info() -> Dict[str, object]:
'sys_version_info': sys.version_info,
'os_environ': os.environ,
'is_installed': _is_installed,
'package_version': _package_version,
'package_version': package_version,
# We need this, otherwise `_should_be_applied` can generate a warning:
'sys': sys,
})
Expand Down Expand Up @@ -121,20 +118,6 @@ def _is_installed(package: str) -> bool:
return True


def _package_version(
package: str,
) -> Optional[Tuple[int, ...]]:
"""
Helper function that fetches distribution version.
Can throw multiple exceptions.
Be careful, use ``is_installed`` before using this one.
Returns parsed varsion to be easily worked with.
"""
return version.parse(metadata_version(package)).release


def coverage_init(reg, options) -> None:
"""
Entrypoint, part of the ``coverage`` API.
Expand Down
22 changes: 22 additions & 0 deletions coverage_conditional_plugin/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Optional, Tuple

try: # pragma: no cover
from importlib.metadata import version as metadata_version
except ImportError: # pragma: no cover
from importlib_metadata import version as metadata_version # type: ignore

from packaging import version


def package_version(
package: str,
) -> Optional[Tuple[int, ...]]:
"""
Helper function that fetches distribution version.
Can throw multiple exceptions.
Be careful, use ``is_installed`` before using this one.
Returns parsed varsion to be easily worked with.
"""
return version.parse(metadata_version(package)).release
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "coverage-conditional-plugin"
version = "0.6.0"
version = "0.7.0"
description = "Conditional coverage based on any rules you define!"
license = "MIT"

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extend-exclude =
per-file-ignores =
# we need nested import and block variable overlap for conditional
# importlib_metadata import
coverage_conditional_plugin/__init__.py: WPS433, WPS440
coverage_conditional_plugin/version.py: WPS433, WPS440
# Disable `test_project` complexity checks:
test_project/example.py: WPS202
# Enable `assert` keyword and magic numbers for tests:
Expand Down Expand Up @@ -95,6 +95,6 @@ warn_redundant_casts = true
warn_unused_configs = true
warn_unreachable = true

[mypy-coverage_conditional_plugin]
[mypy-coverage_conditional_plugin.version]
# We allow unused `ignore` comments, because we cannot sync it between versions:
warn_unused_ignores = false
7 changes: 4 additions & 3 deletions tests/test_implementation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from coverage_conditional_plugin import _is_installed, _package_version
from coverage_conditional_plugin import _is_installed
from coverage_conditional_plugin.version import package_version


def test_is_installed():
Expand All @@ -10,8 +11,8 @@ def test_is_installed():

def test_package_version():
"""Ensures that ``_package_version`` is correct."""
coverage_version = _package_version('coverage')
pytest_version = _package_version('pytest')
coverage_version = package_version('coverage')
pytest_version = package_version('pytest')

assert coverage_version is not None
assert coverage_version < (1000, 0, 0)
Expand Down

0 comments on commit abe734b

Please sign in to comment.