diff --git a/.gitignore b/.gitignore index 6e9b081..d1a68d9 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,9 @@ cython_debug/ # IDEs/editors *.sw* +# build version metadata +_version.py + # PyCharm # JetBrains specific template is maintained in a separate JetBrains.gitignore that can # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore diff --git a/gp2040ce_bintools/__init__.py b/gp2040ce_bintools/__init__.py index 143abe4..53ee1d0 100644 --- a/gp2040ce_bintools/__init__.py +++ b/gp2040ce_bintools/__init__.py @@ -8,9 +8,20 @@ import sys import grpc +# dynamically generate version number +try: + # packaged/pip install -e . value + from ._version import version as __version__ +except ImportError: + # local clone value + from setuptools_scm import get_version + __version__ = get_version(root='..', relative_to=__file__) + logger = logging.getLogger(__name__) +# parse flags that are common to many tools (e.g. adding paths for finding .proto files) core_parser = argparse.ArgumentParser(add_help=False) +core_parser.add_argument('-v', '--version', action='version', version=f"%(prog)s {__version__}") core_parser.add_argument('--proto-files-path', type=pathlib.Path, default=list(), action='append', help="path to .proto files to read, including dependencies; you will likely need " "to supply this twice, once for GP2040-CE's .proto files and once for nanopb's") diff --git a/gp2040ce_bintools/storage.py b/gp2040ce_bintools/storage.py index b2ee81d..7fc266d 100644 --- a/gp2040ce_bintools/storage.py +++ b/gp2040ce_bintools/storage.py @@ -24,7 +24,6 @@ def get_config(filename): def visualize(): """Pretty print the contents of GP2040-CE's storage.""" parser = argparse.ArgumentParser( - prog="visualize-storage", description="Read a the configuration storage section from a GP2040-CE board dump and print out its contents.", parents=[core_parser], ) diff --git a/pyproject.toml b/pyproject.toml index 66761d3..803aa8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,8 @@ +[build-system] +requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] + [project] name = "gp2040ce-binary-tools" -version = "0" description = "Tools for working with GP2040-CE binary dumps." readme = "README.md" license = {text = "MIT"} @@ -9,13 +11,17 @@ authors = [ ] requires-python = ">=3.8" dependencies = ["grpcio-tools"] +dynamic = ["version"] [project.optional-dependencies] dev = ["flake8", "flake8-blind-except", "flake8-builtins", "flake8-docstrings", "flake8-executable", "flake8-fixme", - "flake8-isort", "flake8-logging-format", "flake8-mutable", "flake8-pyproject", "pip-tools"] + "flake8-isort", "flake8-logging-format", "flake8-mutable", "flake8-pyproject", "pip-tools", "setuptools-scm"] [project.scripts] visualize-storage = "gp2040ce_bintools.storage:visualize" [tool.flake8] max-line-length = 120 + +[tool.setuptools_scm] +write_to = "gp2040ce_bintools/_version.py" diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index e578681..693ceee 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --extra=dev --output-file=requirements/requirements-dev.txt pyproject.toml +# pip-compile --extra=dev --output-file=requirements/requirements-dev.txt # build==0.10.0 # via pip-tools @@ -44,7 +44,9 @@ isort==5.12.0 mccabe==0.7.0 # via flake8 packaging==23.1 - # via build + # via + # build + # setuptools-scm pip-tools==6.13.0 # via gp2040ce-binary-tools (pyproject.toml) protobuf==4.23.3 @@ -57,12 +59,17 @@ pyflakes==3.0.1 # via flake8 pyproject-hooks==1.0.0 # via build +setuptools-scm==7.1.0 + # via gp2040ce-binary-tools (pyproject.toml) snowballstemmer==2.2.0 # via pydocstyle tomli==2.0.1 # via # build # flake8-pyproject + # setuptools-scm +typing-extensions==4.6.3 + # via setuptools-scm wheel==0.40.0 # via pip-tools diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 4fd21e2..672f6d6 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --output-file=requirements/requirements.txt pyproject.toml +# pip-compile --output-file=requirements/requirements.txt # grpcio==1.54.2 # via grpcio-tools