Skip to content

Commit 84d75d0

Browse files
committed
Squashed commit of the following:
commit cd78cf9 Author: Martin Wendt <github@wwwendt.de> Date: Thu Feb 16 21:53:03 2023 +0100 prompt for token and repo commit 235f15e Author: Martin Wendt <github@wwwendt.de> Date: Thu Feb 16 21:19:22 2023 +0100 Try fix travis for 3.7 commit d4a4b09 Author: Martin Wendt <github@wwwendt.de> Date: Mon Feb 13 21:33:06 2023 +0100 `yabs init`
1 parent 2fba0fb commit 84d75d0

9 files changed

+493
-127
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,4 @@ dmypy.json
132132
.vscode/
133133
docs/sphinx-build/
134134
.DS_Store
135+
new-yabs.yaml

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
env: TOXENV=py37
1818
dist: xenial
1919
before_install:
20+
# Fix error: can't find Rust compiler
21+
- pip install -U pip
2022
# Fix "AttributeError: 'str' object has no attribute 'name'" on Py37
2123
- pip install -U importlib_metadata
2224
# - python: "3.6"

Pipfile

+2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ tox = "*"
1616
yabs = {editable = true, path = "."}
1717

1818
[packages]
19+
click = "*"
1920
GitPython = "*"
21+
jinja2 = "*"
2022
PyGithub = "*"
2123
PyYAML = "*"
2224
requests = "*"

Pipfile.lock

+205-124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yabs/cli.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from snazzy import Snazzy, enable_colors
1919

2020
from yabs import __version__
21+
from yabs.cmd_init import handle_init_command
2122
from yabs.commands import handle_info_command, handle_run_command
2223
from yabs.plugin_manager import PluginManager
2324
from yabs.util import CONFIG_NAME, check_cli_verbose, init_logging
@@ -80,7 +81,23 @@ def run():
8081
)
8182
subparsers = parser.add_subparsers(help="sub-command help")
8283

83-
# # --- Create the parser for the "info" command -----------------------------
84+
# --- Create the parser for the "init" command -----------------------------
85+
86+
sp = subparsers.add_parser(
87+
"init",
88+
parents=parents,
89+
allow_abbrev=False,
90+
help="create a new yabs configuration",
91+
)
92+
sp.add_argument(
93+
"filename",
94+
nargs="?",
95+
default=f"./{CONFIG_NAME}",
96+
help="path to new config file (default: %(default)s)",
97+
)
98+
sp.set_defaults(cmd_handler=handle_init_command, cmd_name="init")
99+
100+
# --- Create the parser for the "info" command -----------------------------
84101

