Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* * @cmccandless @BethanyG
* @cmccandless @bethanyg
.github/CODEOWNERS @exercism/maintainers-admin
26 changes: 25 additions & 1 deletion representer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""
Representer for Python.
"""
import json
from typing import Dict


from . import utils
from .normalizer import Normalizer

Expand Down Expand Up @@ -55,11 +57,33 @@ def represent(slug: utils.Slug, input: utils.Directory, output: utils.Directory)
"""
Normalize the `directory/slug.py` file representation.
"""
src = input.joinpath(slug.replace("-", "_") + ".py")

# get exercise name from config file or compose it from the passed-in slug
config_file = input.joinpath(".meta").joinpath("config.json")
src = None

if config_file.is_file():
editor_config = json.loads(config_file.read_text())\
.get("editor", {})\
.get("solution_files", [])

if editor_config:
src = input.joinpath(editor_config[0])
else:
raise FileNotFoundError("No exercise file was found in config.json.")

else:
src = f'{input.joinpath(slug.replace("-", "_"))}.py'

if not src.is_file():
print('No exercise file was found in the input directory.', err)
return

out_dst = output.joinpath("representation.out")
txt_dst = output.joinpath("representation.txt")
map_dst = output.joinpath("mapping.json")


# parse the tree from the file contents
representation = Representer(src.read_text())

Expand Down