json-prettifier 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: json-prettifier
3
+ Version: 0.1.0
4
+ Summary: A simple CLI tool to beautify and format JSON data.
5
+ Home-page: https://github.com/yourusername/json-prettifier
6
+ Author: Your Name
7
+ Author-email: your.email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Utilities
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: click>=8.0.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
File without changes
@@ -0,0 +1 @@
1
+ __version__ = "0.1.7"
@@ -0,0 +1,78 @@
1
+ """
2
+ Entrypoint for CLI tool
3
+ """
4
+
5
+ import json
6
+ import click
7
+ import os
8
+
9
+ @click.command()
10
+ @click.option("--string", "-s", help="Raw JSON string")
11
+ @click.option("--file", "-f", type=click.File('r'), help="File containing JSON object")
12
+ @click.option(
13
+ "--replace",
14
+ "-r",
15
+ is_flag=True,
16
+ default=True, # <--- Change 1: Set default to True
17
+ help="Overwrite the original input file with the beautified JSON. Default is True; use --no-replace to print to standard output." # <--- Change 2: Update help text
18
+ )
19
+ @click.argument("input", required=False)
20
+
21
+ def main(string, file, replace, input):
22
+ ''' Beautify JSON object '''
23
+
24
+ input_file_path = None # To store the path if the input is a file we might replace
25
+
26
+ if string:
27
+ data = string
28
+ elif file:
29
+ data = file.read()
30
+ # The file option has type=click.File('r'), so 'file' is a file object.
31
+ # We can get the name (path) from its 'name' attribute.
32
+ input_file_path = file.name
33
+ elif input:
34
+ try:
35
+ # Check if 'input' is a file path
36
+ if os.path.exists(input) and os.path.isfile(input):
37
+ with open(input, 'r') as f:
38
+ data = f.read()
39
+ input_file_path = input
40
+ # Otherwise, treat 'input' as a raw JSON string
41
+ else:
42
+ data = input
43
+ except Exception:
44
+ # Fallback in case of other file-related issues, treat as string
45
+ data = input
46
+ else:
47
+ print("error")
48
+ raise click.UsageError("Error: please provide a JSON string or file")
49
+
50
+
51
+ try:
52
+ # 1. Parse the JSON data
53
+ parsed = json.loads(data)
54
+
55
+ # 2. Beautify the JSON
56
+ beautified_json = json.dumps(parsed, indent=4)
57
+
58
+ # 3. Handle the output based on the 'replace' flag and input type
59
+ # Logic remains the same: overwrite only if 'replace' is True (now default) AND we have a file path.
60
+ if replace and input_file_path:
61
+ # Overwrite the original file
62
+ with open(input_file_path, 'w') as f:
63
+ f.write(beautified_json)
64
+ # Optionally notify the user
65
+ click.echo(f"Successfully beautified and overwrote file: {input_file_path}", err=True)
66
+ else:
67
+ # Print to standard output
68
+ click.echo(beautified_json)
69
+
70
+ except json.JSONDecodeError as e:
71
+ raise click.ClickException(f"Invalid JSON: {e}")
72
+ except Exception as e:
73
+ # Catch any other potential errors (like writing to file)
74
+ raise click.ClickException(f"An error occurred: {e}")
75
+
76
+
77
+ if __name__ == "__main__":
78
+ main()
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: json-prettifier
3
+ Version: 0.1.0
4
+ Summary: A simple CLI tool to beautify and format JSON data.
5
+ Home-page: https://github.com/yourusername/json-prettifier
6
+ Author: Your Name
7
+ Author-email: your.email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Utilities
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: click>=8.0.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
@@ -0,0 +1,10 @@
1
+ README.md
2
+ setup.py
3
+ json_prettifier/__init__.py
4
+ json_prettifier/cli.py
5
+ json_prettifier.egg-info/PKG-INFO
6
+ json_prettifier.egg-info/SOURCES.txt
7
+ json_prettifier.egg-info/dependency_links.txt
8
+ json_prettifier.egg-info/entry_points.txt
9
+ json_prettifier.egg-info/requires.txt
10
+ json_prettifier.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ jb = json_prettifier.cli:main
3
+ json-prettifier = json_prettifier.cli:main
@@ -0,0 +1 @@
1
+ click>=8.0.0
@@ -0,0 +1 @@
1
+ json_prettifier
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,32 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='json-prettifier',
5
+ version='0.1.0',
6
+ description='A simple CLI tool to beautify and format JSON data.',
7
+ long_description=open('README.md').read(),
8
+ long_description_content_type='text/markdown',
9
+ author='Your Name', # Replace with your name
10
+ author_email='your.email@example.com', # Replace with your email
11
+ url='https://github.com/yourusername/json-prettifier', # Replace with your repo URL
12
+ packages=find_packages(),
13
+ install_requires=[
14
+ 'click>=8.0.0', # We need click for the CLI framework
15
+ ],
16
+ # Define the console scripts entry points
17
+ entry_points={
18
+ 'console_scripts': [
19
+ # jb = json_prettifier.cli:main
20
+ 'jb = json_prettifier.cli:main',
21
+ # json-prettifier = json_prettifier.cli:main
22
+ 'json-prettifier = json_prettifier.cli:main',
23
+ ],
24
+ },
25
+ classifiers=[
26
+ 'Programming Language :: Python :: 3',
27
+ 'License :: OSI Approved :: MIT License',
28
+ 'Operating System :: OS Independent',
29
+ 'Topic :: Utilities',
30
+ ],
31
+ python_requires='>=3.6',
32
+ )