def main(): if subprocess.check_output(shlex.split('git status -s')): _print('some uncommitted changes:') subprocess.run(shlex.split('git status')) if not util.confirm('publish regardless?'): sys.exit() with open('./setup.py') as f: data = f.read() VERSION_RE = re.compile(r"\s*version='(?P<ver>\d+(?:\.\d+)+)',") version = VERSION_RE.search(data).groupdict()['ver'] parsed = semver.VersionInfo.parse(version) bumped = parsed.bump_patch() if bumped.patch == 10: bumped = parsed.bump_minor() if util.confirm(f'current version is {version}, bump to {bumped}?'): bump_version(data, version, bumped) if Path('./dist').is_dir() or Path('./build').is_dir(): cmd = 'rm -rf dist build' if util.confirm(f"run '{cmd}'?"): if run(shlex.split(cmd)) is None: sys.exit(1) else: _print("dist and/or build dirs don't exist") if not Path('./env').is_dir(): _print('./env is not a directory') sys.exit(1) if not any( pkg.startswith('twine') for pkg in run(shlex.split('pip freeze'))): _print('twine is not installed') sys.exit(1) cmds = [ './env/bin/python setup.py sdist bdist_wheel', './env/bin/python -m twine upload dist/*' ] for cmd in cmds: if util.confirm(f"run '{cmd}'?"): if run(shlex.split(cmd)) is None: sys.exit(1)
def test__bright_foreground_on_std_background(confirm): print(title(f'bright foreground on standard background (random {K})')) if confirm and not util.confirm(): return pairs = list( zip(choices(common.bright_fg_colors, k=K), choices(common.background_colors, k=K))) while common.has_duplicates(pairs) or any(p[0] == p[1] for p in pairs): # prevent ('white', 'white') pairs = list( zip(choices(common.bright_fg_colors, k=K), choices(common.background_colors, k=K))) for bright_fg, bg in pairs: bright_fg_code = core.BRIGHT_FOREGROUND_COLOR_CODES[bright_fg] bg_code = core.BACKGROUND_COLOR_CODES[bg] _print(f"bright {bright_fg} on {bg}", f"{bright_fg_code};{bg_code}")
python_requires='>=3.7', ) dry_run = False confirm = False DRY_RUN_RE = re.compile('^[-]+dry[-_]?run$') CONFIRM_RE = re.compile('^[-]+ok$') for arg in sys.argv[1:]: if arg == '-n' or DRY_RUN_RE.fullmatch(arg): dry_run = True sys.argv.remove(arg) continue if CONFIRM_RE.fullmatch(arg): confirm = True sys.argv.remove(arg) continue print(f'sys.argv[1:]: {sys.argv[1:]}', f'dry_run: {dry_run}', f'confirm: {confirm}', sep='\n') if confirm: from pprint import pprint print('setup args:') pprint(setup_args) if not util.confirm(): print('aborting') sys.exit() if dry_run: print('dry run: not calling setup(**setup_args). exiting') sys.exit() setup(**setup_args)
def test__bright_fg_color_codes__sanity(confirm): print(title('bright foreground colors: sanity')) if confirm and not util.confirm(): return for color, code in core.BRIGHT_FOREGROUND_COLOR_CODES.items(): _print(color, code)
def test__std_bg_color_codes__sanity(confirm): print(title('standard background colors: sanity')) if confirm and not util.confirm(): return for color, code in core.STANDARD_BACKGROUND_COLOR_CODES.items(): _print(color, code)
def test__formatting_color_codes__sanity(confirm): print(title(f'formatting colors: sanity')) if confirm and not util.confirm(): return for color, code in core.FORMATTING_COLOR_CODES.items(): _print(color, code)