szn commented on a change in pull request #12023: URL: https://github.com/apache/airflow/pull/12023#discussion_r516058086
########## File path: scripts/ci/pre_commit/pre_commit_check_setup_installation.py ########## @@ -0,0 +1,108 @@ +#!/usr/bin/env python +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Checks if all the libraries in setup.py are listed in installation.rst file +""" + +import os +import re +from os.path import dirname +from typing import Dict, List + +AIRFLOW_SOURCES_DIR = os.path.join(dirname(__file__), os.pardir, os.pardir, os.pardir) +SETUP_PY_FILE = 'setup.py' +DOCS_FILE = 'installation.rst' +PY_IDENTIFIER = r'[a-zA-Z_][a-zA-Z0-9_\.]*' + + +def get_file_content(*path_elements: str) -> str: + file_path = os.path.join(AIRFLOW_SOURCES_DIR, *path_elements) + with open(file_path) as file_to_read: + return file_to_read.read() + + +def get_extras_from_setup() -> Dict[str, List[str]]: + """ + Returns an array EXTRAS_REQUIREMENTS with aliases from setup.py file in format: + {'package name': ['alias1', 'alias2], ...} + """ + setup_content = get_file_content(SETUP_PY_FILE) + + extras_section_regex = re.compile( + r'^EXTRAS_REQUIREMENTS: Dict[^{]+{([^}]+)}', re.MULTILINE) + extras_section = extras_section_regex.findall(setup_content)[0] + + extras_regex = re.compile( + rf'^\s+[\"\']({PY_IDENTIFIER})[\"\']:\s*({PY_IDENTIFIER})[^#\n]*(#\s*TODO.*)?$', re.MULTILINE) + + extras_dict: Dict[str, List[str]] = {} + for extras in extras_regex.findall(extras_section): + package = extras[1] + alias = extras[0] + if not extras_dict.get(package): + extras_dict[package] = [] + extras_dict[package].append(alias) + return extras_dict Review comment: @mik-laj I tried smth similar while working on this issue: ``` > AIRFLOW_SOURCES_DIR = os.path.join(dirname(__file__), os.pardir, os.pardir, os.pardir) > sys.path.insert(0, AIRFLOW_SOURCES_DIR) > from setup import EXTRAS_REQUIREMENTS ``` The struggle is here: ``` > pprint(EXTRAS_REQUIREMENTS) 'apache.atlas': ['atlasclient>=0.1.2'], 'apache.beam': ['apache-beam[gcp]'], 'apache.cassandra': ['cassandra-driver>=3.13.0,<3.21.0'], 'apache.druid': ['pydruid>=0.4.1'], ``` as you can see this `Dict` forms a 'package'–'dependencies' association. I can't tell anymore which are aliases (having the same list of dependencies doesn't sound like a valid proof). I commented this out in the original pull-request but forgot to mention it after I re-do it. Sorry. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
