semtag 0.1.3__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,6 +56,9 @@ venv.bak/
56
56
  *.swo
57
57
  *~
58
58
 
59
+ # Linter
60
+ .ansible/
61
+
59
62
  # OS
60
63
  .DS_Store
61
64
  Thumbs.db
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: semtag
3
- Version: 0.1.3
3
+ Version: 0.2.1
4
4
  Summary: A tool for managing semantic version tags in git repositories
5
5
  Author-email: Mateusz Mikrut <mateusz.mikrut@gmail.com>
6
6
  License-Expression: MIT
@@ -25,7 +25,7 @@ Dynamic: license-file
25
25
 
26
26
  # Semantic Version GIT Tagger
27
27
 
28
- A pretty trivial python script to easely manage git tags with semantic versioning (semver.org)
28
+ A pretty trivial python script to easily manage git tags with semantic versioning (semver.org)
29
29
 
30
30
  ## Usage
31
31
 
@@ -35,15 +35,21 @@ semtag [options]
35
35
 
36
36
  ### Options
37
37
 
38
- - `-p, --patch` - Increment patch version (x.x.PATCH)
39
- - `-m, --minor` - Increment minor version (x.MINOR.0)
40
- - `-M, --major` - Increment major version (MAJOR.0.0)
41
- - `-b, --by` - Increment by a specific number (default: 1)
42
- - `-l, --label` - Add label to the version (e.g., -l rc1 creates 1.0.0-rc1)
43
- - `-u, --push` - Push the new tag to remote repository
44
- - `-n, --nofetch` - Do not fetch tags from remote prior creating new one
45
- <!-- - `-f, --force` - Force operation even if not on main/master branch -->
46
- - `-v, --verbose` - Increase verbosity (use -v, -vv, or -vvv for more detail)
38
+ <!-- OPTIONS:START -->
39
+ ```
40
+ -h, --help show this help message and exit
41
+ -v, --verbose Verbosity (-v for INFO, -vv for DEBUG)
42
+ -b, --by BY Increment by a specific number
43
+ -p, --patch Increment patch version (x.x.PATCH)
44
+ -m, --minor Increment minor version (x.MINOR.0)
45
+ -M, --major Increment major version (MAJOR.0.0)
46
+ -l, --label LABEL Add label to the version (e.g., -l rc1 creates 1.0.0-rc1)
47
+ -a, --msg MSG Annotated tags message
48
+ -u, --push Push the new tag to remote repository
49
+ -U, --pushall Push all local tags to remote repository
50
+ -n, --no-fetch Do not fetch tags from remote before operation
51
+ ```
52
+ <!-- OPTIONS:END -->
47
53
 
48
54
  ### Examples
49
55
 
@@ -1,6 +1,6 @@
1
1
  # Semantic Version GIT Tagger
2
2
 
3
- A pretty trivial python script to easely manage git tags with semantic versioning (semver.org)
3
+ A pretty trivial python script to easily manage git tags with semantic versioning (semver.org)
4
4
 
5
5
  ## Usage
6
6
 
@@ -10,15 +10,21 @@ semtag [options]
10
10
 
11
11
  ### Options
12
12
 
13
- - `-p, --patch` - Increment patch version (x.x.PATCH)
14
- - `-m, --minor` - Increment minor version (x.MINOR.0)
15
- - `-M, --major` - Increment major version (MAJOR.0.0)
16
- - `-b, --by` - Increment by a specific number (default: 1)
17
- - `-l, --label` - Add label to the version (e.g., -l rc1 creates 1.0.0-rc1)
18
- - `-u, --push` - Push the new tag to remote repository
19
- - `-n, --nofetch` - Do not fetch tags from remote prior creating new one
20
- <!-- - `-f, --force` - Force operation even if not on main/master branch -->
21
- - `-v, --verbose` - Increase verbosity (use -v, -vv, or -vvv for more detail)
13
+ <!-- OPTIONS:START -->
14
+ ```
15
+ -h, --help show this help message and exit
16
+ -v, --verbose Verbosity (-v for INFO, -vv for DEBUG)
17
+ -b, --by BY Increment by a specific number
18
+ -p, --patch Increment patch version (x.x.PATCH)
19
+ -m, --minor Increment minor version (x.MINOR.0)
20
+ -M, --major Increment major version (MAJOR.0.0)
21
+ -l, --label LABEL Add label to the version (e.g., -l rc1 creates 1.0.0-rc1)
22
+ -a, --msg MSG Annotated tags message
23
+ -u, --push Push the new tag to remote repository
24
+ -U, --pushall Push all local tags to remote repository
25
+ -n, --no-fetch Do not fetch tags from remote before operation
26
+ ```
27
+ <!-- OPTIONS:END -->
22
28
 
