Skip to content

Commit

Permalink
Support major only Python environments and enable uv verbose mode on …
Browse files Browse the repository at this point in the history
…2 or more -v for tox

Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Feb 19, 2024
1 parent 194a908 commit fd80fa1
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 15 deletions.
45 changes: 45 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Bug report
about: Create a report to help us improve
title: ""
labels: bug
assignees: ""
---

## Issue

<!-- Describe what's the expected behavior and what you're observing. -->

## Environment

Provide at least:

- OS:

<details open>
<summary>Output of <code>pip list</code> of the host Python, where <code>tox</code> is installed</summary>

```console

```

</details>

## Output of running tox

<details open>
<summary>Output of <code>tox -rvv</code></summary>

```console

```

</details>

## Minimal example

<!-- If possible, provide a minimal reproducer for the issue. -->

```console

```
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ref: https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser
blank_issues_enabled: true # default
contact_links:
- name: 🤷💻🤦 Discussions
url: https://github.com/tox-dev/tox/discussions
about: |
Ask typical Q&A here. Please note that we cannot give support about Python packaging in general, questions about structuring projects and so on.
- name: 📝 PyPA Code of Conduct
url: https://www.pypa.io/en/latest/code-of-conduct/
about: ❤ Be nice to other members of the community. ☮ Behave.
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Feature request
about: Suggest an enhancement for this project
title: ""
labels: enhancement
assignees: ""
---

## What's the problem this feature will solve?

<!-- What are you trying to do, that you are unable to achieve with tox as it currently stands? -->

## Describe the solution you'd like

<!-- Clear and concise description of what you want to happen. -->

<!-- Provide examples of real world use cases that this would enable and how it solves the problem described above. -->

## Alternative Solutions

<!-- Have you tried to workaround the problem using tox or other tools? Or a different approach to solving this issue?
Please elaborate here. -->

## Additional context

<!-- Add any other context, links, etc. about the feature here. -->
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- "3.8"
os:
- ubuntu-latest
# - windows-latest # not yet supported
# - windows-latest
- macos-latest
steps:
- name: setup python for tox
Expand All @@ -50,7 +50,7 @@ jobs:
file_handler.write(env)
shell: python
- name: setup test suite
run: tox -vv --notest
run: tox -vvv --notest
- name: run test suite
run: tox --skip-pkg-install

Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ repos:
rev: "1.7.0"
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.12.1"]
additional_dependencies: ["tox>=4.13"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.2.1"
rev: "v0.2.2"
hooks:
- id: ruff-format
- id: ruff
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dynamic = [
]
dependencies = [
"tox<5,>=4.13",
"uv<1,>=0.1.2",
"uv<1,>=0.1.4",
]
optional-dependencies.test = [
"covdefaults>=2.3",
Expand Down Expand Up @@ -112,4 +112,4 @@ run.plugins = ["covdefaults"]
python_version = "3.11"
show_error_codes = true
strict = true
overrides = [{ module = ["virtualenv.*"], ignore_missing_imports = true }]
overrides = [{ module = ["virtualenv.*", "uv.*"], ignore_missing_imports = true }]
10 changes: 6 additions & 4 deletions src/tox_uv/_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from __future__ import annotations

import logging
import sys
from collections import defaultdict
from pathlib import Path
from typing import TYPE_CHECKING, Any, Sequence, cast

from packaging.requirements import Requirement
Expand All @@ -16,6 +14,7 @@
from tox.tox_env.python.package import EditableLegacyPackage, EditablePackage, SdistPackage, WheelPackage
from tox.tox_env.python.pip.pip_install import Pip
from tox.tox_env.python.pip.req_file import PythonDeps
from uv.__main__ import find_uv_bin # noqa: PLC2701

if TYPE_CHECKING:
from tox.config.main import Config
Expand All @@ -33,10 +32,13 @@ def _register_config(self) -> None:

@property
def uv(self) -> str:
return str(Path(sys.executable).parent / "uv")
return cast(str, find_uv_bin())

def default_install_command(self, conf: Config, env_name: str | None) -> Command: # noqa: ARG002
return Command([self.uv, "pip", "install", "{opts}", "{packages}"])
cmd = [self.uv, "pip", "install", "{opts}", "{packages}"]
if self._env.options.verbosity > 2: # noqa: PLR2004
cmd.append("-v")
return Command(cmd)

def post_process_install_command(self, cmd: Command) -> Command:
install_command = cmd.args
Expand Down
12 changes: 8 additions & 4 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tox.execute.local_sub_process import LocalSubProcessExecutor
from tox.execute.request import StdinSource
from tox.tox_env.python.api import Python, PythonInfo, VersionInfo
from uv.__main__ import find_uv_bin # noqa: PLC2701
from virtualenv.discovery.py_spec import PythonSpec

from ._installer import UvInstaller
Expand Down Expand Up @@ -90,7 +91,7 @@ def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: PLR

@property
def uv(self) -> str:
return str(Path(sys.executable).parent / "uv")
return cast(str, find_uv_bin())

@property
def venv_dir(self) -> Path:
Expand All @@ -103,12 +104,15 @@ def environment_variables(self) -> dict[str, str]:
return env

def create_python_env(self) -> None:
base = self.base_python
cmd = [self.uv, "venv", "-p", base.version_dot]
base = self.base_python.version_info
version_spec = f"{base.major}.{base.minor}" if base.minor else f"{base.major}"
cmd: list[str] = [self.uv, "venv", "-p", version_spec]
if self.options.verbosity > 2: # noqa: PLR2004
cmd.append("-v")
if self.conf["uv_seed"]:
cmd.append("--seed")
cmd.append(str(self.venv_dir))
outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="venv", show=False)
outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="venv", show=None)
outcome.assert_success()

@property
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def test_uv_venv_spec(tox_project: ToxProjectCreator) -> None:
result.assert_success()


def test_uv_venv_spec_major_only(tox_project: ToxProjectCreator) -> None:
ver = sys.version_info
project = tox_project({"tox.ini": f"[testenv]\npackage=skip\nbase_python={ver.major}"})
result = project.run("-vv")
result.assert_success()


def test_uv_venv_na(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[testenv]\npackage=skip\nbase_python=1.0"})
result = project.run("-vv")
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ commands =
description = run static analysis and style check using flake8
skip_install = true
deps =
pre-commit>=3.6.1
pre-commit>=3.6.2
pass_env =
HOMEPATH
PROGRAMDATA
Expand Down

0 comments on commit fd80fa1

Please sign in to comment.