Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit 9cee419

Browse files
authored
Added Testing to READMEs (#38)
* Setting up testing section * Added requirements * Added test data to README * Added Glotter notes to all READMEs * Added install requires to setup.py * Added Testing info to READMEs * Added requirements links * Updated setup version * Wrote a wild regex... * Added future fix * Fixed lowercase issue
1 parent 2599861 commit 9cee419

File tree

4 files changed

+100
-22
lines changed

4 files changed

+100
-22
lines changed

generate_docs/markdown.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import pathlib
3+
import sys
34
from urllib.error import HTTPError
45
from urllib import request
56

@@ -46,6 +47,20 @@ def build_doc_link(sample_program: SampleProgram, text: str) -> str:
4647
return markdown_url
4748

4849

50+
def build_req_link(sample_program: SampleProgram) -> str:
51+
"""
52+
A handy abstraction for the create_md_link() method which creates a link to a sample programs docs page.
53+
(e.g., https://sample-programs.therenegadecoder.com/projects/even-odd/c/)
54+
:param sample_program: the sample program
55+
:return: a markdown link to the docs page if it exists; an empty string otherwise
56+
"""
57+
if not verify_link(sample_program.sample_program_req_url):
58+
print(f"{sample_program.file_name} is not currently supported by this repo.")
59+
sys.exit(1)
60+
else:
61+
return f"{create_md_link('Requirements', sample_program.sample_program_req_url)}"
62+
63+
4964
def verify_link(url: str) -> bool:
5065
"""
5166
Verifies that a URL is a valid URL.

generate_docs/readme.py

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
from generate_docs.markdown import MarkdownPage, build_doc_link, verify_link
1+
from generate_docs.markdown import MarkdownPage, build_doc_link, verify_link, build_req_link
22
from generate_docs.repo import Repo, LanguageCollection
33

44

55
def _get_intro_text(language: LanguageCollection) -> str:
66
introduction = f"Welcome to Sample Programs in {language.get_readable_name()}!"
77
docs = f"""To find documentation related to the {language.get_readable_name()}
8-
code in this repo, look [here]({language.sample_program_url}).
9-
"""
10-
interlude_valid = "Otherwise, below you'll find a list of code snippets in this collection."
11-
interlude_invalid = "Below, you'll find a list of code snippets in this collection."
12-
emojis = """
13-
Code snippets preceded by :warning: link to a GitHub
14-
issue query featuring a possible article request issue. If an article request issue
15-
doesn't exist, we encourage you to create one. Meanwhile, code snippets preceded
16-
by :white_check_mark: link to an existing article which provides further documentation.
17-
"""
8+
code in this repo, look [here]({language.sample_program_url})."""
189
if not verify_link(language.sample_program_url):
19-
return " ".join([introduction, interlude_invalid, emojis])
10+
return introduction
2011
else:
21-
return " ".join([introduction, docs, interlude_valid, emojis])
12+
return " ".join([introduction, docs])
13+
14+
15+
def _get_sample_programs_text() -> str:
16+
return """Below, you'll find a list of code snippets in this collection.
17+
Code snippets preceded by :warning: link to a GitHub
18+
issue query featuring a possible article request issue. If an article request issue
19+
doesn't exist, we encourage you to create one. Meanwhile, code snippets preceded
20+
by :white_check_mark: link to an existing article which provides further documentation."""
2221

2322

2423
def _generate_program_list(language: LanguageCollection) -> list:
@@ -31,13 +30,45 @@ def _generate_program_list(language: LanguageCollection) -> list:
3130
for program in language.sample_programs:
3231
readable_name = program.normalized_name.replace("-", " ").title()
3332
doc_link = build_doc_link(program, f"{readable_name} in {language.get_readable_name()}")
34-
list_items.append(f"- {doc_link}")
33+
req_link = build_req_link(program)
34+
list_items.append(f"- {doc_link} [{req_link}]")
3535
return list_items
3636

3737

38+
def _generate_testing_section(language: LanguageCollection):
39+
test_data = language.get_test_data()
40+
if not test_data:
41+
return """This language currently does not feature testing. If you'd like to help in the efforts to test all
42+
of the code in this repo, consider creating a testinfo.yml file with the following information:
43+
44+
```yml
45+
folder:
46+
extension:
47+
naming:
48+
49+
container:
50+
image:
51+
tag:
52+
cmd:
53+
```
54+
55+
See the [Glotter project](https://github.com/auroq/glotter) for more information on how to create a testinfo file.
56+
"""
57+
else:
58+
return f"""The following list shares details about what we're using to test all Sample Programs in
59+
{language.get_readable_name()}.
60+
61+
- Docker Image: {test_data["container"]["image"]}
62+
- Docker Tag: {test_data["container"]["tag"]}
63+
64+
See the [Glotter project](https://github.com/auroq/glotter) for more information on how we handle testing.
65+
"""
66+
67+
3868
def _generate_credit():
39-
return """This page was generated automatically by the Sample Programs Docs Generator.
40-
Find out how to support this project [here](https://github.com/TheRenegadeCoder/sample-programs-docs-generator)."""
69+
return """---
70+
This page was generated automatically by the Sample Programs Docs Generator.
71+
Find out how to support this project [here](https://github.com/TheRenegadeCoder/sample-programs-docs-generator)."""
4172

4273

4374
class ReadMeCatalog:
@@ -61,13 +92,26 @@ def _build_readme(self, language: LanguageCollection) -> None:
6192
:return: None
6293
"""
6394
page = MarkdownPage("README")
95+
96+
# Introduction
6497
page.add_content(f"# Sample Programs in {language.get_readable_name()}")
6598
page.add_section_break()
6699
page.add_content(_get_intro_text(language))
67100
page.add_section_break()
101+
102+
# Sample Programs List
103+
page.add_content("## Sample Programs List")
104+
page.add_section_break()
105+
page.add_content(_get_sample_programs_text())
106+
page.add_section_break()
68107
page.add_content(*_generate_program_list(language))
69108
page.add_section_break()
109+
110+
# Testing
111+
page.add_content("## Testing")
112+
page.add_content(_generate_testing_section(language))
70113
page.add_content(_generate_credit())
114+
71115
self.pages[language.name] = page
72116

73117
def _build_readmes(self) -> None:

generate_docs/repo.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import os
1111
import re
12+
import yaml
1213
from typing import Optional
1314

1415

@@ -135,7 +136,7 @@ def _generate_urls(self) -> None:
135136
def _organize_collection(self):
136137
self.sample_programs.sort(key=lambda program: program.normalized_name.casefold())
137138

138-
def get_readable_name(self):
139+
def get_readable_name(self) -> str:
139140
"""
140141
Generates as close to the proper language name as possible given a language
141142
name in plain text separated by hyphens
@@ -154,6 +155,13 @@ def get_readable_name(self):
154155
else:
155156
return " ".join(tokens).title()
156157

158+
def get_test_data(self) -> Optional[dict]:
159+
test_data = None
160+
if self.test_file_path:
161+
with open(os.path.join(self.path, self.test_file_path)) as test_file:
162+
test_data = yaml.safe_load(test_file)
163+
return test_data
164+
157165

158166
class SampleProgram:
159167
"""
@@ -171,6 +179,7 @@ def __init__(self, path: str, file_name: str, language: str):
171179
self.file_name = file_name
172180
self.language = language
173181
self.sample_program_doc_url: Optional[str] = None
182+
self.sample_program_req_url: Optional[str] = None
174183
self.sample_program_issue_url: Optional[str] = None
175184
self.normalized_name: Optional[str] = None
176185
self._generate_urls()
@@ -193,11 +202,12 @@ def get_language(self) -> str:
193202
def _normalize_program_name(self):
194203
stem = os.path.splitext(self.file_name)[0]
195204
if len(stem.split("-")) > 1:
196-
url = stem
205+
url = stem.lower()
197206
elif len(stem.split("_")) > 1:
198-
url = stem.replace("_", "-")
207+
url = stem.replace("_", "-").lower()
199208
else:
200-
url = "-".join(re.findall('[a-zA-Z][^A-Z]*', stem)).lower()
209+
# TODO: this is brutal. At some point, we should loop in the glotter test file.
210+
url = re.sub('((?<=[a-z])[A-Z0-9]|(?!^)[A-Z](?=[a-z]))', r'-\1', stem).lower()
201211
return url
202212

203213
def _generate_urls(self) -> None:
@@ -207,8 +217,14 @@ def _generate_urls(self) -> None:
207217

208218
self.normalized_name = self._normalize_program_name()
209219

220+
# req URL
221+
if "export" in self.normalized_name or "import" in self.normalized_name:
222+
self.sample_program_req_url = f"{doc_url_base}/import-export"
223+
else:
224+
self.sample_program_req_url = f"{doc_url_base}/{self.normalized_name}"
225+
210226
# doc URL
211-
self.sample_program_doc_url = f"{doc_url_base}/{self.normalized_name}/{self.language}"
227+
self.sample_program_doc_url = f"{self.sample_program_req_url}/{self.language}"
212228

213229
# issue URL
214230
program = self.normalized_name.replace("-", "+")

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

66
setuptools.setup(
77
name="generate_docs",
8-
version="2.1.0",
8+
version="2.2.0",
99
author="The Renegade Coder",
1010
author_email="jeremy.grifski@therenegadecoder.com",
1111
description="A docs generation package for the Sample Programs repo",
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",
1414
url="https://github.com/TheRenegadeCoder/sample-programs-docs-generator",
1515
packages=setuptools.find_packages(),
16+
install_requires=[
17+
"PyYAML~=5.4.1"
18+
],
1619
entry_points={
1720
"console_scripts": [
1821
'wikig = generate_docs.generator:main_wiki',

0 commit comments

Comments
 (0)