Repository: pylint-dev/astroid

Issue:
astroid has an undeclared dependency on setuptools.
The dependency is here: https://github.com/PyCQA/astroid/blob/1342591e2beb955a377e4486e5595478f79789e8/astroid/__pkginfo__.py#L29

The lack of declaration is here: https://github.com/PyCQA/astroid/blob/1342591e2beb955a377e4486e5595478f79789e8/setup.cfg#L37-L41


Discussion:
Hmm, thank you for opening a report for this. There is the same problem in pylint btw. I thought `pkg_resources` was a builtin. Do you know a way to remove this dependency for python < 3.8 ? We can use ` from importlib.metadata import version` for python > 3.8. If there is no way to do that for 3.6 and 3.7 we could add a conditional requirements for those interpreters.
You can use https://pypi.org/project/importlib-metadata/ for 3.6 and 3.7 if I understand correctly.
Ho that's still a dependency to add but that's better, thank you for the advise, will do :) 
I'd send up an MR but this is all from my phone. On a road trip today and won't be back to a keyboard for a few days. Happy to review the fix though. Thanks for looking into this.
I have a feeling that astroid do not need to calculate it's version like this so we could remove the dependency altogether. But pylint will need it because we broke a lot of pylint related tool when we removed the numversion in 2.8.0. Having to add a dependency for such a small benefit makes me rethink using ``setuptools_scm``. Having proper github actions would probably be better than that. There is such a release here: https://github.com/python/importlib_metadata/blob/main/.github/workflows/main.yml#L61. Maybe we just have to create a small script that will update the version in two places and be done with it. Thoughts @cdce8p ?
> Maybe we just have to create a small script that will update the version in two places and be done with it.

I believe there are already tools for it. `tbump` certainly looks promising although I haven't used it yet.
https://github.com/dmerejkowsky/tbump

Patch:
diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py
--- a/astroid/__pkginfo__.py
+++ b/astroid/__pkginfo__.py
@@ -24,13 +24,5 @@
 # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
 # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE
 
-"""astroid packaging information"""
-
-from pkg_resources import DistributionNotFound, get_distribution
-
-try:
-    __version__ = get_distribution("astroid").version
-except DistributionNotFound:
-    __version__ = "2.5.7+"
-
+__version__ = "2.6.0-dev0"
 version = __version__
diff --git a/astroid/helpers.py b/astroid/helpers.py
--- a/astroid/helpers.py
+++ b/astroid/helpers.py
@@ -5,8 +5,8 @@
 # Copyright (c) 2020 Simon Hewitt <si@sjhewitt.co.uk>
 # Copyright (c) 2020 Bryce Guinta <bryce.guinta@protonmail.com>
 # Copyright (c) 2020 Ram Rachum <ram@rachum.com>
-# Copyright (c) 2021 Andrew Haigh <hello@nelf.in>
 # Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
+# Copyright (c) 2021 Andrew Haigh <hello@nelf.in>
 
 # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
 # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -23,9 +23,9 @@
 # Copyright (c) 2019 kavins14 <kavinsingh@hotmail.com>
 # Copyright (c) 2020 Raphael Gaschignard <raphael@rtpg.co>
 # Copyright (c) 2020 Bryce Guinta <bryce.guinta@protonmail.com>
-# Copyright (c) 2021 Andrew Haigh <hello@nelf.in>
-# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
 # Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
+# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
+# Copyright (c) 2021 Andrew Haigh <hello@nelf.in>
 # Copyright (c) 2021 Federico Bond <federicobond@gmail.com>
 
 # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
diff --git a/astroid/transforms.py b/astroid/transforms.py
--- a/astroid/transforms.py
+++ b/astroid/transforms.py
@@ -1,8 +1,8 @@
 # Copyright (c) 2015-2016, 2018 Claudiu Popa <pcmanticore@gmail.com>
 # Copyright (c) 2016 Ceridwen <ceridwenv@gmail.com>
 # Copyright (c) 2018 Nick Drozd <nicholasdrozd@gmail.com>
-# Copyright (c) 2021 Andrew Haigh <hello@nelf.in>
 # Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
+# Copyright (c) 2021 Andrew Haigh <hello@nelf.in>
 
 # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
 # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE
