-
-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Support custom package root #226
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
base: main
Are you sure you want to change the base?
Changes from all commits
1a30032
e178b1a
55d3b76
2622838
6964a0c
de7401f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ __pycache__ | |
/build | ||
dist | ||
src/tox_uv/version.py | ||
|
||
uv.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import sys | ||
import sysconfig | ||
from abc import ABC | ||
from configparser import ConfigParser | ||
from functools import cached_property | ||
from importlib.resources import as_file, files | ||
from pathlib import Path | ||
|
@@ -309,6 +310,19 @@ def _py_info(self) -> PythonInfo: # pragma: win32 no cover | |
extra={}, | ||
) | ||
|
||
@cached_property | ||
def package_root(self) -> Path: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a cached property. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
try: | ||
return self.core["package_root"] | ||
except KeyError: | ||
config = self.core["tox_root"] / "tox.ini" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a lot more, than just ini, like toml and various other file sources we support. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. How do you suggest to handle this? Is there an utility or example in the project? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we doing this entire dance? Why not just use |
||
if config.is_file(): | ||
parser = ConfigParser() | ||
parser.read(config) | ||
if parser.has_section("tox") and parser.has_option("tox", "setupdir"): | ||
return self.core["tox_root"] / parser.get("tox", "setupdir") | ||
return self.core["tox_root"] | ||
|
||
|
||
__all__ = [ | ||
"UvVenv", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from tox.pytest import ToxProjectCreator | ||
|
||
|
||
def test_setupdir_respected(tox_project: ToxProjectCreator) -> None: | ||
project = tox_project({ | ||
"tox.ini": """ | ||
[tox] | ||
skipsdist = true | ||
setupdir = src | ||
env_list = py | ||
[testenv] | ||
runner = uv-venv-runner | ||
commands = python -c 'print("hello")' | ||
""", | ||
"src": { | ||
"pyproject.toml": """ | ||
[project] | ||
name = 'demo' | ||
version = '0' | ||
""", | ||
}, | ||
}) | ||
result = project.run("-e", "py") | ||
result.assert_success() | ||
|
||
|
||
def test_setupdir_with_package_root(tox_project: ToxProjectCreator) -> None: | ||
project = tox_project({ | ||
"tox.ini": """ | ||
[tox] | ||
skipsdist = true | ||
setupdir = src | ||
env_list = py | ||
[testenv] | ||
runner = uv-venv-runner | ||
package_root = src | ||
commands = python -c 'print("hello")' | ||
""", | ||
"pyproject.toml": "", | ||
"src": { | ||
"pyproject.toml": """ | ||
[project] | ||
name = 'demo' | ||
version = '0' | ||
""", | ||
}, | ||
}) | ||
result = project.run("-e", "py") | ||
result.assert_success() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really want to publicize
setupdir
, ratherpackage_root
is what we should only advertise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, good point. Maybe at this point is too much to indicate this on
README.md
considering that people would expect consistency onpackage_root
usage?