Skip to content

Commit

Permalink
Implement usethis version (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjmcdougall authored Jan 11, 2025
1 parent 32e8a90 commit fa9926b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center">
<img src="doc/logo.svg"><br>
<img src="https://raw.githubusercontent.com/nathanjmcdougall/usethis-python/refs/heads/main/doc/logo.svg"><br>
</h1>

# usethis
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ source = "vcs"
"Releases" = "https://github.com/nathanjmcdougall/usethis-python/releases"
"Source Archive" = "https://github.com/nathanjmcdougall/usethis-python/archive/{commit_hash}.zip"

[tool.hatch.build.hooks.vcs]
version-file = "src/usethis/_version.py"

[tool.ruff]
line-length = 88

Expand Down Expand Up @@ -144,6 +147,7 @@ layers = [
]
containers = [ "usethis" ]
exhaustive = true
exhaustive_ignores = [ "_version" ]

[[tool.importlinter.contracts]]
name = "Integrations Modular Design"
Expand Down
1 change: 1 addition & 0 deletions src/usethis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_version.py
15 changes: 15 additions & 0 deletions src/usethis/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import typer

import usethis._interface.badge
Expand All @@ -10,6 +12,11 @@
from usethis._core.readme import add_readme
from usethis._tool import PreCommitTool, RuffTool

try:
from usethis._version import __version__
except ImportError:
__version__ = None

app = typer.Typer(
help=(
"Automate Python package and project setup tasks that are otherwise "
Expand Down Expand Up @@ -39,6 +46,14 @@ def readme(
add_pre_commit_badge()


@app.command(help="Display the version of usethis.")
def version() -> None:
if __version__ is not None:
print(__version__)
else:
sys.exit(1)


app(prog_name="usethis")


Expand Down

0 comments on commit fa9926b

Please sign in to comment.