diff --git a/.autorelease/autorelease.yml b/.autorelease/autorelease.yml new file mode 100644 index 0000000..4d35090 --- /dev/null +++ b/.autorelease/autorelease.yml @@ -0,0 +1,40 @@ +# project configuration +project: + project_name: Autorelease + repo_owner: dwhswenson + repo_name: autorelease + +# repo configuration: how you organize releases and the repo +repo: + # these are relative to where you run the script from + repo-path: '.' + setup-path: '.' + release-branches: + - stable + release-tag: "v{BASE_VERSION}" + +# writing release notes +notes: + labels: + - label: enhancement + heading: New features + - label: bugfix + heading: Bugs fixed + - label: misc PR + heading: Miscellaneous improvements + + standard_contributors: + - dwhswenson + +# running release checks +release-check: + versions: + - setup-cfg + - conda: devtools/conda-recipe/meta.yaml + skip: [] + + +# TODO: this replaces various environment variables +env: + package-import-name: 'autorelease' + dry: "" diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ca7bbb9..3fbf0d2 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -23,10 +23,11 @@ jobs: strategy: matrix: CONDA_PY: - - 3.9 - - 3.8 - - 3.7 - - 2.7 + - "3.11" + - "3.10" + - "3.9" + - "3.8" + - "3.7" steps: - uses: actions/checkout@v2 @@ -59,3 +60,4 @@ jobs: python -c "import autorelease" autorelease-release -h python release_check.py + autorelease check diff --git a/autorelease-travis.yml b/autorelease-travis.yml index b8fc25f..86ee2c1 100644 --- a/autorelease-travis.yml +++ b/autorelease-travis.yml @@ -1,4 +1,4 @@ -# AUTORELEASE v0.3.2 +# AUTORELEASE v0.4.0 # for nonrelease, use @main # for release, use v${VERSION}, e.g., v1.0.0 stages: @@ -9,7 +9,7 @@ stages: - deploy pypi import: - - dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@v0.3.2 - - dwhswenson/autorelease:travis_stages/test_testpypi.yml@v0.3.2 - - dwhswenson/autorelease:travis_stages/cut_release.yml@v0.3.2 - - dwhswenson/autorelease:travis_stages/deploy_pypi.yml@v0.3.2 + - dwhswenson/autorelease:travis_stages/deploy_testpypi.yml@v0.4.0 + - dwhswenson/autorelease:travis_stages/test_testpypi.yml@v0.4.0 + - dwhswenson/autorelease:travis_stages/cut_release.yml@v0.4.0 + - dwhswenson/autorelease:travis_stages/deploy_pypi.yml@v0.4.0 diff --git a/autorelease/scripts/check.py b/autorelease/scripts/check.py index 79b6f97..85cf048 100644 --- a/autorelease/scripts/check.py +++ b/autorelease/scripts/check.py @@ -24,9 +24,9 @@ def checker_from_yaml_dict(release_check): return checker -def run_checks(yml, branch=None, event=None, allow_patch_skip=False): - dct = yaml.load(yml, Loader=yaml.FullLoader) +def run_checks(dct, branch=None, event=None, allow_patch_skip=False): release_check = dct['release-check'] + release_check.update(dct['repo']) checker = checker_from_yaml_dict(release_check) if branch is None and event is None: branch, event = checker.get_branch_event_from_github_env() diff --git a/autorelease/scripts/cli.py b/autorelease/scripts/cli.py index 133ed5a..70db92c 100644 --- a/autorelease/scripts/cli.py +++ b/autorelease/scripts/cli.py @@ -1,18 +1,83 @@ +import os import click +import yaml from autorelease.scripts.vendor import vendor_actions from autorelease.scripts.check import run_checks +from autorelease import ReleaseNoteWriter + + +def _find_first_file(pathlist): + for p in pathlist: + if os.path.exists(p): + return p + return None + +def load_yaml(user_input, default_pathlist): + if user_input is not None: + dct = yaml.load(user_input, Loader=yaml.FullLoader) + else: + filename = _find_first_file(default_pathlist) + if filename is None: + raise RuntimeError("No config file could be found") + with open(filename, mode='r') as f: + dct = yaml.load(f, Loader=yaml.FullLoader) + + return dct + +def load_config(user_input): + paths = [ + ".autorelease.yml", + "autorelease.yml", + os.path.join(".autorelease", "autorelease.yml"), + os.path.join(".autorelease", "conf.yml"), + ] + return load_yaml(user_input, paths) + +def load_auth(user_input): + paths = [ + os.path.join(os.path.expanduser("~"), ".autorelease-auth.yml"), + os.path.join(".autorelease", "auth.yml"), + os.path.join(".autorelease", "autorelease-auth.yml"), + ".autorelease-auth.yml", + "autorelease-auth.yml", + ] + return load_yaml(user_input, paths) + @click.group() def cli(): pass @cli.command() -@click.option('--conf', type=click.File('r'), default='autorelease.yml') +@click.option('--conf', type=click.File('r')) @click.option('--branch', default=None) @click.option('--event', default=None) def check(conf, branch, event): - run_checks(conf, branch, event) + dct = load_config(conf) + run_checks(dct, branch, event) + +@cli.command() +@click.option('--conf', type=click.File('r')) +def config(conf): + from pprint import pprint + config = load_config(conf) + pprint(config) + + +@cli.command() +@click.option('--conf', type=click.File('r')) +@click.option('--auth', type=click.File('r')) +@click.option('--since-release', type=str, default=None) +@click.option('-o', '--output', type=str) +def notes(conf, auth, since_release, output): + config = load_config(conf) + github_user = load_auth(auth) + notes_conf = config['notes'] + notes_conf.update(github_user) + notes_conf['project'] = config['project'] + writer = ReleaseNoteWriter(config=notes_conf) + writer.write_release_notes(outfile=output) @click.group() def vendor(): diff --git a/autorelease/scripts/release.py b/autorelease/scripts/release.py index fff8ffe..3d9b58d 100644 --- a/autorelease/scripts/release.py +++ b/autorelease/scripts/release.py @@ -82,7 +82,7 @@ def main(): repo=repo, github_user=github_user ) - + # testing expected_pr = releaser.find_relevant_pr() print("Expected PR: " + str(expected_pr)) diff --git a/autorelease/scripts/vendor.py b/autorelease/scripts/vendor.py index 266a404..8dd81d4 100644 --- a/autorelease/scripts/vendor.py +++ b/autorelease/scripts/vendor.py @@ -1,5 +1,8 @@ import string -import pathlib +try: + import pathlib +except ImportError: # py2 + import pathlib2 import pkg_resources from packaging.version import Version import autorelease diff --git a/autorelease/version_checks.py b/autorelease/version_checks.py index c20cceb..a759314 100644 --- a/autorelease/version_checks.py +++ b/autorelease/version_checks.py @@ -6,9 +6,20 @@ from autorelease.version import get_setup_version # reuse the vendored from autorelease.utils import conda_recipe_version +import importlib + +def import_and_get(fully_qualified): + path = fully_qualified.split('.') + to_load = path.pop(-1) + module = ".".join(path) + mod = importlib.import_module(module) + return getattr(mod, to_load) + + version_getters = { 'setup-cfg': lambda path: get_setup_version(None, path), 'conda': conda_recipe_version, + 'getattr': import_and_get, } default_args = { diff --git a/devtools/conda-recipe/meta.yaml b/devtools/conda-recipe/meta.yaml index fb2b8d1..3409fbb 100644 --- a/devtools/conda-recipe/meta.yaml +++ b/devtools/conda-recipe/meta.yaml @@ -1,7 +1,7 @@ package: name: autorelease # add ".dev0" for unreleased versions - version: "0.3.2" + version: "0.4.0" source: path: ../../ diff --git a/requirements.txt b/requirements.txt index 11dc6fd..180e278 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ pyyaml gitpython requests future +pathlib2 diff --git a/setup.cfg b/setup.cfg index 8c34fa2..c551984 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = autorelease -version = 0.3.2 +version = 0.4.0 # version should end in .dev0 if this isn't to be released short_description = Tools to keep the release process clean. description = Tools to keep the release process clean. @@ -28,6 +28,7 @@ classifiers = Topic :: Software Development :: Testing [options] +python_requires = >=3.7 install_requires = packaging pyyaml