diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..7a5c0a4a5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,52 @@ +name: release + +on: + release: + types: + - published + +jobs: + build: + name: Build and publish new release + runs-on: "ubuntu-latest" + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r dev-requirements.txt + + - name: Check that versions match + id: version + run: | + echo "Release tag: [${{ github.event.release.tag_name }}]" + PACKAGE_VERSION=$(python -c "import ccds; print(ccds.__version__)") + echo "Package version: [$PACKAGE_VERSION]" + [ ${{ github.event.release.tag_name }} == "v$PACKAGE_VERSION" ] || { exit 1; } + echo "::set-output name=major_minor_version::v${PACKAGE_VERSION%.*}" + + - name: Build package + run: | + make dist + + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@v1.3.0 + with: + user: ${{ secrets.PYPI_TEST_USERNAME }} + password: ${{ secrets.PYPI_TEST_PASSWORD }} + repository_url: https://test.pypi.org/legacy/ + skip_existing: true + + - name: Publish to Production PyPI + uses: pypa/gh-action-pypi-publish@v1.3.0 + with: + user: ${{ secrets.PYPI_PROD_USERNAME }} + password: ${{ secrets.PYPI_PROD_PASSWORD }} + skip_existing: false \ No newline at end of file diff --git a/Makefile b/Makefile index 4307ee1cc..bfc440797 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,31 @@ lint: isort --check --profile black ccds hooks tests docs/scripts black --check ccds hooks tests docs/scripts +clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts + +clean-build: ## remove build artifacts + rm -fr build/ + rm -fr dist/ + rm -fr .eggs/ + find . -name '*.egg-info' -exec rm -fr {} + + find . -name '*.egg' -exec rm -f {} + + +clean-pyc: ## remove Python file artifacts + find . -name '*.pyc' -exec rm -f {} + + find . -name '*.pyo' -exec rm -f {} + + find . -name '*~' -exec rm -f {} + + find . -name '__pycache__' -exec rm -fr {} + + +clean-test: ## remove test and coverage artifacts + rm -fr .tox/ + rm -f .coverage + rm -fr htmlcov/ + rm -fr .pytest_cache + +dist: clean ## builds source and wheel package + python -m build + ls -l dist + ### DOCS diff --git a/README.md b/README.md index 9ba6e549a..b54e67809 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,14 @@ The directory structure of your new project will look something like this (depen └── plots.py <- Code to create visualizations ``` +## Using unreleased changes + +By default, `ccds` will use the version of the template that corresponds to the installed version (e.g., if you have installed version 2.0.1, you'll use the 2.0.1 version of the template by default). If there are any _unreleased_ changes to the template (or changes in a separate branch) that you want to incorporate, you can do so by checking out whatever branch you'd like to use (checkout `master` for the latest changes): + +```bash +ccds -c master +``` + ## Using v1 If you want to use the old v1 project template, you need to have either the cookiecutter-data-science package or cookiecutter package installed. Then, use either command-line program with the `-c v1` option: diff --git a/ccds/__init__.py b/ccds/__init__.py index e69de29bb..0a728d815 100644 --- a/ccds/__init__.py +++ b/ccds/__init__.py @@ -0,0 +1,3 @@ +from ccds.version import __version__ + +__version__ diff --git a/ccds/__main__.py b/ccds/__main__.py index f9262d172..668a5329b 100644 --- a/ccds/__main__.py +++ b/ccds/__main__.py @@ -23,6 +23,8 @@ from cookiecutter import cli from cookiecutter import main as api_main # noqa: F401 referenced by tests +from ccds.version import __version__ + def default_ccds_main(f): """Set the default for the cookiecutter template argument to the CCDS template.""" @@ -31,6 +33,11 @@ def _main(*args, **kwargs): f.params[1].default = ( "https://github.com/drivendataorg/cookiecutter-data-science" ) + # Find the "checkout" option in the cookiecutter cli (currently the fifth) + # Per #389, set this to the currently released version by default + param_names = [p.name for p in f.params] + checkout_index = param_names.index("checkout") + f.params[checkout_index].default = __version__ return f(*args, **kwargs) return _main diff --git a/ccds/version.py b/ccds/version.py new file mode 100644 index 000000000..97367528e --- /dev/null +++ b/ccds/version.py @@ -0,0 +1,9 @@ +import sys + +if sys.version_info[:2] >= (3, 8): + import importlib.metadata as importlib_metadata +else: + import importlib_metadata + + +__version__ = importlib_metadata.version("cookiecutter-data-science") diff --git a/docs/docs/all-options.md b/docs/docs/all-options.md index c7295f7d2..e35fb9ff2 100644 --- a/docs/docs/all-options.md +++ b/docs/docs/all-options.md @@ -3,4 +3,12 @@ CCDS provides a number of choices that you can use to customize your project. The defaults work well for many projects, but lots of tooling choices are supported. Here are the options for tools that you can use: - \ No newline at end of file + + +## Checking out other branches / using unreleased changes to the template + +By default, `ccds` will download the most recently _released_ version of the template. If there are any _unreleased_ changes to the template (or changes in a separate branch) that you want to incorporate, you can do so by checking out whatever branch you'd like to use (checkout `master` for the latest changes): + +```bash +ccds -c master +```