You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/06/21 23:48:08 UTC

[GitHub] [airflow] blag opened a new pull request, #24591: Convert version command to click

blag opened a new pull request, #24591:
URL: https://github.com/apache/airflow/pull/24591

   This is part of a series of PRs breaking up #22613 into smaller, more reviewable chunks. The end result will be rewriting the existing `airflow` CLI to use Click instead of argparse. For motivation, please see #22708.
   
   This PR adds `airflow version` command to the `airflow-ng` command. It's exactly the same as the `airflow version` command, it's just implemented with Click. This PR also adds an additional test module for the new command. I opted to copy/add a new test module instead of keeping a single module and making it compatible with both argparse and Click, because that way it will be easier to remove the tests that rely on argparse once all commands are rewritten, the CLI is completely converted to utilize Click, and the `airflow-ng` command replaces the `airflow` command.
   
   While this incorporates the changes from #24590, I will rebase this once that PR is merged to make the relevant changes in this PR smaller and easier to separate out and review.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] ashb commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
ashb commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r910798256


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   I'm all for using click so long as we can get the performance we need. And actually, one way of achieving that might be to move more and more code out of the `cli/command` files to elsewhere in the API, which has double benefits of a) Making the CLI code small so risk of slow imports is greatly reduced, and b) makes it easier for the CLI to use an API. (Yes I know that is massive feature creep on this original issue, so feel free to ignore this for now)
   
   @uranusjr The docs claim to, but by looking at issues on click the code for that doesn't seem to exist.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] blag commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
blag commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909439388


##########
airflow/cli/commands/version.py:
##########
@@ -0,0 +1,28 @@
+# 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.
+"""Version command"""
+from rich.console import Console
+
+import airflow
+from airflow.cli import airflow_cmd
+
+
+@airflow_cmd.command('version')
+def version():
+    """Displays Airflow version at the command line"""
+    console = Console()

Review Comment:
   I don't disagree that a `Console()` singleton and a single theme/setting would be ideal. But I tried to scope down these PRs to ensure that converting to Click was as "mechanical" of a process as possible. Similar to the pre-commit hook below, I think that is a great idea to do after we convert over to using Click, and I have expanded the "Styling Customization" subsection in [the original omnibus PR description](https://github.com/apache/airflow/pull/22613) to include that.
   
   But as below, please let me know if you'd like me to do that now, or if we can defer that to an issue for later work.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] ashb commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
ashb commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909607447


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   I like click for witing CLIs, it's nice and easy, but if it doesn't help us get what we actually want for our users (and I'm going to always say we as developers of Airflow should take a bit more pain writing things if it makes their lives better) maybe we shouldn't use it?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] ashb commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
ashb commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909599452


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   @potiuk Honest question then: Given click's architecture (load eveyrthing at once) seems counter to our goals (speedly startup, quick completion) why are we actually using click for `airflow`?
   
   Did we ever discuss this in a wider audience?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] blag commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
blag commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909432967


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   @uranusjr Thanks for the pointer with `__all__`. I don't have comprehensive statistics on additional overhead, although that was discussed [starting here](https://github.com/apache/airflow/pull/22613#issuecomment-1086788871) in the "omnibus" PR, and improved in [a related PR](https://github.com/astronomer/airflow/pull/1486). I think it might be easier to address any slowdowns on a case-by-case basis for each command rewrite instead of all at once in this PR. That being said, here is some not-super-scientific timings for the `version` subcommand:
   
   #### argparse ####
   ```
   ❯ time ( for i in $(seq 10); do airflow version --help 1>/dev/null; done )
   ( for i in $(seq 10); do; airflow version --help > /dev/null; done; )  4.59s user 0.90s system 99% cpu 5.533 total
   ```
   
   #### Click ####
   ```
   ❯ time ( for i in $(seq 10); do airflow-ng version --help 1>/dev/null; done )
   ( for i in $(seq 10); do; airflow-ng version --help > /dev/null; done; )  4.21s user 0.83s system 99% cpu 5.093 total
   ```
   
   #### argparse ####
   ```
   ❯ time ( for i in $(seq 10); do airflow version 1>/dev/null; done )
   ( for i in $(seq 10); do; airflow version > /dev/null; done; )  4.57s user 0.90s system 99% cpu 5.513 total
   ```
   
   #### Click ####
   ```
   ❯ time ( for i in $(seq 10); do airflow-ng version 1>/dev/null; done )
   ( for i in $(seq 10); do; airflow-ng version > /dev/null; done; )  4.20s user 0.82s system 98% cpu 5.069 total
   ```
   
   @potiuk I have tweaked the imports for this subcommand to improve timing, and captured your suggestion in the original omnibus PR description (in the "Future Work" section). I'm happy to also create an issue to ensure that doesn't get lost, but I think that might be out of the scope for this PR. I _do_ think that should be implemented before we finally switch the `airflow` command to being Click-based, but since this is only modifying a brand new, totally separate `airflow-ng` command I don't think it should be a requirement for this PR, or other PRs converting other commands, to be merged.
   
   But I'll leave the final resolution up to you. Please let me know if you'd like me to add that pre-commit hook now, or if we can defer it to an issue for later work.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r912005454


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   I think the learning from that discussion in this  PR is - click introduction is far from "done deal". Merging any PR with click changes when there are so many doubts about whether it will be performant enough. 
   
   Seems that at least few of us are extremely concerned about it and seems to be something really important that can break the whole benefit click might bring and make the experience worse.
   
   Merging any click related PR makes no sense before those concerns are addressed IMHO. And we have good set of ideas that could be explored to find out an answer to the question "are we able to make click performance good enough for us". There should be Proof Of Concept that should explore those possibilities and see if this might work for us and likely an AIP describing it - trying to implement some of the most potentially troublesome cases and measuring what are the delays introduced and how we can  structure the code (and possibly implement other options like mypyc) speed it up.  Some studies involving the acceptable delays can be found and referred to I think.
   
   My proposal @blag  - if you want to continue introducing your idea -  is to turn your work (and experience you gained so far when preparing this PR and other CLI actions) into this POC that will explore those options and lead the process on proposing, discussing and voting on the AIP based on that POC. I think just merging this PR without doing this exploration makes very little sense. 
   
   It's not a "scope creep" - it's just realising that scope of the orignal PR does not bring answers to more general question "do we really want to do it?" which results from the knowledge of "can we make it good enough?". 
   
   I think the discussion above was valuable to show that we currently have no answer to either of those questions and merging the PR does not bring us any closer - so we should not do it.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] github-actions[bot] commented on pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #24591:
URL: https://github.com/apache/airflow/pull/24591#issuecomment-1165847769

   The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909539094


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   I think console "accessibility" can be quite easily deferred - it's easy to change later (however it would be great that people who take care about implementing other parts will have an understanding what is our approach of user communication is and how they should write their CLI's - but this does not impact design and implementation approach as much, so it can be done as "next" PR (but it should be done before others get engaged- to make sure we keep consistent approach).  
   
   But I'd say pre-commit or some other (not necessary pre-commit) gate for not doing unnecessary imports and making sure our CLI commands are optimized for the way how click works are absolutely necessary as a "founding PR" - mainly to work out which approach will be good and make sure any next command will follow it.
   
   I personally think it is quite important because this will gate contributors from making mistakes that are not at all obvious but they can easily compound into unusable CLI. Once we get out of the gates, it's very difficult to keep it if there is no check in place. If you look at some history, every now and then mainly @ashb performs such ad-hoc clean-ups which will speed-up CLI import by a factor of few times - impacting heavily user performance. 
   An example of this here: https://github.com/apache/airflow/pull/21438/files (there were a few more complex but I found this one first). I think this is a "known" and "expected" problem, and we should rather prevent this problem from even occuring - it is always cheaper to prevent stuff in the first place than deal with it afterwards.
   
   The thing here is that just implementing such gate might reveal some problems and influence the way our modules are structured, and how they intract with rest of airlfow. 
   
   Main problem is that we have not kept it in check from the very beginning and we have no verification - so any new command added might break the "fast import" approach (and well - they did, many times). 
   
   Problems with those command and using click, this will get far worse than current implementation of the CLI - if we don't gate it from the beginning, because we have less control over it. Click heavily relies on importing all modules in  all click-annotated functions and it's not possible (afaik) to change it. And it is super easy to make even simple mistake that leads to huge slow-down for example by adding a TypeHint to a function in the same module that has an click-annotated command).  If we don't gate it, we will likely see the slow-downs rapidly growing if we are not careful. 
   
   And it's not "academic" discussion. We've already been there - if you look at the history https://github.com/apache/airflow/pull/6594 - the original CLI implementation of Airflow had the very same problem  and it became unbearable and borderline unusable. With click we can't do this lazy import the same way as @mik-laj did, because click will simply make all the "click" annotated methods load at startup. And even worse - alll of them are actually parsed every time user presses <TAB> for auto-completion. This last point can likely be optimized by pre-computing and caching completion, but AFAIK there is no good implementation of such caching yet ( I thought about writing one but had no time to do it). But the architecture of click currently kind of "forces" you to write optimized command definitions.
   
   And we want click interface/autocomplete to be better than the current one - not to regress.
   
   Also airflow at places has rather "bad legacy" of dragging literally *half* of the airflow imports once some classes are imported (especially conf). One bad import at top level might add literally seconds to boostrap time. While this is something yet-to-be-solved, this one is rather difficult due to backwards compatibility so we rather make sure that people adding commands will not fall into the same trap.
   
   Those are not isolated airflow concerns - those problem even made "pre-commit" maintainer plainly refused accepting click as a cli solution in order to implement auto-complete (https://github.com/pre-commit/pre-commit/issues/1119 - where multiple people - including myself - offered help in optimizing it).  And our CLI is far more complex and elaborated than pre-commit one.
   
   So I believe, we need to make sure our click-annotaed files commands are implemented - from day 0. Otherwise we risk that some decisions made by the authors and the commands are implemented in the way that makes it difficult to change, so basically the author of the original implementation might not realize that decisions made when implementing it have some bad consequences and chooses an "easy path" instead of - for example - refactor some part of code and remove unnecessary couplings. The bad thing is that it will not be immediately visible. The nature of it is that it will get slower with every new command and we will only realise that we need to optimize when it will need a change similar to Kamil's #6594 - +4000,-3000 lines of code.
   
   I do not want to hold it off - so I'd ask what @ashb and @mik-laj  think as they were mainly dealing with the CLI problems of Airflow.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python. The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we would manage to pull-it-off. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code and mypy into much faster compied C-code.  And (comparing to other similar approaches it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://www.youtube.com/watch?v=-Kku_hFUtY0  (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my gues that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909642422


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   This is a very good point :). I don't think we are at the point yet when we "know" we will use it. It's a proposal from @blag (which also coincidentally reflect my preferences, but even with Breeze's experience I am not 100% sure if I know how click will behave with Airlfow. 
   
   We use it in Breeze and well, the usability of it is great, the integration with rich is cool and it has some really good features - for example combining  click, rich and rich-click has the very nice SVG export which is fantastic way of documenting CLI (and we use all of them).
   
   The story is a follows:
   
   I am personally not yet 100% sure if click is good. I think so (but I think it has never been really "thoroughly" discussed - mainly because  we had no "base for dicussion I think .  Some time ago  we had this short "poll" (after I switched to it in Breeze) -  https://lists.apache.org/thread/fcs3wwwon3wyv7bynjqvdj6nvjy5lx5l - but that was just "sentiment" of few people and I netiher planned or did anything there and we had very little responses.
   
   Then - rather independently - @blag proposed it in https://github.com/apache/airflow/issues/22708 and I encouraged to experiment with it in https://github.com/apache/airflow/pull/24628 - but I suggested @blag to start small and get a founding PR and treat it as an experiment. And I think this PR here is really the "founding" PR that should give us some answers if this is worht or not. I think the first few (or maybe even THE FIRST) PR should give us enough answers that we should be able to discuss it. The proposal from @blag was to name the tool "airlfow-ng" and keep it as experiment in parallel to airflow. But for sure once we finish the experimentation phase there has to be a proper plan on how to migrate (if we decide to). 
   
   I personally tihnk that click has big value from the user side (especially when connected with rich and rich-click) and that - when treated very carefully it can be made performant enough for us (and my comments above reflect that) that click can be made performant enough for our needs (but - as mentioned above - with the caveat of making sure that whoever contributes will not "incrementally" break the experience (hence the strong preferrence from my side on some kind of gating - also coming from our bad experiences with our "own" CLI). The worst thing I can imagine is that we switch to a new CLI that will be "way worse" due to performance issues and even worse that if some contribution will make it "gradually worse".
   
   I think this PR is perfect opportunity to see all the pros-cons and experiment with the architecture to see if the performance will be good for us and what we would need to do to make it works. For example in Breeze, we have the gate in the form of pre-commit, that simply runs auto-complete `feature` of click in a completely separate virtualenv with just rich and click installed, making sure that no other external library is imported (It fails when it tries to impoert any external package) and it already prevented us from importing some stuff like yaml (which we know is on its own too havy to be used in auto-complete). But Breeze has quite a different architecture - flat set of commands (so there is no capability of lazy-loading of sub-commands you mentioned), it does not have the "huge import chain" (I deliberately made it architected in the way that it has very little small, independent modules + it's like 100 times smaller than airflow, so I felt external deps are all that we n
 eed to get. 
   
   I think we will not know until we try :). So I'd suggest (but that's really up to @blag how to approach it)  in this small PR we shoudl explore what it is to make click works for airlfow and make it a proposal. Not sure if AIP is needed eventually (probably not) but for sure a deliberate discussion with learnings and  our approach how we are going to gate the performance is needed I think
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] jedcunningham commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
jedcunningham commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r906318092


##########
airflow/cli/commands/version.py:
##########
@@ -0,0 +1,28 @@
+# 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.
+"""Version command"""
+from rich.console import Console
+
+import airflow
+from airflow.cli import airflow_cmd
+
+
+@airflow_cmd.command('version')
+def version():
+    """Displays Airflow version at the command line"""
+    console = Console()
+    console.print(airflow.__version__)

Review Comment:
   ```suggestion
       """Displays Airflow version"""
       Console().print(airflow.__version__)
   ```
    
   nit



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #24591:
URL: https://github.com/apache/airflow/pull/24591#issuecomment-1169897689

   > Does [pallets/click#945](https://github.com/pallets/click/issues/945) help btw?
   
   Yep. This is very much in line with what I thought.  We should explore those options and check it as part of the  founding PR - because it **might** impact the way we want to write the commands (and make sure that either we verify that whatever rules we will have to keep it optimized. It does not have to be pre-commit - just "unified" way of approaching the CLI in the way that will keep them optimized and making sure it's verified at PR time (if it is not easily verifiable by review).


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] ashb commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
ashb commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909522502


##########
airflow/cli/commands/version.py:
##########
@@ -0,0 +1,28 @@
+# 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.
+"""Version command"""
+from rich.console import Console
+
+import airflow
+from airflow.cli import airflow_cmd
+
+
+@airflow_cmd.command('version')
+def version():
+    """Displays Airflow version at the command line"""
+    console = Console()

Review Comment:
   > Yeah. I think it's a good idea to setup a consistent communication approach -> i.e. have custom "message type" tags rather than color tags - having that and documenting why and how to use them (like we did here) https://github.com/apache/airflow/blob/main/dev/breeze/doc/adr/0011-unified-communication-with-the-users.md - brings consistent user experience. And introducing themes makes it easy to switch to a "colour-blind-friendly" mode from the beginning.
   > 
   > There are 8% males with red/green collour defficiency https://en.wikipedia.org/wiki/Color_blindness and males are (for better or worse) most of the airflow users, so it might make sense to implement a consistent "theme" approach and ability to switch, especially that it is rather easy and except the need of retrieving console dynamically, does not bring too much of an overhead in the long run.
   
   Sure, but I would not do that in this PR, but  convert first, then add theme support as a follow up. a) Focus on one thing at a time, and b) that can be done in parallel to the migration work.
   
   To make it easier we could have
   
   
   ```python
   @cache
   def get_console() -> Console:
       return Console()
   ```
   
   in `airflow/cli/__init__.py`, just so that everything in the CLI uses that singleton already.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909679325


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   > I like click for witing CLIs, it's nice and easy, but if it doesn't help us get what we actually want for our users (and I'm going to always say we as developers of Airflow should take a bit more pain writing things if it makes their lives better) maybe we shouldn't use it?
   
   I am quite there with you @ashb  - if we cannot make it "better" (both UI/performance) we should not do it. But if we find a way to make it as performant as what we have today, the UI side of it is great for feature discoverability of the users and make their airflow experience pleasant (again - as long as it does not lag ~ 100 ms or so for auto-complete and command execution - there are some studies that we would need to look at but I think 100ms is around being noticeable ). Colour and nice layout is a great way to communicate things - warning, errors, information etc. (but also it cannot be the only one because of the ~ 8% of color blind males - who are - for better or worse - our main users). This is main reason why we added colours some time ago to logs and I must say as much as I was used to browse logs with just error levels, the colour output make it way more effective in communicating things like warnings or errors (and I realized how important it is since).
   
   Also there is one - very, very important aspect - look at the [survey results](https://airflow.apache.org/blog/airflow-survey-2022/#which-interfaces-of-airflow-do-you-use-as-part-of-your-current-role-multiple-choice) the CLI is important to 50% of our users (BTW. I was quite suprised by the almost 100% of the UI). 
   
   CLI is big part of what the users "see" and experience as Airflow. Using modern, nicely laid out and colorful output  has the added benefit of give airflow "modern" look. For met this is also a communication tool with our users "we are fresh and modern" - same reason the "modernized" Airlfow UI make us able to not be classified as "the dinozaurs". 
   
   I am not say we have to convert to click. I don't even say we should. But I would really love to see if we CAN. 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909679325


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   > I like click for witing CLIs, it's nice and easy, but if it doesn't help us get what we actually want for our users (and I'm going to always say we as developers of Airflow should take a bit more pain writing things if it makes their lives better) maybe we shouldn't use it?
   
   I am quite there with you @ashb  - if we cannot make it "better" (both UI/performance) we should not do it. But if we find a way to make it as performant as what we have today, the UI side of it is great for feature discoverability of the users and make their airflow experience pleasant (again - as long as it does not lag ~ 100 ms or so for auto-complete and command execution - there are some studies that we would need to look at but I think 100ms is around being noticeable ). Colour and nice layout is a great way to communicate things - warning, errors, information etc. (but also it cannot be the only one because of the ~ 8% of color blind males - who are - for better or worse - our main users). This is main reason why we added colours some time ago to logs and I must say as much as I was used to browse logs with just error levels, the colour output make it way more effective in communicating things like warnings or errors (and I realized how important it is since).
   
   Also there is one - very, very important aspect - look at the [survey results](https://airflow.apache.org/blog/airflow-survey-2022/#which-interfaces-of-airflow-do-you-use-as-part-of-your-current-role-multiple-choice) the CLI is important to 50% of our users (BTW. I was quite suprised by the almost 100% of the UI). 
   
   CLI is big part of what the users "see" and experience as Airflow. Using modern, nicely laid out and colorful output  has the added benefit of giving airflow "modern" look. For me this is also a communication tool with our users "we are fresh and modern" - same reason the "modernized" Airlfow UI make us able to not be classified as "the dinozaurs". 
   
   I am not say we have to convert to click. I don't even say we should. But I would really love to see if we CAN. 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r910627207


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Click claims to support subcommand lazy loading (never tried it myself) so theoratically we only need to always load the list of subcommands, not everything.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python. The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we would manage to pull-it-off. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code using mypy into much faster compied C-code.  And (comparing to other similar approaches) it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://www.youtube.com/watch?v=-Kku_hFUtY0  (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my gues that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python. The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we would manage to pull-it-off. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code using mypy into much faster compied C-code.  And (comparing to other similar approaches it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://www.youtube.com/watch?v=-Kku_hFUtY0  (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my gues that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python. The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we would manage to pull-it-off. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code using mypy into much faster compied C-code.  And (comparing to other similar approaches) it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://youtu.be/-Kku_hFUtY0?t=3063 (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my guess that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911426774


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   And this is even more important actually if we decide to explore mypyc route, to work out the right structure of the code so that it can be `mypyc-d`. 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r906637113


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   You can use `__all__` to avoid the NOQA comment instead.
   
   Also, how much additional overhead is introduced for other commands, due to Click needing to be initiated?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r912005454


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   I think the learning from that discussion in this  PR is - click introduction is far from "done deal". Merging any PR with click changes when there are so many doubts about whether it will be performant enough. 
   
   Seems that at least few of us are extremely concerned about and seems to be something really important that can break the whole benefit click might bring and make the experience worse.
   
   Merging any click related PR makes no sense before those concerns are addressed IMHO. And we have good set of ideas that could be explored to find out an answer to the question "are we able to make click performance good enough for us". There should be Proof Of Concept that should explore those possibilities and see if this might work for us and likely an AIP describing it - trying to implement some of the most potentially troublesome cases and measuring what are the delays introduced and how we can  structure the code (and possibly implement other options like mypyc) speed it up.  Some studies involving the acceptable delays can be found and referred to I think.
   
   My proposal @blag  - if you want to continue introducing your idea -  is to turn your work (and experience you gained so far when preparing this PR and other CLI actions) into this POC that will explore those options and lead the process on proposing, discussing and voting on the AIP based on that POC. I think just merging this PR without doing this exploration makes very little sense. 
   
   It's not a "scope creep" - it's just realising that scope of the orignal PR does not bring answers to more general question "do we really want to do it?" which results from the knowledge of "can we make it good enough?". 
   
   I think the discussion above was valuable to show that we currently have no answer to either of those questions and merging the PR does not bring us any closer - so we should not do it.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909642422


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   This is a very good point :). I don't think we are at the point yet when we "know" we will use it. It's a proposal from @blag (which also coincidentally reflect my preferences, but even with Breeze's experience I am not 100% sure if I know how click will behave with Airlfow. 
   
   We use it in Breeze and well, the usability of it is great, the integration with rich is cool and it has some really good features - for example combining  click, rich and rich-click has the very nice SVG export which is fantastic way of documenting CLI (and we use all of them).
   
   The story is a follows:
   
   I am personally not yet 100% sure if click is good. I think so (but I think it has never been really "thoroughly" discussed - mainly because  we had no "base for dicussion I think .  Some time ago  we had this short "poll" (after I switched to it in Breeze) -  https://lists.apache.org/thread/fcs3wwwon3wyv7bynjqvdj6nvjy5lx5l - but that was just "sentiment" of few people and I netiher planned nor did anything there and we had very little responses.
   
   Then - rather independently - @blag proposed it in https://github.com/apache/airflow/issues/22708 and I encouraged to experiment with it in https://github.com/apache/airflow/pull/24628 - but I suggested @blag to start small and get a founding PR and treat it as an experiment. And I think this PR here is really the "founding" PR that should give us some answers if this is worht or not. I think the first few (or maybe even THE FIRST) PR should give us enough answers that we should be able to discuss it. The proposal from @blag was to name the tool "airlfow-ng" and keep it as experiment in parallel to airflow. But for sure once we finish the experimentation phase there has to be a proper plan on how to migrate (if we decide to). 
   
   I personally tihnk that click has big value from the user side (especially when connected with rich and rich-click) and that - when treated very carefully it can be made performant enough for us (and my comments above reflect that) that click can be made performant enough for our needs (but - as mentioned above - with the caveat of making sure that whoever contributes will not "incrementally" break the experience (hence the strong preferrence from my side on some kind of gating - also coming from our bad experiences with our "own" CLI). The worst thing I can imagine is that we switch to a new CLI that will be "way worse" due to performance issues and even worse that if some contribution will make it "gradually worse".
   
   I think this PR is perfect opportunity to see all the pros-cons and experiment with the architecture to see if the performance will be good for us and what we would need to do to make it works. For example in Breeze, we have the gate in the form of pre-commit, that simply runs auto-complete `feature` of click in a completely separate virtualenv with just rich and click installed, making sure that no other external library is imported (It fails when it tries to impoert any external package) and it already prevented us from importing some stuff like yaml (which we know is on its own too havy to be used in auto-complete). But Breeze has quite a different architecture - flat set of commands (so there is no capability of lazy-loading of sub-commands you mentioned), it does not have the "huge import chain" (I deliberately made it architected in the way that it has very little small, independent modules + it's like 100 times smaller than airflow, so I felt external deps are all that we n
 eed to get. 
   
   I think we will not know until we try :). So I'd suggest (but that's really up to @blag how to approach it)  in this small PR we shoudl explore what it is to make click works for airlfow and make it a proposal. Not sure if AIP is needed eventually (probably not) but for sure a deliberate discussion with learnings and  our approach how we are going to gate the performance is needed I think
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909642422


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   This is a very good point :). I don't think we are at the point yet when we "know" we will use it. It's a proposal from @blag (which also coincidentally reflect my preferences, but even with Breeze's experience I am not sure if I know how click will behave with Airlfow. 
   
   We use it in Breeze and well, the usability of it is great, the integration with rich is cool and it has some really good features - for example combining  click, rich and rich-click has the very nice SVG export which is fantastic way of documenting CLI (and we use all of them).
   
   The story is a follows:
   
   I am personally not yet 100% sure if click is good. I think so (but I think it has never been really "thoroughly" discussed - mainly because  we had no "base for dicussion I think .  Some time ago  we had this short "poll" (after I switched to it in Breeze) -  https://lists.apache.org/thread/fcs3wwwon3wyv7bynjqvdj6nvjy5lx5l - but that was just "sentiment" of few people and I netiher planned or did anything there and we had very little responses.
   
   Then - rather independently - @blag proposed it in https://github.com/apache/airflow/issues/22708 and I encouraged to experiment with it in https://github.com/apache/airflow/pull/24628 - but I suggested @blag to start small and get a founding PR and treat it as an experiment. And I think this PR here is really the "founding" PR that should give us some answers if this is worht or not. I think the first few (or maybe even THE FIRST) PR should give us enough answers that we should be able to discuss it. The proposal from @blag was to name the tool "airlfow-ng" and keep it as experiment in parallel to airflow. But for sure once we finish the experimentation phase there has to be a proper plan on how to migrate (if we decide to). 
   
   I personally tihnk that click has big value from the user side (especially when connected with rich and rich-click) and that - when treated very carefully it can be made performant enough for us (and my comments above reflect that) that click can be made performant enough for our needs (but - as mentioned above - with the caveat of making sure that whoever contributes will not "incrementally" break the experience (hence the strong preferrence from my side on some kind of gating - also coming from our bad experiences with our "own" CLI). The worst thing I can imagine is that we switch to a new CLI that will be "way worse" due to performance issues and even worse that if some contribution will make it "gradually worse".
   
   I think this PR is perfect opportunity to see all the pros-cons and experiment with the architecture to see if the performance will be good for us and what we would need to do to make it works. For example in Breeze, we have the gate in the form of pre-commit, that simply runs auto-complete `feature` of click in a completely separate virtualenv with just rich and click installed, making sure that no other external library is imported (It fails when it tries to impoert any external package) and it already prevented us from importing some stuff like yaml (which we know is on its own too havy to be used in auto-complete). But Breeze has quite a different architecture - flat set of commands (so there is no capability of lazy-loading of sub-commands you mentioned), it does not have the "huge import chain" (I deliberately made it architected in the way that it has very little small, independent modules + it's like 100 times smaller than airflow, so I felt external deps are all that we n
 eed to get. 
   
   I think we will not know until we try :). So I'd suggest (but that's really up to @blag how to approach it)  in this small PR we shoudl explore what it is to make click works for airlfow and make it a proposal. Not sure if AIP is needed eventually (probably not) but for sure a deliberate discussion with learnings and  our approach how we are going to gate the performance is needed I think
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r906717837


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Agree with @uranusjr. Until we have https://peps.python.org/pep-0690/ implemented (which if we are lucky gets into python 3.12 IMHO) - comment from `breeze' experience - we have implemented a check to make sure that only minimum set of imorts is actually done while the @click decorators are being parsed.
   
   This means (and in Breeze we are following it) that most of the imports used in "command" are local imports. But we do not only have to implement it now, but also make sure it will be kept in the future, otherwise anyone committing changes to commands in the future will not fall into a "trap" of adding top-level import and influencing auto-complete to take even several hundred milliseconds - which will make it barely usable.
   
   We have a pre-commit for it:
   
   https://github.com/apache/airflow/blob/main/.pre-commit-config.yaml#L638
   
   And I guess similar pre-commit should be run for all @click commands 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911426774


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   And this is even more important actually if we decide to explore mypyc route, to work out the right structure of the code so that it can be mypyc'd. 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909679325


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   > I like click for witing CLIs, it's nice and easy, but if it doesn't help us get what we actually want for our users (and I'm going to always say we as developers of Airflow should take a bit more pain writing things if it makes their lives better) maybe we shouldn't use it?
   
   I am quite there with you @ashb  - if we cannot make it "better" (both UI/performance) we should not do it. But if we find a way to make it as performant as what we have today, the UI side of it is great for feature discoverability of the users and make their airflow experience pleasant (again - as long as it does not lag ~ 100 ms or so for auto-complete 
   and command execution - there are some studies that we would need to look at but I think 100ms is around being noticeable ). Colour and nice layout is a great way to communicate things - warning, errors, information etc. (but also it cannot be the only one because of the ~ 8% of color blind males - who are - for better or worse - our main users). This is main reason why we added colours some time ago to logs and I must say as much as I was used to browse logs with just error levels, the colour output make it way more effective in communicating things like warnings or errors (and I realized how important it is since).
   
   Also there is one - very, very important aspect - look at the [survey results](https://airflow.apache.org/blog/airflow-survey-2022/#which-interfaces-of-airflow-do-you-use-as-part-of-your-current-role-multiple-choice) the CLI is important to 50% of our users (BTW. I was quite suprised by the almost 100% of the UI). 
   
   CLI is big part of what the users "see" and experience as Airflow. Using modern, nicely laid out and colorful output  has the added benefit of give airflow "modern" look. For met this is also a communication tool with our users "we are fresh and modern" - same reason the "modernized" Airlfow UI make us able to not be classified as "the dinozaurs". 
   
   I am not say we have to convert to click. I don't even say we should. But I would really love to see if we CAN. 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911994193


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   > And if we do have larger re-architecting questions we need to resolve before converting over to Click, then perhaps an AIP and a broader discussion (to capture hard requirements and overall goals of the CLI, and investigate possible alternatives besides just Click) would be appropriate after all. In which case, I will simply close this and all related PRs and wait until there's some consensus on the way forward.
   
   Yes. I think this is the best way forward.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] blag closed pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
blag closed pull request #24591: Rewrite the 'version' command to use Click
URL: https://github.com/apache/airflow/pull/24591


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python). The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we would manage to pull-it-off. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code using mypy into much faster compied C-code.  And (comparing to other similar approaches) it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://youtu.be/-Kku_hFUtY0?t=3063 (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my guess that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911420960


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   BTW. I updated the link to start time of the presentation of Łukasz - he starts in Polish but he quickly switches over to English.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909642422


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   This is a very good point :). I don't think we are at the point yet when we "know" we will use it. It's a proposal from @blag (which also coincidentally reflect my preferences, but even with Breeze's experience I am not 100% sure if I know how click will behave with Airlfow. 
   
   We use it in Breeze and well, the usability of it is great, the integration with rich is cool and it has some really good features - for example combining  click, rich and rich-click has the very nice SVG export which is fantastic way of documenting CLI (and we use all of them).
   
   The story is a follows:
   
   I am personally not yet 100% sure if click is good. I think so (but I think it has never been really "thoroughly" discussed - mainly because  we had no "base for dicussion I think .  Some time ago  we had this short "poll" (after I switched to it in Breeze) -  https://lists.apache.org/thread/fcs3wwwon3wyv7bynjqvdj6nvjy5lx5l - but that was just "sentiment" of few people and I netiher planned nor did anything there and we had very little responses.
   
   Then - rather independently - @blag proposed it in https://github.com/apache/airflow/issues/22708 and I encouraged to experiment with it in https://github.com/apache/airflow/pull/24628 - but I suggested @blag to start small and get a founding PR and treat it as an experiment. And I think this PR here is really the "founding" PR that should give us some answers if this is worht or not. I think the first few (or maybe even THE FIRST) PR should give us enough answers that we should be able to discuss it. The proposal from @blag was to name the tool "airlfow-ng" and keep it as experiment in parallel to airflow. But for sure once we finish the experimentation phase there has to be a proper plan on how to migrate (if we decide to). 
   
   I personally tihnk that click has big value from the user side (especially when connected with rich and rich-click) and that - when treated very carefully -  it can be made performant enough for us (and my comments above reflect that) that click can be made performant enough for our needs (but - as mentioned above - with the caveat of making sure that whoever contributes will not "incrementally" break the experience (hence the strong preferrence from my side on some kind of gating - also coming from our bad experiences with our "own" CLI). The worst thing I can imagine is that we switch to a new CLI that will be "way worse" due to performance issues and even worse that if some contribution will make it "gradually worse".
   
   I think this PR is perfect opportunity to see all the pros-cons and experiment with the architecture to see if the performance will be good for us and what we would need to do to make it works. For example in Breeze, we have the gate in the form of pre-commit, that simply runs auto-complete `feature` of click in a completely separate virtualenv with just rich and click installed, making sure that no other external library is imported (It fails when it tries to impoert any external package) and it already prevented us from importing some stuff like yaml (which we know is on its own too havy to be used in auto-complete). But Breeze has quite a different architecture - flat set of commands (so there is no capability of lazy-loading of sub-commands you mentioned), it does not have the "huge import chain" (I deliberately made it architected in the way that it has very little small, independent modules + it's like 100 times smaller than airflow, so I felt external deps are all that we n
 eed to get. 
   
   I think we will not know until we try :). So I'd suggest (but that's really up to @blag how to approach it)  in this small PR we shoudl explore what it is to make click works for airlfow and make it a proposal. Not sure if AIP is needed eventually (probably not) but for sure a deliberate discussion with learnings and  our approach how we are going to gate the performance is needed I think
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r912020838


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   BTW. Just to encourage you @blag - this very much resembles my story in Airlfow (which was quoted in https://github.com/readme/featured/oss-decision-making). I though I was 100% sure I know how the change to our dependency management shoudl be - and I was sure it is right by talking to a few people - but when I "announced" publicly the change as a "change is coming" and sparked a more wide-spread conversation I was reminded that this needs far more of a discussion, delibration and thoughts.
   
   I rolled my sleeves up then and  started to do the ground work. Four implemented AIPs, becoming a committer, PMC member in the meantime and about 2 years later we got a process where we had a good solution to the problem I saw when I started - very, very different from what I announced, but it was handling all the complexities of the problems, I had no idea they existed in the first place.
   
   I hope this story might encourage you to follow up.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] ashb commented on pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
ashb commented on PR #24591:
URL: https://github.com/apache/airflow/pull/24591#issuecomment-1169858833

   Does https://github.com/pallets/click/issues/945 help btw?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r909679325


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   > I like click for witing CLIs, it's nice and easy, but if it doesn't help us get what we actually want for our users (and I'm going to always say we as developers of Airflow should take a bit more pain writing things if it makes their lives better) maybe we shouldn't use it?
   
   I am quite there with you @ashb  - if we cannot make it "better" (both UI/performance) we should not do it. But if we find a way to make it as performant as what we have today, the UI side of it is great for feature discoverability of the users and make their airflow experience pleasant (again - as long as it does not lag ~ 100 ms or so for auto-complete and command execution - there are some studies that we would need to look at but I think 100ms is around being noticeable ). Colour and nice layout is a great way to communicate things - warning, errors, information etc. (but also it cannot be the only one because of the ~ 8% of color blind males - who are - for better or worse - our main users). This is main reason why we added colours some time ago to logs and I must say as much as I was used to browse logs with just error levels, the colour output make it way more effective in communicating things like warnings or errors (and I realized how important it is since).
   
   Also there is one - very, very important aspect - look at the [survey results](https://airflow.apache.org/blog/airflow-survey-2022/#which-interfaces-of-airflow-do-you-use-as-part-of-your-current-role-multiple-choice) the CLI is important to 50% of our users (BTW. I was quite suprised by the almost 100% of the UI). 
   
   CLI is big part of what the users "see" and experience as Airflow. Using modern, nicely laid out and colorful output  has the added benefit of giving airflow "modern" look. For me this is also a communication tool with our users "we are fresh and modern" - same reason the "modernized" Airlfow UI make us able to not be classified as "the dinozaurs". 
   
   I am not saying we have to convert to click. I don't even say we should. But I would really love to see if we CAN. 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python). The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we could manage to pull-it-off. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code using mypy into much faster compied C-code.  And (comparing to other similar approaches) it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://youtu.be/-Kku_hFUtY0?t=3063 (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my guess that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] ashb commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
ashb commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r910798256


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   I'm all for using click so long as we can get the performance we need. And actually, one way of achieving that might be to move more and more code out of the `cli/command` files to elsewhere in the API, which has double benefits of a) Making the CLI code small so risk of slow imports is greatly reduced, and b) makes it easier for the CLI to use an (http) API. (Yes I know that is massive feature creep on this original issue, so feel free to ignore this for now)
   
   @uranusjr The docs claim to, but by looking at issues on click the code for that doesn't seem to exist.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r906716931


##########
airflow/cli/commands/version.py:
##########
@@ -0,0 +1,28 @@
+# 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.
+"""Version command"""
+from rich.console import Console
+
+import airflow
+from airflow.cli import airflow_cmd
+
+
+@airflow_cmd.command('version')
+def version():
+    """Displays Airflow version at the command line"""
+    console = Console()

Review Comment:
   Yeah. I think it's a good idea to setup a consistent communication approach -> i.e. have custom "message type" tags rather than color tags - having that and documenting why and how to use them (like we did here) https://github.com/apache/airflow/blob/main/dev/breeze/doc/adr/0011-unified-communication-with-the-users.md - brings consistent user experience. And introducing themes  makes it easy to switch to a "colour-blind-friendly" mode from the beginning.
   
   There are 8% males with red/green collour defficiency https://en.wikipedia.org/wiki/Color_blindness and males are (for better or worse) most of the airflow users, so it might make sense to implement a consistent "theme" approach and ability to switch, especially that it is rather easy and except the need of retrieving console dynamically, does not bring too much of an overhead in the long run.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r906717837


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Agree with @uranusjr. Until we have https://peps.python.org/pep-0690/ implemented (which if we are lucky gets into python 3.12 IMHO) - comment from `breeze' experience - we have implemented a check to make sure that only minimum set of imorts is actually done while the @click decorators are being parsed.
   
   This meand (and in Breeze we are following it) that most of the imports used in "command" are local imports. But we do not only have to implement it now, but also make sure it will be kept in the future, otherwise anyone committing changes to commands in the future will not fall into a "trap" of adding top-level import and influencing auto-complete to take even several hundred milliseconds - which will make it barely usable.
   
   We have a pre-commit for it:
   
   https://github.com/apache/airflow/blob/main/.pre-commit-config.yaml#L638
   
   And I guess similar pre-commit should be run for all @click commands 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] bhirsz commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
bhirsz commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r906365299


##########
airflow/cli/commands/version.py:
##########
@@ -0,0 +1,28 @@
+# 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.
+"""Version command"""
+from rich.console import Console
+
+import airflow
+from airflow.cli import airflow_cmd
+
+
+@airflow_cmd.command('version')
+def version():
+    """Displays Airflow version at the command line"""
+    console = Console()

Review Comment:
   New Breeze already uses rich click. Maybe it should also use the same architecture, ie define console as singleton with configured theme/settings. See here https://github.com/apache/airflow/blob/main/dev/breeze/src/airflow_breeze/utils/console.py



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] ashb commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
ashb commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911241479


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   100ms is going to be ambitious for any python project I think - and caching can be added for completion side of things to get there, so I'm mostly concerned about time to error/help - i.e. how long does it take to give me the help page when I ask for it/make a typo 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python. The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we would manage to pull-of. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code and mypy into much faster compied C-code.  And (comparing to other similar approaches it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://www.youtube.com/watch?v=-Kku_hFUtY0  (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my gues that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911417103


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   Yeah 100ms might be a challenge. Or maybe not?
   
   Actually I participated last week in PyWaw meetup with none other than Łukasz Langa (the entrepreneur-in-residence of Python. The talk was precisely about speeding up Python code. They are in the very advanced phase of speeding up Python wiht Python 3.11 but this one was about something else - namely about speeding up Python code by using `mypyc`. This would be HUGE win if we would manage to pull-it-off. The super-nice thing about mypyc is that it does not require you to change the way you write python code, it has a number of limitations (for example we would not be able to use it with the metaclasses we use here and there and dynamic loading of classes we do with "airflow" module and only single-inheritance is supported). 
   
   They (Łukasz was part of the team) managed to make `black` compatible with mypyc and speed it up. In short MyPyc allows to turn fully type-hinted Python code using mypy into much faster compied C-code.  And (comparing to other similar approaches) it actually allows to do that with very little limitations on what you can use in the python code you compile. 
   
   The main "prrof" and goal they had was to make `black` faster, and I think they succeeded:
   
   <img width="896" alt="Screenshot 2022-06-30 at 22 05 36" src="https://user-images.githubusercontent.com/595491/176768599-4d0d53f2-64cf-4ca5-9422-1e9d12752967.png">
   
   You should definitely watch the talk: https://www.youtube.com/watch?v=-Kku_hFUtY0  (you can hear me by the end asking about how we can use it in airflow). Besides having a TON of useful information and experiences about speeding up Python in general, it is very entertaining, Łukasz is a great speaker and he is a great person in general. We went to after-party with a group of Pythonistas and I picked a lot of Łukasz's brain about the subject. It was over (more than) couple of beers, so take it with a grain of salt :). But what I brought from that is that if we have a separate python module with CLI-only functionalitty that we could separate out from rest of airflow and compile with mypyc, that would be a huge win for the speed of CLI.
   
   This is even more scope creep on the PR but maybe the first founding PR should also explore this possibility - this way we could see if we CAN do such aa speedup and make super-fast CLI which would be compiled with mypyc. Łukasz - answering my question specifically confirmed my guess that for the core of airflow (mostly DB and networking) mypyc will have very limited impact - but the CLI part  might heavily benefit it (of course that would complicate our build setup but - if we are going to rewrite the CLI to click, maybe it's worth checking if it can be done with mypyc.
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] potiuk commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911426774


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   And this is even more important actually if we decide to explore mypyc route, to work out the right structure of the code so that it can be "mypyc-ed". 



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] blag commented on a diff in pull request #24591: Rewrite the 'version' command to use Click

Posted by GitBox <gi...@apache.org>.
blag commented on code in PR #24591:
URL: https://github.com/apache/airflow/pull/24591#discussion_r911465304


##########
airflow/cli/__main__.py:
##########
@@ -18,6 +18,7 @@
 # under the License.
 
 from airflow.cli import airflow_cmd
+from airflow.cli.commands import version  # noqa: F401

Review Comment:
   In general, it might be more helpful to comment in #22613 if you are making suggestions for future work. A GitHub or mailing list discussion might be more appropriate if you would like more people to explore restructuring the code to better fit other pursuits.
   
   And if you would like to provide feedback about the `version` subcommand rewrite, this comment thread, or the general comments for this PR would be great for that.
   
   But I'm having difficulty figuring out what the hard requirements _for this PR_ are, what the softer goals of the rewrite as a whole are, and what are proposals for future work.
   
   I would like to keep the scope of this PR as small as possible. Is this PR a good Click implementation of the `version` subcommand or not - that's the question here.
   
   If we need to pause the Click CLI rewrite and restructure the CLI to resolve other issues first, that's fine. But it seems like major scope creep to go from this `version` subcommand conversion all the way to "research and possibly completely restructure the CLI for an entirely different goal".
   
   And if we do have larger re-architecting questions we need to resolve before converting over to Click, then perhaps an AIP and a broader discussion (to capture hard requirements and overall goals of the CLI, and investigate possible alternatives besides just Click) would be appropriate after all. In which case, I will simply close this and all related PRs and wait until there's some consensus on the way forward.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org