85102
sp = subparsers.add_parser(
86103
"info",

yabs/cmd_init.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
# (c) 2020-2022 Martin Wendt and contributors; see https://github.com/mar10/yabs
3+
# Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php
4+
"""
5+
"""
6+
from argparse import ArgumentParser, Namespace
7+
from pathlib import Path
8+
9+
import click
10+
from jinja2 import Environment, PackageLoader, select_autoescape
11+
12+
from .util import datetime_to_iso
13+
14+
15+
def handle_init_command(parser: ArgumentParser, args: Namespace):
16+
res = run(parser, args)
17+
return res
18+
19+
20+
def run(parser: ArgumentParser, args: Namespace):
21+
22+
target = Path(args.filename)
23+
# target = Path(".") / "new-yabs.yaml"
24+
target = target.absolute()
25+
if target.exists():
26+
click.confirm(f"Overwrite {target} ?", abort=True)
27+
28+
full_repo_name = click.prompt("GitHub Repo name (format: USER/PROJECT)", type=str)
29+
if full_repo_name.count("/") != 1:
30+
raise click.BadParameter(full_repo_name)
31+
32+
github_token_env_name = click.prompt(
33+
"GitHub OAUTH token environment variable", default="GITHUB_OAUTH_TOKEN"
34+
)
35+
36+
context = {
37+
"date": datetime_to_iso(),
38+
"full_repo_name": full_repo_name,
39+
"github_token_env_name": github_token_env_name,
40+
}
41+
file_type = click.prompt(
42+
"Type",
43+
type=click.Choice({"full", "compact"}),
44+
default="full",
45+
)
46+
click.confirm(f"Create {target} ?", abort=True, default=True)
47+
48+
_copy_template(f"yabs-{file_type}.yaml", target, context)
49+
50+
51+
def _copy_template(tmpl_name: str, target: Path, ctx: dict) -> None:
52+
env = Environment(
53+
loader=PackageLoader("yabs"), # defaults to 'templates' folder
54+
autoescape=select_autoescape(),
55+
)
56+
template = env.get_template(tmpl_name)
57+
expanded = template.render(**ctx)
58+
# logger.info("Writing {:,} bytes to {!r}...".format(len(tmpl), target_path))
59+
with target.open("wt") as fp:
60+
fp.write(expanded)
61+
return

yabs/templates/yabs-compact.yaml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Yabs Workflow Definition
2+
# See https://github.com/mar10/yabs
3+
file_version: yabs#1
4+
5+
config:
6+
repo: '{{ full_repo_name }}'
7+
gh_auth:
8+
oauth_token_var: {{ github_token_env_name }}
9+
version:
10+
- type: __version__
11+
file: src/test_release_tool/__init__.py
12+
branches: master
13+
14+
15+
tasks:
16+
# The following tools are available. They are executed in the order
17+
# listed here
18+
19+
# 'check': Assert preconditons and fail otherwise
20+
- task: check
21+
build: true # dist/ folder exists
22+
can_push: true # Test if 'git push' would/would not succeed
23+
clean: true # Repo must/must not contain modifications
24+
python: ">=3.9" # SemVer specifier
25+
twine: true # `twine` is available
26+
up_to_date: true # everything pulled from remote
27+
venv: true # running inside a virtual environment
28+
version: true # `setup.py --version` returns the configured version
29+
# winget: true # `wingetcreate` is available
30+
yabs: ">=0.5" # SemVer specifier
31+
32+
# 'exec': Run arbitrary shell command
33+
- task: exec
34+
args: ["tox", "-e", "lint"] # shell command and optional arguments
35+
always: true # `true`: run even in dry-run mode
36+
37+
# 'bump': Increment project version (requires argument: `yabs run --inc INC`)
38+
- task: bump
39+
inc: null # Use value passed as 'yabs run --inc INC'
40+
41+
# 'commit': Commit modified files
42+
- task: commit
43+
add_known: true # Commit with -a flag
44+
message: |
45+
Bump version to {version}
46+
47+
# 'tag': Create an annotated tag
48+
- task: tag
49+
name: v{version}
50+
message: |
51+
Version {version}
52+
53+
# 'push': Push changes and tags
54+
- task: push
55+
tags: true
56+
57+
# 'pypi_release': Create a release on PyPI using `twine`
58+
- task: pypi_release
59+
build:
60+
- sdist
61+
- bdist_wheel
62+
upload: true
63+
64+
# 'github_release': Create a release on GitHub
65+
- task: github_release
66+
draft: false
67+
68+
# Bump 'v1.2.3' => 'v1.2.4-a1'
69+
- task: bump
70+
inc: "postrelease"
71+
72+
# Commit using '[ci skip]' as part of the message to prevent CI testing
73+
- task: commit
74+
add_known: true
75+
message: |
76+
Bump prerelease ({version}) [ci skip]
77+
78+
# Push to GitHub
79+
- task: push

yabs/templates/yabs-full.yaml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Release-Tool Workflow Definition
2+
# See https://github.com/mar10/yabs
3+
#
4+
# Created using `yabs init` {{ date }}
5+
6+
7+
file_version: yabs#1
8+
config:
9+
# Options used as default for all tools in this workflow
10+
repo: '{{ full_repo_name }}'
11+
# GitHub access token
12+
gh_auth:
13+
oauth_token_var: {{ github_token_env_name }}
14+
version:
15+
- type: __version__ # First entry is master for synchronizing
16+
file: src/test_release_tool/__init__.py
17+
# match: '__version__\s*=\s*[''\"](\d+\.\d+\.\d+).*[''\"]'
18+
# template: '__version__ = "{version}"'
19+
# - type: setup_cfg # First entry is master for synchronizing
20+
# entry: metadata.version
21+
# template:
22+
max_increment: minor
23+
branches: # Allowed git branches
24+
- master
25+
26+
27+
tasks:
28+
# The following tools are available. They are executed in the order
29+
# listed here
30+
31+
# 'check': Assert preconditons and fail otherwise
32+
- task: check
33+
build: true # dist/ folder exists
34+
can_push: true # Test if 'git push' would/would not succeed
35+
github: true # GitHub repo name valid and online accessible
36+
clean: true # Repo must/must not contain modifications
37+
os: null # (str, list)
38+
python: ">=3.9" # SemVer specifier
39+
twine: true # `twine` is available
40+
up_to_date: true # everything pulled from remote
41+
venv: true # running inside a virtual environment
42+
version: true # `setup.py --version` returns the configured version
43+
# winget: true # `wingetcreate` is available
44+
yabs: ">=0.5" # SemVer specifier
45+
46+
# 'run': Run arbitrary shell command
47+
- task: exec
48+
args: ["tox", "-e", "lint"] # shell command and optional arguments
49+
# dry_run_args: ["pwd"] #
50+
always: true # `true`: run even in dry-run mode
51+
silent: true # `true`: suppress output
52+
ignore_errors: false # `true`: show warning, but proceed on errors (exit code != 0)
53+
54+
- task: exec
55+
args: ["tox"] # shell command and optional arguments
56+
# dry_run_args: ["pwd"] #
57+
always: true # `true`: run even in dry-run mode
58+
silent: true # `true`: suppress output
59+
ignore_errors: false # `true`: show warning, but proceed on errors (exit code != 0)
60+
61+
# 'bump': Increment project version (requires argument: `yabs run --inc INC`)
62+
- task: bump
63+
inc: null # Use value passed as 'yabs run --inc INC'
64+
65+
# # 'replace': In-place string replacements
66+
# # (Uses https://github.com/outaTiME/applause)
67+
# - task: replace
68+
# files: null # minimatch globbing pattern
69+
# patterns: [] # See https://github.com/outaTiME/applause
70+
# # Shortcut patterns (pass false to disable):
71+
# # Replace '@@timestamp' with current datetime
72+
# setVersion: '{version}' # Replace '@@version' with current version
73+
74+
# 'commit': Commit modified files
75+
- task: commit
76+
add: [] # Also `git add` these files ('.' for all)
77+
add_known: true # Commit with -a flag
78+
message: |
79+
Bump version to {version}
80+
81+
# 'tag': Create an annotated tag
82+
- task: tag #
83+
name: v{version} #
84+
message: | #
85+
Version {version}
86+
87+
# 'push': Push changes and tags
88+
- task: push
89+
tags: true # Use `--follow-tags`
90+
91+
# 'pypi_release': Create a release on PyPI
92+
- task: pypi_release
93+
build:
94+
- sdist
95+
- bdist_wheel
96+
upload: true
97+
# revert_bump_on_error: true
98+
99+
# 'github_release': Create a release on GitHub
100+
- task: github_release
101+
# Override `config.gh_gh_auth`:
102+
gh_auth: null
103+
name: 'v{version}'
104+
message: |
105+
Released {version}
106+
107+
[Changelog](https://github.com/{repo}/blob/master/CHANGELOG.md),
108+
[Commit details](https://github.com/{repo}/compare/{org_tag_name}...{tag_name}).
109+
# draft: true
110+
prerelease: null # null: guess from version number format
111+
upload:
112+
- sdist
113+
- bdist_wheel
114+
115+
- task: bump
116+
inc: "postrelease"
117+
118+
- task: commit
119+
add_known: true
120+
message: |
121+
Bump prerelease ({version}) [ci skip]
122+
123+
- task: push

yabs/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,12 @@ def plural_s(value) -> str:
638638
return "" if n == 1 else "s"
639639

640640

641-
def datetime_to_iso(dt=None, microseconds=False):
641+
def datetime_to_iso(dt=None, *, microseconds: bool = False) -> str:
642642
"""Return current UTC datetime as ISO formatted string."""
643643
if dt is None:
644644
dt = datetime.now()
645645
if not microseconds:
646-
dt.replace(microsecond=0)
646+
dt = dt.replace(microsecond=0)
647647
return dt.isoformat(sep=" ")
648648

649649

0 commit comments

Comments
 (0)