Repository: pytest-dev/pytest-django

Issue:
Provide easy access to version info.
I understand [`setuptools_scm` provides programmatic access to version info](https://github.com/pypa/setuptools_scm#programmatic-usage), but I think it would be nice if we could provide easy access in here, kinda following what `pytest` is doing. I can work on a PR, although if this is not something we'd want to do, let me know!


Discussion:
Just out of interest: what's your use case?
I have a few projects still running old versions of Django which latest `pytest-django` doesn't really support, so they don't have access to newer features. The idea is to port the implementation into those projects only when running `pytest-django` with a version lower than `<some-version-of-pytest-django>` so that once we can get them updated, those feature-ports are easily identifiable and removable. At the moment there's no easy way to do that. We _could_ work around it by checking the Django version but other variables might come into play so I'm not sure that's optimal.

Does that make sense?

Resolving patch:
diff --git a/pytest_django/__init__.py b/pytest_django/__init__.py
--- a/pytest_django/__init__.py
+++ b/pytest_django/__init__.py
@@ -0,0 +1,10 @@
+try:
+    from ._version import version as __version__
+except ImportError:  # pragma: no cover
+    # Broken installation, we don't even try.
+    __version__ = "unknown"
+
+
+__all__ = (
+    "__version__",
+)
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,67 +1,7 @@
-#!/usr/bin/env python
-
-import codecs
-import os
-
 from setuptools import setup
 
-
-# Utility function to read the README file.
-# Used for the long_description.  It's nice, because now 1) we have a top level
-# README file and 2) it's easier to type in the README file than to put a raw
-# string in below ...
-def read(fname):
-    file_path = os.path.join(os.path.dirname(__file__), fname)
-    return codecs.open(file_path, encoding='utf-8').read()
-
-
 setup(
-    name='pytest-django',
-    use_scm_version=True,
-    description='A Django plugin for pytest.',
-    author='Andreas Pelme',
-    author_email='andreas@pelme.se',
-    maintainer="Andreas Pelme",
-    maintainer_email="andreas@pelme.se",
-    url='https://pytest-django.readthedocs.io/',
-    license='BSD-3-Clause',
-    packages=['pytest_django'],
-    long_description=read('README.rst'),
-    python_requires='>=3.5',
-    setup_requires=['setuptools_scm>=1.11.1'],
-    install_requires=[
-        'pytest>=5.4.0',
-    ],
-    extras_require={
-        'docs': [
-            'sphinx',
-            'sphinx_rtd_theme',
-        ],
-        'testing': [
-            'Django',
-            'django-configurations>=2.0',
-        ],
-    },
-    classifiers=['Development Status :: 5 - Production/Stable',
-                 'Framework :: Django',
-                 'Framework :: Django :: 2.2',
-                 'Framework :: Django :: 3.0',
-                 'Framework :: Django :: 3.1',
-                 'Intended Audience :: Developers',
-                 'License :: OSI Approved :: BSD License',
-                 'Operating System :: OS Independent',
-                 'Programming Language :: Python',
-                 'Programming Language :: Python :: 3.5',
-                 'Programming Language :: Python :: 3.6',
-                 'Programming Language :: Python :: 3.7',
-                 'Programming Language :: Python :: 3.8',
-                 'Programming Language :: Python :: Implementation :: CPython',
-                 'Programming Language :: Python :: Implementation :: PyPy',
-                 'Topic :: Software Development :: Testing',
-                 ],
-    project_urls={
-        'Source': 'https://github.com/pytest-dev/pytest-django',
-        'Changelog': 'https://pytest-django.readthedocs.io/en/latest/changelog.html',
+    use_scm_version={
+        'write_to': 'pytest_django/_version.py',
     },
-    # the following makes a plugin available to pytest
-    entry_points={'pytest11': ['django = pytest_django.plugin']})
+)


Test patch: