Skip to content

Commit

Permalink
feat: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
liblaf committed May 25, 2023
1 parent 6d30859 commit 86d8d11
Show file tree
Hide file tree
Showing 76 changed files with 667 additions and 429 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2

updates:
- package-ecosystem: gitsubmodule
directory: /
schedule:
interval: weekly
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
- package-ecosystem: pip
directory: /
schedule:
interval: weekly
2 changes: 2 additions & 0 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings

# Automatically delete head branches after merging PRs. Defaults to `true`.
deleteBranchOnMerge: true
8 changes: 2 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
name: CI
name: CI/CD

on:
push:
branches:
- main

# - [x] Settings > General > Pull Requests > Automatically delete head branches
# - [x] Settings > Actions > General > Workflow permissions > Allow GitHub Actions to create and approve pull requests
permissions:
contents: write
pull-requests: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
outputs:
releases-created: ${{ steps.release.outputs.releases_created }}
tag-name: ${{ steps.release.outputs.tag_name }}
steps:
- id: release
name: Release
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:

jobs:
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -26,7 +27,8 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
cache-dependency-path: docs/requirements.txt
- name: Install Python Dependencies
run: make pip
run: pip install --requirement docs/requirements.txt
- name: Deploy to GitHub Pages
run: make docs-gh-deploy
run: make --jobs docs-deploy-gh
7 changes: 4 additions & 3 deletions .github/workflows/license.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: Update LICENSE Year(s)
name: Update LICENSE Year

on:
schedule:
- cron: 0 3 1 1 * # Jan 1 03:00:00 AM UTC
- cron: 0 3 1 1 * # 03:00 AM on January 1

permissions:
contents: write

jobs:
license:
name: Update LICENSE Year
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update LICENSE Year(s)
- name: Update LICENSE Year
uses: FantasticFiasco/action-update-license-year@v3
with:
token: ${{ github.token }}
146 changes: 136 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,156 @@
ci:
skip:
- go-unit-tests
- go-build

repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: "3.2.2"
hooks:
- id: commitizen
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
stages:
- commit
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
hooks:
- id: check-added-large-files
- id: check-ast
# - id: check-byte-order-marker # deprecated
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
# - id: check-shebang-scripts-are-executable
# - id: pretty-format-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
# - id: detect-aws-credentials
- id: detect-private-key
# - id: double-quote-string-fixer
- id: end-of-file-fixer
# - id: file-contents-sorter
- id: fix-byte-order-marker
# - id: fix-encoding-pragma
# - id: forbid-new-submodules
# - id: forbid-submodules
- id: mixed-line-ending
- id: name-tests-test
# - id: no-commit-to-branch
# - id: requirements-txt-fixer
# - id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v16.0.3"
hooks:
- id: clang-format
types_or:
- c
- c++
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
- repo: https://github.com/dnephin/pre-commit-golang
rev: "v0.5.1"
hooks:
- id: go-fmt
# - id: go-vet
# - id: go-lint
# - id: go-imports
# - id: go-cyclo
# - id: validate-toml
- id: no-go-testing
# - id: golangci-lint
# - id: go-critic
- id: go-unit-tests
- id: go-build
- id: go-mod-tidy
files: go.mod
- repo: https://github.com/psf/black
rev: "23.3.0"
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort
args:
- --profile
- black
- repo: https://github.com/commitizen-tools/commitizen
rev: "3.2.2"
hooks:
- id: commitizen
# - id: commitizen-branch
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: "v0.6.13"
hooks:
- id: cmake-format
- id: cmake-lint
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.23.0"
hooks:
# - id: check-jsonschema
# - id: check-metaschema
- id: check-azure-pipelines
- id: check-bamboo-spec
- id: check-buildkite
- id: check-dependabot
- id: check-github-actions
- id: check-github-workflows
- id: check-gitlab-ci
- id: check-readthedocs
- id: check-renovate
- id: check-travis
- repo: https://github.com/sirosen/texthooks
rev: "0.5.0"
hooks:
- id: fix-smartquotes
- id: fix-ligatures
- id: fix-spaces
- id: forbid-bidi-controls
- id: macro-expand
- repo: https://github.com/scop/pre-commit-shfmt
rev: "v3.6.0-2"
hooks:
- id: shfmt
files: (.sh|.zsh|.zsh-theme|envrc|zshrc)(.tmpl)?$
types:
- text
args:
- --write
- --simplify
- --indent
- "2"
- --case-indent
- --space-redirects
# - id: shfmt-docker
- repo: https://github.com/cmhughes/latexindent.pl
rev: "V3.21.1"
hooks:
- id: latexindent
files: .(tex|sty|cls|bib)$
types:
- text
args:
- --overwriteIfDifferent
- --silent
- --cruft=/tmp
- --modifylinebreaks
- --GCString
# - id: latexindent-conda
# - id: latexindent-docker

