Skip to content

Commit

Permalink
Update pre-commit hooks
Browse files Browse the repository at this point in the history
… and make the appropriate changes to make the checks pass
  • Loading branch information
abravalheri committed Nov 3, 2020
1 parent 0fd9171 commit ea91026
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ about: Create a report to help us improve

**Please provide a minimal, self-contained, and reproducible example.**
```python
[Your code here]
# [Your code here]
```

**Please provide the full traceback.**
```python
[The error output here]
# [The error output here]
```

**Please provide any additional information below.**
Expand Down
25 changes: 21 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: '^(src/pyscaffold/contrib|docs/conf.py|docs/gfx)'

repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v3.3.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -17,18 +17,35 @@ repos:
- id: mixed-line-ending
args: ['--fix=no']

- repo: https://github.com/myint/autoflake.git
rev: v1.4
hooks:
- id: autoflake
args: [
--in-place,
--remove-all-unused-imports,
--remove-unused-variables,
]

- repo: http://github.com/timothycrosley/isort
rev: 5.4.2
rev: 5.6.4
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: stable
rev: 20.8b1
hooks:
- id: black
language_version: python3

- repo: https://github.com/asottile/blacken-docs
rev: v1.8.0
hooks:
- id: blacken-docs
additional_dependencies: [black]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.8.4
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
71 changes: 40 additions & 31 deletions docs/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ of the list of actions:
class MyExtension(Extension):
"""Help text on commandline when running putup -h"""
def activate(self, actions):
"""Activate extension
Expand All @@ -161,8 +162,8 @@ of the list of actions:
Returns:
list: updated list of actions
"""
actions = helpers.register(actions, self.action, after='create_structure')
actions = helpers.unregister(actions, 'init_git')
actions = helpers.register(actions, self.action, after="create_structure")
actions = helpers.unregister(actions, "init_git")
return actions
def action(self, struct, opts):
Expand Down Expand Up @@ -292,56 +293,64 @@ extension which defines the ``define_awesome_files`` action:
assert awesome() == "Awesome!"
"""
class AwesomeFiles(Extension):
"""Adding some additional awesome files"""
def activate(self, actions):
return helpers.register(actions, self.define_awesome_files)
def define_awesome_files(self, struct, opts):
struct = helpers.merge(struct, {
opts['project']: {
'src': {
opts['package']: {
'awesome.py': MY_AWESOME_FILE.format(**opts)
struct = helpers.merge(
struct,
{
opts["project"]: {
"src": {
opts["package"]: {"awesome.py": MY_AWESOME_FILE.format(**opts)},
},
"tests": {
"awesome_test.py": (
MY_AWESOME_TEST.format(**opts),
helpers.NO_OVERWRITE,
)
},
}
'tests': {
'awesome_test.py': (
MY_AWESOME_TEST.format(**opts),
helpers.NO_OVERWRITE
)
}
}
})
},
)
struct['.python-version'] = ('3.6.1', helpers.NO_OVERWRITE)
struct[".python-version"] = ("3.6.1", helpers.NO_OVERWRITE)
for filename in ['awesome_file1', 'awesome_file2']:
for filename in ["awesome_file1", "awesome_file2"]:
struct = helpers.ensure(
struct,
PurePath(opts['project'], 'src', 'awesome', filename),
content='AWESOME!', update_rule=helpers.NO_CREATE)
# The second argument is the file path, represented by a
# list of file parts or a string.
# Alternatively in this example:
# path = '{project}/src/awesome/{filename}'.format(
# filename=filename, **opts)
PurePath(opts["project"], "src", "awesome", filename),
content="AWESOME!",
update_rule=helpers.NO_CREATE,
)
# The second argument is the file path, represented by a
# list of file parts or a string.
# Alternatively in this example:
# path = '{project}/src/awesome/{filename}'.format(
# filename=filename, **opts)
# The `reject` can be used to avoid default files being generated.
struct = helpers.reject(
struct, '{project}/src/{package}/skeleton.py'.format(**opts))
# Alternatively in this example:
# path = [opts['project'], 'src', opts['package'], 'skeleton.py'])
struct, "{project}/src/{package}/skeleton.py".format(**opts)
)
# Alternatively in this example:
# path = [opts['project'], 'src', opts['package'], 'skeleton.py'])
# `modify` can be used to change contents in an existing file
struct = helpers.modify(
struct,
PurePath(opts['project'], 'tests', 'awesome_test.py'),
lambda content: 'import pdb\n' + content)
PurePath(opts["project"], "tests", "awesome_test.py"),
lambda content: "import pdb\n" + content,
)
# And/or change the update behavior
struct = helpers.modify(struct, [opts['project'], '.travis.yml'],
update_rule=helpers.NO_CREATE)
struct = helpers.modify(
struct, [opts["project"], ".travis.yml"], update_rule=helpers.NO_CREATE
)
# It is import to remember the return values
return struct, opts
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template* with everything you need for some serious coding. After the usual::

you are all set and ready to go which means in a Python shell you can do the following:

.. code-block:: python
.. code-block:: pycon
>>> from my_project.skeleton import fib
>>> fib(10)
Expand Down
12 changes: 7 additions & 5 deletions docs/python-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ The following example illustrates a typical embedded usage of PyScaffold:
logging.getLogger(LOGGER_NAME).setLevel(logging.INFO)
create_project(project="my-proj-name", author="Your Name",
namespace="some.namespace", license="mit",
extensions=[Tox('tox'),
Travis('travis'),
Namespace('namespace')])
create_project(
project="my-proj-name",
author="Your Name",
namespace="some.namespace",
license="mit",
extensions=[Tox("tox"), Travis("travis"), Namespace("namespace")],
)
Note that no built-in extension (e.g. tox, travis and namespace support) is
activated by default. The ``extensions`` option should be manually populated
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def parse(root):
except IOError:
return parse_git(root)

config = dict(version_scheme=version2str, local_scheme=local_version2str,)
config = dict(
version_scheme=version2str,
local_scheme=local_version2str,
)

if has_entrypoints:
return dict(use_pyscaffold=True)
Expand Down
2 changes: 1 addition & 1 deletion src/pyscaffold/extensions/cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __call__(self, parser, namespace, values, option_string=None):
# 'extensions' attribute:
extensions = getattr(namespace, "extensions", [])
extensions.append(obj_ref)
setattr(namespace, "extensions", extensions)
namespace.extensions = extensions

# Now the extra parameters can be stored
setattr(namespace, self.dest, values)
Expand Down
2 changes: 1 addition & 1 deletion src/pyscaffold/extensions/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_namespace_parser(obj_ref):

class NamespaceParser(argparse.Action):
"""Consumes the values provided, but also appends the extension
function to the extensions list.
function to the extensions list.
"""

def __call__(self, parser, namespace, values, option_string=None):
Expand Down
6 changes: 3 additions & 3 deletions src/pyscaffold/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def is_git_configured():
def check_git():
"""Checks for git and raises appropriate exception if not
Raises:
:class:`~.GitNotInstalled`: when git command is not available
:class:`~.GitNotConfigured`: when git does not know user information
Raises:
:class:`~.GitNotInstalled`: when git command is not available
:class:`~.GitNotConfigured`: when git does not know user information
"""
if not is_git_installed():
raise GitNotInstalled
Expand Down
12 changes: 6 additions & 6 deletions src/pyscaffold/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def level(self, value):
self.wrapped.setLevel(value)

def process(self, msg, kwargs):
"""Method overridden to augment LogRecord with the `nesting` attribute.
"""
"""Method overridden to augment LogRecord with the `nesting` attribute."""
(msg, kwargs) = super(ReportLogger, self).process(msg, kwargs)
extra = kwargs.get("extra", {})
extra["nesting"] = self.nesting
Expand Down Expand Up @@ -276,9 +275,10 @@ def indent(self, count=1):
.. code-block:: python
from pyscaffold.log import logger
logger.report('invoke', 'custom_action')
logger.report("invoke", "custom_action")
with logger.indent():
logger.report('create', 'some/file/path')
logger.report("create", "some/file/path")
# Expected logs:
# --------------------------------------
Expand Down Expand Up @@ -309,7 +309,7 @@ def copy(self):

return clone

def reconfigure(self, opts={}, **kwargs):
def reconfigure(self, opts=None, **kwargs):
"""Reconfigure some aspects of the logger object.
Args:
Expand All @@ -322,7 +322,7 @@ def reconfigure(self, opts={}, **kwargs):
Additional keyword arguments will be ignored.
"""
opts = opts.copy()
opts = (opts or {}).copy()
opts.update(kwargs)

if "log_level" in opts:
Expand Down
2 changes: 1 addition & 1 deletion src/pyscaffold/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_template(name, relative_to=__name__):
from pyscaffold.templates import get_template
from . import templates as my_templates
tpl1 = get_template('file1', relative_to=my_templates)
tpl1 = get_template("file1", relative_to=my_templates)
# OR
# tpl1 = get_template('file1', relative_to=my_templates.__name__)
Expand Down
28 changes: 24 additions & 4 deletions src/pyscaffold/templates/pre-commit-config.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: '^docs/conf.py'

repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v3.3.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -17,18 +17,38 @@ repos:
- id: mixed-line-ending
args: ['--fix=no']

## If you want to avoid flake8 errors due to unused vars or imports:
# - repo: https://github.com/myint/autoflake.git
# rev: v1.4
# hooks:
# - id: autoflake
# args: [
# --in-place,
# --remove-all-unused-imports,
# --remove-unused-variables,
# ]

- repo: http://github.com/timothycrosley/isort
rev: 5.4.2
rev: 5.6.4
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: stable
rev: 20.8b1
hooks:
- id: black
language_version: python3

## If like to embrace black styles even in the docs:
# - repo: https://github.com/asottile/blacken-docs
# rev: v1.8.0
# hooks:
# - id: blacken-docs
# additional_dependencies: [black]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.8.4
hooks:
- id: flake8
## You can add flake8 plugins via `additional_dependencies`:
# additional_dependencies: [flake8-bugbear]
3 changes: 1 addition & 2 deletions src/pyscaffold/templates/skeleton.template
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def main(args):


def run():
"""Entry point for console_scripts
"""
"""Entry point for console_scripts"""
main(sys.argv[1:])


Expand Down

0 comments on commit ea91026

Please sign in to comment.