You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2020/12/06 18:59:20 UTC

[airflow] branch master updated: Add conditional version retrieval from setup. (#12853)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 537aba7  Add conditional version retrieval from setup. (#12853)
537aba7 is described below

commit 537aba738cf44f471dfc55db2e860d227c58dd55
Author: Jarek Potiuk <ja...@polidea.com>
AuthorDate: Sun Dec 6 19:58:17 2020 +0100

    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.
---
 airflow/version.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/airflow/version.py b/airflow/version.py
index 6260ff9..9ff90a5 100644
--- a/airflow/version.py
+++ b/airflow/version.py
@@ -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