Skip to content

Commit

Permalink
🎉 Init template
Browse files Browse the repository at this point in the history
  • Loading branch information
nymann committed Aug 27, 2022
0 parents commit 94f96ba
Show file tree
Hide file tree
Showing 24 changed files with 414 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = True

[*]
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = True
trim_trailing_whitespace = True

[*.py]
charset = utf-8

[*.{js,json}]
charset = utf-8
indent_size = 2

[*.{yml,yaml,md,rb}]
indent_size = 2

[Makefile,*.mk]
indent_style = tab
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: PDF Scrub CI Lint

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Pip
run: |
python -m pip install --upgrade pip
- name: Run Lint
run: |
make tests
34 changes: 34 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Package

on:
push:
tags:
- "*"

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Pip
run: |
python -m pip install --upgrade pip
- name: Make package
run: |
pip install wheel
make package
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: PDF Scrub CI Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Pip
run: python -m pip install --upgrade pip
- name: Run Tests
run: make test
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
bin
include
lib
lib64
pyvenv.cfg
tags

.eggs:
pytest_runner-5.3.1-py3.9.egg
README.txt

src/pdf_scrub.egg-info:
dependency_links.txt
entry_points.txt
PKG-INFO
requires.txt
src/pdf_scrub/version.py
SOURCES.txt
top_level.txt
__pycache__/
.coverage
coverage.xml
htmlcov
.idea
.cache/
41 changes: 41 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
### Cross platform development

By installing `make` you can do the following:

```sh
$ make help
make install
- Installs pdf_scrub.
make install-all
- Install pdf_scrub, all development and tests dependencies.
make test
- Runs integration tests and unit tests
make unit-test
- Runs integration tests
make integration-tests
- Runs unit tests
make lint
- Lints your code (black, flake8 and mypy).
make fix
- Autofixes imports and some formatting.
```

### Developing on Linux

#### Run helping tools automatically on file change

While the `make` targets is an okay way to run things, I find it helpful to have my tests and linter running in separate terminal windows to get continous quick feedback.

The command `ag` is from The Silver Searcher program which can be found [here](https://archlinux.org/packages/community/x86_64/the_silver_searcher/). And the `entr` program can be found [here](https://archlinux.org/packages/community/x86_64/entr/).

###### Run `unit tests` on file change automatically

```sh
alias unit="ag -l | entr -c pytest --durations=0 tests/unit_tests"
```

###### Run `flake8` on file change automatically

```sh
alias flakeit="ag -l | entr -c flake8 tests src"
```
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
graft src
global-exclude *.pyc
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
COMPONENT?=pdf_scrub
VERSION:=src/${COMPONENT}/version.py
.DEFAULT:help
include make/help.mk
include make/common.mk
include make/install.mk
include make/test.mk
include make/lint.mk
include make/ci.mk

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PDF Scrub

## Development

For help getting started developing check [DEVELOPMENT.md](DEVELOPMENT.md)
4 changes: 4 additions & 0 deletions make/ci.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package: ${VERSION} setup.py
@python setup.py sdist bdist_wheel

.PHONY:package
2 changes: 2 additions & 0 deletions make/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
${VERSION}:
@echo "__version__ = \"$(shell git describe --tag --always | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "0.0.0")\"" > ${VERSION}
14 changes: 14 additions & 0 deletions make/help.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
help:
@printf "\e[92m%s\e[0m\n" "make install"
@echo " - Installs ${COMPONENT}."
@printf "\e[92m%s\e[0m\n" "make install-all"
@echo " - Install ${COMPONENT}, all development and tests dependencies in editable mode."
@printf "\e[92m%s\e[0m\n" "make test"
@echo " - Runs unit tests"
@printf "\e[92m%s\e[0m\n" "make lint"
@echo " - Lints your code (black, flake8 and mypy)."
@printf "\e[92m%s\e[0m\n" "make fix"
@echo " - Autofixes imports and some formatting."

.PHONY: help
.DEFAULT: help
11 changes: 11 additions & 0 deletions make/install.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
install: ${VERSION}
@pip install .

install-all: ${VERSION}
@pip install -e '.[all]'

install-dev: ${VERSION}
@pip install -e '.[dev]'

install-tests: ${VERSION}
@pip install -e '.[tests]'
15 changes: 15 additions & 0 deletions make/lint.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ensure-lint-dependencies:
command -v black flake8 mypy 2>/dev/null || make install-dev

ensure-fix-dependencies:
command -v black isort 2>/dev/null || make install-dev


lint: ensure-lint-dependencies $(VERSION)
black --check -q src tests
flake8 src tests
mypy src tests

fix: ensure-fix-dependencies $(VERSION)
black src tests
isort src tests
5 changes: 5 additions & 0 deletions make/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ensure-test-dependencies:
command -v pytest 2>/dev/null || make install-tests

test: ${VERSION} ensure-test-dependencies
pytest tests/unit_tests
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool.black]
line-length = 120

