Skip to content

Commit

Permalink
Linted
Browse files Browse the repository at this point in the history
  • Loading branch information
costastf committed Jul 7, 2021
1 parent 6899f36 commit e74d67f
Show file tree
Hide file tree
Showing 18 changed files with 409 additions and 311 deletions.
1 change: 1 addition & 0 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pep257:
ignore-paths:
- _CI
- build
- docs
4 changes: 4 additions & 0 deletions INSTALLATION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ Or, if you have virtualenvwrapper installed::
Or, if you are using pipenv::

$ pipenv install toonapilib

Or, if you are using pipx::

$ pipx install toonapilib
18 changes: 9 additions & 9 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ name = "pypi"

[dev-packages]

# Documenting
flake8 = "==3.8.0"
sphinx = "~=2.1.2"
sphinx-rtd-theme = "~=0.4.3"
prospector = "==1.1.6.2"
prospector = "~=1.3.0"
coverage = "~=4.5.4"
nose = "~=1.3.7"
nose-htmloutput = "~=0.6.0"
tox = "~=3.13.2"
betamax = "~=0.8.1"
betamax-serializers = "~=0.2.1"
semver = "~=2.8.1"
gitwrapperlib = "~=0.9.1"
gitwrapperlib = "~=0.9.2"
twine = "~=1.13.0"
coloredlogs = "~=10.0"
emoji = "~=0.5.3"
toml = "~=0.10.0"


[packages]

coloredlogs = "~=10.0"
requests = "~=2.22.0"
cachetools = "~=3.1.1"
dateparser = "~=0.7.1"
backoff = "~=1.9.2"
coloredlogs = ">=10.0"
requests = ">=2.25"
cachetools = ">=3.1"
dateparser = ">=0.7"
backoff = ">=1.9.2"
574 changes: 326 additions & 248 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ To develop on toonapilib:
_CI/scripts/build.py
# To see the package version
_CI/scipts/tag.py
_CI/scripts/tag.py
# To bump semantic versioning [--major|--minor|--patch]
_CI/scipts/tag.py --major|--minor|--patch
_CI/scripts/tag.py --major|--minor|--patch
# To upload the project to a pypi repo if user and password are properly provided
_CI/scripts/upload.py
Expand Down
2 changes: 1 addition & 1 deletion _CI/configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
'sh.streamreader',
'sh.stream_bufferer']

BRANCHES_SUPPORTED_FOR_TAG = ['master']
BRANCHES_SUPPORTED_FOR_TAG = ['main']

PROJECT_SLUG = ENVIRONMENT_VARIABLES.get('PROJECT_SLUG')
60 changes: 36 additions & 24 deletions _CI/library/core_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@
class Package:
def __init__(self,
name: str,
full_version: str,
index: str = "",
markers: str = "",
version: str,
index: str = '',
markers: str = '',
hashes: list = field(default=list)) -> None:
self.name = name
self.index = index
self.markers = markers
self.hashes = hashes
self.comparator, self.version = self._decompose_full_version(full_version)
self.comparator, self.version = self._decompose_full_version(version)

@staticmethod
def _decompose_full_version(full_version: str) -> (str, str):
comparator = ""
version = "*"
if full_version == "*":
comparator = ''
version = '*'
if full_version == '*':
return comparator, version
# We need to check for the most common pinning cases
# >, <, <=, >=, ~=, ==
Expand All @@ -78,25 +78,33 @@ def _decompose_full_version(full_version: str) -> (str, str):
if full_version.startswith(operator):
break
else:
raise ValueError(f"Could not find where the comparator pin ends in {full_version}")
raise ValueError(f'Could not find where the comparator pin ends in {full_version}')
version = full_version[len(operator):]

return operator, version

@property
def full_version(self):
return f"{self.comparator}{self.version}"
return f'{self.comparator}{self.version}'

@full_version.setter
def full_version(self, full_version):
self.comparator, self.version = self._decompose_full_version(full_version)

# Processes the two versions both in Pipfile and Pipfile.lock, and matches
# the pinning from the Pipfile and the exact version from the Pipfile.lock
def compare_versions(self, pipfile_full_version, pipfile_lock_full_version):
"""Processes the two versions both in Pipfile and Pipfile.lock
Matches the pinning from the Pipfile and the exact version from the Pipfile.lock
Args:
pipfile_full_version (str): The string of the full version specified in the Pipfile
pipfile_lock_full_version (str): The string of the full version specified in the Pipfile.lock file
Returns:
"""
pipfile_comparator, pipfile_version = self._decompose_full_version(pipfile_full_version)
pipfile_lock_comparator, pipfile_lock_version = self._decompose_full_version(pipfile_lock_full_version)
self.comparator = pipfile_comparator
self.comparator = pipfile_comparator if pipfile_comparator else '~='
self.version = pipfile_lock_version


