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

feat: minimal python project gh repo template #2

Merged
merged 28 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 18 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
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
ignore = W503, C901, ANN101
max-line-length = 88
max-complexity = 10
docstring-convention = google
allow-star-arg-any = true
per-file-ignores =
# Don't require docstrings or type annotations in tests
tests/*:D100,D102,D103,D104,DAR,ANN
7 changes: 7 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

# Ending a path in a `/` will specify the code owners for every file
# nested in that directory, on any level

# Default owners
* @meltano/engineering
58 changes: 58 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Bug Report
description: File a bug report
title: "[Bug]: <title>"
labels: ["kind/Bug"]
assignees:
- meltano/engineering

body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: input
id: package_version
attributes:
label: Package Version
description: Version/commit hash of this package that you are using
placeholder: "0.0.1"
validations:
required: true
- type: dropdown
id: python_version
attributes:
label: Python Version
description: Version of Python you are using
options:
- "3.6 (deprecated)"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "NA"
validations:
required: true
- type: input
id: os
attributes:
label: Operating System
description: What operating system you are using
placeholder: "Windows"
validations:
required: true
- type: textarea
id: what-happened
attributes:
label: Description
description: Describe what you were trying to get done
placeholder: Tell us what happened, what went wrong, and what you expected to happen
validations:
required: true
- type: textarea
id: failing-code
attributes:
label: Code
description: Paste the failing code and/or traceback, if applicable
render: python
validations:
required: false
30 changes: 30 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Config ref: https://github.com/Ezard/semantic-prs

# Validate the PR title, and ignore all commit messages
titleOnly: true

# Provides a custom URL for the "Details" link, which appears next to the success/failure message from the app:
targetUrl: https://github.com/meltano/basic-python-template/blob/main/CONTRIBUTING.md#semantic-pull-requests

# The values allowed for the "type" part of the PR title/commit message.
# e.g. for a PR title/commit message of "feat: add some stuff", the type would be "feat"
types:
- ci
- chore
- build
- docs
- feat
- fix
- perf
- refactor
- revert
- style
- test

# The values allowed for the "scope" part of the PR title/commit message.
# e.g. for a PR title/commit message of "feat(awesome-feature): add some stuff",
# the scope would be "awesome-feature"
# edit or add scopes are needed
scopes:
- deps # production dependencies
- deps-dev # development depencencies (testing, linting, etc.)
65 changes: 65 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request: {}
schedule:
- cron: '37 10 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on:
pull_request: {}
push:
branches: [main]
workflow_dispatch:
inputs: {}

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
run: |
pipx install poetry
poetry --version
- name: Install dependencies
run: |
poetry install
- name: Test with pytest
run: |
poetry run pytest
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
ci:
autofix_prs: true
autoupdate_schedule: weekly
autoupdate_commit_msg: 'chore: pre-commit autoupdate'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-json
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
exclude: (docs/.*|samples/.*\.json)
- id: trailing-whitespace
exclude: |
(?x)^(
.bumpversion.cfg
)$

- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
- darglint==1.8.1
- flake8-annotations==2.9.0
- flake8-docstrings==1.6.0

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py37-plus]
47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Contributing to this package

Let's build together! Please see our [Contributor Guide](https://docs.meltano.com/contribute/)
for more information on contributing to Meltano.

We believe that everyone can contribute and we welcome all contributions.

Chat with us in [#contributing](https://meltano.slack.com/archives/C013Z450LCD) on [Slack](https://meltano.com/slack).

Contributors are expected to follow our [Code of Conduct](https://docs.meltano.com/contribute/#code-of-conduct).

## Semantic Pull Requests

This repo uses the [semantic-prs](https://github.com/Ezard/semantic-prs) GitHub app to check all PRs againts the conventional commit syntax.

Pull requests should be named according to the conventional commit syntax to streamline changelog and release notes management. We encourage (but do not require) the use of conventional commits in commit messages as well.

In general, PR titles should follow the format "<type>: <desc>", where type is any one of these:

- `ci`
- `chore`
- `build`
- `docs`
- `feat`
- `fix`
- `perf`
- `refactor`
- `revert`
- `style`
- `test`

More advanced rules and settings can be found within the file [`.github/semantic.yml`](https://github.com/meltano/basic-python-template/blob/main/.github/semantic.yml).

## Workspace Development Strategies for Meltano Python packages

### Universal Code Formatting

- From the [Black](https://black.readthedocs.io) website:
> By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters. **Black makes code review faster by producing the smallest diffs possible.** Blackened code looks the same regardless of the project you’re reading. **Formatting becomes transparent after a while and you can focus on the content instead.**

### Pervasive Python Type Hints

Type hints allow us to spend less time reading documentation. Public modules should be checked for type annotations on all methods and functions.
WillDaSilva marked this conversation as resolved.
Show resolved Hide resolved

### Docstring convention

All public modules in the Meltano python packages are checked for the presence of docstrings in classes and functions. We follow the [Google Style convention](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html) for Python docstrings so functions are required to have a description of every argument and the return value, if applicable.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# basic-python-template
# Basic-python-template

A github repo template for generic Meltano python projects

## Using this template

1. create a new github project - selecting this repo as the source template - [doc: creating a repo from a template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
2. Update `pyproject.toml` renaming the repo and python packages as needed
3. Rename or remove the `basic_python_template` directory as needed
4. Update or remove the `tests` as needed
5. Take a look at the `.github` dir and update the issue templates and semantic prs workflow as needed
6. Visit the [internal-tech-ops](https://github.com/meltano/internal-tech-ops) and [open an issue](https://github.com/meltano/internal-tech-ops/issues/new?title=github%20apps%20install%20request) requesting that the following two github apps be installed for your new repo:
1. semantic prs
2. pre-commit ci
7. Verify the team permissions and settings for the repo (recommended settings below). You can also create an issue in [internal-tech-ops](https://github.com/meltano/internal-tech-ops) for additional assistance/validation/etc.
1. Access - Collaborators and teams
1. @aaronsteers -> role: admin
2. @meltano/engineer -> role: maintain
3. @meltano/team -> role: write
2. Branches - Branch protection rules
1. Require pull request for merging
1. Require approvals -> Required number of approvals: 1
2. Require status checks to pass before merge
3. Require conversations to be resolved before merge
3. Code security and analysis
1. Code scanning -> Enabled (config already supplied in repo)
8. Replace this README.md with something more appropriate
9. Go forth and build something cool!
3 changes: 3 additions & 0 deletions basic_python_template/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Example package. Update/remove/rename as needed."""

__version__ = "0.1.0"
43 changes: 43 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[tool.poetry]
name = "basic-python-template"
version = "0.1.0"
description = ""
authors = ["Meltano Team and Contributors"]
maintainers = ["Meltano Team and Contributors"]
readme = "README.md"
homepage = "https://meltano.com"
repository = "https://github.com/meltano/basic-python-template"
license = "Apache 2.0"

packages = [{include = "basic_python_template"}]

[tool.poetry.dependencies]
python = "<3.10,>=3.7"
pandemicsyn marked this conversation as resolved.
Show resolved Hide resolved

[tool.poetry.urls]
"Issue Tracker" = "https://github.com/meltano/basic-python-template/issues"
"Twitter" = "https://twitter.com/meltanodata/"
"Changelog" = "https://github.com/meltano/basic-python-template/blob/main/CHANGELOG.md"
"Slack" = "https://meltano.com/slack"
"Youtube" = "https://www.youtube.com/meltano"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
isort = "^5.10.1"
black = "^22.6"
darglint = "^1.8.0"
flake8 = "^3.9.0"
flake8-annotations = "^2.9.1"
flake8-docstrings = "^1.6.0"

[tool.poetry.group.dev.dependencies]
pre-commit = "^2.20.0"

[tool.isort]
profile = "black"
multi_line_output = 3 # Vertical Hanging Indent
src_paths = "basic_python_template"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Example test. Update/remove/ignore as needed."""
pandemicsyn marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions tests/test_basic_python_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from basic_python_template import __version__


def test_version():
assert __version__ == "0.1.0"