[tool.nitpick]
style = "https://raw.githubusercontent.com/nymann/python-styleguide/master/styles/nitpick-style.toml"
cache = "never"
112 changes: 112 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[metadata]
name = pdf_scrub
url = "https://github.com/nymann/pdf-scrub"
maintainer = Kristian Nymann Jakobsen
maintainer_email = [email protected]
description = PDF Scrub
long_description = file: README.md
long_description_content_type = text/markdown

[options]
packages = find:
include_package_data = true
package_dir = = src
python_requires = >= 3.9
setup_requires =
pytest-runner
install_requires =
typer >= 0.4.1

[options.extras_require]
all =
%(dev)s
%(tests)s
dev =
isort
wemake-python-styleguide
mypy
black
nitpick
add-trailing-comma
tests =
pytest
pytest-cov
pytest-mock

[options.packages.find]
where = src

[options.entry_points]
console_scripts =
pdf_scrub = pdf_scrub.main:app


[tool:pytest]
testpaths = tests
addopts =
--color=yes
--cov-report=xml
--cov-report=html
--cov=src
--cov-report=term-missing

[coverage:run]
branch = true
omit = src/pdf_scrub/version.py
source =
src
tests

[coverage:paths]
source =
src

[aliases]
test=pytest

[pydocstyle]
convention=google

[flake8]
docstring-style = google
format = wemake
ignore = WPS305,D100,D101,D102,D103,D104,D107,H601,WPS306
max-complexity = 6
max-line-length = 120
show-source = True
strictness = long
inline-quotes = double
per-file-ignores =
tests/**.py:WPS218,WPS432,WPS442,S101,src/**/version.py:WPS410

[isort]
combine_as_imports = True
force_grid_wrap = 0
force_single_line = True
force_sort_within_sections = True
include_trailing_comma = True
lexicographical = True
line_length = 120
multi_line_output = 3
single_line_exclusions = typing
src_paths = src,tests

[mypy]
allow_redefinition = False
check_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_calls = True
disallow_untyped_decorators = False
disallow_untyped_defs = True
ignore_errors = False
ignore_missing_imports = True
implicit_reexport = False
local_partial_types = True
no_implicit_optional = True
strict_equality = True
strict_optional = True
warn_no_return = True
warn_redundant_casts = True
warn_unreachable = True
warn_unused_configs = True
warn_unused_ignores = True
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from distutils import util
from typing import Dict

import setuptools

version: Dict[str, str] = {}
path = util.convert_path("src/pdf_scrub/version.py")
with open(path) as version_file:
exec(version_file.read(), version) # noqa: S102 DUO105, WPS421

setuptools.setup(version=version["__version__"])
Empty file added src/pdf_scrub/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions src/pdf_scrub/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import typer

app = typer.Typer()


@app.command()
def welcome(name: str) -> None:
typer.echo(f"Welcome {name}!")


if __name__ == "__main__":
app()
Empty file added tests/__init__.py
Empty file.
Empty file added tests/unit_tests/__init__.py
Empty file.
Loading

0 comments on commit 94f96ba

Please sign in to comment.