Skip to content

Commit

Permalink
20.1: black, revamp requirements
Browse files Browse the repository at this point in the history
This updates the version to 20.1 after running black on the source code
and removed the need to use tox.
  • Loading branch information
Joshua Powers committed Jun 21, 2020
1 parent 4383849 commit 5add8a1
Show file tree
Hide file tree
Showing 24 changed files with 233 additions and 287 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
language: python
dist: xenial
dist: bionic
python:
- 3.5
- 3.6
- 3.7
- 3.8
install:
- pip install -r requirements.txt -r requirements-test.txt
script:
- tox
- make test
- python setup.py install
- whatsthis version
- whatsthis features
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include LICENSE MANIFEST.in requirements.txt requirements-test.txt tox.ini
include LICENSE requirements.txt requirements-test.txt
37 changes: 16 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
# This file is part of whatsthis. See LICENSE file for license information.

PYTHON = python3
SETUP := $(PYTHON) setup.py

.PHONY: build clean install publish source test venv

build:
$(SETUP) build
build: clean
python3 setup.py build

clean:
$(SETUP) clean
rm -rf .coverage .tox .mypy_cache .eggs *.egg-info build dist
python3 setup.py clean
rm -rf .pytest_cache build dist *.egg-info .coverage
@find . -regex '.*\(__pycache__\|\.py[co]\)' -delete

install:
$(SETUP) install
install: clean
pip install -r requirements.txt
python3 setup.py install

