Skip to content

Commit

Permalink
fix for pip-show parser with multi-line fields starting with a blank …
Browse files Browse the repository at this point in the history
…line
  • Loading branch information
kellyjonbrazil committed May 2, 2024
1 parent 4f66faa commit 8a3997c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
jc changelog

20240429 v1.25.3
20240502 v1.25.3
- Add `battery_percentage` field to `bluetoothctl` parser output
- Fix `pci-ids` parser to correctly handle multiple subdevices
- Fix `pip-show` parser to handle multi-line fields with a beginning blank line
- Fix `top` parsers to quiet uptime info parsing
- Fix `traceroute` parser to correctly handle hops with multiple IPs
- Optimize some tests by removing timezone settings and using quiet=True
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/pip_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd

Source: [`jc/parsers/pip_show.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/pip_show.py)

Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
4 changes: 3 additions & 1 deletion jc/parsers/pip_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.4'
version = '1.5'
description = '`pip show` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
Expand Down Expand Up @@ -144,6 +144,8 @@ def parse(
item_value = None

if last_key_data and last_key != item_key:
if not isinstance(package[last_key], str):
package[last_key] = ''
package[last_key] = package[last_key] + '\n' + '\n'.join(last_key_data)
last_key_data = []

Expand Down
2 changes: 1 addition & 1 deletion man/jc.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH jc 1 2024-04-29 1.25.3 "JSON Convert"
.TH jc 1 2024-05-02 1.25.3 "JSON Convert"
.SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
and strings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"setuptools","version":"39.2.0","summary":"Easily download, build, install, upgrade, and uninstall Python packages","home_page":"https://github.com/pypa/setuptools","author":"Python Packaging Authority","author_email":"distutils-sig@python.org","license":"UNKNOWN","location":"/usr/lib/python3.6/site-packages","requires":null,"required_by":"twine"},{"name":"pkginfo","version":"1.5.0.1","summary":"Query metadatdata from sdists / bdists / installed packages.","home_page":"https://code.launchpad.net/~tseaver/pkginfo/trunk","author":"Tres Seaver, Agendaless Consulting","author_email":"tseaver@agendaless.com","license":"MIT","location":"/home/kbrazil/.local/lib/python3.6/site-packages","requires":null,"required_by":"twine"},{"name":"cppy","version":"1.2.1","summary":"UNKNOWN","home_page":"https://github.com/nucleic/cppy","author":"None","author_email":"The Nucleic Development Team <sccolbert@gmail.com>","license":"\nCopyright (c) 2014, Nucleic\nAll rights reserved.\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n* Redistributions of source code must retain the above copyright notice, this\nlist of conditions and the following disclaimer.\n* Redistributions in binary form must reproduce the above copyright notice,\nthis list of conditions and the following disclaimer in the documentation\nand/or other materials provided with the distribution.\n* Neither the name of the copyright holder nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.","location":"/usr/home/bryder/.local/lib/python3.7/site-packages","requires":null,"required_by":null},{"name":"six","version":"1.12.0","summary":"Python 2 and 3 compatibility utilities","home_page":"https://github.com/benjaminp/six","author":"Benjamin Peterson","author_email":"benjamin@python.org","license":"MIT","location":"/home/kbrazil/.local/lib/python3.6/site-packages","requires":null,"required_by":"readme-renderer, bleach"},{"name":"cppy","version":"1.2.1","summary":"UNKNOWN","home_page":"https://github.com/nucleic/cppy","author":"None","author_email":"The Nucleic Development Team <sccolbert@gmail.com>","license":"\n\nCopyright (c) 2014, Nucleic\nAll rights reserved.\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n* Redistributions of source code must retain the above copyright notice, this\nlist of conditions and the following disclaimer.\n* Redistributions in binary form must reproduce the above copyright notice,\nthis list of conditions and the following disclaimer in the documentation\nand/or other materials provided with the distribution.\n* Neither the name of the copyright holder nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.","location":"/usr/home/bryder/.local/lib/python3.7/site-packages","requires":null,"required_by":null}]
99 changes: 99 additions & 0 deletions tests/fixtures/generic/pip-show-multiline-license-first-blank.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Name: setuptools
Version: 39.2.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License: UNKNOWN
Location: /usr/lib/python3.6/site-packages
Requires:
Required-by: twine
---
Name: pkginfo
Version: 1.5.0.1
Summary: Query metadatdata from sdists / bdists / installed packages.
Home-page: https://code.launchpad.net/~tseaver/pkginfo/trunk
Author: Tres Seaver, Agendaless Consulting
Author-email: tseaver@agendaless.com
License: MIT
Location: /home/kbrazil/.local/lib/python3.6/site-packages
Requires:
Required-by: twine
---
Name: cppy
Version: 1.2.1
Summary: UNKNOWN
Home-page: https://github.com/nucleic/cppy
Author: None
Author-email: The Nucleic Development Team <sccolbert@gmail.com>
License:
Copyright (c) 2014, Nucleic
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Location: /usr/home/bryder/.local/lib/python3.7/site-packages
Requires:
Required-by:
---
Name: six
Version: 1.12.0
Summary: Python 2 and 3 compatibility utilities
Home-page: https://github.com/benjaminp/six
Author: Benjamin Peterson
Author-email: benjamin@python.org
License: MIT
Location: /home/kbrazil/.local/lib/python3.6/site-packages
Requires:
Required-by: readme-renderer, bleach
---
Name: cppy
Version: 1.2.1
Summary: UNKNOWN
Home-page: https://github.com/nucleic/cppy
Author: None
Author-email: The Nucleic Development Team <sccolbert@gmail.com>
License:

Copyright (c) 2014, Nucleic
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Location: /usr/home/bryder/.local/lib/python3.7/site-packages
Requires:
Required-by:
12 changes: 12 additions & 0 deletions tests/test_pip_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license.out'), 'r', encoding='utf-8') as f:
generic_pip_show_multiline_license = f.read()

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license-first-blank.out'), 'r', encoding='utf-8') as f:
generic_pip_show_multiline_license_first_blank = f.read()

# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/pip-show.json'), 'r', encoding='utf-8') as f:
centos_7_7_pip_show_json = json.loads(f.read())
Expand All @@ -40,6 +43,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license.json'), 'r', encoding='utf-8') as f:
generic_pip_show_multiline_license_json = json.loads(f.read())

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/pip-show-multiline-license-first-blank.json'), 'r', encoding='utf-8') as f:
generic_pip_show_multiline_license_first_blank_json = json.loads(f.read())


def test_pip_show_nodata(self):
"""
Expand Down Expand Up @@ -77,6 +83,12 @@ def test_pip_show_multiline_license(self):
"""
self.assertEqual(jc.parsers.pip_show.parse(self.generic_pip_show_multiline_license, quiet=True), self.generic_pip_show_multiline_license_json)

def test_pip_show_multiline_license_first_blank(self):
"""
Test 'pip show' with a multiline license where the first line is blank
"""
self.assertEqual(jc.parsers.pip_show.parse(self.generic_pip_show_multiline_license_first_blank, quiet=True), self.generic_pip_show_multiline_license_first_blank_json)


if __name__ == '__main__':
unittest.main()

0 comments on commit 8a3997c

Please sign in to comment.