From 58b46574ee803396e6a340799ed37e611ad1627a Mon Sep 17 00:00:00 2001 From: Kronopt Date: Mon, 22 Oct 2018 15:42:54 +0100 Subject: [PATCH 1/8] Fixed ChainLink Because a ChainLink contains an instance of itself, it needed to be recursive, but that isn't possible in beckett. Therefore the current solution implements 3 nearly identical ChainLink classes (ChainLinkSubResource, ChainLink1SubResource and ChainLink2SubResource) each one containing the next one. The last one in the chain is missing the 'evolves_to' attribute, effectively ending the recursion. No more than 3 ChainLinks should be necessary as long as there are no evolution chains longer than 3 (ex: bulbasaur -> ivysaur -> venussaur), which there currently are none. Note: 3 is the maximum depth of evolution chains (as per the last pokemon generation). Pokemons with branching evolutions (such as eevee), even though they might have more than 2 evolutions, the evolution chain depth still doesn't go beyond 3. --- pykemon/resourcesV2.py | 47 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/pykemon/resourcesV2.py b/pykemon/resourcesV2.py index b2bdeda..9c469a9 100644 --- a/pykemon/resourcesV2.py +++ b/pykemon/resourcesV2.py @@ -10,7 +10,9 @@ from .beckett_tweaks import BaseResource +############################## # Common Models (SubResources) +############################## class APIResourceSubResource(SubResource): @@ -212,7 +214,9 @@ def __repr__(self): self.text.capitalize()[:10] + "...") +############## # SubResources +############## class BerryFlavorMapSubResource(BaseResource): @@ -292,6 +296,45 @@ def __repr__(self): return '<%s>' % self.Meta.name +# A ChainLink is tricky to implement with beckett because it is recursive. +# The current solution is to have 3 nearly identical ChainLink classes +# (so far, the maximum number of chaining evolutions depth is 3) +# the last one not having the evolves_to subresource, ending the recursion. + + +class ChainLink2SubResource(BaseResource): + class Meta(BaseResource.Meta): + name = 'Chain_Link2' + identifier = 'is_baby' + attributes = ( + 'is_baby', + ) + subresources = { + 'species': NamedAPIResourceSubResource, + 'evolution_details': EvolutionDetailSubResource + } + + def __repr__(self): + return '<%s>' % self.Meta.name + + +class ChainLink1SubResource(BaseResource): + class Meta(BaseResource.Meta): + name = 'Chain_Link1' + identifier = 'is_baby' + attributes = ( + 'is_baby', + ) + subresources = { + 'species': NamedAPIResourceSubResource, + 'evolution_details': EvolutionDetailSubResource, + 'evolves_to': ChainLink2SubResource + } + + def __repr__(self): + return '<%s>' % self.Meta.name + + class ChainLinkSubResource(BaseResource): class Meta(BaseResource.Meta): name = 'Chain_Link' @@ -302,7 +345,7 @@ class Meta(BaseResource.Meta): subresources = { 'species': NamedAPIResourceSubResource, 'evolution_details': EvolutionDetailSubResource, - 'evolves_to': lambda *args, **kwargs: ChainLinkSubResource # TODO - This doesn't work... + 'evolves_to': ChainLink1SubResource } def __repr__(self): @@ -961,7 +1004,9 @@ def __repr__(self): return '<%s>' % self.Meta.name +########### # Resources +########### class BerryResource(BaseResource): From 9c36414eac62865dfd6050423ecdf96b13032711 Mon Sep 17 00:00:00 2001 From: Kronopt Date: Mon, 22 Oct 2018 23:15:03 +0100 Subject: [PATCH 2/8] Changed to Circleci (instead of travis) --- .circleci/config.yml | 24 +++++++++++++++--------- .gitignore | 1 - .travis.yml | 18 ------------------ CONTRIBUTING.rst | 6 ++---- requirements.txt | 2 +- 5 files changed, 18 insertions(+), 33 deletions(-) delete mode 100644 .travis.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 87c3c87..5e076f2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,9 +9,11 @@ jobs: steps: - checkout - run: - command: | - pip install -r requirements.txt --user - python -m unittest tests.test_pykemon + name: Install Requirements + command: pip install -r requirements.txt --user + - run: + name: Run Tests + command: python -m unittest tests.test_pykemon py36_tests: docker: @@ -19,9 +21,11 @@ jobs: steps: - checkout - run: - command: | - pip install -r requirements.txt --user - python -m unittest tests.test_pykemon + name: Install Requirements + command: pip install -r requirements.txt --user + - run: + name: Run Tests + command: python -m unittest tests.test_pykemon py37_tests: docker: @@ -29,9 +33,11 @@ jobs: steps: - checkout - run: - command: | - pip install -r requirements.txt --user - python -m unittest tests.test_pykemon + name: Install Requirements + command: pip install -r requirements.txt --user + - run: + name: Run Tests + command: python -m unittest tests.test_pykemon workflows: version: 2 diff --git a/.gitignore b/.gitignore index c98c785..da51686 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,6 @@ pip-log.txt # Unit test / coverage reports .coverage .tox -nosetests.xml # Translations *.mo diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 09af859..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -# Config file for automatic testing at travis-ci.org - -language: python - -python: - - "2.7" - - "3.6" - - "3.7" - -# Travis still doesn't support Python 3.7 yet, so the following 2 lines are needed -dist: xenial -sudo: true - -# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors -install: pip install -r requirements.txt - -# command to run tests, e.g. python setup.py test -script: python -m unittest tests.test_pykemon diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 281e69c..192e8bd 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -80,7 +80,7 @@ Ready to contribute? Here's how to set up `pykemon` for local development. $ flake8 pykemon tests $ tox - To get flake8 and tox, just pip install them into your virtualenv. + To get pep8, flake8 and tox, just pip install them into your virtualenv. 6. Commit your changes and push your branch to GitHub:: @@ -99,9 +99,7 @@ Before you submit a pull request, check that it meets these guidelines: 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 2.7, 3.6, and 3.7. Check - https://travis-ci.org/phalt/pykemon/pull_requests - and make sure that the tests pass for all supported Python versions. +3. The pull request should work for Python 2.7, 3.6, and 3.7. Tips ---- diff --git a/requirements.txt b/requirements.txt index 61f4f3f..61a783a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ flake8==3.5.0 # tests pep8==1.7.1 # tests requests-mock==1.5.2 # tests Sphinx==1.8.1 # docs -tox==3.5.2 # tests \ No newline at end of file +tox==3.5.2 # tests From 1453af1c7d22c074133baf22ef5d421b079db533 Mon Sep 17 00:00:00 2001 From: Kronopt Date: Mon, 29 Oct 2018 15:14:18 +0000 Subject: [PATCH 3/8] Switched to pylint for linting --- .pylintrc | 565 ++++++++++++++++++++ Makefile | 4 +- docs/pykemon.rst | 4 +- pykemon/__init__.py | 20 +- pykemon/api.py | 99 ++-- pykemon/{resourcesV2.py => resources_v2.py} | 0 requirements.txt | 7 +- tests/test_pykemon.py | 2 +- 8 files changed, 633 insertions(+), 68 deletions(-) create mode 100644 .pylintrc rename pykemon/{resourcesV2.py => resources_v2.py} (100%) diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..d2297d8 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,565 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=docs + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use. +jobs=0 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED. +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=missing-docstring, + function-redefined, + too-many-lines, + no-member, + + # Disabled by default: + + print-statement, + parameter-unpacking, + unpacking-in-except, + old-raise-syntax, + backtick, + long-suffix, + old-ne-operator, + old-octal-literal, + import-star-module-level, + non-ascii-bytes-literal, + raw-checker-failed, + bad-inline-option, + locally-disabled, + locally-enabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + use-symbolic-message-instead, + apply-builtin, + basestring-builtin, + buffer-builtin, + cmp-builtin, + coerce-builtin, + execfile-builtin, + file-builtin, + long-builtin, + raw_input-builtin, + reduce-builtin, + standarderror-builtin, + unicode-builtin, + xrange-builtin, + coerce-method, + delslice-method, + getslice-method, + setslice-method, + no-absolute-import, + old-division, + dict-iter-method, + dict-view-method, + next-method-called, + metaclass-assignment, + indexing-exception, + raising-string, + reload-builtin, + oct-method, + hex-method, + nonzero-method, + cmp-method, + input-builtin, + round-builtin, + intern-builtin, + unichr-builtin, + map-builtin-not-iterating, + zip-builtin-not-iterating, + range-builtin-not-iterating, + filter-builtin-not-iterating, + using-cmp-argument, + eq-without-hash, + div-method, + idiv-method, + rdiv-method, + exception-message-attribute, + invalid-str-codec, + sys-max-int, + bad-python3-import, + deprecated-string-function, + deprecated-str-translate-call, + deprecated-itertools-function, + deprecated-types-field, + next-method-defined, + dict-items-not-iterating, + dict-keys-not-iterating, + dict-values-not-iterating, + deprecated-operator-function, + deprecated-urllib-function, + xreadlines-attribute, + deprecated-sys-function, + exception-escape, + comprehension-escape + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages. +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit + + +[BASIC] + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style. +#argument-rgx= + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma. +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Naming style matching correct class attribute names. +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. +#class-attribute-rgx= + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming- +# style. +#class-rgx= + +# Naming style matching correct constant names. +const-naming-style=snake_case + +# Regular expression matching correct constant names. Overrides const-naming- +# style. +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style. +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _ + +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=yes + +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. +#inlinevar-rgx= + +# Naming style matching correct method names. +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style. +#method-rgx= + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style. +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes=abc.abstractproperty + +# Naming style matching correct variable names. +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style. +variable-rgx=[a-z0-9_]{1,75}$ + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module. +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma, + dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules=logging + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package.. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore. +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict, + _fields, + _replace, + _source, + _make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=cls + + +[DESIGN] + +# Maximum number of arguments for function / method. +max-args=10 # default = 5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in an if statement. +max-bool-expr=5 + +# Maximum number of branch for function / method body. +max-branches=12 + +# Maximum number of locals for function / method body. +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=500 # default = 20 + +# Maximum number of return / yield for function / method body. +max-returns=6 + +# Maximum number of statements in function / method body. +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=0 # default = 2 + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma. +deprecated-modules=optparse,tkinter.tix + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled). +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled). +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled). +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception". +overgeneral-exceptions=Exception diff --git a/Makefile b/Makefile index 4cb1322..1fd9be5 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ help: @echo "clean-build - remove build artifacts" @echo "clean-pyc - remove Python file artifacts" - @echo "lint - check style with flake8" + @echo "lint - check style with pylint" @echo "test - run tests quickly with the default Python" @echo "testall - run tests on every Python version with tox" @echo "coverage - check code coverage quickly with the default Python" @@ -24,7 +24,7 @@ clean-pyc: find . -name '*~' -exec rm -f {} + lint: - flake8 pykemon tests + pylint pykemon tests setup.py test: python -m unittest tests.test_pykemon diff --git a/docs/pykemon.rst b/docs/pykemon.rst index 41f3b69..817a850 100644 --- a/docs/pykemon.rst +++ b/docs/pykemon.rst @@ -20,10 +20,10 @@ pykemon.beckett_tweaks module :undoc-members: :show-inheritance: -pykemon.resourcesV2 module +pykemon.resources_v2 module -------------------------- -.. automodule:: pykemon.resourcesV2 +.. automodule:: pykemon.resources_v2 :members: :undoc-members: :show-inheritance: diff --git a/pykemon/__init__.py b/pykemon/__init__.py index f69530b..40ba33c 100644 --- a/pykemon/__init__.py +++ b/pykemon/__init__.py @@ -1,16 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -__author__ = 'Paul Hallett' -__email__ = 'hello@phalt.co' -__credits__ = ["Paul Hallett", "Owen Hallett", "Kronopt"] -__version__ = '0.4' -__copyright__ = 'Copyright Paul Hallett 2016' -__license__ = 'BSD' - -from .api import V2Client - - """ ======== @@ -27,3 +17,13 @@ """ + +__author__ = 'Paul Hallett' +__email__ = 'hello@phalt.co' +__credits__ = ["Paul Hallett", "Owen Hallett", "Kronopt"] +__version__ = '0.4' +__copyright__ = 'Copyright Paul Hallett 2016' +__license__ = 'BSD' + + +from .api import V2Client diff --git a/pykemon/api.py b/pykemon/api.py index 1cf4f94..7b3e478 100644 --- a/pykemon/api.py +++ b/pykemon/api.py @@ -7,61 +7,62 @@ """ from .beckett_tweaks import BaseClient -from . import resourcesV2 as rV2 +from . import resources_v2 as rv2 class V2Client(BaseClient): + """Pokeapi client""" class Meta(BaseClient.Meta): name = 'pykemon-v2-client' base_url = 'https://pokeapi.co/api/v2' resources = ( - rV2.BerryResource, - rV2.BerryFirmnessResource, - rV2.BerryFlavorResource, - rV2.ContestTypeResource, - rV2.ContestEffectResource, - rV2.SuperContestEffectResource, - rV2.EncounterMethodResource, - rV2.EncounterConditionResource, - rV2.EncounterConditionValueResource, - rV2.EvolutionChainResource, - rV2.EvolutionTriggerResource, - rV2.GenerationResource, - rV2.PokedexResource, - rV2.VersionResource, - rV2.VersionGroupResource, - rV2.ItemResource, - rV2.ItemAttributeResource, - rV2.ItemCategoryResource, - rV2.ItemFlingEffectResource, - rV2.ItemPocketResource, - rV2.MachineResource, - rV2.MoveResource, - rV2.MoveAilmentResource, - rV2.MoveBattleStyleResource, - rV2.MoveCategoryResource, - rV2.MoveDamageClassResource, - rV2.MoveLearnMethodResource, - rV2.MoveTargetResource, - rV2.LocationResource, - rV2.LocationAreaResource, - rV2.PalParkAreaResource, - rV2.RegionResource, - rV2.AbilityResource, - rV2.CharacteristicResource, - rV2.EggGroupResource, - rV2.GenderResource, - rV2.GrowthRateResource, - rV2.NatureResource, - rV2.PokeathlonStatResource, - rV2.PokemonResource, - rV2.PokemonColorResource, - rV2.PokemonFormResource, - rV2.PokemonHabitatResource, - rV2.PokemonShapeResource, - rV2.PokemonSpeciesResource, - rV2.StatResource, - rV2.TypeResource, - rV2.LanguageResource + rv2.BerryResource, + rv2.BerryFirmnessResource, + rv2.BerryFlavorResource, + rv2.ContestTypeResource, + rv2.ContestEffectResource, + rv2.SuperContestEffectResource, + rv2.EncounterMethodResource, + rv2.EncounterConditionResource, + rv2.EncounterConditionValueResource, + rv2.EvolutionChainResource, + rv2.EvolutionTriggerResource, + rv2.GenerationResource, + rv2.PokedexResource, + rv2.VersionResource, + rv2.VersionGroupResource, + rv2.ItemResource, + rv2.ItemAttributeResource, + rv2.ItemCategoryResource, + rv2.ItemFlingEffectResource, + rv2.ItemPocketResource, + rv2.MachineResource, + rv2.MoveResource, + rv2.MoveAilmentResource, + rv2.MoveBattleStyleResource, + rv2.MoveCategoryResource, + rv2.MoveDamageClassResource, + rv2.MoveLearnMethodResource, + rv2.MoveTargetResource, + rv2.LocationResource, + rv2.LocationAreaResource, + rv2.PalParkAreaResource, + rv2.RegionResource, + rv2.AbilityResource, + rv2.CharacteristicResource, + rv2.EggGroupResource, + rv2.GenderResource, + rv2.GrowthRateResource, + rv2.NatureResource, + rv2.PokeathlonStatResource, + rv2.PokemonResource, + rv2.PokemonColorResource, + rv2.PokemonFormResource, + rv2.PokemonHabitatResource, + rv2.PokemonShapeResource, + rv2.PokemonSpeciesResource, + rv2.StatResource, + rv2.TypeResource, + rv2.LanguageResource ) diff --git a/pykemon/resourcesV2.py b/pykemon/resources_v2.py similarity index 100% rename from pykemon/resourcesV2.py rename to pykemon/resources_v2.py diff --git a/requirements.txt b/requirements.txt index 61a783a..29cd389 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ beckett==0.8.0 # main functionality -coverage==4.5.1 # tests -flake8==3.5.0 # tests -pep8==1.7.1 # tests -requests-mock==1.5.2 # tests Sphinx==1.8.1 # docs +pylint==2.1.1 # tests - style +coverage==4.5.1 # tests - coverage +requests-mock==1.5.2 # tests tox==3.5.2 # tests diff --git a/tests/test_pykemon.py b/tests/test_pykemon.py index 1524b93..4ae05b0 100644 --- a/tests/test_pykemon.py +++ b/tests/test_pykemon.py @@ -10,8 +10,8 @@ import unittest import requests_mock -import pykemon from beckett.exceptions import InvalidStatusCodeError +import pykemon def base_get_test(self, resource, method="name"): From fd1984fdfd995a8b1c8447be69dee539c0f354ec Mon Sep 17 00:00:00 2001 From: Kronopt Date: Mon, 29 Oct 2018 15:37:23 +0000 Subject: [PATCH 4/8] Update circleci config - Separated requirements.txt into several files to avoid errors during CI in different python versions --- .circleci/config.yml | 9 ++++++--- CONTRIBUTING.rst | 7 +++---- requirements-dev.txt | 2 ++ requirements-dev27.txt | 4 ++++ requirements.txt | 7 +------ 5 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 requirements-dev.txt create mode 100644 requirements-dev27.txt diff --git a/.circleci/config.yml b/.circleci/config.yml index 5e076f2..8e330ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ jobs: - checkout - run: name: Install Requirements - command: pip install -r requirements.txt --user + command: pip install -r requirements.txt -r requirements-dev27.txt --user - run: name: Run Tests command: python -m unittest tests.test_pykemon @@ -22,7 +22,7 @@ jobs: - checkout - run: name: Install Requirements - command: pip install -r requirements.txt --user + command: pip install -r requirements.txt -r requirements-dev27.txt --user - run: name: Run Tests command: python -m unittest tests.test_pykemon @@ -34,7 +34,10 @@ jobs: - checkout - run: name: Install Requirements - command: pip install -r requirements.txt --user + command: pip install -r requirements.txt -r requirements-dev.txt --user + - run: + name: Lint + command: pylint pykemon tests setup.py - run: name: Run Tests command: python -m unittest tests.test_pykemon diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 192e8bd..f4c3c49 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -74,13 +74,12 @@ Ready to contribute? Here's how to set up `pykemon` for local development. Now you can make your changes locally. -5. When you're done making changes, check that your changes pass flake8, pep8 and the tests, including testing other Python versions with tox:: +5. When you're done making changes, check that your changes pass pylint and the tests, including testing other Python versions with tox:: - $ pep8 pykemon - $ flake8 pykemon tests + $ pylint pykemon tests setup.py $ tox - To get pep8, flake8 and tox, just pip install them into your virtualenv. + To get pylint and tox, just pip install them into your virtualenv. 6. Commit your changes and push your branch to GitHub:: diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..db637ab --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +-r requirements_dev27.txt +pylint==2.1.1 # style diff --git a/requirements-dev27.txt b/requirements-dev27.txt new file mode 100644 index 0000000..cf5b087 --- /dev/null +++ b/requirements-dev27.txt @@ -0,0 +1,4 @@ +Sphinx==1.8.1 # docs +coverage==4.5.1 # coverage +requests-mock==1.5.2 # tests +tox==3.5.2 # tests diff --git a/requirements.txt b/requirements.txt index 29cd389..b9840bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1 @@ -beckett==0.8.0 # main functionality -Sphinx==1.8.1 # docs -pylint==2.1.1 # tests - style -coverage==4.5.1 # tests - coverage -requests-mock==1.5.2 # tests -tox==3.5.2 # tests +beckett==0.8.0 From 59ddcb2750b3c83b5cb7e8a42ce4593fe0e32f05 Mon Sep 17 00:00:00 2001 From: Kronopt Date: Mon, 29 Oct 2018 15:40:07 +0000 Subject: [PATCH 5/8] fix typo in requirements-dev.txt --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index db637ab..6808d86 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,2 @@ --r requirements_dev27.txt +-r requirements-dev27.txt pylint==2.1.1 # style From 30b77bd960bd4e003d47dbc6be6aac0ba2bf3b38 Mon Sep 17 00:00:00 2001 From: Kronopt Date: Mon, 29 Oct 2018 15:42:29 +0000 Subject: [PATCH 6/8] Update .circleci/config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8e330ec..e41418b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,7 @@ jobs: command: pip install -r requirements.txt -r requirements-dev.txt --user - run: name: Lint - command: pylint pykemon tests setup.py + command: python -m pylint pykemon tests setup.py - run: name: Run Tests command: python -m unittest tests.test_pykemon From 691c2834ff926e482d83d61e8acb5eb5eefe34b0 Mon Sep 17 00:00:00 2001 From: Kronopt Date: Mon, 29 Oct 2018 17:11:09 +0000 Subject: [PATCH 7/8] test code without using 'uid=' as parameter --- tests/test_pykemon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_pykemon.py b/tests/test_pykemon.py index 4ae05b0..d8af7e1 100644 --- a/tests/test_pykemon.py +++ b/tests/test_pykemon.py @@ -25,7 +25,7 @@ def base_get_test(self, resource, method="name"): with requests_mock.mock() as mock: mock.get('%s/%s/1' % (self.base_url, resource), text=self.mock_data) response = getattr(self.client, - 'get_%s' % resource.replace("-", "_"))(uid=1)[0] + 'get_%s' % resource.replace("-", "_"))(1)[0] if method == "name": self.assertEqual(response.name, 'test_name') @@ -45,7 +45,7 @@ def base_404_test(self, resource): self.assertRaises( InvalidStatusCodeError, lambda: getattr(self.client, - 'get_%s' % resource.replace("-", "_"))(uid=1)[0]) + 'get_%s' % resource.replace("-", "_"))(1)[0]) class TestV2Client(unittest.TestCase): From 6e63e82419e62d09f1644b43537352cb4d51f1c8 Mon Sep 17 00:00:00 2001 From: Kronopt Date: Tue, 30 Oct 2018 18:49:55 +0000 Subject: [PATCH 8/8] Bump requests to version 2.20.0 In response to CVE-2018-18074 --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b9840bb..35bab5a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -beckett==0.8.0 +beckett==0.8.0 # main functionality +requests==2.20.0 # used by beckett (bumped to avoid CVE-2018-18074)