Commit

Fixes and additions

1. Fix test_{{cookiecutter.project_slug}} when not using pytest
2. Add hooks for verification and post-processing
3. Add option for the use of Pipenv
4. Add pytest.ini and Pipfile according to selected options
5. Add pylintrc
Daniel Moch committed 5 years ago (Tree)

Diffstat

 cookiecutter.json | 3 
 hooks/post_gen_project.py | 22 
 hooks/pre_gen_project.py | 13 
 {{cookiecutter.project_slug}}/Pipfile | 16 
 {{cookiecutter.project_slug}}/pytest.ini | 2 
 {{cookiecutter.project_slug}}/tests/pylintrc | 571 
 {{cookiecutter.project_slug}}/tests/test_{{cookiecutter.project_slug}}.py | 12 

cookiecutter.json

8 8 "project_short_description": "Flit Boilerplate contains all the boilerplate you need to create a Python Flit package.",
9 9 "pypi_username": "{{ cookiecutter.github_username }}",
10 10 "version": "0.1.0",
11 - "use_pytest": "n",
11 + "use_pytest": "y",
12 + "use_pipenv": "y",
12 13 "open_source_license": ["MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"]
13 14 }

hooks/post_gen_project.py (created)

1 +#!/usr/bin/env python
2 +import os
3 +
4 +PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
5 +
6 +
7 +def remove_file(filepath):
8 + os.remove(os.path.join(PROJECT_DIRECTORY, filepath))
9 +
10 +
11 +if __name__ == '__main__':
12 +
13 + if '{{ cookiecutter.use_pytest }}' == 'y':
14 + remove_file('tests/__init__.py')
15 + else:
16 + remove_file('pytest.ini')
17 +
18 + if 'Not open source' == '{{ cookiecutter.open_source_license }}':
19 + remove_file('LICENSE')
20 +
21 + if '{{ cookiecutter.use_pipenv }}' == 'n':
22 + remove_file('Pipfile')

hooks/pre_gen_project.py (created)

1 +import re
2 +import sys
3 +
4 +
5 +MODULE_REGEX = r'^[_a-zA-Z][_a-zA-Z0-9]+$'
6 +
7 +module_name = '{{ cookiecutter.project_slug}}'
8 +
9 +if not re.match(MODULE_REGEX, module_name):
10 + print('ERROR: The project slug (%s) is not a valid Python module name. Please do not use a - and use _ instead' % module_name)
11 +
12 + #Exit to cancel project
13 + sys.exit(1)

{{cookiecutter.project_slug}}/Pipfile (created)

1 +[[source]]
2 +url = "https://pypi.org/simple"
3 +verify_ssl = true
4 +name = "pypi"
5 +
6 +[packages]
7 +
8 +[dev-packages]
9 +{%- if cookiecutter.use_pytest == 'y' %}
10 +pytest = "*"
11 +pytest-cov = "*"
12 +pytest-pylint = "*"
13 +{%- endif %}
14 +
15 +[requires]
16 +python_version = "3.7"

{{cookiecutter.project_slug}}/pytest.ini (created)

1 +[pytest]
2 +addopts= --cov={{ cookiecutter.project_slug }} --cov-report=term-missing --pylint --pylint-rcfile=tests/pylintrc

{{cookiecutter.project_slug}}/tests/pylintrc (created)

