Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug: Serialization to JSON is not deterministic #39

Closed
apirogov opened this issue Mar 28, 2023 · 3 comments
Closed

Possible bug: Serialization to JSON is not deterministic #39

apirogov opened this issue Mar 28, 2023 · 3 comments
Assignees
Labels
bug Something isn't working ready Done/implemented, but release still pending

Comments

@apirogov
Copy link

apirogov commented Mar 28, 2023

I'm using codemetapy as a linter with pre-commit and noticed that for some reason it fails sometimes because the codemeta.json file changed.

In my case, this is caused by my classifiers:

classifiers = [
    "Operating System :: POSIX :: Linux",
    "Development Status :: 3 - Alpha",
    "Intended Audience :: Science/Research",
    "Intended Audience :: Developers",
]

Then codemetapy will randomly orders them, sometimes resulting in:

    "audience": [
        {
            "@type": "Audience",
            "audienceType": "Science/Research"
        },
        {
            "@type": "Audience",
            "audienceType": "Developers"
        }
    ],

and sometimes in:

    "audience": [
        {
            "@type": "Audience",
            "audienceType": "Developers"
        },
        {
            "@type": "Audience",
            "audienceType": "Science/Research"
        }
    ],

Would it be possible to make sure that a consistent order is ensured?

As a workaround I currently add a global exclude: '^codemeta.json$' to my hook, which is not nice because it prevents my JSON linter to format the JSON.

Expected behavior

On the same input files exactly the same output file should be generated.

@proycon
Copy link
Owner

proycon commented Mar 29, 2023

Thanks for the report, I agree that the output should be deterministic. It already is in the ordering of fields in a map but not yet in the ordering of objects in a sequence, I'll implement a solution for it.

@proycon
Copy link
Owner

proycon commented Sep 18, 2023

Should be fixed and released now

@proycon proycon closed this as completed Sep 18, 2023
@apirogov
Copy link
Author

Great! Thanks for fixing this and all the others issues! I will test the new version once I have a bit of time in the coming days/weeks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready Done/implemented, but release still pending
Projects
None yet
Development

No branches or pull requests

2 participants