23
29
  ### Examples
24
30
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: semtag
3
- Version: 0.1.3
3
+ Version: 0.2.1
4
4
  Summary: A tool for managing semantic version tags in git repositories
5
5
  Author-email: Mateusz Mikrut <mateusz.mikrut@gmail.com>
6
6
  License-Expression: MIT
@@ -25,7 +25,7 @@ Dynamic: license-file
25
25
 
26
26
  # Semantic Version GIT Tagger
27
27
 
28
- A pretty trivial python script to easely manage git tags with semantic versioning (semver.org)
28
+ A pretty trivial python script to easily manage git tags with semantic versioning (semver.org)
29
29
 
30
30
  ## Usage
31
31
 
@@ -35,15 +35,21 @@ semtag [options]
35
35
 
36
36
  ### Options
37
37
 
38
- - `-p, --patch` - Increment patch version (x.x.PATCH)
39
- - `-m, --minor` - Increment minor version (x.MINOR.0)
40
- - `-M, --major` - Increment major version (MAJOR.0.0)
41
- - `-b, --by` - Increment by a specific number (default: 1)
42
- - `-l, --label` - Add label to the version (e.g., -l rc1 creates 1.0.0-rc1)
43
- - `-u, --push` - Push the new tag to remote repository
44
- - `-n, --nofetch` - Do not fetch tags from remote prior creating new one
45
- <!-- - `-f, --force` - Force operation even if not on main/master branch -->
46
- - `-v, --verbose` - Increase verbosity (use -v, -vv, or -vvv for more detail)
38
+ <!-- OPTIONS:START -->
39
+ ```
40
+ -h, --help show this help message and exit
41
+ -v, --verbose Verbosity (-v for INFO, -vv for DEBUG)
42
+ -b, --by BY Increment by a specific number
43
+ -p, --patch Increment patch version (x.x.PATCH)
44
+ -m, --minor Increment minor version (x.MINOR.0)
45
+ -M, --major Increment major version (MAJOR.0.0)
46
+ -l, --label LABEL Add label to the version (e.g., -l rc1 creates 1.0.0-rc1)
47
+ -a, --msg MSG Annotated tags message
48
+ -u, --push Push the new tag to remote repository
49
+ -U, --pushall Push all local tags to remote repository
50
+ -n, --no-fetch Do not fetch tags from remote before operation
51
+ ```
52
+ <!-- OPTIONS:END -->
47
53
 
48
54
  ### Examples
49
55
 
@@ -5,11 +5,11 @@ SemanticVersion.py
5
5
  pyproject.toml
6
6
  requirements.txt
7
7
  semtag.py
8
- .ansible/.lock
9
8
  .github/workflows/publish.yml
10
9
  semtag.egg-info/PKG-INFO
11
10
  semtag.egg-info/SOURCES.txt
12
11
  semtag.egg-info/dependency_links.txt
13
12
  semtag.egg-info/entry_points.txt
14
13
  semtag.egg-info/requires.txt
15
- semtag.egg-info/top_level.txt
14
+ semtag.egg-info/top_level.txt
15
+ tools/pre-commit
@@ -14,19 +14,12 @@ logger = logging.getLogger(__name__)
14
14
 
15
15
  def main():
16
16
  """ Main function """
17
- ########################
18
- ### Argument Parsing ###
19
- ########################
17
+
18
+ ### Arguments
20
19
  parser = argparse.ArgumentParser(
21
20
  description='SemTag - Manage semantic version tags in git repositories',
22
21
  formatter_class=argparse.RawDescriptionHelpFormatter,
23
- epilog="""
24
- Examples:
25
- %(prog)s -m # Increment minor version (1.0.0 -> 1.1.0)
26
- %(prog)s -M # Increment major version (1.0.0 -> 2.0.0)
27
- %(prog)s -p -b 5 # Increment patch version by 5 (1.0.0 -> 1.0.5)
28
- %(prog)s -p -l rc1 # Increment patch and add label (1.0.0 -> 1.0.1-rc1)
29
- """
22
+ epilog="\n"
30
23
  )
