Skip to content

Commit

Permalink
Merge pull request #179 from workhorsy/bye_bye_py2
Browse files Browse the repository at this point in the history
Bye bye py2
  • Loading branch information
workhorsy authored Sep 5, 2022
2 parents 44c6e08 + 5dffea0 commit 635811d
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: ["2.7", "3.7", "3.9", "3.10"]
python-version: ["3.7", "3.9", "3.10"]
architecture: [x64, x86]
exclude:
- os: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Release 8.1.0
* Fixed Bug #177: Officially drop support for Python 2
* Fixed Bug #171: Replace Python 3.11 deprecated unittest.makeSuite
* Fixed Bug #173: Fix lgtm.com alerts
* Fixed Bug #165: Support Wheel
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2021 Matthew Brennan Jones <[email protected]>
Copyright (c) 2014-2022 Matthew Brennan Jones <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ clean-dist-files:
rm -f -rf py-cpuinfo-$(VERSION)
rm -f -rf py-cpuinfo-$(VERSION).tar.gz
rm -f -rf py-cpuinfo-$(VERSION).zip
rm -f -rf py_cpuinfo-$(VERSION)-py2.py3-none-any.whl
rm -f -rf py_cpuinfo-$(VERSION)-py3-none-any.whl

.PHONY: clean
clean: clean-temp-files clean-dist-files
Expand All @@ -41,7 +41,7 @@ build: clean _actual_build move_built
move_built:
mv dist/py-cpuinfo-$(VERSION).tar.gz py-cpuinfo-$(VERSION).tar.gz
mv dist/py-cpuinfo-$(VERSION).zip py-cpuinfo-$(VERSION).zip
mv dist/py_cpuinfo-$(VERSION)-py2.py3-none-any.whl py_cpuinfo-$(VERSION)-py2.py3-none-any.whl
mv dist/py_cpuinfo-$(VERSION)-py3-none-any.whl py_cpuinfo-$(VERSION)-py3-none-any.whl

.PHONY: release
release:
Expand All @@ -56,7 +56,7 @@ release:
.PHONY: upload
upload: clean _actual_build
twine upload dist/py-cpuinfo-$(VERSION).tar.gz
twine upload dist/py_cpuinfo-$(VERSION)-py2.py3-none-any.whl
twine upload dist/py_cpuinfo-$(VERSION)-py3-none-any.whl

install: remove
tar xzf py-cpuinfo-$(VERSION).tar.gz
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ py-cpuinfo

Py-cpuinfo gets CPU info with pure Python. Py-cpuinfo should work without any
extra programs or libraries, beyond what your OS provides. It does not require
any compilation(C/C++, assembly, et cetera) to use. It works with Python 2
and 3.
any compilation(C/C++, assembly, et cetera) to use. It works with Python 3.


Example
Expand Down Expand Up @@ -44,9 +43,9 @@ Fields
-----
| key | Example value | Return Format |
| :---------------------------- | :------------------------ | :-------------------- |
| "python_version" | "2.7.12.final.0 (64 bit)" | string |
| "cpuinfo_version" | (4, 0, 0) | (int, int, int) |
| "cpuinfo_version_string" | "4.0.0" | string |
| "python_version" | "3.10.4.final.0 (64 bit)" | string |
| "cpuinfo_version" | (8, 0, 0) | (int, int, int) |
| "cpuinfo_version_string" | "8.0.0" | string |
| "hz_advertised_friendly" | "2.9300 GHz" | string |
| "hz_actual_friendly" | "1.7330 GHz" | string |
| "hz_advertised" | (2930000000, 0) | (int, int) |
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ py-cpuinfo
Py-cpuinfo gets CPU info with pure Python. Py-cpuinfo should work
without any extra programs or libraries, beyond what your OS provides.
It does not require any compilation(C/C++, assembly, et cetera) to use.
It works with Python 2 and 3.
It works with Python 3.

Documentation can be viewed here: https://github.com/workhorsy/py-cpuinfo
6 changes: 1 addition & 5 deletions cpuinfo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@

import sys

if sys.version_info[0] == 2:
from cpuinfo import *
else:
from cpuinfo.cpuinfo import *
from cpuinfo.cpuinfo import *


30 changes: 9 additions & 21 deletions cpuinfo/cpuinfo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright (c) 2014-2021 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python 2 & 3
# Copyright (c) 2014-2022 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python
# It uses the MIT License
# It is hosted at: https://github.com/workhorsy/py-cpuinfo
#
Expand Down Expand Up @@ -34,7 +34,6 @@
import ctypes


IS_PY2 = sys.version_info[0] == 2
CAN_CALL_CPUID_IN_SUBPROCESS = True

g_trace = None
Expand All @@ -47,11 +46,7 @@ def __init__(self, is_active, is_stored_in_string):
return

from datetime import datetime

if IS_PY2:
from cStringIO import StringIO
else:
from io import StringIO
from io import StringIO

if is_stored_in_string:
self._output = StringIO()
Expand Down Expand Up @@ -335,9 +330,8 @@ def _run_and_get_stdout(command, pipe_command=None):

# Get the stdout and stderr
stdout_output, stderr_output = p1.communicate()
if not IS_PY2:
stdout_output = stdout_output.decode(encoding='UTF-8')
stderr_output = stderr_output.decode(encoding='UTF-8')
stdout_output = stdout_output.decode(encoding='UTF-8')
stderr_output = stderr_output.decode(encoding='UTF-8')

# Send the result to the logger
g_trace.command_output('return code:', str(p1.returncode))
Expand Down Expand Up @@ -394,9 +388,7 @@ def _b64_to_obj(thing):
return {}

