-
Notifications
You must be signed in to change notification settings - Fork 122
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
Remove incremental #491
Remove incremental #491
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -8,12 +8,12 @@ | |||||||||||||
|
||||||||||||||
from __future__ import annotations | ||||||||||||||
|
||||||||||||||
import importlib.metadata as importlib_metadata | ||||||||||||||
import sys | ||||||||||||||
|
||||||||||||||
from importlib import import_module | ||||||||||||||
from types import ModuleType | ||||||||||||||
|
||||||||||||||
from incremental import Version as IncrementalVersion | ||||||||||||||
from typing import Any | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def _get_package(package_dir: str, package: str) -> ModuleType: | ||||||||||||||
|
@@ -38,47 +38,45 @@ def _get_package(package_dir: str, package: str) -> ModuleType: | |||||||||||||
|
||||||||||||||
|
||||||||||||||
def get_version(package_dir: str, package: str) -> str: | ||||||||||||||
module = _get_package(package_dir, package) | ||||||||||||||
version: Any | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why Any? Any opts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to str #627 |
||||||||||||||
|
||||||||||||||
module = _get_package(package_dir, package) | ||||||||||||||
version = getattr(module, "__version__", None) | ||||||||||||||
|
||||||||||||||
if not version: | ||||||||||||||
raise Exception("No __version__, I don't know how else to look") | ||||||||||||||
try: | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like this is not only about removing incremental, but also about using I think is best to do this as part of a separate PR ..l like #502 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale comment as linked PR has been merged. Updated and integrated latest trunk in #627 |
||||||||||||||
version = importlib_metadata.version(package) | ||||||||||||||
except importlib_metadata.PackageNotFoundError: | ||||||||||||||
raise Exception(f"Package not installed and no {package}.__version__ found") | ||||||||||||||
|
||||||||||||||
if isinstance(version, str): | ||||||||||||||
return version.strip() | ||||||||||||||
|
||||||||||||||
if isinstance(version, IncrementalVersion): | ||||||||||||||
# FIXME:https://github.com/twisted/incremental/issues/81 | ||||||||||||||
# Incremental uses `.rcN`. | ||||||||||||||
# importlib uses `rcN` (without a dot separation). | ||||||||||||||
# Here we make incremental work like importlib. | ||||||||||||||
return version.base().strip().replace(".rc", "rc") | ||||||||||||||
|
||||||||||||||
if isinstance(version, tuple): | ||||||||||||||
return ".".join(map(str, version)).strip() | ||||||||||||||
|
||||||||||||||
# Try duck-typing as an Incremental version. | ||||||||||||||
if hasattr(version, "base"): | ||||||||||||||
try: | ||||||||||||||
version = str(version.base()).strip() | ||||||||||||||
# Incremental uses `X.Y.rcN`. | ||||||||||||||
# Standardize on importlib (and PEP440) use of `X.YrcN`: | ||||||||||||||
return version.replace(".rc", "rc") # type: ignore | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this has been fixed on the Incremental side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you are referring to. Should anything in this PR be changed as a result? |
||||||||||||||
except TypeError: | ||||||||||||||
pass | ||||||||||||||
|
||||||||||||||
raise Exception( | ||||||||||||||
"I only know how to look at a __version__ that is a str, " | ||||||||||||||
"an Increment Version, or a tuple. If you can't provide " | ||||||||||||||
"that, use the --version argument and specify one." | ||||||||||||||
"Version must be a string, tuple, or an Incremental Version." | ||||||||||||||
" If you can't provide that, use the --version argument and specify one." | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def get_project_name(package_dir: str, package: str) -> str: | ||||||||||||||
module = _get_package(package_dir, package) | ||||||||||||||
|
||||||||||||||
version = getattr(module, "__version__", None) | ||||||||||||||
# Incremental has support for package names, try duck-typing it. | ||||||||||||||
try: | ||||||||||||||
return str(version.package) # type: ignore | ||||||||||||||
except AttributeError: | ||||||||||||||
pass | ||||||||||||||
Comment on lines
+77
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
is more idiomatic, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done #627 |
||||||||||||||
|
||||||||||||||
if not version: | ||||||||||||||
# welp idk | ||||||||||||||
return package.title() | ||||||||||||||
|
||||||||||||||
if isinstance(version, str): | ||||||||||||||
return package.title() | ||||||||||||||
|
||||||||||||||
if isinstance(version, IncrementalVersion): | ||||||||||||||
# Incremental has support for package names | ||||||||||||||
return version.package | ||||||||||||||
|
||||||||||||||
raise TypeError(f"Unsupported type for __version__: {type(version)}") | ||||||||||||||
return package.title() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,25 @@ | |
|
||
from __future__ import annotations | ||
|
||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
import click | ||
|
||
from click_default_group import DefaultGroup | ||
|
||
from ._version import __version__ | ||
from .build import _main as _build_cmd | ||
from .check import _main as _check_cmd | ||
from .create import _main as _create_cmd | ||
|
||
|
||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can still keep the I this way, we don't have to repeat the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do this lazily using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
_version = version("towncrier") | ||
except PackageNotFoundError: # pragma: no cover | ||
_version = "unknown" | ||
|
||
|
||
@click.group(cls=DefaultGroup, default="build", default_if_no_args=True) | ||
@click.version_option(__version__.public()) | ||
@click.version_option(_version) | ||
def cli() -> None: | ||
""" | ||
Towncrier is a utility to produce useful, summarised news files for your project. | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Remove incremental dependency from towncrier. | ||
|
||
Towncrier can still read incremental versions, it just doesn't rely on the package itself any more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
# Copyright (c) Amber Brown, 2015 | ||
# See LICENSE for details. | ||
|
||
from incremental import Version | ||
from twisted.trial.unittest import TestCase | ||
|
||
from towncrier._version import _hatchling_version | ||
import towncrier | ||
|
||
|
||
class TestPackaging(TestCase): | ||
def test_version_warning(self): | ||
def no_version_attr(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this runs if it doesn't have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed test to check for deprecationwarning instead #627 |
||
""" | ||
Import __version__ from towncrier returns an Incremental version object | ||
and raises a warning. | ||
towncrier.__version__ was deprecated, now no longer exists. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if For private API, raising AttributeError is ok. |
||
""" | ||
with self.assertWarnsRegex( | ||
DeprecationWarning, "Accessing towncrier.__version__ is deprecated.*" | ||
): | ||
from towncrier import __version__ | ||
|
||
self.assertIsInstance(__version__, Version) | ||
self.assertEqual(_hatchling_version, __version__.short()) | ||
with self.assertRaises(AttributeError): | ||
towncrier.__version__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this should be removed. It seems like there's still a bit of software relying on
pkg.__version__
such that I've starte de-deprecating it in my own packages. See also python-attrs/attrs#1136(to be clear: it has to be ported, not just left around ;))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-added #627