Skip to content

Exercise retrieval updates #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 11, 2020
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