Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

### Added

- `using_uv()` for detecting UV projects


## [0.1.0] - 2025-02-07

Initial release
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ami

![PyPI - Version](https://img.shields.io/pypi/v/ami)
[![Codecov test
coverage](https://codecov.io/gh/briandconnelly/ami-py/branch/main/graph/badge.svg)](https://app.codecov.io/gh/briandconnelly/ami-py?branch=main)

`ami` (Am I...?) is a Python package that provides simple functions to detect various runtime environments and configurations.

## Requirements
Expand Down
2 changes: 2 additions & 0 deletions src/ami/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from .python import using_python_version
from .quarto import using_quarto
from .testing import using_pytest, using_tox
from .uv import using_uv
from .virtualenv import using_virtualenv
from .vscode import using_vscode

Expand Down Expand Up @@ -86,6 +87,7 @@
"using_solaris",
"using_tox",
"using_travis_ci",
"using_uv",
"using_virtualenv",
"using_vscode",
"using_windows",
Expand Down
15 changes: 15 additions & 0 deletions src/ami/uv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Module for detecting uv environments.
"""

from .envvar import using_envvar


def using_uv() -> bool:
"""
Check if running in a uv package or project environment

Returns:
bool: True if running in uv, False otherwise.
"""
return using_envvar("UV")
36 changes: 36 additions & 0 deletions tests/test_uv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Tests for the uv module.
"""

from typing import Any

import pytest

from ami.uv import using_uv


@pytest.fixture
def clean_env(monkeypatch: Any) -> None:
"""Remove UV variables from environment."""
monkeypatch.delenv("UV", raising=False)


@pytest.mark.parametrize(
"env_var,env_value,expected",
[
("UV", "1", True), # UV enabled
("UV", "", True), # Empty value
(None, None, False), # Not in UV
],
)
def test_using_uv(
clean_env: None,
monkeypatch: Any,
env_var: str | None,
env_value: str | None,
expected: bool,
) -> None:
"""Test UV detection."""
if env_var is not None and env_value is not None:
monkeypatch.setenv(env_var, env_value)
assert using_uv() is expected