31
24
  parser.add_argument('-v', '--verbose', action='count', default=0, help='Verbosity (-v for INFO, -vv for DEBUG)')
32
25
  # parser.add_argument('-f', '--force', action='store_true', default=False, help='Force the operation even if not on main/master branch')
@@ -38,11 +31,13 @@ Examples:
38
31
  version_group.add_argument('-M', '--major', action='store_true', help='Increment major version (MAJOR.0.0)')
39
32
 
40
33
  parser.add_argument('-l', '--label', type=str, default=None, help='Add label to the version (e.g., -l rc1 creates 1.0.0-rc1)')
34
+ parser.add_argument('-a', '--msg', type=str, help='Annotated tags message', default=None)
41
35
  parser.add_argument('-u', '--push', action='store_true', help='Push the new tag to remote repository', default=False)
36
+ parser.add_argument('-U', '--pushall', action='store_true', help='Push all local tags to remote repository', default=False)
42
37
  parser.add_argument('-n', '--no-fetch', action='store_true', help='Do not fetch tags from remote before operation', default=False)
43
38
  args = parser.parse_args()
44
39
 
45
- ### Logging based on verbosity ###
40
+ ### Logging based on verbosity
46
41
  if args.verbose == 0:
47
42
  log_level = logging.WARNING
48
43
  elif args.verbose == 1:
@@ -54,14 +49,12 @@ Examples:
54
49
  level=log_level,
55
50
  format='%(message)s' # Keep it simple (no timestamps, severity etc.)
56
51
  )
57
-
58
- ##################
59
- ### Main Logic ###
60
- ##################
52
+
53
+ ### Main Logic
61
54
  logger.debug(f"Arguments: {args}")
62
55
  pwd = Path('.').resolve()
63
56
 
64
- ### Check if this is a git workspace ###
57
+ ### Check if this is a git workspace
65
58
  try:
66
59
  repo = git.Repo(pwd, search_parent_directories=True)
67
60
  logger.debug(f"Found git repository at {repo.working_dir}")
@@ -73,7 +66,7 @@ Examples:
73
66
  exit(99)
74
67
 
75
68
  reponame = Path(repo.working_dir).name
76
- logger.debug(f"Repository name : {reponame}")
69
+ logger.info(f"Repository name : {reponame}")
77
70
 
78
71
  ## Check if on main/master branch (warning only)
79
72
  # try:
@@ -84,30 +77,31 @@ Examples:
84
77
  # logger.warning("HEAD is detached, not on any branch")
85
78
  # exit(2)
86
79
 
87
-
88
- # Fetch tags from remote to avoid duplicates
80
+ ### Fetch tags from remote to avoid duplicates
89
81
  if not args.no_fetch:
90
82
  try:
91
83
  logger.debug("Fetching tags from remote...")
92
84
  repo.remotes.origin.fetch(tags=True)
93
- logger.debug("Tags fetched successfully")
85
+ logger.info("Tags fetched successfully")
94
86
  except Exception as e:
95
87
  logger.warning(f"Error fetching tags: {e}")
96
-
88
+
89
+ ### Sort and filter semantic tags
90
+ logger.debug(f"All tags in repository: {repo.tags}")
97
91
  tags = semsort([tag.name for tag in repo.tags])
92
+ logger.debug(f"Sorted semantic tags: {tags}")
98
93
 
94
+ ### No tags case
99
95
  if tags:
100
96
  latest_tag = tags[0]
101
- logger.debug(f"Latest semantic version tag: {latest_tag}")
97
+ logger.info(f"Latest semantic version tag: {latest_tag}")
102
98
  else:
103
- # No tags found, start with 0.0.0
104
- logger.debug("No semantic version tags found. Starting with 0.0.0")
105
99
  latest_tag = '0.0.0'
100
+ logger.info("No semantic version tags found. Starting with 0.0.0")
106
101
 
