Skip to content

Commit fa9926b

Browse files
Implement usethis version (#165)
1 parent 32e8a90 commit fa9926b

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1 align="center">
2-
<img src="doc/logo.svg"><br>
2+
<img src="https://raw.githubusercontent.com/nathanjmcdougall/usethis-python/refs/heads/main/doc/logo.svg"><br>
33
</h1>
44

55
# usethis

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ source = "vcs"
7070
"Releases" = "https://github.com/nathanjmcdougall/usethis-python/releases"
7171
"Source Archive" = "https://github.com/nathanjmcdougall/usethis-python/archive/{commit_hash}.zip"
7272

73+
[tool.hatch.build.hooks.vcs]
74+
version-file = "src/usethis/_version.py"
75+
7376
[tool.ruff]
7477
line-length = 88
7578

@@ -144,6 +147,7 @@ layers = [
144147
]
145148
containers = [ "usethis" ]
146149
exhaustive = true
150+
exhaustive_ignores = [ "_version" ]
147151

148152
[[tool.importlinter.contracts]]
149153
name = "Integrations Modular Design"

src/usethis/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_version.py

src/usethis/__main__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import typer
24

35
import usethis._interface.badge
@@ -10,6 +12,11 @@
1012
from usethis._core.readme import add_readme
1113
from usethis._tool import PreCommitTool, RuffTool
1214

15+
try:
16+
from usethis._version import __version__
17+
except ImportError:
18+
__version__ = None
19+
1320
app = typer.Typer(
1421
help=(
1522
"Automate Python package and project setup tasks that are otherwise "
@@ -39,6 +46,14 @@ def readme(
3946
add_pre_commit_badge()
4047

4148

49+
@app.command(help="Display the version of usethis.")
50+
def version() -> None:
51+
if __version__ is not None:
52+
print(__version__)
53+
else:
54+
sys.exit(1)
55+
56+
4257
app(prog_name="usethis")
4358

4459

0 commit comments

Comments
 (0)