mik-laj commented on a change in pull request #10303: URL: https://github.com/apache/airflow/pull/10303#discussion_r469505904
########## File path: docs/packages.rst ########## @@ -0,0 +1,75 @@ + .. 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. + + + +Loading Packages in Python and Airflow +====================================== + +How does Python load packages? +------------------------------ +Python's `sys <https://docs.python.org/3/library/sys.html>`_ package provides key variables and functions that are used +or maintained by the interpreter. One such variable is ``sys.path``. It's a list of directories which is searched by +Python during imports. for example, + +.. code-block:: pycon + + >>> import sys + >>> from pprint import pprint + >>> pprint(sys.path) + ['', + '/home/arch/.pyenv/versions/3.7.4/lib/python37.zip', + '/home/arch/.pyenv/versions/3.7.4/lib/python3.7', + '/home/arch/.pyenv/versions/3.7.4/lib/python3.7/lib-dynload', + '/home/arch/venvs/airflow/lib/python3.7/site-packages'] + +``sys.path`` is initialized during program startup. The first precedence is given to the current directory, +i.e, ``path[0]`` is the directory containing the current script that was used to invoke or an empty string in case +it was an interactive shell. Second precedence is given to the ``PYTHONPATH``, followed by installation-dependent +default paths which is managed by `site <https://docs.python.org/3/library/site.html#module-site>`_ module. + Review comment: > In the variable: `sys.path` there is a directory` site-packages`` which contains **external packages * installed, which means you can install packages with `pip` or` anaconda` `and you can use them in Airflow. In the __TODO__ section, you will learn how to create your own simple installable package. > You can specify additional directories to be added to ``sys.path`` with the ** environment variable. :envvar:`PYTHONPATH` **. See section TODO for more information. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
