Repository: cookiecutter/cookiecutter

Issue:
2.2.0 CLI reports version 2.1.2dev0 
* Cookiecutter version: 2.2.0 (or 2.1.2dev0, depending on who you ask)
* Template project url: n/a
* Python version: 3.11
* Operating System: linux

### Description:

Get the accurate version of cookiecutter from the CLI

### What I've run:

```bash
cookiecutter --version
Cookiecutter 2.1.2.dev0 from $PREFIX/lib/python3.11/site-packages (Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0])
```

Would be a one-line fix, but ideally would be always be sourced from exactly one place:
- `setup.py` and `importlib_metadata`
- `__init__.py`
- a `VERSION` file


Discussion:
@ericof @jensens I can reproduce the error.

```
❯ pip install cookiecutter -U
Requirement already satisfied: cookiecutter in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (2.1.1)
Collecting cookiecutter
  Using cached cookiecutter-2.2.0-py3-none-any.whl (38 kB)
Requirement already satisfied: binaryornot>=0.4.4 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cookiecutter) (0.4.4)
Requirement already satisfied: Jinja2<4.0.0,>=2.7 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cookiecutter) (3.1.2)
Requirement already satisfied: click<9.0.0,>=7.0 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cookiecutter) (8.1.3)
Requirement already satisfied: pyyaml>=5.3.1 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cookiecutter) (6.0)
Requirement already satisfied: python-slugify>=4.0.0 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cookiecutter) (8.0.1)
Requirement already satisfied: requests>=2.23.0 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cookiecutter) (2.31.0)
Requirement already satisfied: arrow in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from cookiecutter) (1.2.3)
Requirement already satisfied: chardet>=3.0.2 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from binaryornot>=0.4.4->cookiecutter) (5.1.0)
Requirement already satisfied: MarkupSafe>=2.0 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from Jinja2<4.0.0,>=2.7->cookiecutter) (2.1.3)
Requirement already satisfied: text-unidecode>=1.3 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from python-slugify>=4.0.0->cookiecutter) (1.3)
Requirement already satisfied: charset-normalizer<4,>=2 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from requests>=2.23.0->cookiecutter) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from requests>=2.23.0->cookiecutter) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from requests>=2.23.0->cookiecutter) (2.0.3)
Requirement already satisfied: certifi>=2017.4.17 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from requests>=2.23.0->cookiecutter) (2023.5.7)
Requirement already satisfied: python-dateutil>=2.7.0 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from arrow->cookiecutter) (2.8.2)
Requirement already satisfied: six>=1.5 in ./.pyenv/versions/3.11.3/lib/python3.11/site-packages (from python-dateutil>=2.7.0->arrow->cookiecutter) (1.16.0)
Installing collected packages: cookiecutter
  Attempting uninstall: cookiecutter
    Found existing installation: cookiecutter 2.1.1
    Uninstalling cookiecutter-2.1.1:
      Successfully uninstalled cookiecutter-2.1.1
Successfully installed cookiecutter-2.2.0

~ 
❯ cookiecutter -V
Cookiecutter 2.1.2.dev0 from /home/luzfcb/.pyenv/versions/3.11.3/lib/python3.11/site-packages (Python 3.11.3 (main, May 19 2023, 15:36:47) [GCC 11.3.0])

```

https://pypi.org/project/cookiecutter/#history
Yep, it's maintained by me, but we build from the tar.gz on pypi, so likely
would affect any downstream. I just patched init and moved on, but am happy
to pr if an approach mentioned sounds good.

I will make a 2.2.2 release to fix this issue
The `.tar.gz` and `.whl` on PyPI for ~~`2.2.0`~~ `2.2.2` both still contain the following `__init__.py`:

```py
"""Main package for Cookiecutter."""
__version__ = "2.1.2.dev0"
```

Resulting in:

```bash
cookiecutter --version
Cookiecutter 2.1.2.dev0 # ... extraneous python info ...
```

As previously suggested: this should likely be solved by having exactly one source-of-truth, handled either:
- directly through a `setup.cfg`/`setup.py` that reads `__init__.py`
- indirectly, by `__init__.py` reading the `importlib_metadata.version('cookiecutter')`
- a `VERSION` file read by both `setup.py`/`setup.cfg` _and_ `__init__.py` 
@bollwyvl Could you please test with version 2.2.2 ?
(We decided against re-releasing 2.2.0)
Sorry, my bad: this persists with `2.2.2`:

https://pypi.org/project/cookiecutter/2.2.2/
You are correct. I just checked in here.

Resolving patch:
diff --git a/cookiecutter/__init__.py b/cookiecutter/__init__.py
--- a/cookiecutter/__init__.py
+++ b/cookiecutter/__init__.py
@@ -1,2 +1,12 @@
 """Main package for Cookiecutter."""
-__version__ = "2.1.2.dev0"
+from pathlib import Path
+
+
+def _get_version() -> str:
+    """Read VERSION.txt and return its contents."""
+    path = Path(__file__).parent.resolve()
+    version_file = path / "VERSION.txt"
+    return version_file.read_text().strip()
+
+
+__version__ = _get_version()
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,11 +1,22 @@
 """cookiecutter distutils configuration."""
+from pathlib import Path
 from setuptools import setup
 
-version = "2.2.3.dev0"
+
+def _get_version() -> str:
+    """Read cookiecutter/VERSION.txt and return its contents."""
+    path = Path("cookiecutter").resolve()
+    version_file = path / "VERSION.txt"
+    return version_file.read_text().strip()
+
+
+version = _get_version()
+
 
 with open('README.md', encoding='utf-8') as readme_file:
     readme = readme_file.read()
 
+
 requirements = [
     'binaryornot>=0.4.4',
     'Jinja2>=2.7,<4.0.0',


Test patch: