beeware / beeware/briefcase

External Packages with `data_files` are not correctly working (eg. with `pydevd-pycharm`)

Open
#2,152 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
3.3k
Forks
549
Avg merge
1d 4h
Merged PRs (30d)
40

Description

### Describe the bug

To debug a packaged application with PyCharm, the package [`pydevd-pycharm`](https://pypi.org/project/pydevd-pycharm/) must be used. I can use it via `briefcase dev` without any problems. However, when I run `briefcase run` I get the following error:

```
Traceback (most recent call last):
File "\app\helloworld\__main__.py", line 4, in
main().main_loop()
~~~~^^
File "\app\helloworld\app.py", line 194, in main
start_debugger()
~~~~~~~~~~~~~~^^
File "\app\helloworld\app.py", line 133, in start_debugger
import pydevd_pycharm
File "\app_packages\pydevd_pycharm.py", line 3, in
from pydevd import settrace, stoptrace
File "\app_packages\pydevd.py", line 16, in
from _pydevd_bundle.pydevd_collect_try_except_info import collect_return_info
ModuleNotFoundError: No module named '_pydevd_bundle.pydevd_collect_try_except_info'
```

If you compare the `_pydevd_bundle` folder of the virtual environment (`.venv\Lib\site-packages\_pydevd_bundle`) used by `briefcase dev` with the one from the packaged application (`build\helloworld\windows\app\src\app_packages\_pydevd_bundle`) used by `briefcase run`, you can see that many `.py` files are missing in the packaged application. There is only the data in the packaged application that is available in the virtual environment under (`.venv\_pydevd_bundle`), which is only the [`data_files`](https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#data-files).

This is due to a bug in the combination of the pip parameters `--target=` in combination with `--upgrade`, which are used [here](https://github.com/beeware/briefcase/blob/135e22ba9787c5bdc9157035f8069d4e8c3a1761/src/briefcase/commands/create.py#L604) by briefcase. There is already a [ticket in the pip repo](https://github.com/pypa/pip/issues/8799) for this.

I have temporary removed `--upgrade` at the position in briefcase and then it works as desired. Maybe it is a possibility to remove the `--upgrade` option from briefcase completely?

### Steps to reproduce

1. Follow the [BeeWare tutorial](https://docs.beeware.org/en/latest/index.html)
2. Add `pydevd-pycharm~=243.23654.177` to `requires` in `pyproject.toml`
3. Add the following to your code:

```python
import pydevd_pycharm
pydevd_pycharm.settrace("localhost", port=5678, stdoutToServer=True, stderrToServer=True, suspend=False)
```

4. Run `briefcase run`

### Expected behavior

Importing `pydevd_pycharm` should work.

### Screenshots

_No response_

### Environment

- Operating System: Windows 11
- Python version: 3.13
- PyCharm 2024.3.2 (Professional Edition)
- Software versions:
- Briefcase: 0.3.21

### Logs

```

```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in src/briefcase/commands/create.py at the pip invocation linked in the issue, then reproduce with pydevd-pycharm and compare the virtual-environment and packaged _pydevd_bundle files. Investigate the interaction between --target and --upgrade, using the linked pip issue for context. Done means briefcase run can import pydevd_pycharm with its data_files package contents intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.