diff options
author | Ran Benita <ran@unusedvar.com> | 2020-08-10 16:49:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-10 15:49:51 +0200 |
commit | bc8438bda4b33930d9bfa6e56efd74e111900be4 (patch) | |
tree | 8945d84a9712b52d87c1f85a9651a55c9795cd60 | |
parent | ce79e44d14f151e37316144f66dedb2ace2f37dc (diff) | |
download | tablib-bc8438bda4b33930d9bfa6e56efd74e111900be4.tar.gz |
Stop using pkg_resources
tablib imports pkg_resources in order to find its own version. Importing
pkg_resources is very slow (100ms-250ms is common).
Avoid it by letting setuptools-scm generate a file with the version
instead.
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | docs/conf.py | 6 | ||||
-rw-r--r-- | pyproject.toml | 2 | ||||
-rwxr-xr-x | setup.py | 4 | ||||
-rw-r--r-- | src/tablib/__init__.py | 15 |
5 files changed, 18 insertions, 12 deletions
@@ -38,3 +38,6 @@ htmlcov # setuptools noise .eggs *.egg-info + +# generated by setuptools-scm +/src/tablib/_version.py diff --git a/docs/conf.py b/docs/conf.py index 2294b30..eb706c9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,7 +9,7 @@ # # All configuration values have a default; values that are commented out # serve to show the default. -from pkg_resources import get_distribution +import tablib # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -49,9 +49,9 @@ copyright = '2019 Jazzband' # built documents. # # The full version, including alpha/beta/rc tags. -release = get_distribution('tablib').version +release = tablib.__version__ # The short X.Y version. -version = '.'.join(release.split('.')[:2]) +version = '.'.join(tablib.__version__.split('.')[:2]) # for example take major/minor # The language for content autogenerated by Sphinx. Refer to documentation diff --git a/pyproject.toml b/pyproject.toml index c1442ed..f19f1d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.isort] force_grid_wrap = 0 include_trailing_comma = true -known_third_party = ["MarkupPy", "odf", "openpyxl", "pkg_resources", "setuptools", "tablib", "xlrd", "xlwt", "yaml"] +known_third_party = ["MarkupPy", "odf", "openpyxl", "setuptools", "tablib", "xlrd", "xlwt", "yaml"] line_length = 88 multi_line_output = 3 use_parentheses = true @@ -4,7 +4,9 @@ from setuptools import find_packages, setup setup( name='tablib', - use_scm_version=True, + use_scm_version={ + 'write_to': 'src/tablib/_version.py', + }, setup_requires=['setuptools_scm'], description='Format agnostic tabular data library (XLS, JSON, YAML, CSV)', long_description=( diff --git a/src/tablib/__init__.py b/src/tablib/__init__.py index 6e10d78..aecf3a4 100644 --- a/src/tablib/__init__.py +++ b/src/tablib/__init__.py @@ -1,5 +1,12 @@ """ Tablib. """ -from pkg_resources import DistributionNotFound, get_distribution +try: + # Generated by setuptools-scm. + from ._version import version as __version__ +except ImportError: + # Some broken installation. + __version__ = None + + from tablib.core import ( # noqa: F401 Databook, Dataset, @@ -10,9 +17,3 @@ from tablib.core import ( # noqa: F401 import_book, import_set, ) - -try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: - # package is not installed - __version__ = None |