Markdown-Checker 0.0.5__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) 2023 John Aziz
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,3 @@
1
+ include README.md
2
+ include markdown_checker/get_input_args/*
3
+ include setup.cfg
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.1
2
+ Name: markdown-checker
3
+ Version: 0.0.5
4
+ Summary: A markdown validation reporting tool
5
+ Home-page: https://github.com/john0isaac/markdown-checker
6
+ Author: John Aziz
7
+ Author-email: johnaziz269@gmail.com
8
+ Maintainer: John Aziz
9
+ Maintainer-email: johnaziz269@gmail.com
10
+ License: MIT
11
+ Project-URL: Bug Tracker, https://github.com/john0isaac/markdown-checker/issues
12
+ Project-URL: Contributing, https://github.com/john0isaac/markdown-checker/pulls
13
+ Project-URL: Source Code, https://github.com/john0isaac/markdown-checker
14
+ Project-URL: Releases, https://github.com/john0isaac/markdown-checker/releases
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+
24
+ [![PyPi](https://img.shields.io/pypi/v/markdown-checker)](https://pypi.org/project/markdown-checker/)
25
+ [![Downloads](https://img.shields.io/pypi/dm/markdown-checker)](https://pypi.org/project/markdown-checker/)
26
+
27
+ [![GitHub issues](https://img.shields.io/badge/issue_tracking-github-blue.svg)](https://github.com/john0isaac/markdown-checker/issues)
28
+ [![Contributing](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://github.com/john0isaac/markdown-checker/pulls)
29
+
30
+ markdown-checker is a markdown validation reporting tool.
31
+
32
+ # How To
33
+ 1. Run `pip install markdown-checker`.
34
+ 2. Run `markdown-checker -d {src} -f {func}`. Replace `{src}` with the directory you want to analyse and {func} with the available functions like check_broken_paths.
35
+ 3. The output will be displayed in the terminal.
36
+
37
+ # Using markdown-checker in GitHub Actions
38
+ The tool has been designed to be run within a GitHub workflow using the [action-check-markdown](https://github.com/marketplace/actions/action-check-markdown) GitHub action. The action will automatically post the output of the tool to your GitHub pull request as a comment.
@@ -0,0 +1,15 @@
1
+ [![PyPi](https://img.shields.io/pypi/v/markdown-checker)](https://pypi.org/project/markdown-checker/)
2
+ [![Downloads](https://img.shields.io/pypi/dm/markdown-checker)](https://pypi.org/project/markdown-checker/)
3
+
4
+ [![GitHub issues](https://img.shields.io/badge/issue_tracking-github-blue.svg)](https://github.com/john0isaac/markdown-checker/issues)
5
+ [![Contributing](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://github.com/john0isaac/markdown-checker/pulls)
6
+
7
+ markdown-checker is a markdown validation reporting tool.
8
+
9
+ # How To
10
+ 1. Run `pip install markdown-checker`.
11
+ 2. Run `markdown-checker -d {src} -f {func}`. Replace `{src}` with the directory you want to analyse and {func} with the available functions like check_broken_paths.
12
+ 3. The output will be displayed in the terminal.
13
+
14
+ # Using markdown-checker in GitHub Actions
15
+ The tool has been designed to be run within a GitHub workflow using the [action-check-markdown](https://github.com/marketplace/actions/action-check-markdown) GitHub action. The action will automatically post the output of the tool to your GitHub pull request as a comment.
File without changes
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Module providing automatic checks functionality to markdown files
4
+ following some Guidelines
5
+ """
6
+ import argparse
7
+
8
+ def get_input_args() -> None:
9
+ """
10
+ Retrieves and parses the 2 command line arguments provided by the user when
11
+ they run the program from a terminal window. This function uses Python's
12
+ argparse module to created and defined these 2 command line arguments. If
13
+ the user fails to provide some or all of the 2 arguments, then the default
14
+ values are used for the missing arguments.
15
+ Command Line Arguments:
16
+ 1. Tutorials Path as --dir
17
+ 2. Function to be executed as --func
18
+ This function returns these arguments as an ArgumentParser object.
19
+ Parameters:
20
+ None - simply using argparse module to create & store command line arguments
21
+ Returns:
22
+ parse_args() -data structure that stores the command line arguments object
23
+ """
24
+ # Parse using ArgumentParser
25
+ parser = argparse.ArgumentParser()
26
+
27
+ parser.add_argument('-d', '--dir', type = str, default = './',
28
+ help = 'path to the root directory', required=True)
29
+
30
+ parser.add_argument('-f', '--func', type = str, required = True,
31
+ help = 'function to be executed',
32
+ choices=['check_broken_paths',
33
+ 'check_paths_tracking',
34
+ 'check_urls_tracking',
35
+ 'check_urls_locale'])
36
+
37
+ return parser.parse_args()
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Module providing automatic checks functionality to markdown files
4
+ following some Guidelines
5
+ """
6
+ import os
7
+ import re
8
+
9
+ # Helper Functions
10
+
11
+ def get_lessons_paths(root_path: str) -> dict:
12
+ """function to compile a dictionary of directories
13
+
14
+ Keyword arguments:
15
+ root_path -- directory to go through looking for md files
16
+ Return: formatted dictionary with directories as key and an array of files as values
17
+ """
18
+ lessons = {}
19
+ # add root path to the dictionary
20
+ lessons[root_path] = []
21
+ pass_list = ['CODE_OF_CONDUCT.md', 'CONTRIBUTING.md', 'SECURITY.md']
22
+ # get lessons folders
23
+ for item in os.listdir(root_path):
24
+ if os.path.isdir(os.path.join(root_path, item)):
25
+ lessons[item] = []
26
+
27
+ # get lesson exercises (md, ipynb files)
28
+ for lesson, _ in lessons.items():
29
+ if lesson != root_path:
30
+ for item in os.listdir(os.path.join(root_path, lesson)):
31
+ # check for translations directories
32
+ if os.path.isdir(os.path.join(root_path, lesson, item)):
33
+ for sub_item in os.listdir(os.path.join(root_path, lesson, item)):
34
+ if os.path.isdir(os.path.join(root_path, lesson, item, sub_item)):
35
+ for sub_item2 in os.listdir(os.path.join(root_path, lesson, item, sub_item)):
36
+ # check for .md and .ipynb files and store them
37
+ if sub_item2.lower().endswith(('.md', '.ipynb')) and sub_item2 not in pass_list:
38
+ lessons[lesson].append(os.path.join(item, sub_item, sub_item2))
39
+ # check for .md and .ipynb files and store them
40
+ elif sub_item.lower().endswith(('.md', '.ipynb')) and sub_item not in pass_list:
41
+ lessons[lesson].append(os.path.join(item, sub_item))
42
+ # check for .md and .ipynb files and store them
43
+ elif item.lower().endswith(('.md', '.ipynb')) and item not in pass_list:
44
+ lessons[lesson].append(item)
45
+ # get .md and .ipynb in root directory
46
+ for item in os.listdir(root_path):
47
+ if item.lower().endswith(('.md', '.ipynb')) and item not in pass_list:
48
+ lessons[root_path].append(item)
49
+
50
+ # check to remove folders that don't have .md files in them
51
+ lessons = {key: values for key, values in lessons.items() if len(values) > 0}
52
+
53
+ return lessons
54
+
55
+ def check_broken_links(file_path : str, link_type : str , check_type: str) -> str:
56
+ """function that checks if urls and hyperlinks are broken
57
+
58
+ Keyword arguments:
59
+ file_path -- a path to text file to check
60
+ link_type -- path or url
61
+ check_type -- broken or tracking or locale
62
+ Return: broken links and associated file path
63
+ """
64
+ all_links = get_links_from_file(file_path)
65
+
66
+ # check if file has links
67
+ if len(all_links) > 0:
68
+ formatted_output = f" FILE '{file_path}'\n"
69
+ if link_type == "path":
70
+ paths = get_paths_from_links(all_links)
71
+ if check_type == "broken" and len(paths) > 0:
72
+ broken_path = check_paths_exists(file_path, paths)
73
+ if len (broken_path) > 0:
74
+ formatted_output += f' has the following broken relative paths {broken_path}\n'
75
+ return formatted_output
76
+ elif check_type == "tracking" and len(paths) > 0:
77
+ tracking_id_paths = check_url_tracking(paths)
78
+ if len(tracking_id_paths) > 0:
79
+ formatted_output += f' has the following paths with no tracking id {tracking_id_paths}\n'
80
+ return formatted_output
81
+ elif link_type == "url":
82
+ urls = get_urls_from_links(all_links)
83
+ if check_type == "tracking" and len(urls) > 0:
84
+ tracking_id_urls = check_url_tracking(urls)
85
+ if len(tracking_id_urls) > 0:
86
+ formatted_output += f' has the following links with no tracking id {tracking_id_urls}\n'
87
+ return formatted_output
88
+ elif check_type == "locale" and len(urls) > 0:
89
+ country_locale_urls = check_url_locale(urls)
90
+ if len(country_locale_urls) > 0:
91
+ formatted_output += f' has the following links with country locale {country_locale_urls}\n'
92
+ return formatted_output
93
+
94
+ def get_links_from_file(file_path: str) -> list:
95
+ """function to get an array of markdown links from a file
96
+ flags markdown links captures the part inside () that comes right after []
97
+ """
98
+ all_links = []
99
+ with open(file_path, 'r', encoding="utf-8") as file:
100
+ data = file.read()
101
+ link_pattern = re.compile(r'\]\((.*?)\)| \)')
102
+ matches = re.finditer(link_pattern, data)
103
+ for matched_group in matches:
104
+ if matched_group.group(1):
105
+ all_links.append(matched_group.group(1))
106
+ return all_links
107
+
108
+ def get_urls_from_links(all_links: list) -> list:
109
+ """function to get an array of urls from a list"""
110
+ urls = []
111
+ url_pattern = re.compile(r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)')
112
+ allowed_list = ['github.com', 'microsoft.com', 'visualstudio.com', 'aka.ms', 'azure.com']
113
+ for link in all_links:
114
+ matches = re.findall(url_pattern, link)
115
+
116
+ if matches and any(allowed in link.lower() for allowed in allowed_list):
117
+ urls.append(link)
118
+ return urls
119
+
120
+ def get_paths_from_links(all_links: list) -> list:
121
+ """function to get relative paths from a list
122
+ flags paths that start with ./ or ../
123
+ """
124
+ paths = []
125
+ path_pattern = re.compile(r'(\.{1,2}\/)+([A-Za-z0-9-]+\/)*(.+\.[A-Za-z]+)')
126
+
127
+ for link in all_links:
128
+ link = link.split(" ")[0]
129
+ matches = re.findall(path_pattern, link)
130
+ if matches:
131
+ paths.append(link)
132
+ return paths
133
+
134
+ def check_paths_exists(file_path : str, paths : list) -> list:
135
+ """function checks if a path exist if not return non existent paths
136
+ flags any relative path that can't be accessed
137
+ """
138
+ broken_path = []
139
+ for path in paths:
140
+ path = re.sub(r'(\?|\&)(WT|wt)\.mc_id=.*', '', path)
141
+ if not os.path.exists(os.path.normpath(os.path.join(os.path.dirname(file_path), path))):
142
+ broken_path.append(path)
143
+ return broken_path
144
+
145
+ def check_url_locale(urls : list) -> list:
146
+ """function checks if a url has country locale
147
+ flags urls that have ==> /en-us/
148
+ """
149
+ country_locale = []
150
+ for url in urls:
151
+ locale_pattern = re.compile(r'\/[a-z]{2}-[a-z]{2}\/')
152
+ matches = re.findall(locale_pattern, url)
153
+ if matches:
154
+ country_locale.append(url)
155
+ return country_locale
156
+
157
+ def check_url_tracking(urls : list) -> list:
158
+ """function checks if a url has tracking id
159
+ flags urls missing ==> (? or &) plus WT.mc_id= or wt.mc_id=
160
+ """
161
+ tracking_id = []
162
+ for url in urls:
163
+ tracking_pattern = re.compile(r'(\?|\&)(WT|wt)\.mc_id=')
164
+ matches = re.findall(tracking_pattern, url)
165
+ if not matches:
166
+ tracking_id.append(url)
167
+ return tracking_id
168
+
169
+ # DEPRECATED
170
+ def get_urls_from_file(file_path: str) -> list:
171
+ """function to get an array of urls from a file"""
172
+ urls = []
173
+ with open(file_path, 'r', encoding="utf-8") as file:
174
+ data = file.read()
175
+ url_pattern = re.compile(r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)')
176
+ matches = re.finditer(url_pattern, data)
177
+ for matched_group in matches:
178
+ urls.append(matched_group.group())
179
+ return urls
180
+
181
+ def get_paths_from_file(file_path: str) -> list:
182
+ """function to get relative paths from a file"""
183
+ paths = []
184
+ with open(file_path, 'r', encoding="utf-8") as file:
185
+ data = file.read()
186
+ path_pattern = re.compile(r'(\.{1,2}\/)+([A-Za-z0-9-]+\/)*([A-Za-z0-9]+\.[A-Za-z]+)')
187
+ matches = re.finditer(path_pattern, data)
188
+ for matched_group in matches:
189
+ paths.append(matched_group.group())
190
+ return paths
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Module providing automatic checks functionality to markdown files
4
+ following some Guidelines
5
+ """
6
+ import os
7
+ from markdown_checker.get_input_args.get_input_args import get_input_args
8
+ from markdown_checker.markdown_checker import get_lessons_paths, check_broken_links
9
+
10
+ def main() -> None:
11
+ """Main program get inputs and run checks"""
12
+
13
+ # get input arguments directory, function to run
14
+ in_arg = get_input_args()
15
+
16
+ lessons = get_lessons_paths(in_arg.dir)
17
+
18
+ # iterate over the files to validate the content
19
+ for lesson_folder_name, lessons_array in lessons.items():
20
+ for lesson_file_name in lessons_array:
21
+ file_path = os.path.join(
22
+ in_arg.dir,
23
+ lesson_folder_name,
24
+ lesson_file_name)
25
+ if in_arg.dir == lesson_folder_name:
26
+ file_path = os.path.join(lesson_folder_name, lesson_file_name)
27
+ if "check_broken_paths" in in_arg.func:
28
+ formatted_output = check_broken_links(file_path, "path" , "broken")
29
+ if formatted_output:
30
+ print(formatted_output)
31
+ if "check_paths_tracking" in in_arg.func:
32
+ formatted_output = check_broken_links(file_path, "path" , "tracking")
33
+ if formatted_output:
34
+ print(formatted_output)
35
+ if "check_urls_tracking" in in_arg.func:
36
+ formatted_output = check_broken_links(file_path, "url" , "tracking")
37
+ if formatted_output:
38
+ print(formatted_output)
39
+ if "check_urls_locale" in in_arg.func:
40
+ formatted_output = check_broken_links(file_path, "url" , "locale")
41
+ if formatted_output:
42
+ print(formatted_output)
43
+
44
+ if __name__ == "__main__":
45
+ main()
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.1
2
+ Name: markdown-checker
3
+ Version: 0.0.5
4
+ Summary: A markdown validation reporting tool
5
+ Home-page: https://github.com/john0isaac/markdown-checker
6
+ Author: John Aziz
7
+ Author-email: johnaziz269@gmail.com
8
+ Maintainer: John Aziz
9
+ Maintainer-email: johnaziz269@gmail.com
10
+ License: MIT
11
+ Project-URL: Bug Tracker, https://github.com/john0isaac/markdown-checker/issues
12
+ Project-URL: Contributing, https://github.com/john0isaac/markdown-checker/pulls
13
+ Project-URL: Source Code, https://github.com/john0isaac/markdown-checker
14
+ Project-URL: Releases, https://github.com/john0isaac/markdown-checker/releases
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+
24
+ [![PyPi](https://img.shields.io/pypi/v/markdown-checker)](https://pypi.org/project/markdown-checker/)
25
+ [![Downloads](https://img.shields.io/pypi/dm/markdown-checker)](https://pypi.org/project/markdown-checker/)
26
+
27
+ [![GitHub issues](https://img.shields.io/badge/issue_tracking-github-blue.svg)](https://github.com/john0isaac/markdown-checker/issues)
28
+ [![Contributing](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://github.com/john0isaac/markdown-checker/pulls)
29
+
30
+ markdown-checker is a markdown validation reporting tool.
31
+
32
+ # How To
33
+ 1. Run `pip install markdown-checker`.
34
+ 2. Run `markdown-checker -d {src} -f {func}`. Replace `{src}` with the directory you want to analyse and {func} with the available functions like check_broken_paths.
35
+ 3. The output will be displayed in the terminal.
36
+
37
+ # Using markdown-checker in GitHub Actions
38
+ The tool has been designed to be run within a GitHub workflow using the [action-check-markdown](https://github.com/marketplace/actions/action-check-markdown) GitHub action. The action will automatically post the output of the tool to your GitHub pull request as a comment.
@@ -0,0 +1,16 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.cfg
6
+ setup.py
7
+ markdown_checker/__init__.py
8
+ markdown_checker/markdown_checker.py
9
+ markdown_checker/validate_markdown.py
10
+ markdown_checker.egg-info/PKG-INFO
11
+ markdown_checker.egg-info/SOURCES.txt
12
+ markdown_checker.egg-info/dependency_links.txt
13
+ markdown_checker.egg-info/entry_points.txt
14
+ markdown_checker.egg-info/top_level.txt
15
+ markdown_checker/get_input_args/__init__.py
16
+ markdown_checker/get_input_args/get_input_args.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ markdown-checker = markdown_checker.validate_markdown:main
@@ -0,0 +1 @@
1
+ markdown_checker
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,38 @@
1
+ [metadata]
2
+ name = markdown-checker
3
+ version = 0.0.5
4
+ author = John Aziz
5
+ author_email = johnaziz269@gmail.com
6
+ maintainer = John Aziz
7
+ maintainer_email = johnaziz269@gmail.com
8
+ description = A markdown validation reporting tool
9
+ long_description = file: README.md
10
+ long_description_content_type = text/markdown
11
+ license = MIT
12
+ url = https://github.com/john0isaac/markdown-checker
13
+ requires_python = ">=3.8"
14
+ project_urls =
15
+ Bug Tracker = https://github.com/john0isaac/markdown-checker/issues
16
+ Contributing = https://github.com/john0isaac/markdown-checker/pulls
17
+ Source Code = https://github.com/john0isaac/markdown-checker
18
+ Releases = https://github.com/john0isaac/markdown-checker/releases
19
+ classifiers =
20
+ Development Status :: 5 - Production/Stable
21
+ License :: OSI Approved :: MIT License
22
+ Operating System :: OS Independent
23
+ Programming Language :: Python :: 3
24
+ Programming Language :: Python :: 3.8
25
+
26
+ [options]
27
+ include_package_data = True
28
+ packages = find:
29
+ python_requires = >=3.8
30
+
31
+ [options.entry_points]
32
+ console_scripts =
33
+ markdown-checker = markdown_checker.validate_markdown:main
34
+
35
+ [egg_info]
36
+ tag_build =
37
+ tag_date = 0
38
+
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup()