Skip to content

Commit 7d551a0

Browse files
committed
Add directory structure check (linter)
1 parent 3a3a794 commit 7d551a0

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ jobs:
3939
. venv/bin/activate
4040
flake8
4141
black --check .
42+
43+
- run:
44+
name: Directory layout check
45+
command: |
46+
. venv/bin/activate
47+
python .circleci/dircheck.py

.circleci/dircheck.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
Linter to ensure standard folder structure
3+
"""
4+
import pathlib
5+
import re
6+
import sys
7+
8+
IGNORELIST = {
9+
"venv",
10+
"asyncio-walkthrough",
11+
"build-a-gui-with-wxpython",
12+
"consuming-apis-python",
13+
"flask-connexion-rest-part-3",
14+
"flask-connexion-rest-part-4",
15+
"generators",
16+
"intro-to-threading",
17+
"introduction-combining-data-pandas-merge-join-and-concat",
18+
"linked-lists-python",
19+
"nearbyshops",
20+
"oop-in-java-vs-python",
21+
"opencv-color-spaces",
22+
"openpyxl-excel-spreadsheets-python",
23+
"pygame-a-primer",
24+
"pyqt-calculator-tutorial",
25+
"python-bindings",
26+
"python-dash",
27+
"python-eval-mathrepl",
28+
"qt-designer-python",
29+
"rp-portfolio",
30+
"storing-images",
31+
"understanding-asynchronous-programming",
32+
}
33+
FOLDER_NAME_RE = re.compile(r"^[-a-z0-9]{5,}\Z")
34+
35+
has_errors = False
36+
37+
for f in sorted(pathlib.Path(".").glob("*")):
38+
if not f.is_dir():
39+
continue
40+
if str(f).startswith("."):
41+
continue
42+
if str(f) in IGNORELIST:
43+
continue
44+
45+
if not FOLDER_NAME_RE.search(str(f)):
46+
print(
47+
f"{f}: ensure folder name only uses "
48+
f"lowercase letters, numbers, and hyphens"
49+
)
50+
has_error = True
51+
52+
files = sorted(_.name for _ in f.glob("*"))
53+
if "README.md" not in files:
54+
print(f"{f}: no README.md found")
55+
has_errors = True
56+
57+
if has_errors:
58+
print(
59+
"""-----------------------
60+
Please ensure new sample projects are added using the correct
61+
folder structure:
62+
63+
* New files should go into a top-level subfolder, named after the
64+
article slug (lowercase, dashes). For example: my-awesome-article/
65+
66+
* Top-level sample project folders should contain a README.md file.
67+
For example: my-awesome-article/README.md
68+
69+
This helps us keep the repo clean and easy to browse on GitHub.
70+
71+
Thanks!
72+
"""
73+
)
74+
sys.exit(1)

0 commit comments

Comments
 (0)