cooperellidge opened a new issue, #41740:
URL: https://github.com/apache/airflow/issues/41740
### Apache Airflow version
2.10.0
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
I do not get IDE features (LSP stuff) when using
PythonVirtualEnvironmentOperator.
```python
from airflow import DAG
from airflow.decorators import task
from airflow.utils.dates import days_ago
# My IDE has Airflow venv activated to get these top-level imports to be
recognised.
# After activating a fresh new Airflow venv, I use this to install
dependencies
# ```pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint
"${CONSTRAINT_URL}" virtualenv```
with DAG(
"do_something_in_virtual_env",
start_date=days_ago(1),
) as dag:
@task.virtualenv(
task_id="do_something",
requirements=["sqlalchemy==2.*", "scipy"],
)
def do_something() -> None:
import sqlalchemy # v1.4.53 is installed in Airflow venv, but I am
asking for v2.0.32 in this task's venv
import scipy # I don't have scipy installed in Airflow venv, but do
in this task's venv
# ^^^ I get a "Import "scipy" could not be resolved" error
print(sqlalchemy.__version__) # I have auto-complete but for v1:
outputs 2.0.32
print(scipy.__version__) # I have auto-complete but for v1: outputs
1.14.1
# ^^^ I don't get any IDE features for scipy.
do_something()
```
I ran into this use case specifically because a package I require depends on
SQLAlchemy >= 2 so I need to run the task in a virtual environment.
### What you think should happen instead?
I don't actually know how this could even be solved, as my IDE can only have
1 active virtual environment.
I am mostly wondering what the community's solution to getting IDE features
working when using `PythonVirtualEnvironmentOperator`.
### How to reproduce
1. Install Airflow 2.10.0 with constraints file and `virtualenv`
2. Add the above DAG
3. Run `airflow standalone`
4. Manually run the DAG
Inspecting the logs shows successfully setup of the virtual environment and
the expected package versions being printed.
Additionally a pip list in the Airflow virtual environment shows the
expected package versions too.
However, my IDE (vscode) cannot provide LSP features in the task definition
for the task's virtual environment.
### Operating System
Ubuntu
### Versions of Apache Airflow Providers
_No response_
### Deployment
Other
### Deployment details
Just playing around locally with airflow standalone.
### Anything else?
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]