107
- # Initialize obj
108
102
  current_version = SemanticVersion(latest_tag)
109
103
 
110
- ### Increment version ###
104
+ ### Increment version
111
105
  if args.major:
112
106
  logger.debug("Incrementing major version")
113
107
  current_version.inc_major(by=args.by)
@@ -118,24 +112,32 @@ Examples:
118
112
  logger.debug("Incrementing patch version")
119
113
  current_version.inc_patch(by=args.by)
120
114
 
121
- ### Label ###
115
+ ### Label
122
116
  if args.label:
123
117
  logger.debug(f"Adding label: {args.label}")
124
118
  current_version.add_label(args.label)
125
119
 
126
120
  new_tag = str(current_version)
127
- logger.info(f"Generate tag: {new_tag}")
121
+ logger.debug(f"Generated new tag: {new_tag}")
128
122
 
129
- ### Create and push
123
+ ### Create tag
130
124
  try:
131
- #TODO: add tag message option later
132
- #repo.create_tag(new_tag, message=f"Release {new_tag}")
133
- repo.create_tag(new_tag)
125
+ if args.msg:
126
+ logger.debug(f"Creating annotated tag '{new_tag}' with message: {args.msg}")
127
+ repo.create_tag(new_tag, message=args.msg)
128
+ else:
129
+ logger.debug(f"Creating lightweight tag '{new_tag}'")
130
+ repo.create_tag(new_tag)
131
+
134
132
  logger.info(f"Successfully created tag: {new_tag}")
135
133
 
136
- # Push if requested
137
- if args.push:
138
- logger.info(f"Pushing tag '{new_tag}' to remote...")
134
+ ### Push
135
+ if args.pushall:
136
+ logger.debug("Pushing all local tags to remote...")
137
+ repo.remote('origin').push(tags=True)
138
+ logger.info("Successfully pushed all tags to remote")
139
+ elif args.push:
140
+ logger.debug(f"Pushing tag '{new_tag}' to remote...")
139
141
  repo.remote('origin').push(new_tag) # It only pushes the new tag not all from local repo
140
142
  logger.info(f"Successfully pushed new tag: {new_tag}")
141
143
  else:
@@ -145,7 +147,7 @@ Examples:
145
147
  except Exception as e:
146
148
  logger.error(f"Error: {e}")
147
149
 
148
- # Print the new tag to stout as confirmation if not verbose
150
+ ### Print the new tag to stout as confirmation if not verbose
149
151
  if args.verbose == 0:
150
152
  GREEN = '\033[92m'
151
153
  YELLOW = '\033[93m'
@@ -0,0 +1,38 @@
1
+ #!/bin/bash
2
+ # Pre-commit hook to generate README.md options from script argparse help
3
+
4
+ ### Install pre-commit hook:
5
+ # ln -s ./tools/pre-commit/pre-commit .git/hooks/pre-commit
6
+
7
+ REPO_ROOT=$(git rev-parse --show-toplevel)
8
+
9
+ # Check if semtag.py has been modified
10
+ if git diff --cached --name-only | grep -q 'semtag\.py'; then
11
+ echo "Updating README.md options..."
12
+ cd "$REPO_ROOT" || exit 1
13
+
14
+ OPTIONS_TMP=$(mktemp)
15
+ README_TMP=$(mktemp)
16
+
17
+ python semtag.py --help 2>&1 | sed -n '/^options:/,/^$/p' | tail -n +2 > "$OPTIONS_TMP"
18
+
19
+ # README with updated options
20
+ awk -v opts_file="$OPTIONS_TMP" '
21
+ /<!-- OPTIONS:START -->/ { print; print "```"; system("cat " opts_file); print "```"; skip=1; next }
22
+ /<!-- OPTIONS:END -->/ { skip=0 }
23
+ !skip
24
+ ' README.md > "$README_TMP"
25
+
26
+ if [ $? -eq 0 ]; then
27
+ mv "$README_TMP" README.md
28
+ rm -f "$OPTIONS_TMP"
29
+ git add README.md
30
+ echo "README.md options updated and staged"
31
+ else
32
+ echo "Failed to update README.md"
33
+ rm -f "$README_TMP" "$OPTIONS_TMP"
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ exit 0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes