This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 695c59782b0 Alternative method to mark source roots in
PyCharm/IntelliJ IDEA (#47184)
695c59782b0 is described below
commit 695c59782b0e9be087eded129d966c9545cbe4b8
Author: GPK <[email protected]>
AuthorDate: Mon Mar 24 18:41:41 2025 +0000
Alternative method to mark source roots in PyCharm/IntelliJ IDEA (#47184)
* add pycharm idea airflow impl file to mark source root and tests
* add pycharm idea airflow impl file to mark source root and tests
* Update
contributing-docs/quick-start-ide/contributors_quick_start_pycharm.rst
Co-authored-by: Kalyan R <[email protected]>
* Update setup_idea script to create source roots in PyCharm and IntelliJ
---------
Co-authored-by: Kalyan R <[email protected]>
---
.pre-commit-config.yaml | 3 +-
.../contributors_quick_start_pycharm.rst | 27 ++++++
.../quick-start-ide/images/pycharm-airflow.iml.png | Bin 0 -> 337577 bytes
.../quick-start-ide/images/pycharm-modules.xml.png | Bin 0 -> 124438 bytes
setup_idea.py | 99 +++++++++++++++++++++
5 files changed, 128 insertions(+), 1 deletion(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 53314ec11e4..54ae2510b38 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1244,7 +1244,8 @@ repos:
providers/|
scripts|
task-sdk/|
- tests/dags/test_imports\.py
+ tests/dags/test_imports\.py|
+ setup_idea\.py
)
require_serial: true
additional_dependencies: ['rich>=12.4.4']
diff --git
a/contributing-docs/quick-start-ide/contributors_quick_start_pycharm.rst
b/contributing-docs/quick-start-ide/contributors_quick_start_pycharm.rst
index cd40d8310a5..7d13dd1c8cd 100644
--- a/contributing-docs/quick-start-ide/contributors_quick_start_pycharm.rst
+++ b/contributing-docs/quick-start-ide/contributors_quick_start_pycharm.rst
@@ -75,6 +75,33 @@ Setup your project
alt="Invalidate caches and restart Pycharm">
</div>
+5. An alternative way to add source roots is to configure the ``airflow.iml``
file under ``.idea`` directory and update the
+ ``module.xml`` file:
+
+ To setup the source roots for all the modules that exist in the project,
you can run the following command:
+ This needs to done on the airflow repository root directory. It overwrites
the existing ``.idea/airflow.iml`` and
+ ``.idea/modules.xml`` files.
+
+ .. code-block:: bash
+
+ $ python setup_idea.py
+
+ Then Restart the PyCharm/IntelliJ IDEA.
+
+ .. raw:: html
+
+ <div align="center" style="padding-bottom:10px">
+ <img src="images/pycharm-airflow.iml.png"
+ alt="airflow.iml">
+ </div>
+
+ .. raw:: html
+
+ <div align="center" style="padding-bottom:10px">
+ <img src="images/pycharm-modules.xml.png"
+ alt="modules.xml">
+ </div>
+
Setting up debugging
####################
diff --git a/contributing-docs/quick-start-ide/images/pycharm-airflow.iml.png
b/contributing-docs/quick-start-ide/images/pycharm-airflow.iml.png
new file mode 100644
index 00000000000..c8a93009df8
Binary files /dev/null and
b/contributing-docs/quick-start-ide/images/pycharm-airflow.iml.png differ
diff --git a/contributing-docs/quick-start-ide/images/pycharm-modules.xml.png
b/contributing-docs/quick-start-ide/images/pycharm-modules.xml.png
new file mode 100644
index 00000000000..d70d6485348
Binary files /dev/null and
b/contributing-docs/quick-start-ide/images/pycharm-modules.xml.png differ
diff --git a/setup_idea.py b/setup_idea.py
new file mode 100644
index 00000000000..2f8e75d2b6b
--- /dev/null
+++ b/setup_idea.py
@@ -0,0 +1,99 @@
+# 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.
+from __future__ import annotations
+
+import os
+
+iml_xml_template = """<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$">
+ {SOURCE_ROOT_MODULE_PATH}
+ <excludeFolder url="file://$MODULE_DIR$/.build" />
+ <excludeFolder url="file://$MODULE_DIR$/.kube" />
+ <excludeFolder url="file://$MODULE_DIR$/.venv" />
+ </content>
+ <orderEntry type="jdk" jdkName="Python 3.9 (airflow)" jdkType="Python SDK"
/>
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+ <component name="PyDocumentationSettings">
+ <option name="format" value="PLAIN" />
+ <option name="myDocStringFormat" value="Plain" />
+ </component>
+ <component name="TemplatesService">
+ <option name="TEMPLATE_FOLDERS">
+ <list>
+ <option value="$MODULE_DIR$/chart/templates" />
+ </list>
+ </option>
+ </component>
+ <component name="TestRunnerService">
+ <option name="PROJECT_TEST_RUNNER" value="py.test" />
+ </component>
+</module>"""
+
+module_xml_template = """<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea/airflow.iml"
filepath="$PROJECT_DIR$/.idea/airflow.iml" />
+ </modules>
+ </component>
+</project>"""
+
+source_root_module_patter: str = '<sourceFolder
url="file://$MODULE_DIR$/{path}" isTestSource="{status}" />'
+
+source_root_modules: list[str] = ["airflow-core", "airflow-ctl", "dev/breeze",
"task-sdk"]
+
+all_module_paths: list[str] = []
+
+ROOT_DIR: str = "./providers"
+
+
+def setup_idea():
+ # Providers discovery
+ for dirpath, _, filenames in os.walk(ROOT_DIR):
+ if "pyproject.toml" in filenames:
+ relative_path = os.path.relpath(dirpath, ROOT_DIR)
+ source_root_modules.append(f"providers/{relative_path}")
+
+ source_root_modules.sort()
+ for module in source_root_modules:
+
all_module_paths.append(source_root_module_patter.format(path=f"{module}/src",
status="false"))
+
all_module_paths.append(source_root_module_patter.format(path=f"{module}/test",
status="true"))
+
+ source_root_module_path: str = "\n\t\t".join(all_module_paths)
+
+ base_source_root_xml: str =
iml_xml_template.format(SOURCE_ROOT_MODULE_PATH=source_root_module_path)
+
+ with open(".idea/airflow.iml", "w") as file:
+ file.write(base_source_root_xml)
+
+ with open(".idea/modules.xml", "w") as file:
+ file.write(module_xml_template)
+
+
+if __name__ == "__main__":
+ user_input = input(
+ "This script will overwrites the .idea/airflow.iml and
.idea/modules.xml files. Press Enter Y/N to continue: "
+ )
+ if user_input.lower() == "y":
+ setup_idea()
+ print("Updated airflow.iml and modules.xml files, Now restart the
PyCharm/IntelliJ IDEA")
+ else:
+ print("Not updating airflow.iml and modules.xml files")
+ exit(0)