panopticas 0.0.1__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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Peter Freiberg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.1
2
+ Name: panopticas
3
+ Version: 0.0.1
4
+ Summary: The panopticas CLI tool.
5
+ Author-email: Peter Freiberg <peter.freiberg@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Peter Freiberg
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://panopticas.io
29
+ Project-URL: Issues, https://github.com/kospex/panopticas/issues
30
+ Project-URL: Repository, https://github.com/kospex/panopticas.git
31
+ Keywords: analytics,git
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python
35
+ Requires-Python: >=3.10
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: Click
39
+ Requires-Dist: prettytable
40
+ Requires-Dist: pathspec
41
+
42
+ # panopticas
43
+
44
+ Discover insights into the types of data and functions used in your code.
45
+
46
+
@@ -0,0 +1,5 @@
1
+ # panopticas
2
+
3
+ Discover insights into the types of data and functions used in your code.
4
+
5
+
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=70.1.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "panopticas"
7
+ version = "0.0.1"
8
+ description = "The panopticas CLI tool."
9
+ authors = [
10
+ {name = "Peter Freiberg", email = "peter.freiberg@gmail.com"}
11
+ ]
12
+ dependencies = [
13
+ "Click",
14
+ "prettytable",
15
+ "pathspec"
16
+ ]
17
+ requires-python = ">=3.10"
18
+ readme = "README.md"
19
+ keywords = ["analytics", "git"]
20
+ license = {file = "LICENSE"}
21
+
22
+ classifiers = [
23
+ "Development Status :: 3 - Alpha",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Programming Language :: Python"
26
+ ]
27
+
28
+ [project.scripts]
29
+ panopticas = "panopticas:cli"
30
+
31
+ [project.urls]
32
+ Homepage = "https://panopticas.io"
33
+ Issues = "https://github.com/kospex/panopticas/issues"
34
+ Repository = "https://github.com/kospex/panopticas.git"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.1
2
+ Name: panopticas
3
+ Version: 0.0.1
4
+ Summary: The panopticas CLI tool.
5
+ Author-email: Peter Freiberg <peter.freiberg@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Peter Freiberg
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://panopticas.io
29
+ Project-URL: Issues, https://github.com/kospex/panopticas/issues
30
+ Project-URL: Repository, https://github.com/kospex/panopticas.git
31
+ Keywords: analytics,git
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python
35
+ Requires-Python: >=3.10
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: Click
39
+ Requires-Dist: prettytable
40
+ Requires-Dist: pathspec
41
+
42
+ # panopticas
43
+
44
+ Discover insights into the types of data and functions used in your code.
45
+
46
+
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/panopticas.py
5
+ src/panopticas_filetype.py
6
+ src/panopticas.egg-info/PKG-INFO
7
+ src/panopticas.egg-info/SOURCES.txt
8
+ src/panopticas.egg-info/dependency_links.txt
9
+ src/panopticas.egg-info/entry_points.txt
10
+ src/panopticas.egg-info/requires.txt
11
+ src/panopticas.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ panopticas = panopticas:cli
@@ -0,0 +1,3 @@
1
+ Click
2
+ prettytable
3
+ pathspec
@@ -0,0 +1,2 @@
1
+ panopticas
2
+ panopticas_filetype
@@ -0,0 +1,66 @@
1
+ # panopticas.py
2
+ import click
3
+ from prettytable import PrettyTable
4
+ import panopticas_filetype as ft
5
+
6
+ @click.group()
7
+ def cli():
8
+ """Panopticas is a tool for assessing code and git repositories.
9
+
10
+ It is designed to analysis external dependencies (e.g. URLs, cloud providers)
11
+
12
+ For documentation on how commands run `panopticas COMMAND --help`.
13
+
14
+ See also https://panopticas.io/
15
+
16
+ """
17
+
18
+ @cli.command("assess")
19
+ #@click.option('--default', is_flag=True, default=False, help="Create the default ~/code directory.")
20
+ @click.argument('directory', required=False, type=click.Path(exists=True))
21
+ def assess(directory):
22
+ """Assess a directory."""
23
+ click.echo()
24
+ if directory:
25
+ click.echo(f'Assessing directory: {directory}')
26
+ else:
27
+ click.echo('Assessing current directory.')
28
+ directory = "."
29
+ files = ft.identify_files(directory)
30
+ click.echo(f'Found {len(files)} files.\n')
31
+ table = PrettyTable()
32
+ table.field_names = ["File", "Language"]
33
+ table.align["File"] = "l"
34
+ table.align["Language"] = "l"
35
+ for file in files:
36
+ table.add_row([file, files[file]])
37
+ #click.echo(files[file])
38
+ print(table,"\n")
39
+
40
+ @cli.command("file")
41
+ @click.argument('file', required=True,type=click.Path(exists=True))
42
+ def identify(file):
43
+ """Assess a filetype."""
44
+ click.echo(f'\nAssessing filetype for file {file}')
45
+ click.echo()
46
+ table = PrettyTable()
47
+ table.field_names = ["Method", "Result"]
48
+ table.align["Method"] = "l"
49
+ table.align["Result"] = "l"
50
+
51
+ table.add_row(["File extenion", ft.get_fileext(file)])
52
+ table.add_row(["File type", ft.get_extension_filetype(ft.get_fileext(file))])
53
+ shebang = ft.check_shebang(file)
54
+ table.add_row(["Shebang", shebang])
55
+ table.add_row(["Shebang Language", ft.extract_shebang_language(shebang) if shebang else None])
56
+ print(table)
57
+ print()
58
+
59
+ @cli.command("version")
60
+ def version():
61
+ """Print the version of Panopticas."""
62
+ #click.echo(f"Panopticas version {panopticas_core.__version__}")
63
+ click.echo("Panopticas version 0.0.1")
64
+
65
+ if __name__ == '__main__':
66
+ cli()
@@ -0,0 +1,153 @@
1
+ """ File type analysis functions for Panopticas """
2
+ import os
3
+ import pathspec
4
+
5
+ def get_fileext(file_path):
6
+ """ Get the file extension of a file """
7
+ file_type = None
8
+ if os.path.isfile(file_path):
9
+ file_type = os.path.splitext(file_path)[1]
10
+ if file_type:
11
+ return file_type
12
+ else:
13
+ return os.path.basename(file_path)
14
+
15
+ def get_extension_filetype(file_path):
16
+ """ Get the file extension of a file, using an exact match """
17
+ filetypes = {
18
+ '.py': 'Python',
19
+ '.js': 'JavaScript',
20
+ '.html': 'HTML',
21
+ '.htm': 'HTML',
22
+ '.css': 'CSS',
23
+ '.c': 'C',
24
+ '.cpp': 'C++',
25
+ '.java': 'Java',
26
+ '.rb': 'Ruby',
27
+ '.php': 'PHP',
28
+ '.sh': 'Shell',
29
+ '.pl': 'Perl',
30
+ '.go': 'Go',
31
+ '.rs': 'Rust',
32
+ '.kt': 'Kotlin',
33
+ '.swift': 'Swift',
34
+ '.r': 'R',
35
+ '.cs': 'C#',
36
+ '.m': 'Objective-C',
37
+ '.scala': 'Scala',
38
+ '.sql': 'SQL',
39
+ '.json': 'JSON',
40
+ '.yaml': 'YAML',
41
+ '.yml': 'YAML',
42
+ '.toml': 'TOML',
43
+ '.ini': 'INI',
44
+ '.md': 'Markdown',
45
+ '.rst': 'ReStructuredText',
46
+ '.txt': 'Text',
47
+ '.csv': 'CSV',
48
+ '.ts': 'TypeScript',
49
+ '.jsx': 'JSX',
50
+ '.tf': 'Terraform',
51
+ '.tsx': 'TSX',
52
+ '.vue': 'Vue',
53
+ '.xml': 'XML',
54
+ '.gitignore': 'Gitignore',
55
+ '.dockerignore': 'Dockerignore',
56
+ 'dockerfile': 'Dockerfile',
57
+ }
58
+
59
+ if file_path:
60
+ return filetypes.get(file_path.lower(), None)
61
+ else:
62
+ return None
63
+
64
+ def check_shebang(file_path):
65
+ """ Check if a file has a shebang """
66
+ with open(file_path) as file:
67
+ first_line = file.readline()
68
+ if first_line and first_line.startswith("#!"):
69
+ return first_line.strip()
70
+ else:
71
+ return None
72
+
73
+ def get_shebang_language(shebang):
74
+ """ Return the language of a shebang """
75
+ return None
76
+
77
+ def load_gitignore_patterns(directory):
78
+ """
79
+ Load gitignore patterns from a directory
80
+ """
81
+ gitignore_path = os.path.join(directory, '.gitignore')
82
+
83
+ if os.path.exists(gitignore_path):
84
+
85
+ with open(gitignore_path, 'r') as file:
86
+ patterns = file.read().splitlines()
87
+ # Add .git to the patterns
88
+ patterns.append('.git')
89
+ # These seem to be ignore by git
90
+ patterns.append('.jekyll-cache')
91
+ patterns.append('.ruff_cache')
92
+ patterns.append('.DS_Store')
93
+
94
+ return pathspec.PathSpec.from_lines('gitwildmatch', patterns)
95
+ return None
96
+
97
+ def identify_files(directory):
98
+ """ Identify files in a directory """
99
+
100
+ gitignore_spec = load_gitignore_patterns(directory)
101
+
102
+ file_paths = {}
103
+ for root, _, files in os.walk(directory):
104
+ for file in files:
105
+ full_path = os.path.join(root, file)
106
+ relative_path = os.path.relpath(full_path, directory)
107
+ if gitignore_spec and gitignore_spec.match_file(relative_path):
108
+ continue
109
+ ftype = None
110
+ ext = get_fileext(full_path)
111
+ if ext:
112
+ ftype = get_extension_filetype(ext)
113
+
114
+ if directory == ".":
115
+ full_path = full_path.removeprefix("./")
116
+
117
+ file_paths[full_path] = ftype
118
+
119
+ return file_paths
120
+
121
+
122
+ def extract_shebang_language(shebang: str) -> str:
123
+ """
124
+ Take a string like
125
+ #!/usr/bin/env python3
126
+ and return the language (python3)
127
+ """
128
+ parts = shebang.split()
129
+ # Check if the shebang string starts with '#!' and has at least two parts
130
+ # Check for #!/usr/bin/env python3 pattern
131
+ if "#!" in parts[0] and len(parts) > 1:
132
+
133
+ # Split the second part by '/' and check if it contains 'env'
134
+ if 'env' in parts[0]:
135
+ return parts[-1] # The interpreter is the last part
136
+
137
+ # Check for
138
+ # #!/usr/local/bin/perl style pattern
139
+ else:
140
+ return shebang.split('/')[-1] # Otherwise, the interpreter is the last
141
+
142
+ return None
143
+
144
+ def get_language(file_path):
145
+ """ Return the language of a file """
146
+ return None
147
+
148
+ def basename_check(file_path):
149
+ """
150
+ Return a guessed type based on the basename
151
+ """
152
+
153
+ return None