Skip to content

Commit

Permalink
Fix for Issue 18: Output Arguments not used (#19)
Browse files Browse the repository at this point in the history
* Added Bethany and Corey as codeowners for repo.

* Update .github/CODEOWNERS

* Update .github/CODEOWNERS

* Update .github/CODEOWNERS

* Added third output directory argument to run script.

* Added out_path param to dump method.

* Added in_path and out_path as cls vars, params to cls factory method, and in the return for the analyze method and the cls factory method.

* Altered two-fer analyzer analyze method to take an in_path and an out_path.  Modified the dump statements to take and output_file created from the out_path parameter.
  • Loading branch information
BethanyG authored Dec 24, 2020
1 parent da0a2f6 commit 648bf35
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Usage:
# ./bin/run.sh two_fer ~/test/
export PYTHONPATH=/opt/analyzer/lib/$1/
python bin/run.py $1 $2
python bin/run.py $1 $2 $3
4 changes: 2 additions & 2 deletions lib/common/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def refer_to_mentor(cls, comment, pylint_comment=None, approvable=False):
Status.REFER_TO_MENTOR, comment, pylint_comment or [], approvable=approvable
)

def dump(self, path: Path):
def dump(self, out_path: Path):
"""
Dump's the current state to analysis.json.
As a convenience returns the Anaylsis itself.
"""
with open(path, "w") as dst:
with open(out_path, "w") as dst:
json.dump(self, dst, indent=4, cls=AnalysisEncoder)
return self
14 changes: 8 additions & 6 deletions lib/common/exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Exercise(NamedTuple):
"""

name: str
path: Path
in_path: Path
out_path: Path
tests_path: Path

@property
Expand Down Expand Up @@ -53,7 +54,7 @@ def analyze(self):
"""
Perform automatic analysis on this Exercise.
"""
return self.analyzer.analyze(self.path)
return self.analyzer.analyze(self.in_path, self.out_path)

@staticmethod
def sanitize_name(name: str) -> str:
Expand All @@ -70,14 +71,15 @@ def available_analyzers(cls):
return ANALYZERS

@classmethod
def factory(cls, name: str, directory: Path) -> "Exercise":
def factory(cls, name: str, in_directory: Path, out_directory: Path) -> "Exercise":
"""
Build an Exercise from its name and the directory where its files exist.
"""
if name not in cls.available_analyzers():
path = LIBRARY.joinpath(name, "analyzer.py")
raise ExerciseError(f"No analyzer discovered at {path}")
sanitized = cls.sanitize_name(name)
path = directory.joinpath(f"{sanitized}.py").resolve()
tests_path = directory.joinpath(f"{sanitized}_test.py").resolve()
return cls(name, path, tests_path)
in_path = in_directory.joinpath(f"{sanitized}.py").resolve()
out_path = out_directory.joinpath(f"{sanitized}.py").resolve()
tests_path = in_directory.joinpath(f"{sanitized}_test.py").resolve()
return cls(name, in_path, out_path, tests_path)
8 changes: 4 additions & 4 deletions lib/two-fer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Comments(BaseComments):
PERCENT_FORMATTING = ("two-fer", "percent_formatting")


def analyze(path: Path):
def analyze(in_path: Path, out_path: Path):
"""
Analyze the user's Two Fer solution to give feedback and disapprove malformed solutions. Outputs a JSON that
conforms to Exercism's Auto-Mentor project interface.
Expand All @@ -30,11 +30,11 @@ def analyze(path: Path):
and a 'status' string corresponding to the value of the status key in the generated JSON, as its fourth
entry.
"""
output_file = path.parent.joinpath("analysis.json")
output_file = out_path.parent.joinpath("analysis.json")

# Input file
try:
user_solution = path.read_text()
user_solution = in_path.read_text()
except OSError as err:
# If the proper file cannot be found, disapprove this solution
return Analysis.disapprove([Comments.NO_MODULE]).dump(output_file)
Expand Down Expand Up @@ -130,7 +130,7 @@ def analyze(path: Path):
approvable = False

# Use Pylint to generate comments for code, e.g. if code follows PEP8 Style Convention
pylint_stdout, _ = lint.py_run(str(path), return_std=True)
pylint_stdout, _ = lint.py_run(str(in_path), return_std=True)
pylint_comments = [pylint_stdout.getvalue()]

# Handle a known optimal solution
Expand Down

0 comments on commit 648bf35

Please sign in to comment.