Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All things tooling #26

Merged
merged 25 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Main maintainers
* @mgu @ewjoachim
18 changes: 11 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
*.egg-info
.pytest_cache
__pycache__
.tox
htmlcov
.coverage
dist/
build/
/.coverage
.DS_Store
/.mypy_cache
/.pytest_cache
/.tox
*.egg-info
/docs/_build
/htmlcov
/dist
/build
/.venv
36 changes: 33 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ services:

matrix:
include:

# Linting
- python: 3.6
env: TOX_ENV=check-lint
env:
TOX_ENV: check-lint

- python: 3.6
env: TOX_ENV=py36-unit-tests COVERAGE_FLAG=unit
env:
TOX_ENV: py36-unit-tests
COVERAGE_FLAG: unit
- python: 3.6
env:
TOX_ENV: py36-integration-tests
Expand All @@ -20,6 +24,32 @@ matrix:
PGHOST: 127.0.0.1
COVERAGE_FLAG: integration

- python: 3.7
env:
TOX_ENV: py37-unit-tests
COVERAGE_FLAG: unit
- python: 3.7
env:
TOX_ENV: py37-integration-tests
PGUSER: postgres
PGPORT: 5432
PGPASSWORD: ""
PGHOST: 127.0.0.1
COVERAGE_FLAG: integration

- python: 3.8
env:
TOX_ENV: py38-unit-tests
COVERAGE_FLAG: unit
- python: 3.8
env:
TOX_ENV: py38-integration-tests
PGUSER: postgres
PGPORT: 5432
PGPASSWORD: ""
PGHOST: 127.0.0.1
COVERAGE_FLAG: integration

install:
- pip install tox codecov

Expand Down
22 changes: 22 additions & 0 deletions LICENSE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2019, PeopleDoc

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.


10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prune tests
prune docs
prune example_migrations
prune *.egg-info
exclude .codecov.yml
exclude requirements.txt
exclude CONTRIBUTING.rst
exclude CODE_OF_CONDUCT.md
exclude tox.ini
include LICENSE.rst
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ But you're not using Django. You would like a standalone migration tool. You're

## Requirements

This project would only work for PostgreSQL databases 9.6+. We aim to be compatible with Python 2.7+ and Python 3+ (but Python 2 will not stay for long).
This project would only work for PostgreSQL databases 9.6+. We aim to be compatible with Python 3.6+.

## Install

Expand Down
33 changes: 15 additions & 18 deletions example_migrations/schemas/schema_0.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

CREATE TABLE sql_version (
version_num text UNIQUE NOT NULL
)
;
);

-- Init django tables --

Expand All @@ -13,35 +12,35 @@ CREATE TABLE "auth_permission" (
"content_type_id" integer NOT NULL,
"codename" varchar(100) NOT NULL,
UNIQUE ("content_type_id", "codename")
)
;
);

CREATE TABLE "auth_group_permissions" (
"id" serial NOT NULL PRIMARY KEY,
"group_id" integer NOT NULL,
"permission_id" integer NOT NULL REFERENCES "auth_permission" ("id") DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("group_id", "permission_id")
)
;
);

CREATE TABLE "auth_group" (
"id" serial NOT NULL PRIMARY KEY,
"name" varchar(80) NOT NULL UNIQUE
)
;
);

ALTER TABLE "auth_group_permissions" ADD CONSTRAINT "group_id_refs_id_f4b32aac" FOREIGN KEY ("group_id") REFERENCES "auth_group" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE TABLE "auth_user_groups" (
"id" serial NOT NULL PRIMARY KEY,
"user_id" integer NOT NULL,
"group_id" integer NOT NULL REFERENCES "auth_group" ("id") DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("user_id", "group_id")
)
;
);

CREATE TABLE "auth_user_user_permissions" (
"id" serial NOT NULL PRIMARY KEY,
"user_id" integer NOT NULL,
"permission_id" integer NOT NULL REFERENCES "auth_permission" ("id") DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("user_id", "permission_id")
)
;
);

CREATE TABLE "auth_user" (
"id" serial NOT NULL PRIMARY KEY,
"password" varchar(128) NOT NULL,
Expand All @@ -54,8 +53,8 @@ CREATE TABLE "auth_user" (
"is_staff" boolean NOT NULL,
"is_active" boolean NOT NULL,
"date_joined" timestamp with time zone NOT NULL
)
;
);

ALTER TABLE "auth_user_groups" ADD CONSTRAINT "user_id_refs_id_40c41112" FOREIGN KEY ("user_id") REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE "auth_user_user_permissions" ADD CONSTRAINT "user_id_refs_id_4dc23c39" FOREIGN KEY ("user_id") REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED;
-- The following references should be added but depend on non-existent tables:
Expand All @@ -75,15 +74,13 @@ CREATE TABLE "django_content_type" (
"app_label" varchar(100) NOT NULL,
"model" varchar(100) NOT NULL,
UNIQUE ("app_label", "model")
)
;
);

