Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
41761ff
First draft of adding --backend flag to the usethis tool interface
nathanjmcdougall Jun 29, 2025
d11eb0c
Tweak backend selection logic to check whether uv is available.
nathanjmcdougall Jun 30, 2025
75f78a1
Move tests to reflect new package structure
nathanjmcdougall Jun 30, 2025
80ceaf2
Remove duplicated `Test` in `TestOpinionatedUVInit` name
nathanjmcdougall Jun 30, 2025
3f853e5
Revert to importing module to pass mocked tests
nathanjmcdougall Jun 30, 2025
b6a10ad
Add tests for `is_uv_available` and for `get_backend`
nathanjmcdougall Jun 30, 2025
01a6d15
Move tests module to reflect package restructure
nathanjmcdougall Jun 30, 2025
151d45a
Test `add_default_groups` for the `backend=BackendEnum.none` case
nathanjmcdougall Jun 30, 2025
e538536
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 12, 2025
7efdca7
Remove empty file
nathanjmcdougall Jul 12, 2025
8075131
Add some tests to the deps module
nathanjmcdougall Jul 12, 2025
aa25d60
Document `ForbiddenBackendError` in docstring to `call_uv_subprocess`
nathanjmcdougall Jul 12, 2025
013bcee
Add `--backend` option to all interfaces where it makes sense
nathanjmcdougall Jul 12, 2025
47583a4
Fix broken test
nathanjmcdougall Jul 12, 2025
d9612b6
Remove disclaimers regarding uv-centrism
nathanjmcdougall Jul 12, 2025
d844616
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 12, 2025
f968dd4
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 12, 2025
bc5c591
Bump pyright from v1.1.399 -> v1.1.403
nathanjmcdougall Jul 12, 2025
ff4e343
Merge branch 'maint/bump-pyright' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 12, 2025
31bec7f
Add some tests for the none backend when using requirements.txt
nathanjmcdougall Jul 12, 2025
388c570
Implement `get_project_deps` and tests
nathanjmcdougall Jul 14, 2025
96e63bb
Implement `Dependency.to_requirements_string`
nathanjmcdougall Jul 16, 2025
2d2768b
Use `Dependency.to_requirements_string()` in `Dependency.__str__`
nathanjmcdougall Jul 16, 2025
54429b6
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 16, 2025
df11275
Merge branch '850-a-method-on-the-dependency-object-to-display-it-as-…
nathanjmcdougall Jul 16, 2025
9f03084
Merge branch '849-a-method-to-read-in-the-project-dependencies-from-p…
nathanjmcdougall Jul 16, 2025
63e6fb6
Remove duplicated code for `get_project_deps`
nathanjmcdougall Jul 16, 2025
fa6e9a5
Fix broken references and rename `to_requirements_string` to `to_requ…
nathanjmcdougall Jul 16, 2025
ad254a5
Use `get_backend()` in `use_requirements_txt`
nathanjmcdougall Jul 16, 2025
7dd08db
Create correct requirements file using none backend
nathanjmcdougall Jul 16, 2025
8087c64
Generate expected messages for `use_requirements_txt` with none backend
nathanjmcdougall Jul 16, 2025
5c4651a
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 16, 2025
928afbe
Refactor to create abstract project init functions, making it backend…
nathanjmcdougall Jul 16, 2025
8bf38df
Collate UI modules into their own layer
nathanjmcdougall Jul 16, 2025
b392f11
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 18, 2025
e73c504
Fix recursion issue in `ensure_pyproject_toml` by dispatching to `ens…
nathanjmcdougall Jul 22, 2025
caf7d26
Update test to reflect new uv-detection heuristics
nathanjmcdougall Jul 22, 2025
eff331f
Skip test on rate limits
nathanjmcdougall Jul 22, 2025
6727487
Catch exceptions in failing tests' CLI invocation
nathanjmcdougall Jul 22, 2025
ac0563d
Support none backend in `ensure_pyproject_toml`
nathanjmcdougall Jul 22, 2025
0664716
Simplify instructions for checking `uv` version in README
nathanjmcdougall Jul 22, 2025
8bfbdba
Fix issue with missing directory when subprocessing uv.
nathanjmcdougall Jul 22, 2025
175cf8b
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 22, 2025
bedf92e
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 22, 2025
e6f6b80
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 23, 2025
ae6ed04
Add failing test `TestProjectInit.test_none_backend` in `tests\usethi…
nathanjmcdougall Jul 23, 2025
4f64844
Add `project_init` implementation for none backend
nathanjmcdougall Jul 23, 2025
4955525
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 23, 2025
d121bd3
Fix broken imports for re-homed test
nathanjmcdougall Jul 23, 2025
4250023
Sync README with docs
nathanjmcdougall Jul 23, 2025
5ffbb98
Rename uv+python integration functions for clarity
nathanjmcdougall Jul 23, 2025
aa04be4
Support none backend in `install_pre_commit_hooks`
nathanjmcdougall Jul 23, 2025
de2bc64
Support none backend in `uninstall_pre_commit_hooks`
nathanjmcdougall Jul 23, 2025
ad36f84
Test all interfaces, add missing backend pass-through
nathanjmcdougall Jul 23, 2025
9f605c9
Fix broken header in reference.md
nathanjmcdougall Jul 23, 2025
23d6359
Fix file manager issues in tests
nathanjmcdougall Jul 23, 2025
084e5c4
Fix backend flag for `usethis status`
nathanjmcdougall Jul 23, 2025
cfc903a
Don't create README in `use_ci_bitbucket`
nathanjmcdougall Jul 23, 2025
2982eb3
Don't eagerly create `pyproject.toml` in `usethis tool codespell`
nathanjmcdougall Jul 23, 2025
8b84ca3
Break up the complexity of `Tool.add_configs` with a new helper method
nathanjmcdougall Jul 25, 2025
b6c88b6
Don't overwrite an alert-only state in `Tool.add_configs` and `RuffTo…
nathanjmcdougall Jul 25, 2025
7797773
Display message when creating input files when adding config
nathanjmcdougall Jul 29, 2025
eb94f3a
Merge branch 'main' into 241-flag-to-avoid-calling-uv
nathanjmcdougall Jul 29, 2025
f698950
Pass `test_none_backend` tests
nathanjmcdougall Jul 29, 2025
12ba8a9
Change test to reflect new behaviour
nathanjmcdougall Jul 29, 2025
4c46aee
Respect backend in print-how-to-use messages
nathanjmcdougall Aug 1, 2025
94cddf6
Don't use bitwise operators to avoid confusion
nathanjmcdougall Aug 1, 2025
609e670
rework `is_uv_used` for robustness
nathanjmcdougall Aug 1, 2025
e3aa6e5
Refactor `add_configs` for clarity
nathanjmcdougall Aug 1, 2025
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
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ usethis gives detailed messages about what it is doing (and what you need to do

Inspired by an [**R** package of the same name](https://usethis.r-lib.org/index.html), this package brings a similar experience to the Python ecosystem as a CLI tool.

> [!TIP]
> usethis is great for fresh projects using [uv](https://docs.astral.sh/uv), but also supports updating existing projects. However, this should be considered experimental. If you encounter problems or have feedback, please [open an issue](https://github.com/usethis-python/usethis-python/issues/new?template=idea.md).

## Highlights

- 🧰 First-class support for state-of-the-practice tooling: uv, Ruff, pytest, pre-commit, and many more.
Expand All @@ -40,10 +37,7 @@ Inspired by an [**R** package of the same name](https://usethis.r-lib.org/index.
## 🧭 Getting Started

First, it is strongly recommended you [install the uv package manager](https://docs.astral.sh/uv/getting-started/installation/): this is a simple, documented process. If you're already using uv, make sure you're using at least
version v0.6.8. To check this, run `uv self version` to check (if available, otherwise `uv version`), and run `uv self update` to upgrade.

> [!TIP]
> At the moment, usethis assumes you will have uv installed in some circumstances. Support for projects that don't use uv is planned for late 2025.
version v0.6.8 (run `uv --version` to check, and `uv self update` to upgrade).

You can install usethis directly into the project environment:

Expand Down Expand Up @@ -189,9 +183,8 @@ If you're using Cookiecutter, then you can update to a latest version of a templ

Major features planned for later in 2025 are:

- Support for users who aren't using uv, e.g. poetry users,
- Support for automated GitHub Actions workflows ([#57](https://github.com/usethis-python/usethis-python/issues/57)), and
- Support for a typechecker (likely Pyright, [#121](https://github.com/usethis-python/usethis-python/issues/121)).
- Support for automated GitHub Actions workflows ([#57](https://github.com/usethis-python/usethis-python/issues/57)),
- Support for a typechecker (likely Pyright, [#121](https://github.com/usethis-python/usethis-python/issues/121)), and

Other features are tracked in the [GitHub Issues](https://github.com/usethis-python/usethis-python/issues) page.

Expand Down
59 changes: 57 additions & 2 deletions docs/cli/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--quiet` to suppress output
- `--frozen` to leave the virtual environment and lockfile unchanged (i.e. do not install dependencies, nor update lockfiles)
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

## `usethis doc`

Expand Down Expand Up @@ -78,6 +83,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--frozen` to leave the virtual environment and lockfile unchanged
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

See [`usethis tool`](#usethis-tool) for more information.

Expand All @@ -98,6 +108,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--frozen` to leave the virtual environment and lockfile unchanged
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

See [`usethis tool`](#usethis-tool) for more information.

Expand All @@ -118,6 +133,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--frozen` to leave the virtual environment and lockfile unchanged
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

See [`usethis tool`](#usethis-tool) for more information.

Expand All @@ -138,6 +158,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--frozen` to leave the virtual environment and lockfile unchanged
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

See [`usethis tool`](#usethis-tool) for more information.

Expand Down Expand Up @@ -183,6 +208,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--frozen` to leave the virtual environment and lockfile unchanged
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

For `usethis tool ruff`, in addition to the above options, you can also specify:

Expand All @@ -203,6 +233,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--quiet` to suppress output
- `--frozen` to leave the virtual environment and lockfile unchanged (i.e. do not install dependencies, nor update lockfiles)
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

## `usethis badge`

Expand All @@ -229,8 +264,13 @@ Add a README.md file to the project.

Supported options:

- `--quiet` to suppress output
- `--badges` to also add badges to the README.md file
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

## `usethis author`

Expand All @@ -245,6 +285,11 @@ Other supported options:
- `--email` to set the author email address
- `--overwrite` to overwrite all existing author information
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

## `usethis docstyle <style>`

Expand All @@ -267,6 +312,11 @@ Supported options:
- `--offline` to disable network access and rely on caches
- `--quiet` to suppress output
- `--frozen` to leave the virtual environment and lockfile unchanged (i.e. do not install dependencies, nor update lockfiles)
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

## `usethis rule <rulecode>`

Expand All @@ -286,6 +336,11 @@ Supported options:
- `--ignore` to add the rule to the ignore list (or remove it if --remove is specified).
- `--offline` to disable network access and rely on caches
- `--quiet` to suppress output
- `--backend` to specify a package manager backend to use. The default is to auto-detect.
Possible values:
- `auto` to auto-detect the backend (default)
- `uv` to use the [uv](https://docs.astral.sh/uv) package manager
- `none` to not use a package manager backend and display messages for some operations.

## `usethis status <status>`

Expand All @@ -303,8 +358,8 @@ Possible values (required):

Supported options:

- `--quiet` to suppress output
- `--badges` to add an associated badge to the README file
- `--quiet` to suppress output

## `usethis list`

Expand Down
4 changes: 1 addition & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# 🧭 Getting Started

First, it is strongly recommended you [install the uv package manager](https://docs.astral.sh/uv/getting-started/installation/): this is a simple, documented process. If you're already using uv, make sure you're using at least
version v0.6.8. To check this, run `uv self version` to check (if available, otherwise `uv version`), and run `uv self update` to upgrade.

At the moment, usethis assumes you will have uv installed in some circumstances. Support for projects that don't use uv is planned for late 2025.
version v0.6.8 (run `uv --version` to check, and `uv self update` to upgrade).

You can install usethis directly into the project environment:

Expand Down
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ usethis gives detailed messages about what it is doing (and what you need to do

Inspired by an [**R** package of the same name](https://usethis.r-lib.org/index.html), this package brings a similar experience to the Python ecosystem as a CLI tool.

usethis is great for fresh projects using [uv](https://docs.astral.sh/uv), but also supports updating existing projects. However, this should be considered experimental. If you encounter problems or have feedback, please [open an issue](https://github.com/usethis-python/usethis-python/issues/new?template=idea.md).

## Highlights

- 🧰 First-class support for state-of-the-practice tooling: uv, Ruff, pytest, pre-commit, and many more.
Expand Down
37 changes: 26 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,29 +183,35 @@ name = "usethis"
type = "layers"
layers = [
"_test | __main__",
"_app",
"_interface",
"_options",
"_ui",
# Tool implementations
"_toolset",
"_core",
"_tool",
# Specific config file and backend implementations
"_deps | _init",
"_config_file",
"_integrations",
"_io | _pipeweld | _subprocess | _console",
"_config | errors",
"_io | _subprocess | _console",
# Global state and constants
"_config",
"_types | errors",
# Completely independent helper modules
"_pipeweld",
]
containers = [ "usethis" ]
exhaustive = true
exhaustive_ignores = [ "_version" ]

[[tool.importlinter.contracts]]
name = "usethis._interface"
name = "usethis._ui"
type = "layers"
layers = [
# Note; if you're adding an interface, make sure it's in the README too.
"author | badge | browse | ci | doc | docstyle | format_ | init | lint | list | readme | rule | show | spellcheck | status | test | tool | version",
"app",
"interface",
"options",
]
containers = [ "usethis._interface" ]
containers = [ "usethis._ui" ]
exhaustive = true

[[tool.importlinter.contracts]]
Expand All @@ -215,7 +221,6 @@ layers = [
# docstyle uses (Ruff) tool, badge uses readme
"badge | docstyle | list | rule",
"author | browse | ci | readme | show | status | tool",
"enums",
]
containers = [ "usethis._core" ]
exhaustive = true
Expand Down Expand Up @@ -250,7 +255,7 @@ name = "usethis._integrations"
type = "layers"
layers = [
"ci | pre_commit",
"uv | mkdocs | pytest | pydantic | sonarqube",
"backend | mkdocs | pytest | pydantic | sonarqube",
"project | python",
"file",
]
Expand All @@ -268,6 +273,16 @@ layers = [
containers = [ "usethis._integrations.file" ]
exhaustive = true

[[tool.importlinter.contracts]]
name = "usethis._ui.interface"
type = "layers"
layers = [
# Note; if you're adding an interface, make sure it's in the README too.
"author | badge | browse | ci | doc | docstyle | format_ | init | lint | list | readme | rule | show | spellcheck | status | test | tool | version",
]
containers = [ "usethis._ui.interface" ]
exhaustive = true

[[tool.importlinter.contracts]]
name = "usethis._pipeweld"
type = "layers"
Expand Down
2 changes: 1 addition & 1 deletion src/usethis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from usethis._app import app
from usethis._ui.app import app

app(prog_name="usethis")

Expand Down
37 changes: 17 additions & 20 deletions src/usethis/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
from pathlib import Path
from typing import TYPE_CHECKING

from usethis._types.backend import BackendEnum

if TYPE_CHECKING:
from collections.abc import Generator


HOW_DEFAULT = False
REMOVE_DEFAULT = False
FROZEN_DEFAULT = False
OFFLINE_DEFAULT = False
QUIET_DEFAULT = False
BACKEND_DEFAULT = "auto"


@dataclass
Expand All @@ -24,7 +28,8 @@ class UsethisConfig:
quiet: Suppress all output, regardless of any other options.
frozen: Do not install dependencies, nor update lockfiles.
alert_only: Suppress all output except for warnings and errors.
disable_uv_subprocess: Raise an error if a uv subprocess invocation is tried.
backend: The package manager backend to use. Attempted subprocesses to other
backends will raise an error.
disable_pre_commit: Disable pre-commit integrations. Assume that pre-commit is
never used (unless explicitly requested via a function whose
purpose is to modify pre-commit configuration).
Expand All @@ -33,11 +38,11 @@ class UsethisConfig:
working directory dynamically determined at runtime.
"""

offline: bool = False
quiet: bool = False
frozen: bool = False
offline: bool = OFFLINE_DEFAULT
quiet: bool = QUIET_DEFAULT
frozen: bool = FROZEN_DEFAULT
alert_only: bool = False
disable_uv_subprocess: bool = False
backend: BackendEnum = BackendEnum(BACKEND_DEFAULT) # noqa: RUF009
disable_pre_commit: bool = False
subprocess_verbose: bool = False
project_dir: Path | None = None
Expand All @@ -50,7 +55,7 @@ def set( # noqa: PLR0913
quiet: bool | None = None,
frozen: bool | None = None,
alert_only: bool | None = None,
disable_uv_subprocess: bool | None = None,
backend: BackendEnum | None = None,
disable_pre_commit: bool | None = None,
subprocess_verbose: bool | None = None,
project_dir: Path | str | None = None,
Expand All @@ -60,7 +65,7 @@ def set( # noqa: PLR0913
old_quiet = self.quiet
old_frozen = self.frozen
old_alert_only = self.alert_only
old_disable_uv_subprocess = self.disable_uv_subprocess
old_backend = self.backend
old_disable_pre_commit = self.disable_pre_commit
old_subprocess_verbose = self.subprocess_verbose
old_project_dir = self.project_dir
Expand All @@ -73,8 +78,8 @@ def set( # noqa: PLR0913
frozen = old_frozen
if alert_only is None:
alert_only = self.alert_only
if disable_uv_subprocess is None:
disable_uv_subprocess = old_disable_uv_subprocess
if backend is None:
backend = self.backend
if disable_pre_commit is None:
disable_pre_commit = old_disable_pre_commit
if subprocess_verbose is None:
Expand All @@ -86,7 +91,7 @@ def set( # noqa: PLR0913
self.quiet = quiet
self.frozen = frozen
self.alert_only = alert_only
self.disable_uv_subprocess = disable_uv_subprocess
self.backend = backend
self.disable_pre_commit = disable_pre_commit
self.subprocess_verbose = subprocess_verbose
if isinstance(project_dir, str):
Expand All @@ -97,7 +102,7 @@ def set( # noqa: PLR0913
self.quiet = old_quiet
self.frozen = old_frozen
self.alert_only = old_alert_only
self.disable_uv_subprocess = old_disable_uv_subprocess
self.backend = old_backend
self.disable_pre_commit = old_disable_pre_commit
self.subprocess_verbose = old_subprocess_verbose
self.project_dir = old_project_dir
Expand All @@ -109,12 +114,4 @@ def cpd(self) -> Path:
return self.project_dir


usethis_config = UsethisConfig(
offline=OFFLINE_DEFAULT,
quiet=QUIET_DEFAULT,
frozen=FROZEN_DEFAULT,
alert_only=False,
disable_uv_subprocess=False,
disable_pre_commit=False,
subprocess_verbose=False,
)
usethis_config = UsethisConfig()
Loading
Loading