Skip to content

Commit 8803fe5

Browse files
authored
Merge pull request carpentries/styles#446
2 parents 48dd391 + f1cb887 commit 8803fe5

File tree

7 files changed

+54
-39
lines changed

7 files changed

+54
-39
lines changed

Makefile

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,38 @@ JEKYLL_VERSION=3.8.5
88
PARSER=bin/markdown_ast.rb
99
DST=_site
1010

11+
# Check Python 3 is installed and determine if it's called via python3 or python
12+
# (https://stackoverflow.com/a/4933395)
13+
PYTHON3_EXE := $(shell which python3 2>/dev/null)
14+
ifneq (, $(PYTHON3_EXE))
15+
ifeq (,$(findstring Microsoft/WindowsApps/python3,$(subst \,/,$(PYTHON3_EXE))))
16+
PYTHON := python3
17+
endif
18+
endif
19+
20+
ifeq (,$(PYTHON))
21+
PYTHON_EXE := $(shell which python 2>/dev/null)
22+
ifneq (, $(PYTHON_EXE))
23+
PYTHON_VERSION_FULL := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
24+
PYTHON_VERSION_MAJOR := $(word 1,${PYTHON_VERSION_FULL})
25+
ifneq (3, ${PYTHON_VERSION_MAJOR})
26+
$(error "Your system does not appear to have Python 3 installed.")
27+
endif
28+
PYTHON := python
29+
else
30+
$(error "Your system does not appear to have any Python installed.")
31+
endif
32+
endif
33+
34+
1135
# Controls
1236
.PHONY : commands clean files
1337
.NOTPARALLEL:
1438
all : commands
1539

1640
## commands : show all commands.
1741
commands :
18-
@grep -h -E '^##' ${MAKEFILES} | sed -e 's/## //g'
42+
@grep -h -E '^##' ${MAKEFILES} | sed -e "s/## //g"
1943

2044
## docker-serve : use docker to build the site
2145
docker-serve :
@@ -54,7 +78,7 @@ clean-rmd :
5478

5579
## workshop-check : check workshop homepage.
5680
workshop-check :
57-
@bin/workshop_check.py .
81+
@${PYTHON} bin/workshop_check.py .
5882

5983
## ----------------------------------------
6084
## Commands specific to lesson websites.
@@ -93,15 +117,15 @@ _episodes/%.md: _episodes_rmd/%.Rmd
93117

94118
## lesson-check : validate lesson Markdown.
95119
lesson-check : lesson-fixme
96-
@bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
120+
@${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md
97121

98122
## lesson-check-all : validate lesson Markdown, checking line lengths and trailing whitespace.
99123
lesson-check-all :
100-
@bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
124+
@${PYTHON} bin/lesson_check.py -s . -p ${PARSER} -r _includes/links.md -l -w --permissive
101125

102126
## unittest : run unit tests on checking tools.
103127
unittest :
104-
@bin/test_lesson_check.py
128+
@${PYTHON} bin/test_lesson_check.py
105129

106130
## lesson-files : show expected names of generated files for debugging.
107131
lesson-files :

bin/lesson_check.py

100755100644
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
"""
42
Check lesson files and their contents.
53
"""
@@ -29,19 +27,19 @@
2927
# specially. This list must include all the Markdown files listed in the
3028
# 'bin/initialize' script.
3129
REQUIRED_FILES = {
32-
'%/CODE_OF_CONDUCT.md': True,
33-
'%/CONTRIBUTING.md': False,
34-
'%/LICENSE.md': True,
35-
'%/README.md': False,
36-
'%/_extras/discuss.md': True,
37-
'%/_extras/guide.md': True,
38-
'%/index.md': True,
39-
'%/reference.md': True,
40-
'%/setup.md': True,
30+
'CODE_OF_CONDUCT.md': True,
31+
'CONTRIBUTING.md': False,
32+
'LICENSE.md': True,
33+
'README.md': False,
34+
os.path.join('_extras', 'discuss.md'): True,
35+
os.path.join('_extras', 'guide.md'): True,
36+
'index.md': True,
37+
'reference.md': True,
38+
'setup.md': True,
4139
}
4240

4341
# Episode filename pattern.
44-
P_EPISODE_FILENAME = re.compile(r'/_episodes/(\d\d)-[-\w]+.md$')
42+
P_EPISODE_FILENAME = re.compile(r'(\d\d)-[-\w]+.md$')
4543

4644
# Pattern to match lines ending with whitespace.
4745
P_TRAILING_WHITESPACE = re.compile(r'\s+$')
@@ -272,7 +270,7 @@ def check_fileset(source_dir, reporter, filenames_present):
272270
"""Are all required files present? Are extraneous files present?"""
273271

274272
# Check files with predictable names.
275-
required = [p.replace('%', source_dir) for p in REQUIRED_FILES]
273+
required = [os.path.join(source_dir, p) for p in REQUIRED_FILES]
276274
missing = set(required) - set(filenames_present)
277275
for m in missing:
278276
reporter.add(None, 'Missing required file {0}', m)
@@ -282,7 +280,10 @@ def check_fileset(source_dir, reporter, filenames_present):
282280
for filename in filenames_present:
283281
if '_episodes' not in filename:
284282
continue
285-
m = P_EPISODE_FILENAME.search(filename)
283+
284+
# split path to check episode name
285+
base_name = os.path.basename(filename)
286+
m = P_EPISODE_FILENAME.search(base_name)
286287
if m and m.group(1):
287288
seen.append(m.group(1))
288289
else:
@@ -556,7 +557,7 @@ def __init__(self, args, filename, metadata, metadata_len, text, lines, doc):
556557
(re.compile(r'README\.md'), CheckNonJekyll),
557558
(re.compile(r'index\.md'), CheckIndex),
558559
(re.compile(r'reference\.md'), CheckReference),
559-
(re.compile(r'_episodes/.*\.md'), CheckEpisode),
560+
(re.compile(os.path.join('_episodes', '*\.md')), CheckEpisode),
560561
(re.compile(r'.*\.md'), CheckGeneric)
561562
]
562563

