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

Support glob syntax in .airflowignore files (#21392) #22051

Merged
merged 3 commits into from
Apr 13, 2022

Conversation

ianbuss
Copy link
Contributor

@ianbuss ianbuss commented Mar 7, 2022

A new configuration parameter "CORE_IGNOREFILE_SYNTAX" is added to
allow patterns in .airflowignore files to be interpreted as either
regular expressions (the default) or glob expressions as found in
.gitignore files. This allows users to use patterns they will be
familiar with from tools such as git, helm and docker.

Glob expressions support wildcard matches ("*", "?") within a directory
as well as character classes ("[0-9]"). In addition, zero or more
directories can be matched using "**". Patterns can be negated by
prefixing a "!" at the beginning of the pattern.

The "fnmatch" library in core Python does not produce patterns that are
fully compliant with the kind of patterns that users will be used to
from gitignore or dockerignore files, so the globs are parsed using
the gitignore-parser package from PyPI.

To aid with debugging ignorefile patterns a more helpful error
message is emitted in the logs for invalid patterns, which are
now skipped rather than causing a hard-to-read scheduler stack trace.

closes: #21392

^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, 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 UPDATING.md.

@boring-cyborg
Copy link

boring-cyborg bot commented Mar 7, 2022

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

elif '**' in pattern and '/**/' not in pattern:
reason = "'**' must be between '/' chars when not at beginning or end of pattern"
if reason:
log.warning(f"Ignoring glob '{pattern}' from {ignore_file_path}: {reason}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.warning(f"Ignoring glob '{pattern}' from {ignore_file_path}: {reason}")
log.warning(f"Ignoring glob '%s' from %s: %s:', pattern, ignore_file_path, reason)

Please avoid stirring formatting before passing to logger.

@ianbuss
Copy link
Contributor Author

ianbuss commented Mar 11, 2022

Thanks for your review @mik-laj! I will make the changes to the PR based on your comments. I've also found some logic bugs in the dependency being used for the gitignore parsing, so currently looking into workarounds and/or alternatives.

@github-actions
Copy link

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Mar 21, 2022
@potiuk
Copy link
Member

potiuk commented Mar 21, 2022

Seme doc building errors and tests failing @ianbuss :)

A new configuration parameter "CORE_IGNORE_FILE_SYNTAX" is added to
allow patterns in .airflowignore files to be interpreted as either
regular expressions (the default) or glob expressions as found in
.gitignore files. This allows users to use patterns they will be
familiar with from tools such as git, helm and docker.

Glob expressions support wildcard matches ("*", "?") within a directory
as well as character classes ("[0-9]"). In addition, zero or more
directories can be matched using "**". Patterns can be negated by
prefixing a "!" at the beginning of the pattern.

The "fnmatch" library in core Python does not produce patterns that are
fully compliant with the kind of patterns that users will be used to
from gitignore or dockerignore files, so the globs are parsed using
the pathspec package from PyPI.

To aid with debugging ignorefile patterns a more helpful error
message is emitted in the logs for invalid patterns, which are
now skipped rather than causing a hard-to-read scheduler stack trace.
@ianbuss
Copy link
Contributor Author

ianbuss commented Apr 12, 2022

Thanks @potiuk looking into the failing tests now!

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

Some nitpicks

Note that if a ``.airflowignore`` file is found while processing
Note that if an ``.airflowignore`` file is found while processing
Copy link
Member

Choose a reason for hiding this comment

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

For me a is right because .airflowignore is prodounced dot airflow ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yeah, I can go long with that :) Will update.

Comment on lines +238 to +239
The pattern syntax used in the ".airflowignore" files in the DAG directories. Valid values are
``regexp`` or ``glob``.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The pattern syntax used in the ".airflowignore" files in the DAG directories. Valid values are
``regexp`` or ``glob``.
The pattern syntax used in the ".airflowignore" files in the DAG directories. Valid values are
``regexp`` and ``glob``.

I think this is correct English? (I’m non-native so don’t take my words)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think either can work actually in this context, I chose "or" since you have to choose one or the other.

Copy link
Member

Choose a reason for hiding this comment

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

Either makes sense for me too

airflow/models/dagbag.py Outdated Show resolved Hide resolved
airflow/utils/file.py Outdated Show resolved Hide resolved
airflow/utils/file.py Outdated Show resolved Hide resolved
@ianbuss
Copy link
Contributor Author

ianbuss commented Apr 12, 2022

Thanks for your additional review @uranusjr have made changes to the docs.

@kaxil kaxil merged commit 0cd8833 into apache:main Apr 13, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 13, 2022

Awesome work, congrats on your first merged pull request!

@potiuk
Copy link
Member

potiuk commented Apr 13, 2022

Cool it made it to 2.3.0 :)

@ianbuss
Copy link
Contributor Author

ianbuss commented Apr 13, 2022

w00t, thanks @kaxil @potiuk @uranusjr

@jedcunningham
Copy link
Member

Congrats on your first commit @ianbuss 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:plugins full tests needed We need to run full set of tests for this PR to merge kind:documentation type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.airflowignore does not use 'glob' as .gitignore for example
6 participants