Skip to content

Commit

Permalink
Set version dynamically in pyproject
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMili committed May 23, 2024
1 parent 0e471f4 commit 7ac538a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Read VERSION file
id: getversion
run: echo "version=$(cat VERSION.md)" >> $GITHUB_OUTPUT
run: echo "version=$(cat src/VERSION.md)" >> $GITHUB_OUTPUT

- name: Changelog
run: git log $(git describe --tags --abbrev=0)..HEAD --format="%s %h" > LATEST-CHANGES.md
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ build-backend = "hatchling.build"

[project]
name = "isvirtual"
version = "1.0.0"
description = "Detect if your script is running inside a virtual environment"
dynamic = ["version"]
readme = "README.md"
authors = [{ name = "Alex Mili" }]
license = { file = "LICENSE" }
Expand Down Expand Up @@ -39,4 +39,8 @@ Documentation = "https://github.com/AlexMili/isVirtual"
isvirtual = "main:is_virtual_env_cli"

[tool.hatch.build.targets.wheel]
packages = ["."]
packages = ["./src"]

[tool.hatch.version]
path = "src/VERSION.md"
pattern = "(?P<version>.*)"
File renamed without changes.
7 changes: 7 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os.path as osp

version_path = osp.join(osp.dirname(__file__), "VERSION.md")

if osp.exists(version_path):
with open(version_path, "r") as f:
__version__ = f.readline()
7 changes: 1 addition & 6 deletions main.py → src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
import os.path as osp
import sys

version_path = osp.join(osp.dirname(__file__), "VERSION.md")

if osp.exists(version_path):
with open(version_path, "r") as f:
__version__ = f.readline()

config = None


def is_virtual_env() -> str:
# The check for sys.real_prefix covers virtualenv, the equality of
# non-empty sys.base_prefix with sys.prefix covers venv.
Expand Down

0 comments on commit 7ac538a

Please sign in to comment.