Skip to content

Commit 2dd41ee

Browse files
Exercise retrieval updates (#13)
Co-authored-by: Corey McCandless <[email protected]>
1 parent e670ae4 commit 2dd41ee

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
* * @cmccandless @BethanyG
1+
* @cmccandless @bethanyg
22
.github/CODEOWNERS @exercism/maintainers-admin

representer/__init__.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""
22
Representer for Python.
33
"""
4+
import json
45
from typing import Dict
56

7+
68
from . import utils
79
from .normalizer import Normalizer
810

@@ -55,11 +57,33 @@ def represent(slug: utils.Slug, input: utils.Directory, output: utils.Directory)
5557
"""
5658
Normalize the `directory/slug.py` file representation.
5759
"""
58-
src = input.joinpath(slug.replace("-", "_") + ".py")
60+
61+
# get exercise name from config file or compose it from the passed-in slug
62+
config_file = input.joinpath(".meta").joinpath("config.json")
63+
src = None
64+
65+
if config_file.is_file():
66+
editor_config = json.loads(config_file.read_text())\
67+
.get("editor", {})\
68+
.get("solution_files", [])
69+
70+
if editor_config:
71+
src = input.joinpath(editor_config[0])
72+
else:
73+
raise FileNotFoundError("No exercise file was found in config.json.")
74+
75+
else:
76+
src = f'{input.joinpath(slug.replace("-", "_"))}.py'
77+
78+
if not src.is_file():
79+
print('No exercise file was found in the input directory.', err)
80+
return
81+
5982
out_dst = output.joinpath("representation.out")
6083
txt_dst = output.joinpath("representation.txt")
6184
map_dst = output.joinpath("mapping.json")
6285

86+
6387
# parse the tree from the file contents
6488
representation = Representer(src.read_text())
6589

0 commit comments

Comments
 (0)