Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIP-79 Generate assets for Flask application in FAB provider (#44744) #45060

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vincbeck
Copy link
Contributor

Revert the revert #45057 of #44744.

It failed because of:

Traceback (most recent call last):
  File "/opt/airflow/./scripts/ci/pre_commit/compile_www_assets.py", line 86, in <module>
    if is_fab_provider_installed():
  File "/opt/airflow/./scripts/ci/pre_commit/compile_www_assets.py", line 79, in is_fab_provider_installed
    return importlib.util.find_spec("airflow.providers.fab") is not None
  File "/usr/local/lib/python3.9/importlib/util.py", line 94, in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named 'airflow'

I updated the function is_fab_provider_installed and check if airflow is installed first. I ran breeze release-management prepare-airflow-package --package-format wheel and it succeeds (but fails without the fix).


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@vincbeck vincbeck requested a review from jscheffl December 18, 2024 22:02
@vincbeck vincbeck requested review from potiuk and ashb as code owners December 18, 2024 22:02
@vincbeck vincbeck added the full tests needed We need to run full set of tests for this PR to merge label Dec 18, 2024
@vincbeck
Copy link
Contributor Author

Running all tests just to be sure

@vincbeck vincbeck closed this Dec 18, 2024
@vincbeck vincbeck reopened this Dec 18, 2024

def is_fab_provider_installed() -> bool:
return (
importlib.util.find_spec("airflow") is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether this will work. because airflow and providers are not installed in pre-commit.

But as you can be sure the source tree is checked-out, how about checking if source tree is available?

Copy link
Contributor Author

@vincbeck vincbeck Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But when you install, the sources are not available, are not they? So is_fab_provider_installed will return False in this case? Although we wan do want to generate assets for FAB as well. As for the pre-commit, since Airflow is not installed, is_fab_provider_installed will return False.

I am not 100% sure I understand everything correctly here so I might be wrong :)

EDIT: what I meant is, it is okay to not generate the assets for FAB in the CI, however, when Airflow is installed, we definitely should generate them

Copy link
Contributor

@jscheffl jscheffl Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought from the point of lifecycle. The pre-commit hook will be called in CI and locally... at build time. Source tree will be there. And it needs to be called at build-time to create the static JS content as dist folder to be packaged into the wheel.

The check you are referring to is at runtime At pip install apache-airflow-providers-fab time the wheel is only un-packed to site-packages. There will no pre-commit be executed as well as you need to assume that at point of install no yarn will be available (might be the user installing is even offline w/o internet).
Otherwise - not being an expert - if the wheel install need to compile/bind/do something at point of install you need to define this in package meta data - not in a pre-commit script that is not available at install time.

You can see this also for airflow/www - the pre-commit is making the package before the sdist/wheel is built and then the dist is packed into the wheel.

So if the check now makes it more safe... I assume the dist will just not be created during build then and only the TS/TSX source tree will be packaged into the wheel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Following this approach I am at the exact same point as in #45058. I dont quite get the error. Will re-try later

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbovenzi or @pierrejeambrun can you help here? yarn is not really successfully compiling www assets. I assume the yarn lock file is somewhat "different" but I am not an expert why the compile fails. (Still I suspect that loading airflow a Py module is not correct because at CI/compile time the packahe is not installed (chicken+egg))

@vincbeck vincbeck force-pushed the vincbeck/compile_assets branch from 3118f49 to 0fcbcfe Compare December 19, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dev-tools full tests needed We need to run full set of tests for this PR to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants