From d1d8fbee1938bdfbca2638c645f589914fb77c7c Mon Sep 17 00:00:00 2001 From: Rust Saiargaliev Date: Wed, 10 Feb 2021 21:24:29 +0100 Subject: [PATCH 1/3] Modify `setup.py` to not import the whole module for package data --- CHANGELOG.md | 1 + model_bakery/__about__.py | 5 +++++ model_bakery/__init__.py | 7 ------- setup.py | 19 +++++++++++-------- 4 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 model_bakery/__about__.py diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ee5a46..26dabdc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Type hinting fixed for Recipe "_model" parameter +- Modify `setup.py` to not import the whole module for package data, but get it from `__about__.py` ### Removed diff --git a/model_bakery/__about__.py b/model_bakery/__about__.py new file mode 100644 index 00000000..2b70e428 --- /dev/null +++ b/model_bakery/__about__.py @@ -0,0 +1,5 @@ +__version__ = "1.2.1" +__author__ = "berinfontes" +__email__ = "bernardoxhc@gmail.com" +__url__ = "https://github.com/model-bakers/model_bakery" +__license__ = "Apache 2.0" diff --git a/model_bakery/__init__.py b/model_bakery/__init__.py index 028df768..6a5be5bf 100644 --- a/model_bakery/__init__.py +++ b/model_bakery/__init__.py @@ -1,8 +1 @@ -"""Model Bakery module configuration.""" -__version__ = "1.2.1" -__title__ = "model_bakery" -__author__ = "Vanderson Mota" -__license__ = "Apache 2.0" - - from .utils import seq # NoQA diff --git a/setup.py b/setup.py index 92daa3ed..4d41bfe7 100755 --- a/setup.py +++ b/setup.py @@ -1,19 +1,22 @@ -from os.path import dirname, join +from os.path import abspath, dirname, join import setuptools -import model_bakery +about: dict = {} +here = abspath(dirname(__file__)) +with open(join(here, "model_bakery", "__about__.py")) as f: # type: ignore + exec(f.read(), about) setuptools.setup( name="model_bakery", - version=model_bakery.__version__, + version=about["__version__"], + author=about["__author__"], + author_email=about["__email__"], + url=about["__url__"], + license=about["__license__"], packages=["model_bakery"], include_package_data=True, # declarations in MANIFEST.in - install_requires=open(join(dirname(__file__), "requirements.txt")).readlines(), - author="berinfontes", - author_email="bernardoxhc@gmail.com", - url="http://github.com/model-bakers/model_bakery", - license="Apache 2.0", + install_requires=open(join(here, "requirements.txt")).readlines(), description="Smart object creation facility for Django.", long_description=open(join(dirname(__file__), "README.md")).read(), long_description_content_type="text/markdown", From 73bdb9b56532a2f08aa4b93f42f9f44f09a2349b Mon Sep 17 00:00:00 2001 From: Rust Saiargaliev Date: Wed, 10 Feb 2021 21:36:30 +0100 Subject: [PATCH 2/3] mypy to run against lib only --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index ff1e3349..d4619bf0 100644 --- a/tox.ini +++ b/tox.ini @@ -51,4 +51,4 @@ commands=black . --check [testenv:mypy] deps=mypy basepython=python3 -commands=python -m mypy . +commands=python -m mypy model_bakery From eae83e5c0c1b7a1be949f9980c40e59bb87be19e Mon Sep 17 00:00:00 2001 From: Rust Saiargaliev Date: Thu, 11 Feb 2021 16:43:52 +0100 Subject: [PATCH 3/3] Drop obsolete import workaround --- model_bakery/utils.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/model_bakery/utils.py b/model_bakery/utils.py index adae14e0..b44f108d 100644 --- a/model_bakery/utils.py +++ b/model_bakery/utils.py @@ -6,12 +6,7 @@ from types import ModuleType from typing import Any, Callable, Optional, Union -try: - from django.apps import apps -except ModuleNotFoundError: - # probably we are importing this module from setup.py, before installing - # the requirements (and we don't need Django at this point) - apps = None +from django.apps import apps from .timezone import tz_aware