-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0085799
Showing
14 changed files
with
379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[flake8] | ||
max-line-length = 115 | ||
|
||
ignore = | ||
# these rules don't play well with black | ||
E203 # whitespace before : | ||
W503 # line break before binary operator | ||
|
||
per-file-ignores = | ||
# __init__.py files are allowed to have unused imports and lines-too-long | ||
*/__init__.py:F401 | ||
*/**/**/__init__.py:F401,E501 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: pip | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
time: "13:00" | ||
open-pull-requests-limit: 10 | ||
ignore: | ||
- dependency-name: nr-databind-core | ||
versions: | ||
- ">= 0.0.a" | ||
- "< 0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
name: CI | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*.*.*' | ||
|
||
env: | ||
# Change this to invalidate existing cache. | ||
CACHE_PREFIX: v0 | ||
PYTHON_PATH: ./ | ||
DEFAULT_PYTHON: 3.8 | ||
|
||
jobs: | ||
changelog: | ||
name: CHANGELOG | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'pull_request' | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Check if source files have changed | ||
run: | | ||
git diff --name-only $(git merge-base origin/main HEAD) | grep '^my_package/.*\.py$' && echo "source_files_changed=true" >> $GITHUB_ENV || echo "source_files_changed=false" >> $GITHUB_ENV | ||
- name: Check that CHANGELOG has been updated | ||
if: env.source_files_changed == 'true' | ||
run: | | ||
# If this step fails, this means you haven't updated the CHANGELOG.md | ||
# file with notes on your contribution. | ||
git diff --name-only $(git merge-base origin/main HEAD) | grep '^CHANGELOG.md$' && echo "Thanks for helping keep our CHANGELOG up-to-date!" | ||
checks: | ||
name: ${{ matrix.task.name }} | ||
runs-on: [ubuntu-latest] | ||
timeout-minutes: 30 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python: [3.8] | ||
task: | ||
- name: Style | ||
run: | | ||
black --check . | ||
- name: Lint | ||
run: | | ||
flake8 . | ||
- name: Type check | ||
run: | | ||
mypy . | ||
- name: Test | ||
run: | | ||
pytest -v --color=yes tests/ | ||
- name: Build | ||
run: | | ||
python setup.py check | ||
python setup.py bdist_wheel sdist | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
|
||
- name: Install prerequisites | ||
run: | | ||
pip install --upgrade pip setuptools wheel virtualenv | ||
- name: Set build variables | ||
shell: bash | ||
run: | | ||
# Get the exact Python version to use in the cache key. | ||
echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV | ||
echo "RUNNER_ARCH=$(uname -m)" >> $GITHUB_ENV | ||
# Use week number in cache key so we can refresh the cache weekly. | ||
echo "WEEK_NUMBER=$(date +%V)" >> $GITHUB_ENV | ||
- uses: actions/cache@v2 | ||
id: virtualenv-cache | ||
with: | ||
path: .venv | ||
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('dev-requirements.txt') }} | ||
restore-keys: | | ||
${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}- | ||
- name: Setup virtual environment (no cache hit) | ||
if: steps.virtualenv-cache.outputs.cache-hit != 'true' | ||
run: | | ||
test -d .venv || virtualenv -p $(which python) --copies --reset-app-data .venv | ||
. .venv/bin/activate | ||
pip install -r requirements.txt -r dev-requirements.txt | ||
- name: Show environment info | ||
run: | | ||
. .venv/bin/activate | ||
which python | ||
python --version | ||
pip freeze | ||
- name: ${{ matrix.task.name }} | ||
run: | | ||
. .venv/bin/activate | ||
${{ matrix.task.run }} | ||
- name: Upload package distribution files | ||
if: ${{ matrix.task.name }} == 'Build' && ${{ matrix.python }} == ${{ env.DEFAULT_PYTHON }} | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: package | ||
path: dist | ||
|
||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
needs: [checks] | ||
if: startsWith(github.ref, 'refs/tags/') | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ env.DEFAULT_PYTHON }} | ||
|
||
- name: Install requirements | ||
run: | | ||
pip install --upgrade pip setuptools wheel twine | ||
- name: Prepare environment | ||
run: | | ||
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | ||
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | ||
- name: Download package distribution files | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: package | ||
path: dist | ||
|
||
- name: Generate release notes | ||
run: | | ||
./scripts/release_notes.py > ${{ github.workspace }}-RELEASE_NOTES.md | ||
- name: Publish package to PyPI | ||
run: | | ||
twine upload -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} dist/* | ||
- name: Publish GitHub release | ||
uses: softprops/action-gh-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
body_path: ${{ github.workspace }}-RELEASE_NOTES.md | ||
prerelease: ${{ contains(env.TAG, '-rc') }} | ||
files: | | ||
dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## Unreleased |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# python-package-template | ||
|
||
This is a template repository for projects that are Python packages. | ||
|
||
## Getting started | ||
|
||
After creating a new repository from this template, you need to: | ||
|
||
1. Change the name of the `my_package` directory to the name you want. | ||
2. Replace all mentions of `my_package` throughout this repository with the name you want. | ||
|
||
```bash | ||
find . -type f -not -path ./.git -not -path ./README.md | xargs grep 'my_package' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Checks style, syntax, and other useful errors. | ||
flake8 | ||
|
||
# Static type checking | ||
mypy==0.910 | ||
|
||
# Automatic code formatting | ||
black==21.7b0 | ||
|
||
# Allows generation of coverage reports with pytest. | ||
pytest-cov | ||
|
||
# Allows codecov to generate coverage reports | ||
coverage | ||
codecov | ||
|
||
# Needed for packaging and uploading to PyPi | ||
twine>=1.11.0 | ||
setuptools | ||
wheel |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[mypy] | ||
ignore_missing_imports = true | ||
no_site_packages = true | ||
|
||
[mypy-tests.*] | ||
strict_optional = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[tool.black] | ||
line-length = 100 | ||
|
||
include = '\.pyi?$' | ||
|
||
exclude = ''' | ||
( | ||
__pycache__ | ||
| \.git | ||
| \.mypy_cache | ||
| \.pytest_cache | ||
| \.vscode | ||
| \.venv | ||
| \bdist\b | ||
| \bdoc\b | ||
) | ||
''' | ||
|
||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
build-backend = "setuptools.build_meta" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[pytest] | ||
testpaths = tests/ | ||
python_classes = Test* *Test | ||
log_format = %(asctime)s - %(levelname)s - %(name)s - %(message)s | ||
log_level = DEBUG | ||
markers = | ||
filterwarnings = |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# encoding: utf-8 | ||
|
||
""" | ||
Prepares markdown release notes for GitHub releases. | ||
""" | ||
|
||
import os | ||
from typing import List | ||
|
||
TAG = os.environ["TAG"] | ||
|
||
ADDED_HEADER = "### Added 🎉" | ||
CHANGED_HEADER = "### Changed ⚠️" | ||
FIXED_HEADER = "### Fixed ✅" | ||
REMOVED_HEADER = "### Removed 👋" | ||
|
||
|
||
def get_change_log_notes() -> str: | ||
in_current_section = False | ||
current_section_notes: List[str] = [] | ||
with open("CHANGELOG.md") as changelog: | ||
for line in changelog: | ||
if line.startswith("## "): | ||
if line.startswith("## Unreleased"): | ||
continue | ||
if line.startswith(f"## [{TAG}]"): | ||
in_current_section = True | ||
continue | ||
break | ||
if in_current_section: | ||
if line.startswith("### Added"): | ||
line = ADDED_HEADER + "\n" | ||
elif line.startswith("### Changed"): | ||
line = CHANGED_HEADER + "\n" | ||
elif line.startswith("### Fixed"): | ||
line = FIXED_HEADER + "\n" | ||
elif line.startswith("### Removed"): | ||
line = REMOVED_HEADER + "\n" | ||
current_section_notes.append(line) | ||
assert current_section_notes | ||
return "## What's new\n\n" + "".join(current_section_notes).strip() + "\n" | ||
|
||
|
||
def get_commit_history() -> str: | ||
stream = os.popen( | ||
f"git log $(git describe --always --tags --abbrev=0 {TAG}^^)..{TAG}^ --oneline" | ||
) | ||
return "## Commits\n\n" + stream.read() | ||
|
||
|
||
def main(): | ||
print(get_change_log_notes()) | ||
print(get_commit_history()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from setuptools import setup, find_packages | ||
import os | ||
|
||
# Load requirements.txt with a special case for allennlp so we can handle | ||
# cross-library integration testing. | ||
with open("requirements.txt") as requirements_file: | ||
import re | ||
|
||
def fix_url_dependencies(req: str) -> str: | ||
"""Pip and setuptools disagree about how URL dependencies should be handled.""" | ||
m = re.match( | ||
r"^(git\+)?(https|ssh)://(git@)?github\.com/([\w-]+)/(?P<name>[\w-]+)\.git", req | ||
) | ||
if m is None: | ||
return req | ||
else: | ||
return f"{m.group('name')} @ {req}" | ||
|
||
install_requirements = [] | ||
for line in requirements_file: | ||
line = line.strip() | ||
if line.startswith("#") or len(line) <= 0: | ||
continue | ||
install_requirements.append(fix_url_dependencies(line)) | ||
|
||
setup( | ||
name="my_package", | ||
version="0.0.1", | ||
description="", | ||
long_description=open("README.md").read(), | ||
long_description_content_type="text/markdown", | ||
classifiers=[ | ||
"Intended Audience :: Science/Research", | ||
"Development Status :: 3 - Alpha", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Scientific/Engineering :: Artificial Intelligence", | ||
], | ||
keywords="", | ||
url="", | ||
author="Allen Institute for Artificial Intelligence", | ||
author_email="[email protected]", | ||
license="Apache", | ||
packages=find_packages( | ||
exclude=["*.tests", "*.tests.*", "tests.*", "tests"], | ||
), | ||
install_requires=install_requirements, | ||
python_requires=">=3.6.1", | ||
) |
Empty file.