Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage run breaks PYTHONSAFEPATH #1696

Open
flying-sheep opened this issue Nov 10, 2023 · 1 comment · May be fixed by #1700
Open

coverage run breaks PYTHONSAFEPATH #1696

flying-sheep opened this issue Nov 10, 2023 · 1 comment · May be fixed by #1700
Labels
bug Something isn't working

Comments

@flying-sheep
Copy link

flying-sheep commented Nov 10, 2023

Describe the bug
When executing coverage run -m ... with the environment variable PYTHONSAFEPATH=1 set, the working directory appears in sys.path

To Reproduce

Create the following two files

printpath.py

import sys
import json

print(json.dumps(sys.path))

pyproject.toml

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]

[project]
name = "printpath"
version = "0.0.1"
dependencies = ["coverage"]

[tool.hatch.envs.default]
dev-mode = false
[tool.hatch.envs.default.scripts]
printpath = ["PYTHONSAFEPATH=1 python -m printpath"]
printpath-cov = ["PYTHONSAFEPATH=1 coverage run -m printpath"]

then run

$ hatch run printpath
["/usr/lib/python311.zip", "/usr/lib/python3.11", "/usr/lib/python3.11/lib-dynload", "~/.local/share/hatch/env/virtual/printpath/1Fj_Wp0T/printpath/lib/python3.11/site-packages"]
$ hatch run printpath-cov
["~/Dev/Python/_reproducers/coverage-safepath", "/usr/lib/python3.11", "/usr/lib/python3.11/lib-dynload", "~/.local/share/hatch/env/virtual/printpath/1Fj_Wp0T/printpath/lib/python3.11/site-packages"]

Expected behavior
Both commands have the same output

@nedbat
Copy link
Owner

nedbat commented Nov 14, 2023

#1700 is a pull request in progress to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants