-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create UsethisConfig class, enable pyright, refactor handling off bei…
…ng offline (#91) * Create UsethisConfig class, enable pyright, refactor handling off being offline * Rename "Source Archive" URL config for aesthetics. * Pass failing test * Better handling of being offline in `test_max_major_py3` * Run online tests first before offline tests
- Loading branch information
1 parent
54c3798
commit c1d09e6
Showing
22 changed files
with
326 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ requires = [ "hatch-vcs", "hatchling" ] | |
name = "usethis" | ||
description = "Automate Python project setup and development tasks that are otherwise performed manually." | ||
readme = "README.md" | ||
keywords = ["usethis", "project", "init", "setup", "start"] | ||
keywords = [ "init", "project", "setup", "start", "usethis" ] | ||
license = { file = "LICENSE" } | ||
authors = [ | ||
{ name = "Nathan McDougall", email = "[email protected]" }, | ||
|
@@ -48,6 +48,7 @@ dev = [ | |
"import-linter>=2.1", | ||
"pre-commit>=4.0.1", | ||
"pyproject-fmt>=2.4.3", | ||
"pyright>=1.1.387", | ||
"ruff>=0.7.1", | ||
] | ||
test = [ | ||
|
@@ -66,13 +67,14 @@ source = "vcs" | |
"Source Code" = "https://github.com/nathanjmcdougall/usethis-python" | ||
"Bug Tracker" = "https://github.com/nathanjmcdougall/usethis-python/issues" | ||
"Releases" = "https://github.com/nathanjmcdougall/usethis-python/releases" | ||
"source_archive" = "https://github.com/nathanjmcdougall/usethis-python/archive/{commit_hash}.zip" | ||
"Source Archive" = "https://github.com/nathanjmcdougall/usethis-python/archive/{commit_hash}.zip" | ||
|
||
[tool.ruff] | ||
line-length = 88 | ||
|
||
src = [ "src" ] | ||
lint.select = ["C4", "E4", "E7", "E9", "F", "FURB", "I", "PLE", "PLR", "RUF", "SIM", "UP", "PT"] | ||
lint.select = [ "C4", "E4", "E7", "E9", "F", "FURB", "I", "PLE", "PLR", "PT", "RUF", "SIM", "UP" ] | ||
lint.ignore = ["PT004", "PT005"] | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = [ "tests" ] | ||
|
@@ -99,6 +101,7 @@ layers = [ | |
"_tool", | ||
"_integrations", | ||
"_console", | ||
"_config", | ||
"_utils", | ||
] | ||
containers = [ "usethis" ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from collections.abc import Generator | ||
from contextlib import contextmanager | ||
|
||
import typer | ||
from pydantic import BaseModel | ||
|
||
_OFFLINE_DEFAULT = False | ||
_QUIET_DEFAULT = False | ||
|
||
offline_opt = typer.Option(_OFFLINE_DEFAULT, "--offline", help="Disable network access") | ||
quiet_opt = typer.Option(_QUIET_DEFAULT, "--quiet", help="Suppress output") | ||
|
||
|
||
class UsethisConfig(BaseModel): | ||
"""Global-state for command options which affect low level behaviour.""" | ||
|
||
offline: bool | ||
quiet: bool | ||
|
||
@contextmanager | ||
def set(self, *, offline: bool, quiet: bool) -> Generator[None, None, None]: | ||
"""Temporarily set the console to quiet mode.""" | ||
self.offline = offline | ||
self.quiet = quiet | ||
yield | ||
self.offline = _OFFLINE_DEFAULT | ||
self.quiet = _QUIET_DEFAULT | ||
|
||
|
||
usethis_config = UsethisConfig(offline=_OFFLINE_DEFAULT, quiet=_QUIET_DEFAULT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,15 @@ | ||
from collections.abc import Generator | ||
from contextlib import contextmanager | ||
|
||
from pydantic import BaseModel | ||
from rich.console import Console | ||
|
||
typer_console = Console() | ||
|
||
|
||
class UsethisConsole(BaseModel): | ||
quiet: bool | ||
from usethis._config import usethis_config | ||
|
||
def tick_print(self, msg: str) -> None: | ||
if not self.quiet: | ||
typer_console.print(f"✔ {msg}", style="green") | ||
console = Console() | ||
|
||
def box_print(self, msg: str) -> None: | ||
if not self.quiet: | ||
typer_console.print(f"☐ {msg}", style="blue") | ||
|
||
@contextmanager | ||
def set(self, *, quiet: bool) -> Generator[None, None, None]: | ||
"""Temporarily set the console to quiet mode.""" | ||
self.quiet = quiet | ||
yield | ||
self.quiet = False | ||
def tick_print(msg: str) -> None: | ||
if not usethis_config.quiet: | ||
console.print(f"✔ {msg}", style="green") | ||
|
||
|
||
console = UsethisConsole(quiet=False) | ||
def box_print(msg: str) -> None: | ||
if not usethis_config.quiet: | ||
console.print(f"☐ {msg}", style="blue") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.