-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Use pre-commit #396
base: master
Are you sure you want to change the base?
Use pre-commit #396
Changes from all commits
cc031b2
7e67b2b
ebc4e86
05a6e84
7853d2d
ae4ec1d
9c7a35a
a62b9a5
7189a5d
81ddbb1
a60c533
82cdf65
3c07540
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[flake8] | ||
max-line-length = 80 | ||
extend-select = B950 | ||
extend-ignore = E203,E501,E701 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
ci: | ||
autoupdate_schedule: "quarterly" | ||
|
||
default_language_version: | ||
python: "python3.13" | ||
|
||
repos: | ||
- repo: "meta" | ||
hooks: | ||
- id: "check-hooks-apply" | ||
- id: "check-useless-excludes" | ||
|
||
- repo: "https://github.com/pre-commit/pre-commit-hooks" | ||
rev: "v5.0.0" | ||
hooks: | ||
- id: "check-added-large-files" | ||
- id: "check-merge-conflict" | ||
- id: "check-yaml" | ||
- id: "end-of-file-fixer" | ||
- id: "mixed-line-ending" | ||
args: | ||
- "--fix=lf" | ||
- id: "trailing-whitespace" | ||
|
||
- repo: "https://github.com/asottile/pyupgrade" | ||
rev: "v3.19.1" | ||
hooks: | ||
- id: "pyupgrade" | ||
name: "Enforce Python 3.7+ idioms" | ||
args: | ||
- "--py37-plus" | ||
|
||
- repo: "https://github.com/psf/black-pre-commit-mirror" | ||
rev: "25.1.0" | ||
hooks: | ||
- id: "black" | ||
|
||
- repo: "https://github.com/pycqa/isort" | ||
rev: "6.0.0" | ||
hooks: | ||
- id: "isort" | ||
|
||
- repo: "https://github.com/pycqa/flake8" | ||
rev: "7.1.1" | ||
hooks: | ||
- id: "flake8" | ||
additional_dependencies: | ||
- "flake8-bugbear==24.12.12" | ||
|
||
- repo: "https://github.com/rhysd/actionlint" | ||
rev: "v1.7.7" | ||
hooks: | ||
- id: "actionlint" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Example Services for using pypandoc | ||
""" | ||
|
||
from tempfile import NamedTemporaryFile | ||
|
||
import pypandoc | ||
|
||
|
||
class BasePandocService(object): | ||
class BasePandocService: | ||
""" | ||
Base class for converting provided HTML to a doc or docx | ||
""" | ||
|
||
file_object = None | ||
|
||
def __init__(self): | ||
|
@@ -27,23 +28,22 @@ class PandocPDFService(BasePandocService): | |
""" | ||
Generate html to pdf format | ||
""" | ||
|
||
def generate(self, html, **kwargs): | ||
""" | ||
generate the pdf but needs to be set as tex so pandoc handles it | ||
correctly see docs: http://johnmacfarlane.net/pandoc/ #search pdf | ||
""" | ||
from_format = kwargs.get('from_format', 'html') | ||
to_format = kwargs.get('to_format', 'tex') | ||
from_format = kwargs.get("from_format", "html") | ||
to_format = kwargs.get("to_format", "tex") | ||
# create temp file | ||
self.file_object = NamedTemporaryFile(suffix='.pdf') | ||
self.file_object = NamedTemporaryFile(suffix=".pdf") | ||
Comment on lines
-38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was made by black -- it auto-corrects single quotes to double quotes. |
||
|
||
extra_args = ( | ||
'--smart', | ||
'--standalone', | ||
'-o', self.file_object.name | ||
) | ||
extra_args = ("--smart", "--standalone", "-o", self.file_object.name) | ||
Comment on lines
-40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was made by black -- it standardizes tuples and lists to be on a single line if they'll fit, with one exception. If you put a trailing comma after |
||
# generate it using pandoc | ||
self.service.convert_text(html, to_format, format=from_format, extra_args=extra_args) | ||
self.service.convert_text( | ||
html, to_format, format=from_format, extra_args=extra_args | ||
) | ||
# return the file which is now populated with the docx forms | ||
return self.file_object | ||
|
||
|
@@ -52,18 +52,17 @@ class PandocDocxService(BasePandocService): | |
""" | ||
Generate html to docx format | ||
""" | ||
|
||
def generate(self, html, **kwargs): | ||
from_format = kwargs.get('from_format', 'html') | ||
to_format = kwargs.get('to_format', 'docx') | ||
from_format = kwargs.get("from_format", "html") | ||
to_format = kwargs.get("to_format", "docx") | ||
# create temp file | ||
self.file_object = NamedTemporaryFile(suffix='.docx') | ||
self.file_object = NamedTemporaryFile(suffix=".docx") | ||
|
||
extra_args = ( | ||
'--smart', | ||
'--standalone', | ||
'-o', self.file_object.name | ||
) | ||
extra_args = ("--smart", "--standalone", "-o", self.file_object.name) | ||
# generate it using pandoc | ||
self.service.convert_text(html, to_format, format=from_format, extra_args=extra_args) | ||
self.service.convert_text( | ||
html, to_format, format=from_format, extra_args=extra_args | ||
) | ||
# return the file which is now populated with the docx forms | ||
return self.file_object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was made by pyupgrade -- in Python 3, all classes inherit from
object
, so when upgrading to Python 3.7+ syntax and idioms, pyupgrade knows that it isn't necessary to inherit fromobject
.