Fix `pip install tutor-openedx`

Installing from pip was broken because, for some reason, the
templates/apps/xqueue/settings/ folder contained a __pycache__ folder
with compiled *.pyc files. Rendering the binary files was failing
miserably.
This commit is contained in:
Régis Behmo 2019-03-29 06:24:59 -07:00
parent e2b0f3bfde
commit a034f95f83
2 changed files with 23 additions and 10 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## Latest
- [Bugfix] Fix `pip install tutor-openedx`
## v3.3.3 (2019-03-27)
- [Bugfix] Fix login from localhost

View File

@ -28,10 +28,9 @@ def render_target(root, config, target):
hierarchy at `root`.
"""
for src, dst in walk_templates(root, target):
if is_part_of_env(src):
rendered = render_file(config, src)
with open(dst, "w") as of:
of.write(rendered)
rendered = render_file(config, src)
with open(dst, "w") as of:
of.write(rendered)
def render_file(config, path):
with codecs.open(path, encoding='utf-8') as fi:
@ -40,6 +39,9 @@ def render_file(config, path):
except jinja2.exceptions.TemplateError:
print("Error rendering template", path)
raise
except Exception:
print("Unknown error rendering template", path)
raise
def render_dict(config):
"""
@ -84,11 +86,7 @@ def copy_target(root, target):
at `root`.
"""
for src, dst in walk_templates(root, target):
if is_part_of_env(src):
shutil.copy(src, dst)
def is_part_of_env(path):
return not os.path.basename(path).startswith(".")
shutil.copy(src, dst)
def is_up_to_date(root):
return version(root) == __version__
@ -120,6 +118,8 @@ def walk_templates(root, target):
"""
target_root = template_path(target)
for dirpath, _, filenames in os.walk(target_root):
if not is_part_of_env(dirpath):
continue
dst_dir = pathjoin(
root, target,
os.path.relpath(dirpath, target_root)
@ -129,7 +129,16 @@ def walk_templates(root, target):
for filename in filenames:
src = os.path.join(dirpath, filename)
dst = os.path.join(dst_dir, filename)
yield src, dst
if is_part_of_env(src):
yield src, dst
def is_part_of_env(path):
basename = os.path.basename(path)
return not (
basename.startswith(".") or
basename.endswith(".pyc") or
basename == "__pycache__"
)
def template_path(*path):
return os.path.join(TEMPLATES_ROOT, *path)