CREATE TABLE "django_site" (
"id" serial NOT NULL PRIMARY KEY,
"domain" varchar(100) NOT NULL,
"name" varchar(50) NOT NULL
)
;
);

CREATE TABLE django_migrations (
"id" serial NOT NULL PRIMARY KEY,
Expand Down
64 changes: 64 additions & 0 deletions release
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash -eu

BASE_BRANCH="master"
REPO_OWNER="peopledoc"
REPO="septentrion"

# Check that you're on a clean checkout
if ! git diff-index --quiet HEAD -- ;
then
echo "Repository not clean"
git status
exit 1
fi

function increment_version() {
python3 - "$1" <<EOF
import sys
version = sys.argv[1]
rest, last = version.rsplit('.', 1)
print(rest + '.' + str(int(last) + 1))
EOF
}

CHANGELOG="$(changelog $REPO_OWNER $REPO)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo "Here are all the PRs merged since the last tag:"
echo $CHANGELOG
echo

LATEST_VERSION=$(git describe --abbrev=0)
echo "Latest version was $LATEST_VERSION"

LATEST_INCREMENTED=$(increment_version $LATEST_VERSION)
read -p "Version to release ($LATEST_INCREMENTED): " VERSION
VERSION=${VERSION:-$LATEST_INCREMENTED}

echo "Releasing $VERSION:"

echo "- Writing version number to setup.cfg"
sed -i "s/# version placeholder.\\+$/version = ${VERSION}/" setup.cfg

# Python release
echo "- Removing previous build artifacts"
rm -rf dist/ build/
echo "- Creating the release"
python3 setup.py sdist bdist_wheel
echo "- Uploading to PyPI"
twine upload dist/*

echo "- Resetting setup.cfg"
git checkout -- setup.cfg

# Tag
echo "- Creating (signed) tag ${VERSION}"
git tag -s -m "Tag ${VERSION}" ${VERSION}
echo "- Pushing tag"
git push origin ${VERSION}

echo "Released ${VERSION}"
echo

URL="https://github.com/peopledoc/septentrion/releases/new?title=Release $VERSION&body=$CHANGELOG&tag=$VERSION"
echo "Please create the release in github:"
echo " $URL"
python -m webbrowser $URL
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e .[dev,test,lint]
4 changes: 1 addition & 3 deletions septentrion/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def migrate(stylist=style.noop_stylist):
title += " (manual)"
title += " "
if applied:
stylist.draw_checkbox(
checked=True, content="Already applied".format(title)
)
stylist.draw_checkbox(checked=True, content="Already applied")
stylist.echo("") # new line
else:
with stylist.checkbox(
Expand Down
5 changes: 2 additions & 3 deletions septentrion/style.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import print_function

from collections import defaultdict
from contextlib import contextmanager
from typing import Dict

import colorama

Expand Down Expand Up @@ -48,7 +47,7 @@ def checkbox(self, content, content_after=None, margin=2):


class NoopStylist(Stylist):
styles = defaultdict(str)
styles: Dict[str, str] = defaultdict(str)

def echo(self, *args, **kwargs):
pass
Expand Down
37 changes: 29 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
[metadata]
name = septentrion
description = Execute PostGreSQL migrations
version = 0.1.4.dev0
# version placeholder
author = peopledoc
author_email = [email protected]
url = https://github.com/peopledoc/septentrion
long_description = file: README.md
long_description_content_type = text/markdown
keywords = migrations postgresql
license = Apache Software License
license = MIT License
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
License :: OSI Approved :: MIT License

[options]
zip_safe = True
Expand All @@ -29,12 +28,21 @@ install_requires =
sqlparse
colorama

[options.packages.find]
include =
septentrion
septentrion.*

[options.entry_points]
console_scripts =
septentrion = septentrion.__main__:main

[options.extras_require]
dev =
tox
black
isort
github-changelog

test =
pytest
Expand All @@ -45,9 +53,12 @@ test =
lint =
black
isort
flake8
mypy
check-manifest

[bdist_wheel]
universal = 1
[flake8]
max-line-length = 88

[isort]
multi_line_output=3
Expand All @@ -61,3 +72,13 @@ not_skip = __init__.py

[tool:pytest]
addopts = --cov-report term-missing --cov-branch --cov-report html --cov-report term --cov=septentrion -vv

[mypy-setuptools.*,colorama.*,psycopg2.*,sqlparse.*]
ignore_missing_imports = True

[coverage:report]
exclude_lines =
raise NotImplementedError
coverage: exclude
if TYPE_CHECKING:
[ ]+\.\.\.$
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os

import psycopg2
from psycopg2 import sql

import pytest
from psycopg2 import sql


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def test_version(cli_runner):
assert cli_runner.invoke(main, ["--version"]).output == "Septentrion 0.1.4.dev0\n"
assert cli_runner.invoke(main, ["--version"]).output == "Septentrion 0.0.0\n"


def test_current_database_state(cli_runner, db):
Expand Down
Loading