def module_path(self): git_root = git_repo_root() if self.is_library: return os.path.join(git_root, 'python_modules', 'libraries', self.name) else: return os.path.join(git_root, 'python_modules', self.name)
def check_for_cruft(self, autoclean): '''We need to ensure directories don't have spurious files in them before publishing to PyPI. Args: autoclean (bool): Should the script automatically clean up (remove) extraneous files? Raises: Exception: Raised when we aren't able to resolve cruft issues ''' found_cruft = list( itertools.chain.from_iterable(module.find_cruft() for module in self.all_modules)) if found_cruft: if autoclean: wipeout = '!' else: wipeout = input( 'Found potentially crufty directories:\n' ' {found_cruft}\n' '***We strongly recommend releasing from a fresh git clone!***\n' 'Automatically remove these directories and continue? (N/!)' .format(found_cruft='\n '.join(found_cruft))) if wipeout == '!': for cruft_dir in found_cruft: subprocess.check_output(['rm', '-rfv', cruft_dir]) else: raise Exception( 'Bailing: Cowardly refusing to publish with potentially crufty directories ' 'present! We strongly recommend releasing from a fresh git clone.' ) found_pyc_files = [] for root, dir_, files in os.walk(git_repo_root()): for file_ in files: if file_.endswith('.pyc'): found_pyc_files.append(os.path.join(root, file_)) if found_pyc_files: if autoclean: wipeout = '!' else: wipeout = input( 'Found {n_files} .pyc files.\n' 'We strongly recommend releasing from a fresh git clone!\n' 'Automatically remove these files and continue? (N/!)'. format(n_files=len(found_pyc_files))) if wipeout == '!': for file_ in found_pyc_files: os.unlink(file_) else: raise Exception( 'Bailing: Cowardly refusing to publish with .pyc files present! ' 'We strongly recommend releasing from a fresh git clone.')
def get_core_module_directories(): '''List core module directories (not including libraries) under python_modules. Returns: List(os.DirEntry): List of core module directories ''' core_module_root_dir = os.path.join(git_repo_root(), 'python_modules') module_directories = [ dir_ for dir_ in os.scandir(core_module_root_dir) if dir_.is_dir() and not dir_.name.startswith('.') ] return module_directories
def get_library_module_directories(): '''List library module directories under python_modules/libraries. Returns: List(os.DirEntry): List of core module directories ''' library_module_root_dir = os.path.join(git_repo_root(), 'python_modules', 'libraries') library_directories = [ dir_ for dir_ in os.scandir(library_module_root_dir) if dir_.is_dir() and not dir_.name.startswith('.') ] return library_directories