bin/lesson_initialize.py

100755100644
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
"""Initialize a newly-created repository."""
42

53

@@ -14,11 +12,11 @@
1412
'CONTRIBUTING.md',
1513
'README.md',
1614
'_config.yml',
17-
'_episodes/01-introduction.md',
18-
'_extras/about.md',
19-
'_extras/discuss.md',
20-
'_extras/figures.md',
21-
'_extras/guide.md',
15+
os.path.join('_episodes', '01-introduction.md'),
16+
os.path.join('_extras', 'about.md'),
17+
os.path.join('_extras', 'discuss.md'),
18+
os.path.join('_extras', 'figures.md'),
19+
os.path.join('_extras', 'guide.md'),
2220
'index.md',
2321
'reference.md',
2422
'setup.md',
@@ -41,7 +39,7 @@ def main():
4139
# Create.
4240
for path in BOILERPLATE:
4341
shutil.copyfile(
44-
"bin/boilerplate/{}".format(path),
42+
os.path.join('bin', 'boilerplate', path),
4543
path
4644
)
4745

bin/repo_check.py

100755100644
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
"""
42
Check repository settings.
53
"""
@@ -104,7 +102,7 @@ def get_repo_url(repo_url):
104102
# Guess.
105103
cmd = 'git remote -v'
106104
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
107-
close_fds=True, universal_newlines=True)
105+
close_fds=True, universal_newlines=True, encoding='utf-8')
108106
stdout_data, stderr_data = p.communicate()
109107
stdout_data = stdout_data.split('\n')
110108
matches = [P_GIT_REMOTE.match(line) for line in stdout_data]

bin/test_lesson_check.py

100755100644
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
import unittest
42

53
import lesson_check
@@ -12,10 +10,8 @@ def setUp(self):
1210

1311
def test_file_list_has_expected_entries(self):
1412
# For first pass, simply assume that all required files are present
15-
all_filenames = [filename.replace('%', '')
16-
for filename in lesson_check.REQUIRED_FILES]
1713

18-
lesson_check.check_fileset('', self.reporter, all_filenames)
14+
lesson_check.check_fileset('', self.reporter, lesson_check.REQUIRED_FILES)
1915
self.assertEqual(len(self.reporter.messages), 0)
2016

2117

bin/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def read_markdown(parser, path):
117117
# Parse Markdown.
118118
cmd = 'ruby {0}'.format(parser)
119119
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
120-
close_fds=True, universal_newlines=True)
120+
close_fds=True, universal_newlines=True, encoding='utf-8')
121121
stdout_data, stderr_data = p.communicate(body)
122122
doc = json.loads(stdout_data)
123123

bin/workshop_check.py

100755100644
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
'''Check that a workshop's index.html metadata is valid. See the
42
docstrings on the checking functions for a summary of the checks.
53
'''

0 commit comments

Comments
 (0)