uranusjr commented on a change in pull request #16954:
URL: https://github.com/apache/airflow/pull/16954#discussion_r670146636



##########
File path: airflow/utils/python_virtualenv.py
##########
@@ -35,12 +38,44 @@ def _generate_virtualenv_cmd(tmp_dir: str, python_bin: str, 
system_site_packages
     return cmd
 
 
-def _generate_pip_install_cmd(tmp_dir: str, requirements: List[str]) -> 
Optional[List[str]]:
+def _generate_pip_install_cmd(tmp_dir: str,
+                              requirements: List[str],
+                              connection_id: Optional[str] = None
+                              ) -> Optional[List[str]]:
     if not requirements:
         return None
-    # direct path alleviates need to activate
-    cmd = [f'{tmp_dir}/bin/pip', 'install']
-    return cmd + requirements
+
+    if connection_id:
+        con: Connection = BaseHook.get_connection(connection_id)
+        user = con.login
+        schema = con.schema or 'https'
+        password = con.get_password()
+        port = con.port or ''
+        host = con.host
+        path = con.extra_dejson.get('path', '')
+        pypi_as_fallback = con.extra_dejson.get('pypi_as_fallback', False)
+
+        if user:
+            netloc = f'{user}:{password}@{host}'
+        else:
+            netloc = host
+
+        netloc = netloc + f':{port}' if port else netloc
+
+        index_url = SplitResult(scheme=schema,
+                                netloc=netloc, path=path, query='', 
fragment='').geturl()
+
+        private_cmd = [f'{tmp_dir}/bin/pip',
+                       'install',
+                       f'--index-url', index_url]
+
+        if pypi_as_fallback:
+            private_cmd.extend([f'--extra-index-url', 
'https://pypi.org/simple'])

Review comment:
       Se my comment here: 
https://github.com/apache/airflow/pull/16954#discussion_r669168968
   
   If you must allow PyPI, set PyPI as the main index, not an extra index. This 
does not do what most people think it does.
   
   Also I would avoid using the term “fallback” since it gives an impression 
PyPI is only accessed if a package is not available on the private index. That 
is wrong. Something like `allow_pypi` would be better (although I still 
strongly prefer not having this option at all).




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to