Add conditional version retrieval from setup. (#12853)

When airflow is not installed as package (for example for local
development from sources) there is no package metadata.

Many of our unit tests use the version field and they fail if they
are run within virtual environment where airflow is not installed
as package (for example in IntelliJ this is default setting.

This PR adds fall-back to read airflow version from setup in
case it cannot be read from package metadata.
This commit is contained in:
Jarek Potiuk 2020-12-06 19:58:17 +01:00 коммит произвёл GitHub
Родитель 82dfa5f74b
Коммит 537aba738c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@ -24,6 +24,13 @@ try:
except ImportError:
import importlib_metadata as metadata
version = metadata.version('apache-airflow')
try:
version = metadata.version('apache-airflow')
except metadata.PackageNotFoundError:
import logging
log = logging.getLogger(__name__)
log.warning("Package metadata could not be found. Overriding it with version found in setup.py")
from setup import version
del metadata