def to_title(pathlike): """ Read a pathlike as a title. This takes the stem and removes any leading "_". """ stem = PurePath(pathlike).stem return stem[1:] if stem.startswith("_") else stem
def __loadCreatureModules(self): '''Load all the modules in the creatures directory''' # Get all .py files in the creatures directory for creatures_file_name in (Path.cwd() / 'creatures').glob('*.py'): creature_name = PurePath(creatures_file_name).stem # Import each creature (ignoring creature.py) if creature_name != 'creature' and creature_name != 'sun' and not creature_name.startswith( "#"): try: module = importlib.import_module("creatures." + str(creature_name)) self.__modules.append(module) except Exception as e: print("Failed to load module " + creature_name + " " + str(e)) log.logException("Failed to load module " + creature_name)
def __init__(self, project_file): self.files = {} # The sources in this project tree, not including externally built # projects. # Keys: base names, values: full names # Use the Libadalang API to query the sources for this project. # This collects the sources in all the project tree, not including # sources in externally built projects. files = lal.SourceFiles.for_project(project_file) for full_path in files: basename = PurePath(full_path).name # For ad-hoc projects in particular, compilation artifacts # of the form b__* might find themselves in source dirs: # ignore them. if not basename.startswith("b__"): # This could happen in the case of aggregate projects: warn assert ( not basename in self.files ), f"{basename} is present twice in sources - use non-aggregate project" self.files[basename] = str(full_path)