Skip to content

Commit

Permalink
GitHub machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Sep 18, 2023
1 parent 9e9641a commit 9f18ded
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
14 changes: 14 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "basic"

on:
push:

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: pre-commit/action@v3.0.0
with:
extra_args: '--verbose --all-files'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ CONTRIBUTING.md
CODE_OF_CONDUCT.md
conf.py
README2.md

.ruff_cache
.venv
58 changes: 58 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace

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

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.286'
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.35.0
hooks:
- id: markdownlint-fix
args: [ "--ignore", "book/**/*.md", "--ignore", "readme/*.md" ]

- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade

#- repo: 'https://github.com/pre-commit/mirrors-mypy'
# rev: v1.4.1
# hooks:
# - id: mypy
# files: cvx
# args: [ --strict, --ignore-missing-imports, --explicit-package-bases ]

#- repo: https://github.com/python-jsonschema/check-jsonschema
# rev: 0.26.3
# hooks:
# - id: check-dependabot
# args: ["--verbose"]
# - id: check-github-workflows
# args: ["--verbose"]

#- repo: https://github.com/python-poetry/poetry
# rev: '1.6.1' # add version here
# hooks:
# - id: poetry-check
# - id: poetry-lock

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
- id: insert-license
files: ^(cvx)
args:
['--license-filepath', 'copyright.txt', '--no-extra-eol']
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.DEFAULT_GOAL := help

SHELL=/bin/bash

UNAME=$(shell uname -s)

.PHONY: install
install: ## Install a virtual environment
@poetry install -vv

.PHONY: fmt
fmt: ## Run autoformatting and linting
@poetry run pip install pre-commit
@poetry run pre-commit install
@poetry run pre-commit run --all-files

.PHONY: test
test: install ## Run tests
@poetry run pytest

.PHONY: clean
clean: ## Clean up caches and build artifacts
@git clean -X -d -f

.PHONY: coverage
coverage: install ## test and coverage
@poetry run coverage run --source=cvx/. -m pytest
@poetry run coverage report -m
@poetry run coverage html

@if [ ${UNAME} == "Darwin" ]; then \
open htmlcov/index.html; \
elif [ ${UNAME} == "linux" ]; then \
xdg-open htmlcov/index.html 2> /dev/null; \
fi


.PHONY: help
help: ## Display this help screen
@echo -e "\033[1mAvailable commands:\033[0m"
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' | sort


.PHONY: boil
boil: ## Update the boilerplate code
@gh repo clone git@github.com:cvxgrp/boilerplate.git .tmp
@cd .tmp && poetry install -vv && cd ..
@.tmp/.venv/bin/python .tmp/parse.py pyproject.toml
@rm -rf .tmp
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# cvxboilerplate

15 changes: 15 additions & 0 deletions cvx/boilerplate/parse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2023 Stanford University Convex Optimization Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import codecs

from jinja2 import FileSystemLoader, Environment
Expand All @@ -8,10 +21,12 @@ def toml_data(toml_file="pyproject.toml"):
d = toml.load(toml_file)
return d["tool"]["poetry"]


def jinja_environment(folder):
environment = Environment(loader=FileSystemLoader(folder))
return environment


def write(template, output_file, **kwargs):
# output the file
output_file = codecs.open(output_file, "w", "utf-8")
Expand Down
16 changes: 15 additions & 1 deletion parse.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# Copyright 2023 Stanford University Convex Optimization Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path
from loguru import logger

import fire

from cvx.boilerplate.parse import toml_data, write, jinja_environment


def parse(file="pyproject.toml"):
def f(source, target):
logger.info(f"rendering template {source} to {target}")
Expand All @@ -25,5 +39,5 @@ def f(source, target):
f("readme/readmeTemplate.md", "README2.md")


if __name__ == '__main__':
if __name__ == "__main__":
fire.Fire(parse)
10 changes: 4 additions & 6 deletions readme/readmeTemplate.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# [{{ name }}]({{ homepage }}/book)

[![PyPI version](https://badge.fury.io/py/{{ name }}.svg)](https://badge.fury.io/py/{{ name }})
[![Apache 2.0
License](https://img.shields.io/badge/License-APACHEv2-brightgreen.svg)]({{ repository }}/blob/master/LICENSE)
[![Downloads](https://static.pepy.tech/personalized-badge/{{ name }}?period=month&units=international_system&left_color=black&right_color=orange&left_text=PyPI%20downloads%20per%20month)](https://pepy.tech/project/{{ name }})
[![Coverage
Status](https://coveralls.io/repos/github/cvxgrp/{{ name }}/badge.png?branch=main)](https://coveralls.io/github/cvxgrp/{{ name }}?branch=main)
[![PyPI version](https://badge.fury.io/py/{{ name }}.svg)](<https://badge.fury.io/py/{{> name }})
[![Apache 2.0 License](https://img.shields.io/badge/License-APACHEv2-brightgreen.svg)]({{ repository }}/blob/master/LICENSE)
[![Downloads](https://static.pepy.tech/personalized-badge/{{ name }}?period=month&units=international_system&left_color=black&right_color=orange&left_text=PyPI%20downloads%20per%20month)](<https://pepy.tech/project/{{> name }})
[![Coverage Status](https://coveralls.io/repos/github/cvxgrp/{{ name }}/badge.png?branch=main)](<https://coveralls.io/github/cvxgrp/{{> name }}?branch=main)

0 comments on commit 9f18ded

Please sign in to comment.