Skip to content

Commit

Permalink
chore(version): manage string in pyproject
Browse files Browse the repository at this point in the history
app code reads dynamically from installed package version
  • Loading branch information
thekaveman committed Sep 21, 2023
1 parent ce9ab58 commit c72185b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 7 additions & 1 deletion hashfields/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
__version__ = "2023.09.1"
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("hashfields")
except PackageNotFoundError:
# package is not installed
pass
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "hashfields"
dynamic = ["version"]
version = "2023.09.1"
description = "Selectively hash, drop, or keep fields from a flat file (e.g. CSV)."
readme = "README.md"
license = { file = "LICENSE" }
Expand Down Expand Up @@ -36,7 +36,7 @@ dist =[
hashfields = "hashfields.main:main"

[build-system]
requires = ["setuptools>=65", "setuptools-scm"]
requires = ["setuptools>=65", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
Expand All @@ -63,6 +63,3 @@ norecursedirs = [

[tool.setuptools]
packages = ["hashfields"]

[tool.setuptools.dynamic]
version = {attr = "hashfields.__version__"}
10 changes: 8 additions & 2 deletions tests/test_hashfields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import subprocess

import pytest
Expand All @@ -14,6 +15,13 @@ def hashfields():
return "hashfields"


def test_version():
from hashfields import __version__

assert __version__ is not None
assert re.match(r"\d{4}\.\d{1,2}\.\d+", __version__)


def test_hashfields_default(capfd, hashfields):
subprocess.call([hashfields])
capture = capfd.readouterr()
Expand Down Expand Up @@ -78,7 +86,6 @@ def test_hashfields_file(capfd, hashfields, source_file, expected_file):
assert normalize_output(capture.out) == expected


# skip test on windows because it reads files written for *nix OSes
def test_hashfields_skip_drop(capfd, hashfields):
source_file = "./tests/samples/small.csv"
expected_file = "./tests/samples/small.hashed.skip_sub.drop_type.csv"
Expand All @@ -91,7 +98,6 @@ def test_hashfields_skip_drop(capfd, hashfields):
assert normalize_output(capture.out) == expected


# skip test on windows because it reads files written for *nix OSes
@pytest.mark.parametrize(
("source_file", "expected_file"),
[
Expand Down

0 comments on commit c72185b

Please sign in to comment.