def _utf_to_str(input):
if IS_PY2 and isinstance(input, unicode):
return input.encode('utf-8')
elif isinstance(input, list):
if isinstance(input, list):
return [_utf_to_str(element) for element in input]
elif isinstance(input, dict):
return {_utf_to_str(key): _utf_to_str(value)
Expand Down Expand Up @@ -1516,10 +1508,7 @@ def _get_cpu_info_from_cpuid_actual():
It will safely call this function in another process.
'''

if IS_PY2:
from cStringIO import StringIO
else:
from io import StringIO
from io import StringIO

trace = Trace(True, True)
info = {}
Expand Down Expand Up @@ -2733,8 +2722,7 @@ def get_cpu_info_json():
if p1.returncode != 0:
return "{}"

if not IS_PY2:
output = output.decode(encoding='UTF-8')
output = output.decode(encoding='UTF-8')

return output

Expand All @@ -2758,7 +2746,7 @@ def main():
import json

# Parse args
parser = ArgumentParser(description='Gets CPU info with pure Python 2 & 3')
parser = ArgumentParser(description='Gets CPU info with pure Python')
parser.add_argument('--json', action='store_true', help='Return the info in JSON format')
parser.add_argument('--version', action='store_true', help='Return the version of py-cpuinfo')
parser.add_argument('--trace', action='store_true', help='Traces code paths used to find CPU info to file')
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"setuptools == 44.1.1",
"setuptools_scm == 2.1.0",
"setuptools",
"wheel",
]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[bdist_wheel]
universal = 1
universal = 0
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2014-2021 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python 2 & 3
# Copyright (c) 2014-2022 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python
# It uses the MIT License
# It is hosted at: https://github.com/workhorsy/py-cpuinfo

Expand All @@ -14,7 +14,7 @@
version = "8.0.0",
author = "Matthew Brennan Jones",
author_email = "[email protected]",
description = "Get CPU info with pure Python 2 & 3",
description = "Get CPU info with pure Python",
long_description=readme_content,
license = "MIT",
url = "https://github.com/workhorsy/py-cpuinfo",
Expand All @@ -27,7 +27,6 @@
"Development Status :: 5 - Production/Stable",
"Topic :: Utilities",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3"
],
)
4 changes: 2 additions & 2 deletions test_suite.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright (c) 2014-2021 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python 2 & 3
# Copyright (c) 2014-2022 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python
# It uses the MIT License
# It is hosted at: https://github.com/workhorsy/py-cpuinfo
#
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright (c) 2014-2021 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python 2 & 3
# Copyright (c) 2014-2022 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python
# It uses the MIT License
# It is hosted at: https://github.com/workhorsy/py-cpuinfo
#
Expand Down
9 changes: 3 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def test_json(self):

self.assertEqual(0, p1.returncode)

if not IS_PY2:
output = output.decode(encoding='UTF-8')
output = output.decode(encoding='UTF-8')

info = json.loads(output, object_hook = cpuinfo._utf_to_str)

Expand All @@ -40,8 +39,7 @@ def test_version(self):

self.assertEqual(0, p1.returncode)

if not IS_PY2:
output = output.decode(encoding='UTF-8')
output = output.decode(encoding='UTF-8')
output = output.strip()

self.assertEqual(cpuinfo.CPUINFO_VERSION_STRING, output)
Expand Down Expand Up @@ -86,8 +84,7 @@ def test_default(self):

self.assertEqual(0, p1.returncode)

if not IS_PY2:
output = output.decode(encoding='UTF-8')
output = output.decode(encoding='UTF-8')

version = output.split('Cpuinfo Version: ')[1].split('\n')[0].strip()

Expand Down
9 changes: 3 additions & 6 deletions tests/test_compile_errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import sys
import unittest
from cpuinfo import *
import helpers


Expand All @@ -25,11 +25,8 @@ def test_all(self):
p1 = Popen(command.split(' '), stdout=PIPE, stderr=PIPE, stdin=PIPE)
p1_stdout, p1_stderr = p1.communicate()

if not cpuinfo.IS_PY2:
p1_stdout = p1_stdout.decode(encoding='UTF-8')

if not cpuinfo.IS_PY2:
p1_stderr = p1_stderr.decode(encoding='UTF-8')
p1_stdout = p1_stdout.decode(encoding='UTF-8')
p1_stderr = p1_stderr.decode(encoding='UTF-8')

# Check for no errors
self.assertEqual("", p1_stderr)
Expand Down
11 changes: 4 additions & 7 deletions tools/get_system_info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright (c) 2014-2021 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python 2 & 3
# Copyright (c) 2014-2022 Matthew Brennan Jones <[email protected]>
# Py-cpuinfo gets CPU info with pure Python
# It uses the MIT License
# It is hosted at: https://github.com/workhorsy/py-cpuinfo
#
Expand Down Expand Up @@ -40,7 +40,6 @@
except ImportError as err:
pass

IS_PY2 = sys.version_info[0] == 2
is_windows = platform.system().lower() == 'windows'

out_file_name = 'system_info.txt'
Expand All @@ -53,16 +52,14 @@ def run_and_get_stdout(command, pipe_command=None):
if not pipe_command:
p1 = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE)
output = p1.communicate()[0]
if not IS_PY2:
output = output.decode(encoding='UTF-8')
output = output.decode(encoding='UTF-8')
return p1.returncode, output
else:
p1 = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE)
p2 = Popen(pipe_command, stdin=p1.stdout, stdout=PIPE, stderr=PIPE)
p1.stdout.close()
output = p2.communicate()[0]
if not IS_PY2:
output = output.decode(encoding='UTF-8')
output = output.decode(encoding='UTF-8')
return p2.returncode, output

def program_paths(program_name):
Expand Down

0 comments on commit 635811d

Please sign in to comment.