Skip to content

Conversation

HorlogeSkynet
Copy link
Owner

@HorlogeSkynet HorlogeSkynet commented May 8, 2020

python3 -m archey --json

Description

Simple JSON-formatting of entries data.
It's a first basic support, maybe it could be enhanced in the future.

EDIT 2020-05-13 : To keep things clean, DRY and concerns-separated, @ingrinder and myself started to work on a slight rework to make entries' values independent from their corresponding (regular and original) text output.
This will drastically simplify future work on entries data.

Reason and / or context

It would allow one to use Archey as an API or so 😄

How has this been tested ?

Test cases and our machines.

Types of changes :

  • Bug fix (non-breaking change which fixes an issue)
  • Typo / style fix (non-breaking change which improves readability)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist :

  • [IF NEEDED] I have updated the test cases (which pass) accordingly ;
  • My changes looks good ;
  • I agree that my code may be modified in the future ;
  • My code follows the code style of this project (PEP8).

@HorlogeSkynet HorlogeSkynet added the enhancement ⬆️ Implements a new feature, fixes or improves existing ones label May 8, 2020
@HorlogeSkynet HorlogeSkynet added this to the v4.7.2 milestone May 8, 2020
@HorlogeSkynet HorlogeSkynet requested a review from ingrinder May 8, 2020 13:10
@HorlogeSkynet HorlogeSkynet self-assigned this May 8, 2020
@ingrinder
Copy link
Collaborator

Huh, it's funny the CI build passed, since I'm consistently getting a unit test error on this branch:

======================================================================
ERROR: test_json_output_format (archey.test.test_archey_output.TestOutputUtil)
Test how the `output` method handles JSON preferred formatting of entries
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/mock.py", line 1348, in patched
    return func(*newargs, **newkeywargs)
  File "/home/michael/git/archey4/archey/test/test_archey_output.py", line 504, in test_json_output_format
    output = Output(format_to_json=True)
  File "/home/michael/git/archey4/archey/output.py", line 59, in __init__
    if ansi_color and Configuration().get('colors_palette')['honor_ansi_color']:
KeyError: 'honor_ansi_color'

----------------------------------------------------------------------
Ran 108 tests in 0.075s

FAILED (errors=1)

...whether I use python -m unittest or python setup.py -q test. I haven't got a custom configuration file in /etc/archey4 or ~/.config/archey4...

@HorlogeSkynet
Copy link
Owner Author

Yes sorry, related to d559edc52d839654989f1b39e6b0d3159bb71497.
It's (again) related to how Configuration is mocked across test modules (and the fact that it is actually a Singleton never getting reset)...
It should be fixed on your machine now 🙇

@HorlogeSkynet
Copy link
Owner Author

'should be well cleaner now.
I'll even fix a little blemish in our Output.{append,output} flow when #71 will be merged.
Tell me what you think about that !

Bye 👋

Samuel FORESTIER added 6 commits May 12, 2020 13:23
> Rationale : This should be compatible against Python < 3.6
> Rationale: When #71 will be merged, issues due to keys duplication may occur.
>            This patch sets output values as a list anyway, sparing us an API breakage in the future.
> Note: A `Colors.remove_colors` utility method has been added for DRY purposes.
+ Sets results output in a `data` dictionary of the parent document
+ Adds a new `meta` dictionary containing date of generation and Archey version

> Rationale: To keep `Output` concise, API-related code has been moved to a new `API` module.
> Rationale 2: Adding a timestamp would allow developers to perform computations based on collection date.
>              Adding a version identifier would allow **us** to make the API evolve in the future.
@HorlogeSkynet HorlogeSkynet force-pushed the feature/json_format branch from 57e60dd to 32cdee5 Compare May 12, 2020 11:23
ingrinder added 2 commits May 12, 2020 22:30
Adds proper JSON formatting to the following entries when using the `-j`
option:
* Disk
* LanIp
* RAM
* Temperature
* Terminal
* Uptime
* WanIp

Additionally adds a new attribute `_format_to_json` to the `Entry` base
class.
Rationale: Having the raw data in a consistent place makes it far easier
to implement an API with our entries.

* Removed `_format_to_json` attribute introduced in e709d0e.
* Modified all entries to place a generic object (list, string, dict)
  into the `value` attribute which suits the data best.
* Moved pretty-formatting logic to an overriden `output` method.
* Tweaked API implementation to use individual entries rather than their
  outputs (we now deal with the `value` attribute in the API which
  should contain all of an entry's data, even if it outputs multiple
  lines).
* Modified tests as appropriate :)
@ingrinder
Copy link
Collaborator

Sorry for the delays, I've been a little busy 😃. I made a few more modifications since I wasn't fully satisfied after I started work on e709d0e until seeing 32cdee5 inspired me to change how we treat Entry.value. Anyway, I'll try and get back to you with a more detailed response tomorrow if I get the chance 👍.

@HorlogeSkynet
Copy link
Owner Author

HorlogeSkynet commented May 13, 2020

Here we are ! Thanks for your huge work on improving the (raw) value/text output integration.
I think it would allow more modifiability in the future, currently costing us time though, sorry for that.

Changelog for my previous changes :

  • Test cases fixes
  • New output test cases for almost all entries
  • Some optimizations in entries flows/logic
  • max_temperature setting in entry's data (by using the API, setting the value unconditionally would be wise)
  • API meta-data and test enhancements

Once this has been merged, I'll rebase #71 & #72, leaving you #67 😉

Anyway, there are eventually many changes, so a proper review is needed 😨

@HorlogeSkynet
Copy link
Owner Author

HorlogeSkynet commented May 17, 2020

Unfortunately a rebase against new master was a PITA, so I've simply merged it to resolve new conflicts.
Due to past PRs merging order, I've had to roll-back chunks of #71 not required anymore according to global rework/cleanup done here.

Anyway, a proper review is more than required, but future looks simpler once this patch will be merged 👍

Copy link
Collaborator

@ingrinder ingrinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the patches on top of the changes I made earlier! This is looking nice now 😃. I've left a few comments for stuff I'm not so sure about or could do with changing - I'll hopefully submit commits for some of them if I get the chance. 👍

@HorlogeSkynet HorlogeSkynet requested a review from ingrinder May 18, 2020 08:16
Copy link
Collaborator

@ingrinder ingrinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, liking the custom assertions implementation 👍. This LGTM!

Edit: I'll refrain from merging anything and let you have the final go-ahead since last time I assumed we were going to merge the other way around 😄.

@HorlogeSkynet HorlogeSkynet merged commit f1759a9 into master May 19, 2020
@HorlogeSkynet HorlogeSkynet deleted the feature/json_format branch May 19, 2020 07:53
@ingrinder ingrinder mentioned this pull request May 20, 2020
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ⬆️ Implements a new feature, fixes or improves existing ones
Projects
Status: DONE
Development

Successfully merging this pull request may close these issues.

2 participants