-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
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 |
---|---|---|
|
@@ -96,7 +96,8 @@ def _setup_env(self) -> None: # noqa: C901 | |
cmd.append("-v") | ||
if package == "wheel": | ||
# need the package name here but we don't have the packaging infrastructure -> read from pyproject.toml | ||
project_file = self.core["tox_root"] / "pyproject.toml" | ||
root = self.package_root() | ||
project_file = root / "pyproject.toml" | ||
name = None | ||
if project_file.exists(): | ||
with project_file.open("rb") as file_handler: | ||
|
@@ -112,7 +113,14 @@ def _setup_env(self) -> None: # noqa: C901 | |
cmd.extend(("-p", self.env_version_spec())) | ||
|
||
show = self.options.verbosity > 2 # noqa: PLR2004 | ||
outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=show) | ||
cwd = self.package_root() | ||
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. Should be |
||
outcome = self.execute( | ||
cmd, | ||
stdin=StdinSource.OFF, | ||
run_id="uv-sync", | ||
show=show, | ||
cwd=cwd, | ||
) | ||
outcome.assert_success() | ||
if install_pkg is not None: | ||
path = Path(install_pkg) | ||
|
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 | ||
|
@@ -310,6 +311,18 @@ def _py_info(self) -> PythonInfo: # pragma: win32 no cover | |
extra={}, | ||
) | ||
|
||
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. |
||
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. |
||
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.