Skip to content

Commit

Permalink
Apply the library cookiecutter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Nov 17, 2022
1 parent 3e14579 commit cd1a576
Show file tree
Hide file tree
Showing 23 changed files with 750 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .cookiecutter/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"template": "https://github.com/hypothesis/cookiecutters",
"checkout": null,
"directory": "pypackage",
"ignore": [],
"extra_context": {
"name": "data-tasks",
"package_name": "data_tasks",
"slug": "data-tasks",
"short_description": "Small library to run data related scripts",
"python_versions": "3.10.6, 3.9.13, 3.8.13, 3.7.13",
"github_owner": "hypothesis",
"copyright_holder": "Hypothesis",
"visibility": "public",
"console_script": "no",
"devdata": "no",
"services": "no",
"dependabot_pip_interval": "monthly",
"__entry_point": "data-tasks",
"__github_url": "https://github.com/hypothesis/data-tasks",
"__pypi_url": "https://pypi.org/project/data-tasks",
"__hdev_project_type": "library"
}
}
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
day: "sunday"
time: "00:00"
timezone: "Europe/London"
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: CI
on:
push:
workflow_dispatch:
workflow_call:
schedule:
- cron: '0 1 * * *'
jobs:
Format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: python -m pip install tox
- run: tox -e checkformatting
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: python -m pip install tox
- run: tox -e lint
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.9', '3.8', '3.7']
name: Unit tests with Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install tox
- run: tox -e tests
- name: Upload coverage file
uses: actions/upload-artifact@v3
with:
name: coverage
path: .coverage.*
Coverage:
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Download coverage files
uses: actions/download-artifact@v3
with:
name: coverage
- run: python -m pip install tox
- run: tox -e coverage
Functests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.9', '3.8', '3.7']
name: Functional tests with Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install tox
- run: tox -e functests
8 changes: 8 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: PyPI
on:
release:
types: [published]
jobs:
PyPI:
uses: hypothesis/workflows/.github/workflows/pypi.yml@main
secrets: inherit
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
build
coverage
node_modules
yarn-error.log
.coverage*
.tox
*.egg-info
*.pyc
supervisord.log
supervisord.pid
.DS_Store
.devdata.env
4 changes: 4 additions & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3.10.6
3.9.13
3.8.13
3.7.13
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2022, Hypothesis
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98 changes: 98 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
comma := ,

.PHONY: help
help = help::; @echo $$$$(tput bold)$(strip $(1)):$$$$(tput sgr0) $(strip $(2))
$(call help,make help,print this help message)

.PHONY: services

.PHONY: devdata

.PHONY: shell
$(call help,make shell,"launch a Python shell in this project's virtualenv")
shell: python
@pyenv exec tox -qe dev

.PHONY: lint
$(call help,make lint,"lint the code and print any warnings")
lint: python
@pyenv exec tox -qe lint

.PHONY: format
$(call help,make format,"format the code")
format: python
@pyenv exec tox -qe format

.PHONY: checkformatting
$(call help,make checkformatting,"crash if the code isn't correctly formatted")
checkformatting: python
@pyenv exec tox -qe checkformatting

.PHONY: test
$(call help,make test,"run the unit tests in Python 3.10")
test: python
@pyenv exec tox -qe tests

.PHONY: test-py39
$(call help,make test-py39,"run the unit tests in Python 3.9")
test-py39: python
@pyenv exec tox -qe py39-tests

.PHONY: test-py38
$(call help,make test-py38,"run the unit tests in Python 3.8")
test-py38: python
@pyenv exec tox -qe py38-tests

.PHONY: test-py37
$(call help,make test-py37,"run the unit tests in Python 3.7")
test-py37: python
@pyenv exec tox -qe py37-tests

.PHONY: coverage
$(call help,make coverage,"run the tests and print the coverage report")
coverage: python
@pyenv exec tox --parallel -qe 'tests,py{39,38,37}-tests,coverage'

.PHONY: functests
$(call help,make functests,"run the functional tests in Python 3.10")
functests: python
@pyenv exec tox -qe functests

.PHONY: functests-py39
$(call help,make functests-py39,"run the functional tests in Python 3.9")
functests-py39: python
@pyenv exec tox -qe py39-functests

.PHONY: functests-py38
$(call help,make functests-py38,"run the functional tests in Python 3.8")
functests-py38: python
@pyenv exec tox -qe py38-functests

.PHONY: functests-py37
$(call help,make functests-py37,"run the functional tests in Python 3.7")
functests-py37: python
@pyenv exec tox -qe py37-functests

.PHONY: sure
$(call help,make sure,"make sure that the formatting$(comma) linting and tests all pass")
sure: python
sure:
@pyenv exec tox --parallel -qe 'checkformatting,lint,tests,py{39,38,37}-tests,coverage,functests,py{39,38,37}-functests'

