Skip to content

Commit

Permalink
Use setuptools-scm for versioning
Browse files Browse the repository at this point in the history
- generate aiomysql/_scm_version.py at build time, fallback to `unknown` if it doesn't exist
- include setuptools-scm-git-archive to support versioning in archives from git tags
- install aiomysql package in readthedocs and access generated version to embed in docs

Split from #734, including suggestions from @webknjaz

Co-authored-by: Sviatoslav Sydorenko <wk@sydorenko.org.ua>
  • Loading branch information
Nothing4You and webknjaz committed Mar 15, 2022
1 parent 7abaec6 commit cf34652
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions .git_archival.txt
@@ -0,0 +1 @@
ref-names: $Format:%D$
5 changes: 5 additions & 0 deletions .gitattributes
@@ -0,0 +1,5 @@
# Force LF line endings for text files
* text=auto eol=lf

# Needed for setuptools-scm-git-archive
.git_archival.txt export-subst
6 changes: 4 additions & 2 deletions .readthedocs.yaml
Expand Up @@ -19,5 +19,7 @@ formats:
- epub

python:
install:
- requirements: requirements-dev.txt
install:
- requirements: requirements-dev.txt
- method: pip
path: .
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -24,6 +24,7 @@ To be included in 1.0.0 (unreleased)
* Required python version is now properly documented in python_requires instead of failing on setup.py execution #731
* Add rsa extras_require depending on PyMySQL[rsa] #557
* Migrate to PEP 517 build system #746
* Self-reported `__version__` now returns version generated by `setuptools-scm` during build, otherwise `'unknown'` #748


0.0.22 (2021-11-14)
Expand Down
5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

1 change: 1 addition & 0 deletions aiomysql/.gitignore
@@ -0,0 +1 @@
/_scm_version.py
3 changes: 2 additions & 1 deletion aiomysql/__init__.py
Expand Up @@ -32,8 +32,9 @@
from .connection import Connection, connect
from .cursors import Cursor, SSCursor, DictCursor, SSDictCursor
from .pool import create_pool, Pool
from ._version import version

__version__ = '0.0.22'
__version__ = version

__all__ = [

Expand Down
3 changes: 3 additions & 0 deletions aiomysql/_scm_version.pyi
@@ -0,0 +1,3 @@
# This stub file is necessary because `_scm_version.py`
# autogenerated on build and absent on mypy checks time
version: str
4 changes: 4 additions & 0 deletions aiomysql/_version.py
@@ -0,0 +1,4 @@
try:
from ._scm_version import version
except ImportError:
version = "unknown"
25 changes: 4 additions & 21 deletions docs/conf.py
Expand Up @@ -30,25 +30,8 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.

import re, os.path

def get_release():
regexp = re.compile(r"^__version__\W*=\W*'([\d.abrc]+)'")
here = os.path.dirname(__file__)
root = os.path.dirname(here)
init_py = os.path.join(root, 'aiomysql', '__init__.py')
with open(init_py) as f:
for line in f:
match = regexp.match(line)
if match is not None:
return match.group(1)
else:
raise RuntimeError('Cannot find version in aiomysql/__init__.py')


def get_version(release):
parts = release.split('.')
return '.'.join(parts[:2])
from aiomysql import __version__


extensions = [
'sphinx.ext.autodoc',
Expand Down Expand Up @@ -82,8 +65,8 @@ def get_version(release):
# |version| and |release|, also used in various other places throughout the
# built documents.
#
release = get_release()
version = get_version(release)
release = __version__
version = '.'.join(__version__.split('.')[:2])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Expand Up @@ -2,5 +2,12 @@
requires = [
# Essentials
"setuptools >= 42",

# Plugins
"setuptools_scm[toml] >= 6.4",
"setuptools_scm_git_archive >= 1.1",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "aiomysql/_scm_version.py"

0 comments on commit cf34652

Please sign in to comment.