- repo: https://github.com/python-poetry/poetry
rev: "1.4.2"
hooks:
- id: poetry-check
- id: poetry-lock
files: pyproject.toml
- id: poetry-export
args:
- --output=requirements.txt
- --without-hashes
- --without-urls
112 changes: 63 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,64 +1,78 @@
CONFIG_DIR := $(CURDIR)/config
DEMO_DIR := $(CURDIR)/demo
DOCS_DIR := $(CURDIR)/docs
SCRIPT_DIR := $(CURDIR)/script
SRC_DIR := $(CURDIR)/src
TEXMFHOME != kpsewhich -var-value=TEXMFHOME
TMP_DIR := /tmp

DEMO_SRC_LIST :=
DEMO_SRC_LIST += $(DEMO_DIR)/article/chinese/chinese.tex
DEMO_SRC_LIST += $(DEMO_DIR)/article/default/default.tex
DEMO_SRC_LIST += $(DEMO_DIR)/article/two-column/two-column.tex
DEMO_SRC_LIST += $(DEMO_DIR)/work/default/default.tex
SRC_LIST := $(wildcard $(SRC_DIR)/*)

DEMO_PDF_LIST := $(patsubst $(DEMO_DIR)/%.tex, $(DOCS_DIR)/demo/%.pdf, $(DEMO_SRC_LIST))
TARGET_LIST := $(patsubst $(SRC_DIR)/%, $(TEXMFHOME)/tex/latex/%, $(SRC_LIST))

INSTALL_OPTIONS := -D --mode="u=rw,go=r" --no-target-directory --verbose
LATEXMK := env TEXINPUTS="$(SRC_DIR):" latexmk
LATEXMK_OPTIONS := -xelatex -file-line-error -interaction=nonstopmode -shell-escape

all: docs install

clean:
$(RM) --recursive $(DOCS_DIR)/demo
git clean -d --force -X

docs: $(DEMO_PDF_LIST)

docs-gh-deploy: docs
MAKEFLAGS += --jobs

PROJECT := ilatex

CONFIG := $(CURDIR)/config
DEMO := $(CURDIR)/demo
DOCS := $(CURDIR)/docs
SCRIPTS := $(CURDIR)/scripts
SRC := $(CURDIR)/src
TEXMFHOME != kpsewhich -var-value=TEXMFHOME
TMP := /tmp

DEMO_LIST != find $(DEMO) "(" -name "*.tex" -or -name "*.sty" -or -name "*.cls" -or -name "*.bib" ")"
DEMO_PDF_LIST += $(DEMO)/article/chinese/chinese.pdf
DEMO_PDF_LIST += $(DEMO)/article/default/default.pdf
DEMO_PDF_LIST += $(DEMO)/article/manual/manual.pdf
DEMO_PDF_LIST += $(DEMO)/work/chinese/chinese.pdf
DEMO_PDF_LIST += $(DEMO)/work/default/default.pdf
DOCS_LIST += $(DEMO_PDF_LIST:$(DEMO)/%.pdf=$(DOCS)/demo/%.pdf)
DOCS_LIST += $(DOCS)/index.md
LATEXINDENT_CONFIG := $(HOME)/.config/latexindent/latexindent.yaml
SRC_LIST != find $(SRC) "(" -name "*.tex" -or -name "*.sty" -or -name "*.cls" -or -name "*.bib" ")"
TARGET_LIST += $(HOME)/.indentconfig.yaml
TARGET_LIST += $(LATEXINDENT_CONFIG)
TARGET_LIST += $(SRC_LIST:$(SRC)/%=$(TEXMFHOME)/tex/latex/$(PROJECT)/%)

INSTALL_OPTIONS := -D --mode="u=rw,go=r" --no-target-directory --verbose
LATEXINDENT_OPTIONS := --overwriteIfDifferent --silent --cruft=$(TMP) --modifylinebreaks --GCString
LATEXMK := env TEXINPUTS=$(SRC): latexmk
LATEXMK_OPTIONS := -xelatex -file-line-error -interaction=nonstopmode -shell-escape

all:

clean: $(DEMO_LIST:$(CURDIR)/%=clean-$(CURDIR)/%)
@ $(RM) --recursive --verbose $(DOCS)/demo

docs-build: $(DOCS_LIST)
mkdocs build

docs-gh-deploy: $(DOCS_LIST)
mkdocs gh-deploy --force --no-history

docs-serve: docs
docs-serve: $(DOCS_LIST)
mkdocs serve

install: $(TARGET_LIST)
texhash

pretty: $(DEMO_SRC_LIST) $(SRC_LIST)
$(foreach src, $^, latexindent --overwrite --local --cruft=$(TMP_DIR) --modifylinebreaks --GCString $(src);)
$(MAKE) --directory=$(SCRIPT_DIR) pretty

package-to-subsection: $(SCRIPT_DIR)/package-to-subsection.py $(CONFIG_DIR)/packages.yaml | $(DEMO_DIR)/article/default/package
python $< --config $(CONFIG_DIR)/packages.yaml --package-dir $|
pretty: $(CURDIR)/.gitignore $(DEMO_LIST:$(CURDIR)/%=latexindent-$(CURDIR)/%) $(SRC_LIST:$(CURDIR)/%=latexindent-$(CURDIR)/%)
prettier --write --ignore-path $< $(CURDIR)

pip: $(CURDIR)/requirements.txt $(DOCS_DIR)/requirements.txt $(SCRIPT_DIR)/requirements.txt
$(foreach req, $^, pip install --requirement $(req);)
pkg-to-subsection: $(SCRIPTS)/pkg-to-subsection.py $(CONFIG)/pkgs.yaml | $(DEMO)/article/manual/pkg
python $< --config $(CONFIG)/pkgs.yaml --pkg-dir $|

ALWAYS:

$(DEMO_DIR)/%.pdf: $(DEMO_DIR)/%.tex ALWAYS
cd $(dir $<) && $(LATEXMK) $(LATEXMK_OPTIONS) $<
$(DEMO)/%.pdf: $(DEMO)/%.tex ALWAYS
cd $(@D) && $(LATEXMK) $(LATEXMK_OPTIONS) $<

$(DOCS)/demo/%.pdf: $(DEMO)/%.pdf
@ install $(INSTALL_OPTIONS) $< $@

$(LATEXINDENT_CONFIG): $(CURDIR)/.latexindent.yaml
@ install $(INSTALL_OPTIONS) $< $@

$(DEMO_DIR)/article/default/default.tex: package-to-subsection
$(HOME)/.indentconfig.yaml: $(LATEXINDENT_CONFIG)
echo 'paths:' > $@
echo ' - $(LATEXINDENT_CONFIG)' >> $@

$(DEMO_DIR)/article/default/package:
mkdir --parents $@
$(TEXMFHOME)/tex/latex/$(PROJECT)/%: $(SRC)/%
@ install $(INSTALL_OPTIONS) $< $@

$(DOCS_DIR)/demo/%.pdf: $(DEMO_DIR)/%.pdf
install $(INSTALL_OPTIONS) $< $@
clean-$(CURDIR)/%: $(CURDIR)/%
@ $(RM) --recursive --verbose $(<D)/_minted-* $(<D)/*.bbl $(<D)/*.listing $(<D)/*.run.xml $(<D)/indent.log
cd $(<D) && $(LATEXMK) $(LATEXMK_OPTIONS) -C $<

$(TEXMFHOME)/tex/latex/%: $(SRC_DIR)/%
install $(INSTALL_OPTIONS) $< $@
latexindent-$(CURDIR)/%: $(CURDIR)/%
latexindent $(LATEXINDENT_OPTIONS) $<
Loading

0 comments on commit 86d8d11

Please sign in to comment.