Skip to content

Commit

Permalink
Fix poetry version gen (for next time).
Browse files Browse the repository at this point in the history
  • Loading branch information
jlevy committed Nov 28, 2024
1 parent 7da292f commit 172b138
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
19 changes: 16 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,33 @@ jinja2 = "^3.1.4"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

# Auto-generated version in build, based on tag or commit.
# https://sam.hooke.me/note/2023/08/poetry-automatically-generated-package-version-from-git-commit/
# Auto-generated version for builds based on git tag or commit.
# Preferred styles of versioning (PEP 440 compliant):
#
# 1.2.3 (stable release)
# 1.2.3a4 (pre-release, no dash or dots)
# 1.2.3rc1 (release candidate)
# 1.2.3.dev4+abcdef12 (development build, .dev for dev releases and +commit hash)
#
# Tags with a "v" prefix (e.g., v1.2.3) or additional dots (e.g., v1.2.3.rc1) are recognized
# but normalized to the preferred style for distribution.
# See: https://sam.hooke.me/note/2023/08/poetry-automatically-generated-package-version-from-git-commit/
[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
pattern = "^v?(?P<base>\\d+\\.\\d+\\.\\d+)(-?((?P<stage>[a-zA-Z]+)\\.?(?P<revision>\\d+)?))?"
pattern = "^v?(?P<base>\\d+\\.\\d+\\.\\d+)(-?((?P<stage>[a-zA-Z]+)\\.?(?P<revision>\\d+)?))?"
format-jinja = """
{%- if distance == 0 -%}
{{- base -}}
{%- if stage -%}
{{ stage }}{{ revision | default("") }}
{%- endif -%}
{%- else -%}
{{- base }}.dev{{ distance }}+{{commit}}
{%- endif -%}
"""


[tool.poetry.scripts]
repren = "repren:main"

Expand Down
9 changes: 2 additions & 7 deletions repren/repren.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
[repren.py](https://raw.githubusercontent.com/jlevy/repren/master/repren/repren.py) script
somewhere convenient and make it executable.
## Try it
## Try It
Let's try a simple replacement in my working directory (which has a few random source
files):
Expand Down Expand Up @@ -409,12 +409,6 @@ def multi_replace(

# --- Case handling (only used for case-preserving magic) ---

# TODO: Could handle dash-separated names as well.

# FooBarBaz -> Foo, Bar, Baz
# XMLFooHTTPBar -> XML, Foo, HTTP, Bar
_camel_split_pat1 = re.compile("([^A-Z])([A-Z])")
_camel_split_pat2 = re.compile("([A-Z])([A-Z][^A-Z])")

_name_pat = re.compile(r"\w+")

Expand All @@ -424,6 +418,7 @@ def _split_name(name: str) -> Tuple[str, List[str]]:
Split a CamelCase or underscore-formatted name into words.
Return separator and list of words.
"""
# TODO: Could handle dash-separated names as well.
if "_" in name:
# Underscore-separated name
return "_", name.split("_")
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ expect_error() {
echo "(got expected error: status $?)"
}

# A trick to do ls portably, showing just files and types.
# A trick to do ls portably, showing just files, types, and permissions.
# Macos appends an @ to permissions, so we strip it.
ls_portable() {
ls -lF "$@" | tail -n +2 | awk '{gsub(/@/, "", $1); print $1, $NF}'
Expand Down

0 comments on commit 172b138

Please sign in to comment.