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

CI Overhaul #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[flake8]
# B = bugbear
# B9 = bugbear opinions
# BLK = black style warnings
Copy link
Author

Choose a reason for hiding this comment

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

I'm having flake8 check black and isort formatting because I prefer to have flake8 statically check formatting rather than running Git modifying code in CI, although the difference is pretty arbitrary.

# C = mccabe code complexity
# E = pycodestyle errors
# F = pyflakes errors
# I = isort style warnings
# W = pycodestyle warnings
select = B,B9,BLK,C,E,F,W
# B904 = within an `except` clause, raise exceptions with `raise ... from err`
# E203 = slice notation whitespace, invalid
# E501 = line length, handled by bugbear B950
# W503 = bin op line break, invalid
ignore = B904, E203, E501, W503
# up to 88 allowed by bugbear B950
max-line-length = 80
max-complexity = 18
27 changes: 27 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
categories:
- title: ':boom: Breaking Changes'
label: 'breaking'
- title: ':package: Build System'
label: 'build'
- title: ':construction_worker: Continuous Integration'
label: 'ci'
- title: ':books: Documentation'
label: 'documentation'
- title: ':rocket: Features'
label: 'enhancement'
- title: ':beetle: Fixes'
label: 'bug'
- title: ':racehorse: Performance'
label: 'performance'
- title: ':hammer: Refactoring'
label: 'refactoring'
- title: ':fire: Removals and Deprecations'
label: 'removal'
- title: ':lipstick: Style'
label: 'style'
- title: ':rotating_light: Testing'
label: 'testing'
template: |
## What’s Changed

$CHANGES
12 changes: 12 additions & 0 deletions .github/workflows/release-drafter.yml
Copy link
Author

Choose a reason for hiding this comment

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

I haven't gotten a ton of use out of this personally but it's an easy add and I like it in theory. Described here.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Release Drafter
on:
push:
branches:
- master
jobs:
draft_release:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release
on:
release:
types: [published]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.8'
architecture: x64
- run: pip install nox poetry
- run: nox --python 3.8
- run: poetry build
- run: poetry publish --username=__token__ --password=${{ secrets.PYPI_TOKEN }}
Copy link
Author

Choose a reason for hiding this comment

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

You'll need to set up a PyPI API token in GitHub but this will allow you to release to PyPI with a Github release.

22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test
on: [push]
jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.9', '3.8', '3.7']
Copy link
Author

Choose a reason for hiding this comment

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

Not testing past 3.9 yet just for efficiency.

os: [ubuntu-latest]
Copy link
Author

Choose a reason for hiding this comment

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

You may want to eventually add macos-latest here because you mention Mac support in your package classifiers. I'm omitting it for efficiency right now.

name: Test - Python ${{ matrix.python-version }} - ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install Root Dependencies
run: pip install nox poetry
- name: Run Nox Sessions
run: nox --python ${{ matrix.python-version }}
66 changes: 63 additions & 3 deletions .gitignore
Copy link
Author

Choose a reason for hiding this comment

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

Mostly just modernizing this.

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# PyCharm
.idea/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -48,6 +45,8 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -70,14 +69,47 @@ instance/
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
celerybeat.pid

# celery beat schedule file
celerybeat-schedule

Expand Down Expand Up @@ -105,3 +137,31 @@ venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# Nox
.nox

# VSCode
.vscode
*.code-workspace

# Mac
.DS_Store
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
exclude: >
(?x)(
\.mypy_cache/
| \.pytest_cache/
| \.venv/
| build/
| dist/
| \S+\.egg-info/
)

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: check-toml
- id: check-json
- id: pretty-format-json
args: ["--autofix"]
- id: end-of-file-fixer
- id: trailing-whitespace
args: ["--markdown-linebreak-ext=md"]
- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort
types: [python]
language: system
- id: black
name: black
entry: poetry run black
types: [python]
language: system
- id: flake8
name: flake8
entry: poetry run flake8
types: [python]
language: system
- id: mypy
name: mypy
entry: poetry run mypy
types: [python]
language: system
20 changes: 0 additions & 20 deletions .travis.yml
Copy link
Author

Choose a reason for hiding this comment

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

If you have an attachment to Travis CI, feel free to keep using it! This proposal would switch to GH Actions though.

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[![Build Status](https://travis-ci.org/bourbaki-py/introspection.svg?branch=master)](https://travis-ci.org/bourbaki-py/introspection)
[![Coverage Status](https://coveralls.io/repos/github/bourbaki-py/introspection/badge.svg?branch=master)](https://coveralls.io/github/bourbaki-py/introspection?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/bourbaki-py/introspection/badge.svg?branch=master)](https://coveralls.io/github/bourbaki-py/introspection?branch=master)
1 change: 0 additions & 1 deletion bourbaki/__init__.py
Copy link
Author

Choose a reason for hiding this comment

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

Namespaces don't need to be declared anymore.

This file was deleted.

20 changes: 0 additions & 20 deletions bourbaki/introspection/__init__.py
Copy link
Author

Choose a reason for hiding this comment

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

Not sure why this deletion diff got left behind on the git mv into the src directory.

This file was deleted.

62 changes: 62 additions & 0 deletions noxfile.py
Copy link
Author

Choose a reason for hiding this comment

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

I really like nox because you get to write plain Python code to build out your lint/check/test/etc suite. We also get to take advantage of poetry's ability to have an arbitrary number of dependency sections.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Nox sessions."""
import nox
from nox.sessions import Session

nox.options.sessions = "lint", "mypy", "tests"
Copy link
Author

Choose a reason for hiding this comment

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

As mentioned in the .flake8 comment, I try to only have nox run non-Git-modifying code, so black and isort are left out of the default sessions. You can, however, still explicitly run them (e.x. locally).


PACKAGE = "bourbaki-introspection"
LOCATIONS = "src", "tests", "./noxfile.py"
PYTHON = "3.9"
PYTHONS = ["3.9", "3.8", "3.7"]


# Formatting


@nox.session(python=PYTHON)
def isort(session: Session) -> None:
"""Run isort import formatter."""
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--only", "isort", external=True)
session.run("isort", *args)


@nox.session(python=PYTHON)
def black(session: Session) -> None:
"""Run black code formatter."""
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--only", "black", external=True)
session.run("black", *args)


# Linting


@nox.session(python=PYTHONS)
def lint(session: Session) -> None:
"""Lint using flake8."""
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--only", "lint", external=True)
session.run("flake8", *args)


# Typechecking


@nox.session(python=PYTHONS)
def mypy(session: Session) -> None:
"""Type-check using mypy."""
args = session.posargs or LOCATIONS
session.run("poetry", "install", "--only", "main,mypy", external=True)
session.run("mypy", *args)


# Testing


@nox.session(python=PYTHONS)
def tests(session: Session) -> None:
"""Run the test suite."""
args = session.posargs or ["-rxs", "--cov"]
session.run("poetry", "install", "--only", "main,test", external=True)
session.run("pytest", *args)
Loading