publish:
publish: clean
rm -rf dist/
$(SETUP) sdist
python3 setup.py sdist
pip install twine
twine upload dist/*

source:
$(SETUP) sdist

test:
$(SETUP) check -r -s
tox
black --check .
flake8 --max-line-length=88 whatsthis setup.py
py.test --cov=whatsthis whatsthis

venv:
$(PYTHON) -m virtualenv -p /usr/bin/$(PYTHON) venv
venv/bin/pip install -Ur requirements.txt
venv/bin/pip install -Ur requirements-test.txt
python3 -m virtualenv venv
venv/bin/pip install -Ur requirements.txt -Ur requirements-test.txt
@echo "Now run the following to activate the virtual env:"
@echo ". venv/bin/activate"

.PHONY: build clean install publish test venv
14 changes: 5 additions & 9 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
flake8==3.7.7
flake8-docstrings==1.3.0
mypy==0.720
# https://gitlab.com/pycqa/flake8-docstrings/issues/36
pydocstyle<4.0.0
pylint==2.3.1
pytest==4.3.1
pytest-cov==2.6.1
tox==3.3.0
black==19.10b0
flake8==3.8.3
flake8-docstrings==1.5.0
pytest==5.4.3
pytest-cov==2.10.0
38 changes: 19 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@
from whatsthis import __author__, __title__, __version__

PWD = os.path.abspath(os.path.dirname(__title__))
REQUIREMENTS_FILE = os.path.join(PWD, 'requirements.txt')
REQUIREMENTS_FILE = os.path.join(PWD, "requirements.txt")
REQUIREMENTS = []
with open(REQUIREMENTS_FILE, 'r') as req_file:
with open(REQUIREMENTS_FILE, "r") as req_file:
REQUIREMENTS = req_file.read().splitlines()

README_FILE = os.path.join(PWD, 'README.md')
with open(README_FILE, 'r') as readme:
README_FILE = os.path.join(PWD, "README.md")
with open(README_FILE, "r") as readme:
README_TEXT = readme.read()

setup(
name=__title__,
version=__version__,
description=('Am I in a cloud, on a container, or just plain metal?'),
description=("Am I in a cloud, on a container, or just plain metal?"),
long_description=README_TEXT,
long_description_content_type='text/markdown',
long_description_content_type="text/markdown",
author=__author__,
url='https://github.com/powersj/%s' % __title__,
license='GNU General Public License v3 (GPLv3)',
url="https://github.com/powersj/%s" % __title__,
license="GNU General Public License v3 (GPLv3)",
packages=find_packages(),
entry_points={
'console_scripts': ['%s=%s.__main__:launch' % (__title__, __title__)]
"console_scripts": ["%s=%s.__main__:launch" % (__title__, __title__)]
},
python_requires='>=3.4',
python_requires=">=3.6",
install_requires=REQUIREMENTS,
zip_safe=True,
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Utilities',
]
"Development Status :: 2 - Pre-Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
],
)
20 changes: 0 additions & 20 deletions tox.ini

This file was deleted.

19 changes: 5 additions & 14 deletions whatsthis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# This file is part of whatsthis. See LICENSE file for license information.
"""__init__ module."""

__title__ = 'whatsthis'
__version__ = '19.1'
__author__ = 'Joshua Powers'
__title__ = "whatsthis"
__version__ = "20.1"
__author__ = "Joshua Powers"

__features__ = {
'probes': {
'processor': [
'core',
'memory',
]
},
'subcommands': [
'collect',
'features',
'version'
]
"probes": {"processor": ["core", "memory"]},
"subcommands": ["collect", "features", "version"],
}
52 changes: 20 additions & 32 deletions whatsthis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,20 @@

def _setup_args():
"""TODO."""
parser = argparse.ArgumentParser(prog='whatsthis')
parser = argparse.ArgumentParser(prog="whatsthis")
parser.add_argument(
'--data-dir',
help='use previously collected data from specified directory'
)
parser.add_argument(
'--debug', action='store_true', help='enable debug logging'
)
parser.add_argument(
'--json', action='store_true', help='enable output in JSON'
"--data-dir", help="use previously collected data from specified directory"
)
parser.add_argument("--debug", action="store_true", help="enable debug logging")
parser.add_argument("--json", action="store_true", help="enable output in JSON")

subparsers = parser.add_subparsers(title='Subcommands', dest='subcommand')
collect = subparsers.add_parser(
'collect', help='collect required system data'
)
subparsers = parser.add_subparsers(title="Subcommands", dest="subcommand")
collect = subparsers.add_parser("collect", help="collect required system data")
collect.add_argument(
'--output-dir', default='',
help='place collected data here instead of `pwd`'
)
subparsers.add_parser(
'features', help='return parseable list of feature flags'
)
subparsers.add_parser(
'version', help='return version of application'
"--output-dir", default="", help="place collected data here instead of `pwd`"
)
subparsers.add_parser("features", help="return parseable list of feature flags")
subparsers.add_parser("version", help="return version of application")

return parser.parse_args()

Expand All @@ -50,10 +38,10 @@ def _setup_logging(debug=False):

if debug:
level = logging.DEBUG
formatter = logging.Formatter('%(asctime)s - %(message)s')
formatter = logging.Formatter("%(asctime)s - %(message)s")
else:
level = logging.INFO
formatter = logging.Formatter('%(message)s')
formatter = logging.Formatter("%(message)s")

console = logging.StreamHandler()
console.setFormatter(formatter)
Expand All @@ -63,18 +51,18 @@ def _setup_logging(debug=False):

def _verify_platform_support():
"""Determine platform and kernel version support for sysfs."""
if sys.platform != 'linux':
print('error: only linux platform supported')
if sys.platform != "linux":
print("error: only linux platform supported")
sys.exit(1)

major, minor, _ = platform.release().split('.')
major, minor, _ = platform.release().split(".")
if int(major) < 3 or (int(major) == 3 and int(minor) < 6):
print('error: at least kernel 3.6 for sysfs support required')
print("error: at least kernel 3.6 for sysfs support required")
sys.exit(1)

major, minor, _ = platform.python_version_tuple()
if int(major) < 3 or (int(major) == 3 and int(minor) < 5):
print('error: at least python 3.5 required')
print("error: at least python 3.5 required")
sys.exit(1)


Expand All @@ -86,13 +74,13 @@ def launch():

if not args.subcommand:
Discovery(args.data_dir)
elif args.subcommand == 'collect':
elif args.subcommand == "collect":
Collect(args.output_dir)
elif args.subcommand == 'features':
elif args.subcommand == "features":
print(json.dumps(__features__, indent=4, sort_keys=True))
elif args.subcommand == 'version':
elif args.subcommand == "version":
print(__version__)


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(launch())
28 changes: 14 additions & 14 deletions whatsthis/collect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@
class Collect:
"""Collect /proc and /sys from a system."""

def __init__(self, output_dir=''):
def __init__(self, output_dir=""):
"""Initialize the collect class.
Args:
output_dir: directory to place output in (default: current dir)
"""
self.tmp_dir = tempfile.mkdtemp(prefix='whatsthis-')
self.tmp_dir = tempfile.mkdtemp(prefix="whatsthis-")

logging.info('starting collection')
logging.debug('tempdir: %s', self.tmp_dir)
logging.info("starting collection")
logging.debug("tempdir: %s", self.tmp_dir)
self.proc()
self.sys()

tar_filename = '%s-%s.tar.gz' % (
tar_filename = "%s-%s.tar.gz" % (
platform.node(),
datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
datetime.datetime.now().strftime("%Y%m%d-%H%M%S"),
)
tar(self.tmp_dir, os.path.join(output_dir, tar_filename))

Expand All @@ -57,7 +57,7 @@ def __del__(self):

def proc(self):
"""Collect specific files from /proc."""
logging.info('/proc')
logging.info("/proc")

for file_path in proc.FILES:
if not exists(file_path):
Expand All @@ -70,17 +70,17 @@ def sys(self):
Requires the use of -noleaf due to the odd behavior of sysfs.
Cannot assume it acts like any other filesystem.
"""
logging.info('/sys')
logging.info("/sys")

for sys_path in sys.FILES:
result = execute([
'find', sys_path, '-noleaf', '-type', 'f', '-perm', '/444'
])
result = execute(
["find", sys_path, "-noleaf", "-type", "f", "-perm", "/444"]
)

for file_path in sorted(result.split('\n')):
if 'autosuspend_delay_ms' in file_path:
for file_path in sorted(result.split("\n")):
if "autosuspend_delay_ms" in file_path:
continue
if 'thermal_zone' in file_path:
if "thermal_zone" in file_path:
continue

dd(file_path, os.path.join(self.tmp_dir, file_path[1:]))
Loading

0 comments on commit 5add8a1

Please sign in to comment.