Skip to content

Commit

Permalink
Merge pull request #119 from LanceMaverick/upgradebeard
Browse files Browse the repository at this point in the history
Support for old style beards reinstated.
  • Loading branch information
LanceMaverick committed Mar 12, 2017
2 parents 1702e66 + fb81435 commit df39683
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 10 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ def load_beard(beard_name, possible_dirs):
logger.debug("Breaking loop")
break
else:
# Try the old way
logger.warning("Attempting to import {} as an old style beard. Old beards will eventually be deprecated.".format(beard_name))
for beard_path in possible_dirs:
with PythonPathContext(str(beard_path)):
module = importlib.import_module(beard_name)

# TODO make this a much better exception
raise Exception("No beard found!")
if module:
return
else:
raise Exception("No beard found! Looked in: {}. Trying to find: {}".format(possible_dirs, beard_name))

foo = importlib.util.module_from_spec(module_spec)
with PythonPathContext(str(Path(module_spec.origin).parent.parent)):
Expand Down
17 changes: 15 additions & 2 deletions utils/newbeard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
from pathlib import Path
from shutil import copytree

import stringcase

Expand Down Expand Up @@ -60,6 +61,11 @@ def make_setup_beard(dir_, name):
f.write(setup_beard_text)


def copy_existing_old_style_beard(dir_, directory):
pythonpath = str(dir_ / "python/")
copytree(directory, pythonpath)


def make_requirements(dir_, requirements):
requirements_text = "\n".join(requirements)

Expand All @@ -77,6 +83,10 @@ def main():
parser.add_argument(
'-r', '--requirements', default=None,
help="Create requirements file with optional requirements.", nargs="*")
parser.add_argument('-u', '--upgrade',
help="Upgrades an existing beard to a new style beard.",
type=str,
default=None)

parsed = parser.parse_args()

Expand All @@ -89,10 +99,13 @@ def main():
pass

make_readme(parsed.dir, parsed.name)
make_init(parsed.dir, parsed.name)
if parsed.upgrade is None:
make_init(parsed.dir, parsed.name)
else:
copy_existing_old_style_beard(parsed.dir, parsed.upgrade)
make_setup_beard(parsed.dir, parsed.name)
if parsed.requirements is not None:
make_requirements(parsed.dir, parsed.requirements)
make_requirements(parsed.dir, parsed.requirements, parsed.upgrade)


if __name__ == '__main__':
Expand Down

0 comments on commit df39683

Please sign in to comment.