.PHONY: template
$(call help,make template,"update from the latest cookiecutter template")
template: python
@pyenv exec tox -e template -- $$(if [ -n "$${template+x}" ]; then echo "--template $$template"; fi) $$(if [ -n "$${checkout+x}" ]; then echo "--checkout $$checkout"; fi) $$(if [ -n "$${directory+x}" ]; then echo "--directory $$directory"; fi)

.PHONY: clean
$(call help,make clean,"delete temporary files etc")
clean:
@rm -rf build dist .tox
@find . -path '*/__pycache__*' -delete
@find . -path '*.egg-info*' -delete

.PHONY: python
python:
@bin/make_python

-include data_tasks.mk
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<a href="https://github.com/hypothesis/data-tasks/actions/workflows/ci.yml?query=branch%3Amain"><img src="https://img.shields.io/github/workflow/status/hypothesis/data-tasks/CI/main"></a>
<a href="https://pypi.org/project/data-tasks"><img src="https://img.shields.io/pypi/v/data-tasks"></a>
<a><img src="https://img.shields.io/badge/python-3.10 | 3.9 | 3.8 | 3.7-success"></a>
<a href="https://github.com/hypothesis/data-tasks/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-BSD--2--Clause-success"></a>
<a href="https://github.com/hypothesis/cookiecutters/tree/main/pypackage"><img src="https://img.shields.io/badge/cookiecutter-pypackage-success"></a>
<a href="https://black.readthedocs.io/en/stable/"><img src="https://img.shields.io/badge/code%20style-black-000000"></a>

# data-tasks

Small library to run data related scripts

## Setting up Your data-tasks Development Environment

First you'll need to install:

* [Git](https://git-scm.com/).
On Ubuntu: `sudo apt install git`, on macOS: `brew install git`.
* [GNU Make](https://www.gnu.org/software/make/).
This is probably already installed, run `make --version` to check.
* [pyenv](https://github.com/pyenv/pyenv).
Follow the instructions in pyenv's README to install it.
The **Homebrew** method works best on macOS.
The **Basic GitHub Checkout** method works best on Ubuntu.
You _don't_ need to set up pyenv's shell integration ("shims"), you can
[use pyenv without shims](https://github.com/pyenv/pyenv#using-pyenv-without-shims).

Then to set up your development environment:

```terminal
git clone https://github.com/hypothesis/data-tasks.git
cd data-tasks
make help
```

## Releasing a New Version of the Project

1. First, to get PyPI publishing working you need to go to:
<https://github.com/organizations/hypothesis/settings/secrets/actions/PYPI_TOKEN>
and add data-tasks to the `PYPI_TOKEN` secret's selected
repositories.

2. Now that the data-tasks project has access to the `PYPI_TOKEN` secret
you can release a new version by just [creating a new GitHub release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository).
Publishing a new GitHub release will automatically trigger
[a GitHub Actions workflow](.github/workflows/pypi.yml)
that will build the new version of your Python package and upload it to
<https://pypi.org/project/data-tasks>.

## Changing the Project's Python Versions

To change what versions of Python the project uses:

1. Change the Python versions in the
[cookiecutter.json](.cookiecutter/cookiecutter.json) file. For example:

```json
"python_versions": "3.10.4, 3.9.12",
```

2. Re-run the cookiecutter template:

```terminal
make template
```

3. Commit everything to git and send a pull request

## Changing the Project's Python Dependencies

To change the production dependencies in the `setup.cfg` file:

1. Change the dependencies in the [`.cookiecutter/includes/setuptools/install_requires`](.cookiecutter/includes/setuptools/install_requires) file.
If this file doesn't exist yet create it and add some dependencies to it.
For example:

```
pyramid
sqlalchemy
celery
```

2. Re-run the cookiecutter template:

```terminal
make template
```

3. Commit everything to git and send a pull request

To change the project's formatting, linting and test dependencies:

1. Change the dependencies in the [`.cookiecutter/includes/tox/deps`](.cookiecutter/includes/tox/deps) file.
If this file doesn't exist yet create it and add some dependencies to it.
Use tox's [factor-conditional settings](https://tox.wiki/en/latest/config.html#factors-and-factor-conditional-settings)
to limit which environment(s) each dependency is used in.
For example:

```
lint: flake8,
format: autopep8,
lint,tests: pytest-faker,
```

2. Re-run the cookiecutter template:

```terminal
make template
```

3. Commit everything to git and send a pull request
18 changes: 18 additions & 0 deletions bin/make_python
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#
# Ensure that each version of Python in the .python_version file is installed
# in pyenv and that tox is installed within each version of Python.
set -euo pipefail

if [ -n "${CI+x}" ]; then exit; fi

pyenv_root=$(pyenv root)

for python_version in 3.10.6 3.9.13 3.8.13 3.7.13; do
bin_dir=$pyenv_root/versions/$python_version/bin
if [ ! -f "$bin_dir"/tox ]; then
pyenv install --skip-existing "$python_version"
"$bin_dir"/pip install --disable-pip-version-check tox
pyenv rehash
fi
done
Loading

0 comments on commit cd1a576

Please sign in to comment.