diff --git a/script/bump_changelog.py b/script/bump_changelog.py
new file mode 100644
--- /dev/null
+++ b/script/bump_changelog.py
@@ -0,0 +1,77 @@
+"""
+This script permits to upgrade the changelog in astroid or pylint when releasing a version.
+"""
+import argparse
+from datetime import datetime
+from pathlib import Path
+
+DEFAULT_CHANGELOG_PATH = Path("ChangeLog")
+err = "in the changelog, fix that first!"
+TBA_ERROR_MSG = "More than one release date 'TBA' %s" % err
+NEW_VERSION_ERROR_MSG = "The text for this version '{version}' did not exists %s" % err
+NEXT_VERSION_ERROR_MSG = (
+    "The text for the next version '{version}' already exists %s" % err
+)
+
+TODAY = datetime.now()
+WHATS_NEW_TEXT = "What's New in astroid"
+FULL_WHATS_NEW_TEXT = WHATS_NEW_TEXT + " {version}?"
+RELEASE_DATE_TEXT = "Release Date: TBA"
+NEW_RELEASE_DATE_MESSAGE = "Release Date: {}".format(TODAY.strftime("%Y-%m-%d"))
+
+
+def main() -> None:
+    parser = argparse.ArgumentParser(add_help=__doc__)
+    parser.add_argument("version", help="The version we want to release")
+    args = parser.parse_args()
+    if "dev" not in args.version:
+        version = args.version
+        next_version = get_next_version(version)
+        run(version, next_version)
+
+
+def get_next_version(version: str) -> str:
+    new_version = version.split(".")
+    patch = new_version[2]
+    reminder = None
+    if "-" in patch:
+        patch, reminder = patch.split("-")
+    patch = str(int(patch) + 1)
+    new_version[2] = patch if reminder is None else f"{patch}-{reminder}"
+    return ".".join(new_version)
+
+
+def run(version: str, next_version: str) -> None:
+    with open(DEFAULT_CHANGELOG_PATH) as f:
+        content = f.read()
+    content = transform_content(content, version, next_version)
+    with open(DEFAULT_CHANGELOG_PATH, "w") as f:
+        f.write(content)
+
+
+def transform_content(content: str, version: str, next_version: str) -> str:
+    wn_new_version = FULL_WHATS_NEW_TEXT.format(version=version)
+    wn_next_version = FULL_WHATS_NEW_TEXT.format(version=next_version)
+    # There is only one field where the release date is TBA
+    assert content.count(RELEASE_DATE_TEXT) == 1, TBA_ERROR_MSG
+    # There is already a release note for the version we want to release
+    assert content.count(wn_new_version) == 1, NEW_VERSION_ERROR_MSG.format(
+        version=version
+    )
+    # There is no release notes for the next version
+    assert content.count(wn_next_version) == 0, NEXT_VERSION_ERROR_MSG.format(
+        version=next_version
+    )
+    index = content.find(WHATS_NEW_TEXT)
+    content = content.replace(RELEASE_DATE_TEXT, NEW_RELEASE_DATE_MESSAGE)
+    end_content = content[index:]
+    content = content[:index]
+    content += wn_next_version + "\n"
+    content += "=" * len(wn_next_version) + "\n"
+    content += RELEASE_DATE_TEXT + "\n" * 4
+    content += end_content
+    return content
+
+
+if __name__ == "__main__":
+    main()
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,3 @@
 from setuptools import setup
 
-setup(use_scm_version=True)
+setup()


Test patch:
diff --git a/requirements_test.txt b/requirements_test.txt
--- a/requirements_test.txt
+++ b/requirements_test.txt
@@ -4,3 +4,4 @@ coveralls~=3.0
 coverage~=5.5
 pre-commit~=2.13
 pytest-cov~=2.11
+tbump~=6.3.2
diff --git a/script/test_bump_changelog.py b/script/test_bump_changelog.py
new file mode 100644
--- /dev/null
+++ b/script/test_bump_changelog.py
@@ -0,0 +1,83 @@
+import pytest
+from bump_changelog import get_next_version, transform_content
+
+
+@pytest.mark.parametrize(
+    "version,expected", [["2.6.1", "2.6.2"], ["2.6.1-dev0", "2.6.2-dev0"]]
+)
+def test_get_next_version(version, expected):
+    assert get_next_version(version) == expected
+
+
+@pytest.mark.parametrize(
+    "old_content,expected_error",
+    [
+        [
+            """
+What's New in astroid 2.6.1?
+============================
+Release Date: TBA
+
+What's New in astroid 2.6.0?
+============================
+Release Date: TBA
+""",
+            "More than one release date 'TBA'",
+        ],
+        [
+            """===================
+astroid's ChangeLog
+===================
+
+What's New in astroid 2.6.0?
+============================
+Release Date: TBA
+""",
+            "text for this version '2.6.1' did not exists",
+        ],
+        [
+            """
+What's New in astroid 2.6.2?
+============================
+Release Date: TBA
+
+What's New in astroid 2.6.1?
+============================
+Release Date: 2012-02-05
+""",
+            "the next version '2.6.2' already exists",
+        ],
+    ],
+)
+def test_update_content_error(old_content, expected_error):
+    with pytest.raises(AssertionError, match=expected_error):
+        transform_content(old_content, "2.6.1", "2.6.2")
+
+
+def test_update_content():
+    old_content = """
+===================
+astroid's ChangeLog
+===================
+
+What's New in astroid 2.6.1?
+============================
+Release Date: TBA
+"""
+    expected_beginning = """
+===================
+astroid's ChangeLog
+===================
+
+What's New in astroid 2.6.2?
+============================
+Release Date: TBA
+
+
+
+What's New in astroid 2.6.1?
+============================
+Release Date: 20"""
+
+    new_content = transform_content(old_content, "2.6.1", "2.6.2")
+    assert new_content.startswith(expected_beginning)
diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py
--- a/tests/unittest_nodes.py
+++ b/tests/unittest_nodes.py
@@ -16,8 +16,8 @@
 # Copyright (c) 2019 Alex Hall <alex.mojaki@gmail.com>
 # Copyright (c) 2019 Hugo van Kemenade <hugovk@users.noreply.github.com>
 # Copyright (c) 2020 David Gilman <davidgilman1@gmail.com>
-# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
 # Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
+# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
 # Copyright (c) 2021 Federico Bond <federicobond@gmail.com>
 # Copyright (c) 2021 hippo91 <guillaume.peillex@gmail.com>