Skip to content

Commit

Permalink
Merge pull request #173 from cs50/develop
Browse files Browse the repository at this point in the history
show progressbar in --local
  • Loading branch information
cmlsharp authored Jul 30, 2019
2 parents 4cae5c4 + 95b799d commit af8af44
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 57 deletions.
111 changes: 56 additions & 55 deletions check50/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,63 +292,64 @@ def main():
excepthook.output_file = args.output_file

if args.local:
# If developing, assume slug is a path to check_dir
if args.dev:
internal.check_dir = Path(SLUG).expanduser().resolve()
if not internal.check_dir.is_dir():
raise internal.Error(_("{} is not a directory").format(internal.check_dir))
else:
# Otherwise have lib50 create a local copy of slug
try:
internal.check_dir = lib50.local(SLUG, offline=args.offline)
except lib50.ConnectionError:
raise internal.Error(_("check50 could not retrieve checks from GitHub. Try running check50 again with --offline.").format(SLUG))
except lib50.InvalidSlugError:
raise_invalid_slug(SLUG, offline=args.offline)

# Load config
config = internal.load_config(internal.check_dir)
# Compile local checks if necessary
if isinstance(config["checks"], dict):
config["checks"] = internal.compile_checks(config["checks"], prompt=args.dev)

install_translations(config["translations"])

if not args.offline:
install_dependencies(config["dependencies"], verbose=args.verbose)

checks_file = (internal.check_dir / config["checks"]).resolve()

# Have lib50 decide which files to include
included = lib50.files(config.get("files"))[0]

# Only open devnull conditionally
ctxmanager = open(os.devnull, "w") if not args.verbose else nullcontext()
with ctxmanager as devnull:
if args.verbose:
stdout = sys.stdout
stderr = sys.stderr
with lib50.ProgressBar("Checking") if not args.verbose and "ansi" in args.output else nullcontext():
# If developing, assume slug is a path to check_dir
if args.dev:
internal.check_dir = Path(SLUG).expanduser().resolve()
if not internal.check_dir.is_dir():
raise internal.Error(_("{} is not a directory").format(internal.check_dir))
else:
stdout = stderr = devnull

# Create a working_area (temp dir) with all included student files named -
with lib50.working_area(included, name='-') as working_area, \
contextlib.redirect_stdout(stdout), \
contextlib.redirect_stderr(stderr):

runner = CheckRunner(checks_file)

# Run checks
if args.target:
check_results = runner.run(args.target, included, working_area)
# Otherwise have lib50 create a local copy of slug
try:
internal.check_dir = lib50.local(SLUG, offline=args.offline)
except lib50.ConnectionError:
raise internal.Error(_("check50 could not retrieve checks from GitHub. Try running check50 again with --offline.").format(SLUG))
except lib50.InvalidSlugError:
raise_invalid_slug(SLUG, offline=args.offline)

# Load config
config = internal.load_config(internal.check_dir)
# Compile local checks if necessary
if isinstance(config["checks"], dict):
config["checks"] = internal.compile_checks(config["checks"], prompt=args.dev)

install_translations(config["translations"])

if not args.offline:
install_dependencies(config["dependencies"], verbose=args.verbose)

checks_file = (internal.check_dir / config["checks"]).resolve()

# Have lib50 decide which files to include
included = lib50.files(config.get("files"))[0]

# Only open devnull conditionally
ctxmanager = open(os.devnull, "w") if not args.verbose else nullcontext()
with ctxmanager as devnull:
if args.verbose:
stdout = sys.stdout
stderr = sys.stderr
else:
check_results = runner.run_all(included, working_area)

results = {
"slug": SLUG,
"results": check_results,
"version": __version__
}
stdout = stderr = devnull

# Create a working_area (temp dir) with all included student files named -
with lib50.working_area(included, name='-') as working_area, \
contextlib.redirect_stdout(stdout), \
contextlib.redirect_stderr(stderr):

runner = CheckRunner(checks_file)

# Run checks
if args.target:
check_results = runner.run(args.target, included, working_area)
else:
check_results = runner.run_all(included, working_area)

results = {
"slug": SLUG,
"results": check_results,
"version": __version__
}

else:
# TODO: Remove this before we ship
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
message_extractors = {
'check50': [('**.py', 'python', None),],
},
install_requires=["attrs>=18", "bs4>=0", "pexpect>=4.6", "lib50>=1.1.5", "pyyaml>=3.10", "requests>=2.19", "termcolor>=1.1", "jinja2>=2.10"],
install_requires=["attrs>=18", "bs4>=0", "pexpect>=4.6", "lib50>=1.1.8", "pyyaml>=3.10", "requests>=2.19", "termcolor>=1.1", "jinja2>=2.10"],
extras_require = {
"develop": ["sphinx", "sphinx_rtd_theme"]
},
Expand All @@ -26,6 +26,6 @@
"console_scripts": ["check50=check50.__main__:main"]
},
url="https://github.com/cs50/check50",
version="3.0.3",
version="3.0.4",
include_package_data=True
)

0 comments on commit af8af44

Please sign in to comment.