Expand All @@ -111,6 +119,7 @@ def compare_versions(self, pipfile_full_version, pipfile_lock_full_version):
#
"""


def activate_template():
logging_level = os.environ.get('LOGGING_LEVEL', '').upper() or LOGGING_LEVEL
if logging_level == 'DEBUG':
Expand All @@ -137,13 +146,10 @@ def activate_template():
colored_logs = False





# The sequence here is important because it makes sure
# that the virtual environment is loaded as soon as possible
def is_venv_created():
warnings.simplefilter("ignore", ResourceWarning)
warnings.simplefilter('ignore', ResourceWarning)
dev_null = open(os.devnull, 'w')
venv = Popen(['pipenv', '--venv'], stdout=PIPE, stderr=dev_null).stdout.read().strip()
return True if venv else False
Expand Down Expand Up @@ -179,6 +185,7 @@ def activate_virtual_environment():
elif sys.version_info[0] == 2:
execfile(activation_file, dict(__file__=activation_file))


def setup_logging(level):
try:
import coloredlogs
Expand All @@ -197,6 +204,7 @@ def setup_logging(level):
for logger in LOGGERS_TO_DISABLE:
logging.getLogger(logger).disabled = True


# TODO extend debug logging in the following methods

def load_environment_variables(environment_variables):
Expand Down Expand Up @@ -390,6 +398,7 @@ def on_error(func, path, exc_info): # pylint: disable=unused-argument
else:
raise # pylint: disable=misplaced-bare-raise


def clean_up(items, on_error=on_error):
if not isinstance(items, (list, tuple)):
items = [items]
Expand All @@ -409,11 +418,13 @@ def clean_up(items, on_error=on_error):

def get_top_level_dependencies():
pip_packages = Project().parsed_pipfile.get('packages', {}).items()
packages = [Package(name_, version_) for name_, version_ in pip_packages]
packages = [Package(name_, version_) if isinstance(version_, str) else Package(name_, **version_)
for name_, version_ in pip_packages]
pip_dev_packages = Project().parsed_pipfile.get('dev-packages', {}).items()
dev_packages = [Package(name_, version_) for name_, version_ in pip_dev_packages]
LOGGER.debug(f"Packages in Pipfile: {packages}")
LOGGER.debug(f"Development packages in Pipfile: {dev_packages}")
dev_packages =[Package(name_, version_) if isinstance(version_, str) else Package(name_, **version_)
for name_, version_ in pip_dev_packages]
LOGGER.debug(f'Packages in Pipfile: {packages}')
LOGGER.debug(f'Development packages in Pipfile: {dev_packages}')
return packages, dev_packages


Expand Down Expand Up @@ -450,11 +461,12 @@ def _get_packages(top_level_packages, packages):
for top_level_package in top_level_packages:
package = next((item for item in packages if item.name == top_level_package.name), None)
if not package:
raise ValueError(f"Package name {top_level_package} not found in Pipfile.lock")
raise ValueError(f'Package name "{top_level_package.name}" not found in Pipfile.lock')
package.compare_versions(top_level_package.full_version, package.full_version)
pkg.append(package)
return pkg


def save_requirements():
top_level_packages, top_level_dev_packages = get_top_level_dependencies()
all_packages, all_dev_packages = get_all_packages()
Expand Down Expand Up @@ -576,10 +588,10 @@ def update_pipfile(stdout: bool):
config.get('all_packages'))}

if stdout:
LOGGER.debug(f"Outputting Pipfile on stdout")
LOGGER.debug(f'Outputting Pipfile on stdout')
print(toml.dumps(pipfile))
else:
LOGGER.debug(f"Outputting Pipfile top {project.pipfile_location}")
LOGGER.debug(f'Outputting Pipfile top {project.pipfile_location}')
with open(project.pipfile_location, 'w') as writer:
writer.write(toml.dumps(pipfile))

Expand Down
2 changes: 1 addition & 1 deletion _CI/scripts/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def check_branch():

def push(current_version):
git = Git()
git.commit('Updated history file with changelog', 'HISTORY.rst')
git.commit('Add commit to history file', 'HISTORY.rst')
git.commit('Set version to {}'.format(current_version), '.VERSION')
git.add_tag(current_version)
git.push()
Expand Down
10 changes: 6 additions & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
#
# Please use Pipfile to update the requirements.
#
flake8==3.8.0
sphinx~=2.1.2
sphinx-rtd-theme~=0.4.3
prospector==1.1.6.2
prospector~=1.3.1
coverage~=4.5.4
nose~=1.3.7
nose-htmloutput~=0.6.0
tox~=3.13.2
betamax~=0.8.1
betamax-serializers~=0.2.1
semver~=2.8.1
gitwrapperlib~=0.9.1
gitwrapperlib~=0.9.3
twine~=1.13.0
coloredlogs~=10.0
coloredlogs~=15.0.1
emoji~=0.5.4
toml~=0.10.0
toml~=0.10.2
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. toonapilib documentation master file, created by
sphinx-quickstart on 2019-02-16.
sphinx-quickstart on 2021-07-07.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#
# Please use Pipfile to update the requirements.
#
coloredlogs~=10.0
requests~=2.22.0
cachetools~=3.1.1
dateparser~=0.7.2
backoff~=1.9.2
coloredlogs>=15.0.1
requests>=2.25.1
cachetools>=4.2.2
dateparser>=1.0.0
backoff>=1.10.0
6 changes: 3 additions & 3 deletions setup_aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ done

function _activate() {
EXIT_CODE=false
for path in '.venv/bin/activate' '_CI/files/.venv/bin/activate'
for path_ in '.venv/bin/activate' '_CI/files/.venv/bin/activate'
do
if [ -f "${path}" ]; then
. "${path}"
if [ -f "${path_}" ]; then
. "${path_}"
EXIT_CODE=true
break
fi
Expand Down
2 changes: 1 addition & 1 deletion toonapilib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

__author__ = '''Costas Tyfoxylos <[email protected]>'''
__docformat__ = '''google'''
__date__ = '''2017-12-09'''
__date__ = '''09-12-2017'''
__copyright__ = '''Copyright 2017, Costas Tyfoxylos'''
__license__ = '''MIT'''
__maintainer__ = '''Costas Tyfoxylos'''
Expand Down
2 changes: 1 addition & 1 deletion toonapilib/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

__author__ = '''Costas Tyfoxylos <[email protected]>'''
__docformat__ = '''google'''
__date__ = '''2017-12-09'''
__date__ = '''09-12-2017'''
__copyright__ = '''Copyright 2017, Costas Tyfoxylos'''
__license__ = '''MIT'''
__maintainer__ = '''Costas Tyfoxylos'''
Expand Down
12 changes: 6 additions & 6 deletions toonapilib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def _change_state(self, state):
@property
def can_toggle(self):
"""Boolean about the capability of the device to toggle state."""
return False if not self.is_connected or self.is_locked else True
return bool(self.is_connected or self.is_locked)

def turn_off(self):
"""Turns the device off."""
Expand All @@ -302,7 +302,7 @@ def device_uuid(self):
def is_connected(self):
"""Boolean about the connection status of the device."""
value = self._get_value('isConnected')
return True if value else False
return bool(value)

@property
def current_state(self):
Expand All @@ -320,13 +320,13 @@ def device_type(self):
def in_switch_all_group(self):
"""Boolean about whether the device is in a switch group."""
value = self._get_value('inSwitchAll', config=True)
return True if value else False
return bool(value)

@property
def in_switch_schedule(self):
"""Boolean about whether the device is in a switch schedule."""
value = self._get_value('inSwitchSchedule', config=True)
return True if value else False
return bool(value)

@property
def zwave_index(self):
Expand All @@ -339,7 +339,7 @@ def zwave_index(self):
def is_locked(self):
"""Boolean about the lock state of the object."""
value = self._get_value('switchLocked', config=True)
return True if value else False
return bool(value)

@property
def zwave_uuid(self):
Expand Down Expand Up @@ -385,7 +385,7 @@ def usage_capable(self):
"""Boolean about the capability of the device to report power usage."""
if self._usage_capable is None:
value = self._get_value('usageCapable', config=True)
self._usage_capable = True if value else False
self._usage_capable = bool(value)
return self._usage_capable

@property
Expand Down
Loading

0 comments on commit e74d67f

Please sign in to comment.