1 +[MASTER]
2 +
3 +# A comma-separated list of package or module names from where C extensions may
4 +# be loaded. Extensions are loading into the active Python interpreter and may
5 +# run arbitrary code.
6 +extension-pkg-whitelist=
7 +
8 +# Add files or directories to the blacklist. They should be base names, not
9 +# paths.
10 +ignore=CVS .git
11 +
12 +# Add files or directories matching the regex patterns to the blacklist. The
13 +# regex matches against base names, not paths.
14 +ignore-patterns=version.*
15 +
16 +# Python code to execute, usually for sys.path manipulation such as
17 +# pygtk.require().
18 +#init-hook=
19 +
20 +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
21 +# number of processors available to use.
22 +jobs=1
23 +
24 +# Control the amount of potential inferred values when inferring a single
25 +# object. This can help the performance when dealing with large functions or
26 +# complex, nested conditions.
27 +limit-inference-results=100
28 +
29 +# List of plugins (as comma separated values of python modules names) to load,
30 +# usually to register additional checkers.
31 +load-plugins=
32 +
33 +# Pickle collected data for later comparisons.
34 +persistent=no
35 +
36 +# Specify a configuration file.
37 +#rcfile=
38 +
39 +# When enabled, pylint would attempt to guess common misconfiguration and emit
40 +# user-friendly hints instead of false-positive error messages.
41 +suggestion-mode=yes
42 +
43 +# Allow loading of arbitrary C extensions. Extensions are imported into the
44 +# active Python interpreter and may run arbitrary code.
45 +unsafe-load-any-extension=no
46 +
47 +
48 +[MESSAGES CONTROL]
49 +
50 +# Only show warnings with the listed confidence levels. Leave empty to show
51 +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED.
52 +confidence=
53 +
54 +# Disable the message, report, category or checker with the given id(s). You
55 +# can either give multiple identifiers separated by comma (,) or put this
56 +# option multiple times (only on the command line, not in the configuration
57 +# file where it should appear only once). You can also use "--disable=all" to
58 +# disable everything first and then reenable specific checks. For example, if
59 +# you want to run only the similarities checker, you can use "--disable=all
60 +# --enable=similarities". If you want to run only the classes checker, but have
61 +# no Warning level messages displayed, use "--disable=all --enable=classes
62 +# --disable=W".
63 +disable=missing-docstring,
64 + print-statement,
65 + parameter-unpacking,
66 + unpacking-in-except,
67 + old-raise-syntax,
68 + backtick,
69 + long-suffix,
70 + old-ne-operator,
71 + old-octal-literal,
72 + import-star-module-level,
73 + non-ascii-bytes-literal,
74 + raw-checker-failed,
75 + bad-inline-option,
76 + locally-disabled,
77 + locally-enabled,
78 + file-ignored,
79 + suppressed-message,
80 + useless-suppression,
81 + deprecated-pragma,
82 + use-symbolic-message-instead,
83 + apply-builtin,
84 + basestring-builtin,
85 + buffer-builtin,
86 + cmp-builtin,
87 + coerce-builtin,
88 + execfile-builtin,
89 + file-builtin,
90 + long-builtin,
91 + raw_input-builtin,
92 + reduce-builtin,
93 + standarderror-builtin,
94 + unicode-builtin,
95 + xrange-builtin,
96 + coerce-method,
97 + delslice-method,
98 + getslice-method,
99 + setslice-method,
100 + no-absolute-import,
101 + old-division,
102 + dict-iter-method,
103 + dict-view-method,
104 + next-method-called,
105 + metaclass-assignment,
106 + indexing-exception,
107 + raising-string,
108 + reload-builtin,
109 + oct-method,
110 + hex-method,
111 + nonzero-method,
112 + cmp-method,
113 + input-builtin,
114 + round-builtin,
115 + intern-builtin,
116 + unichr-builtin,
117 + map-builtin-not-iterating,
118 + zip-builtin-not-iterating,
119 + range-builtin-not-iterating,
120 + filter-builtin-not-iterating,
121 + using-cmp-argument,
122 + eq-without-hash,
123 + div-method,
124 + idiv-method,
125 + rdiv-method,
126 + exception-message-attribute,
127 + invalid-str-codec,
128 + sys-max-int,
129 + bad-python3-import,
130 + deprecated-string-function,
131 + deprecated-str-translate-call,
132 + deprecated-itertools-function,
133 + deprecated-types-field,
134 + next-method-defined,
135 + dict-items-not-iterating,
136 + dict-keys-not-iterating,
137 + dict-values-not-iterating,
138 + deprecated-operator-function,
139 + deprecated-urllib-function,
140 + xreadlines-attribute,
141 + deprecated-sys-function,
142 + exception-escape,
143 + comprehension-escape
144 +
145 +# Enable the message, report, category or checker with the given id(s). You can
146 +# either give multiple identifier separated by comma (,) or put this option
147 +# multiple time (only on the command line, not in the configuration file where
148 +# it should appear only once). See also the "--disable" option for examples.
149 +enable=c-extension-no-member
150 +
151 +
152 +[REPORTS]
153 +
154 +# Python expression which should return a note less than 10 (10 is the highest
155 +# note). You have access to the variables errors warning, statement which
156 +# respectively contain the number of errors / warnings messages and the total
157 +# number of statements analyzed. This is used by the global evaluation report
158 +# (RP0004).
159 +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
160 +
161 +# Template used to display messages. This is a python new-style format string
162 +# used to format the message information. See doc for all details.
163 +#msg-template=
164 +
165 +# Set the output format. Available formats are text, parseable, colorized, json
166 +# and msvs (visual studio). You can also give a reporter class, e.g.
167 +# mypackage.mymodule.MyReporterClass.
168 +output-format=text
169 +
170 +# Tells whether to display a full report or only the messages.
171 +reports=yes
172 +
173 +# Activate the evaluation score.
174 +score=yes
175 +
176 +
177 +[REFACTORING]
178 +
179 +# Maximum number of nested blocks for function / method body
180 +max-nested-blocks=5
181 +
182 +# Complete name of functions that never returns. When checking for
183 +# inconsistent-return-statements if a never returning function is called then
184 +# it will be considered as an explicit return statement and no message will be
185 +# printed.
186 +never-returning-functions=sys.exit
187 +
188 +
189 +[VARIABLES]
190 +
191 +# List of additional names supposed to be defined in builtins. Remember that
192 +# you should avoid to define new builtins when possible.
193 +additional-builtins=
194 +
195 +# Tells whether unused global variables should be treated as a violation.
196 +allow-global-unused-variables=yes
197 +
198 +# List of strings which can identify a callback function by name. A callback
199 +# name must start or end with one of those strings.
200 +callbacks=cb_,
201 + _cb
202 +
203 +# A regular expression matching the name of dummy variables (i.e. expected to
204 +# not be used).
205 +dummy-variables-rgx=_$|dummy
206 +
207 +# Argument names that match this expression will be ignored. Default to name
208 +# with leading underscore.
209 +ignored-argument-names=mock.*
210 +
211 +# Tells whether we should check for unused import in __init__ files.
212 +init-import=no
213 +
214 +# List of qualified module names which can have objects that can redefine
215 +# builtins.
216 +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
217 +
218 +
219 +[LOGGING]
220 +
221 +# Logging modules to check that the string format arguments are in logging
222 +# function parameter format.
223 +logging-modules=logging
224 +
225 +
226 +[TYPECHECK]
227 +
228 +# List of decorators that produce context managers, such as
229 +# contextlib.contextmanager. Add to this list to register other decorators that
230 +# produce valid context managers.
231 +contextmanager-decorators=contextlib.contextmanager, pytest.fixture
232 +
233 +# List of members which are set dynamically and missed by pylint inference
234 +# system, and so shouldn't trigger E1101 when accessed. Python regular
235 +# expressions are accepted.
236 +generated-members=REQUEST,
237 + acl_users,
238 + aq_parent,
239 + assert_called_once_with,
240 + assert_called_once,
241 + call_count
242 +
243 +# Tells whether missing members accessed in mixin class should be ignored. A
244 +# mixin class is detected if its name ends with "mixin" (case insensitive).
245 +ignore-mixin-members=yes
246 +
247 +# Tells whether to warn about missing members when the owner of the attribute
248 +# is inferred to be None.
249 +ignore-none=yes
250 +
251 +# This flag controls whether pylint should warn about no-member and similar
252 +# checks whenever an opaque object is returned when inferring. The inference
253 +# can return multiple potential results while evaluating a Python object, but
254 +# some branches might not be evaluated, which results in partial inference. In
255 +# that case, it might be useful to still emit no-member and other checks for
256 +# the rest of the inferred objects.
257 +ignore-on-opaque-inference=yes
258 +
259 +# List of class names for which member attributes should not be checked (useful
260 +# for classes with dynamically set attributes). This supports the use of
261 +# qualified names.
262 +ignored-classes=SQLObject,
263 + DateTimeField,
264 + CharField,
265 + ForecastioDataBlock
266 +
267 +# List of module names for which member attributes should not be checked
268 +# (useful for modules/projects where namespaces are manipulated during runtime
269 +# and thus existing member attributes cannot be deduced by static analysis. It
270 +# supports qualified module names, as well as Unix pattern matching.
271 +ignored-modules=
272 +
273 +# Show a hint with possible names when a member name was not found. The aspect
274 +# of finding the hint is based on edit distance.
275 +missing-member-hint=yes
276 +
277 +# The minimum edit distance a name should have in order to be considered a
278 +# similar match for a missing member name.
279 +missing-member-hint-distance=1
280 +
281 +# The total number of similar names that should be taken in consideration when
282 +# showing a hint for a missing member.
283 +missing-member-max-choices=1
284 +
285 +
286 +[MISCELLANEOUS]
287 +
288 +# List of note tags to take in consideration, separated by a comma.
289 +notes=FIXME,
290 + XXX,
291 + TODO
292 +
293 +
294 +[BASIC]
295 +
296 +# Naming style matching correct argument names.
297 +argument-naming-style=snake_case
298 +
299 +# Regular expression matching correct argument names. Overrides argument-
300 +# naming-style.
301 +argument-rgx=[a-z_][a-z0-9_]{2,30}$
302 +
303 +# Naming style matching correct attribute names.
304 +attr-naming-style=snake_case
305 +
306 +# Regular expression matching correct attribute names. Overrides attr-naming-
307 +# style.
308 +attr-rgx=[a-z_][a-z0-9_]{2,30}$
309 +
310 +# Bad variable names which should always be refused, separated by a comma.
311 +bad-names=foo,
312 + bar,
313 + baz,
314 + toto,
315 + tutu,
316 + tata
317 +
318 +# Naming style matching correct class attribute names.
319 +class-attribute-naming-style=any
320 +
321 +# Regular expression matching correct class attribute names. Overrides class-
322 +# attribute-naming-style.
323 +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
324 +
325 +# Naming style matching correct class names.
326 +class-naming-style=PascalCase
327 +
328 +# Regular expression matching correct class names. Overrides class-naming-
329 +# style.
330 +class-rgx=[A-Z_][a-zA-Z0-9]+$
331 +
332 +# Naming style matching correct constant names.
333 +const-naming-style=UPPER_CASE
334 +
335 +# Regular expression matching correct constant names. Overrides const-naming-
336 +# style.
337 +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
338 +
339 +# Minimum line length for functions/classes that require docstrings, shorter
340 +# ones are exempt.
341 +docstring-min-length=-1
342 +
343 +# Naming style matching correct function names.
344 +function-naming-style=snake_case
345 +
346 +# Regular expression matching correct function names. Overrides function-
347 +# naming-style.
348 +function-rgx=[a-z_][a-z0-9_]{2,30}$
349 +
350 +# Good variable names which should always be accepted, separated by a comma.
351 +good-names=i,
352 + j,
353 + k,
354 + ex,
355 + Run,
356 + main,
357 + _
358 +
359 +# Include a hint for the correct naming format with invalid-name.
360 +include-naming-hint=no
361 +
362 +# Naming style matching correct inline iteration names.
363 +inlinevar-naming-style=any
364 +
365 +# Regular expression matching correct inline iteration names. Overrides
366 +# inlinevar-naming-style.
367 +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
368 +
369 +# Naming style matching correct method names.
370 +method-naming-style=snake_case
371 +
372 +# Regular expression matching correct method names. Overrides method-naming-
373 +# style.
374 +method-rgx=[a-z_][a-z0-9_]{2,30}$
375 +
376 +# Naming style matching correct module names.
377 +module-naming-style=snake_case
378 +
379 +# Regular expression matching correct module names. Overrides module-naming-
380 +# style.
381 +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
382 +
383 +# Colon-delimited sets of names that determine each other's naming style when
384 +# the name regexes allow several styles.
385 +name-group=
386 +
387 +# Regular expression which should only match function or class names that do
388 +# not require a docstring.
389 +no-docstring-rgx=__.*__
390 +
391 +# List of decorators that produce properties, such as abc.abstractproperty. Add
392 +# to this list to register other decorators that produce valid properties.
393 +# These decorators are taken in consideration only for invalid-name.
394 +property-classes=abc.abstractproperty
395 +
396 +# Naming style matching correct variable names.
397 +variable-naming-style=snake_case
398 +
399 +# Regular expression matching correct variable names. Overrides variable-
400 +# naming-style.
401 +variable-rgx=[a-z_][a-z0-9_]{2,30}$
402 +
403 +
404 +[FORMAT]
405 +
406 +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
407 +expected-line-ending-format=
408 +
409 +# Regexp for a line that is allowed to be longer than the limit.
410 +ignore-long-lines=^\s*(# )?<?https?://\S+>?$
411 +
412 +# Number of spaces of indent required inside a hanging or continued line.
413 +indent-after-paren=8
414 +
415 +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
416 +# tab).
417 +indent-string=' '
418 +
419 +# Maximum number of characters on a single line.
420 +max-line-length=80
421 +
422 +# Maximum number of lines in a module.
423 +max-module-lines=1000
424 +
425 +# List of optional constructs for which whitespace checking is disabled. `dict-
426 +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
427 +# `trailing-comma` allows a space between comma and closing bracket: (a, ).
428 +# `empty-line` allows space-only lines.
429 +no-space-check=trailing-comma,
430 + dict-separator
431 +
432 +# Allow the body of a class to be on the same line as the declaration if body
433 +# contains single statement.
434 +single-line-class-stmt=no
435 +
436 +# Allow the body of an if to be on the same line as the test if there is no
437 +# else.
438 +single-line-if-stmt=no
439 +
440 +
441 +[SPELLING]
442 +
443 +# Limits count of emitted suggestions for spelling mistakes.
444 +max-spelling-suggestions=4
445 +
446 +# Spelling dictionary name. Available dictionaries: none. To make it working
447 +# install python-enchant package..
448 +spelling-dict=
449 +
450 +# List of comma separated words that should not be checked.
451 +spelling-ignore-words=
452 +
453 +# A path to a file that contains private dictionary; one word per line.
454 +spelling-private-dict-file=
455 +
456 +# Tells whether to store unknown words to indicated private dictionary in
457 +# --spelling-private-dict-file option instead of raising a message.
458 +spelling-store-unknown-words=no
459 +
460 +
461 +[SIMILARITIES]
462 +
463 +# Ignore comments when computing similarities.
464 +ignore-comments=yes
465 +
466 +# Ignore docstrings when computing similarities.
467 +ignore-docstrings=yes
468 +
469 +# Ignore imports when computing similarities.
470 +ignore-imports=no
471 +
472 +# Minimum lines number of a similarity.
473 +min-similarity-lines=4
474 +
475 +
476 +[DESIGN]
477 +
478 +# Maximum number of arguments for function / method.
479 +max-args=5
480 +
481 +# Maximum number of attributes for a class (see R0902).
482 +max-attributes=7
483 +
484 +# Maximum number of boolean expressions in an if statement.
485 +max-bool-expr=5
486 +
487 +# Maximum number of branch for function / method body.
488 +max-branches=20
489 +
490 +# Maximum number of locals for function / method body.
491 +max-locals=15
492 +
493 +# Maximum number of parents for a class (see R0901).
494 +max-parents=7
495 +
496 +# Maximum number of public methods for a class (see R0904).
497 +max-public-methods=20
498 +
499 +# Maximum number of return / yield for function / method body.
500 +max-returns=6
501 +
502 +# Maximum number of statements in function / method body.
503 +max-statements=50
504 +
505 +# Minimum number of public methods for a class (see R0903).
506 +min-public-methods=2
507 +
508 +
509 +[CLASSES]
510 +
511 +# List of method names used to declare (i.e. assign) instance attributes.
512 +defining-attr-methods=__init__,
513 + __new__,
514 + setUp
515 +
516 +# List of member names, which should be excluded from the protected access
517 +# warning.
518 +exclude-protected=_asdict,
519 + _fields,
520 + _replace,
521 + _source,
522 + _make
523 +
524 +# List of valid names for the first argument in a class method.
525 +valid-classmethod-first-arg=cls
526 +
527 +# List of valid names for the first argument in a metaclass class method.
528 +valid-metaclass-classmethod-first-arg=mcs
529 +
530 +
531 +[IMPORTS]
532 +
533 +# Allow wildcard imports from modules that define __all__.
534 +allow-wildcard-with-all=no
535 +
536 +# Analyse import fallback blocks. This can be used to support both Python 2 and
537 +# 3 compatible code, which means that the block might have code that exists
538 +# only in one or another interpreter, leading to false positives when analysed.
539 +analyse-fallback-blocks=no
540 +
541 +# Deprecated modules which should not be used, separated by a comma.
542 +deprecated-modules=regsub,
543 + TERMIOS,
544 + Bastion,
545 + rexec
546 +
547 +# Create a graph of external dependencies in the given file (report RP0402 must
548 +# not be disabled).
549 +ext-import-graph=
550 +
551 +# Create a graph of every (i.e. internal and external) dependencies in the
552 +# given file (report RP0402 must not be disabled).
553 +import-graph=
554 +
555 +# Create a graph of internal dependencies in the given file (report RP0402 must
556 +# not be disabled).
557 +int-import-graph=
558 +
559 +# Force import order to recognize a module as part of the standard
560 +# compatibility libraries.
561 +known-standard-library=
562 +
563 +# Force import order to recognize a module as part of a third party library.
564 +known-third-party=enchant
565 +
566 +
567 +[EXCEPTIONS]
568 +
569 +# Exceptions that will emit a warning when being caught. Defaults to
570 +# "Exception".
571 +overgeneral-exceptions=Exception

{{cookiecutter.project_slug}}/tests/test_{{cookiecutter.project_slug}}.py

41 41
42 42 def test_000_something(self):
43 43 """Test something."""
44 -{%- if cookiecutter.command_line_interface|lower == 'click' %}
45 -
46 - def test_command_line_interface(self):
47 - """Test the CLI."""
48 - runner = CliRunner()
49 - result = runner.invoke(cli.main)
50 - assert result.exit_code == 0
51 - assert '{{ cookiecutter.project_slug }}.cli.main' in result.output
52 - help_result = runner.invoke(cli.main, ['--help'])
53 - assert help_result.exit_code == 0
54 - assert '--help Show this message and exit.' in help_result.output
55 -{%- endif %}
56 44 {%- endif %}