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/10 09:54:57 UTC

[GitHub] [airflow] basjacobs93 opened a new pull request, #24368: Fix requirements.txt path in Python operator

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

   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   The `requirements` parameter in `PythonVirtualEnvOperator` was not read properly in the case it was a string referring to a file path. Rather than the contents of the file, the file path was taken as a requirement, but this gives an error when trying to install with pip.
   
   This PR reads the contents of the requirements file and passes those to pip.
   
   related: #16037


-- 
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] closed pull request #24368: Fix requirements.txt path in Python operator

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #24368: Fix requirements.txt path in Python operator
URL: https://github.com/apache/airflow/pull/24368


-- 
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 #24368: Fix requirements.txt path in Python operator

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


##########
airflow/operators/python.py:
##########
@@ -433,7 +433,8 @@ def execute_callable(self):
             if not isinstance(self.requirements, str):
                 requirements_file_contents = "\n".join(str(dependency) for dependency in self.requirements)
             else:
-                requirements_file_contents = self.requirements
+                with open(self.requirements, "r") as file:
+                    requirements_file_contents = "\n".join(file.readlines())

Review Comment:
   Perhaps we can do this:
   
   ```python
   if not isinstance(self.requirements, str):
       ...
   elif os.path.exists(self.requirements):
       with open(self.requirements, "r") as f:
           ...
   else:
       requirements_file_contents = self.requirements
   ```
   
   This helps keep compatibility to the “incorrect” use of providing one single requirement as the argument.



-- 
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 #24368: Fix requirements.txt path in Python operator

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


##########
airflow/operators/python.py:
##########
@@ -408,7 +408,8 @@ def __init__(
         if not requirements:
             self.requirements: Union[List[str], str] = []
         elif isinstance(requirements, str):
-            self.requirements = requirements
+            with open(requirements, "r") as file:
+                self.requirements = file.readlines()

Review Comment:
   Overriding `prepare_template` to post-process `self.requirements` may be a viable approach to achieve this.



-- 
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 #24368: Fix requirements.txt path in Python operator

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


##########
airflow/operators/python.py:
##########
@@ -408,7 +408,8 @@ def __init__(
         if not requirements:
             self.requirements: Union[List[str], str] = []
         elif isinstance(requirements, str):
-            self.requirements = requirements
+            with open(requirements, "r") as file:
+                self.requirements = file.readlines()

Review Comment:
   This does not work if the task is distributed onto a worker, which is not necessarily the same machine as the scheduler. The file should only need to exist on the worker (that only runs the task code), not the scheduler (which runs the Airflow scheduling logic).
   
   So this must continue to store only the filename in `__init__`, and reading the file can only happen in `execute`.



-- 
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] boring-cyborg[bot] commented on pull request #24368: Fix requirements.txt path in Python operator

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on PR #24368:
URL: https://github.com/apache/airflow/pull/24368#issuecomment-1152187198

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (flake8, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
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 #24368: Fix requirements.txt path in Python operator

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

   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
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] basjacobs93 commented on a diff in pull request #24368: Fix requirements.txt path in Python operator

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


##########
airflow/operators/python.py:
##########
@@ -408,7 +408,8 @@ def __init__(
         if not requirements:
             self.requirements: Union[List[str], str] = []
         elif isinstance(requirements, str):
-            self.requirements = requirements
+            with open(requirements, "r") as file:
+                self.requirements = file.readlines()

Review Comment:
   Thanks, I was not aware of that. I have moved the reading of the file to `execute_callable()`



-- 
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] basjacobs93 commented on pull request #24368: Fix requirements.txt path in Python operator

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

   There is some discussion on templating and XCom variables in https://github.com/apache/airflow/issues/16037, but to be honest I do not see how that functionality is included in the way the requirements parsing is done currently (nor how it was done before my changes)


-- 
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 #24368: Fix requirements.txt path in Python operator

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

   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


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