def main(): """ Starts a new Python package instance""" print(colored.green("Enter the name of the package:")) package_name = string_input() # Check for clean_make if os.path.isdir(package_name) and os.path.isfile("{0}/{0}/__init__.py".format(package_name)): print(colored.red("The package already exists, destroy and clean make? (y/n)")) choice = string_input() if choice == 'y': lib.remove_package(package_name) elif choice == 'n': print(colored.red("Please pick a different package name, aborting.")) sys.exit() else: logging.error(" Invalid choice") # Create the initial structure lib.create_package_structure(package_name) # Create starter files lib.create_starter_files(package_name) # Create docs directory lib.create_docs_directory(package_name) # Create tests directory lib.create_tests_package(package_name) print(colored.yellow("Package {} was created successfully.".format(package_name)))
def test_create_readme(self): self.path = 'test_path' self.readpath = join(self.path, "README.rst") os.mkdir(self.path) lib.create_readme(self.path, self.status) # Check if the file was created successfully self.assertTrue(isfile(self.readpath)) lib.remove_package(self.path)
def test_create_readme(self): self.path = 'test_path' self.readpath = '{}/README.rst'.format(self.path) os.mkdir(self.path) lib.create_readme(self.path) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.readpath)) lib.remove_package(self.path)
def test_create_makefile(self): self.path = "{}/testpath".format(os.path.dirname(__file__)) self.makepath = '{}/Makefile'.format(self.path) os.mkdir(self.path) lib.create_makefile(self.path) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.makepath)) lib.remove_package(self.path)
def test_create_requirements(self): self.path = 'test_path' self.reqpath = '{}/requirements.txt'.format(self.path) os.mkdir(self.path) lib.create_requirements(self.path) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.reqpath)) lib.remove_package(self.path)
def test_create_manifest(self): self.path = 'test_path' self.manpath = '{}/MANIFEST.in'.format(self.path) os.mkdir(self.path) lib.create_manifest(self.path) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.manpath)) lib.remove_package(self.path)
def test_create_gitignore(self): self.path = 'test_path' self.gitpath = '{}/.gitignore'.format(self.path) os.mkdir(self.path) lib.create_git_ignore(self.path) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.gitpath)) lib.remove_package(self.path)
def test_create_setup(self): self.path = join(os.path.dirname(__file__), "testpath") self.setuppath = join(self.path, "setup.py") os.mkdir(self.path) lib.create_setup(self.path, self.status, test=True) # Check if the file was created successfully self.assertTrue(isfile(self.setuppath)) lib.remove_package(self.path)
def test_gpl(self): self.path = "{}/testpath".format(os.path.dirname(__file__)) self.licpath = '{}/LICENSE'.format(self.path) os.mkdir(self.path) lib.gpl_lic(self.path) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.licpath)) lib.remove_package(self.path)
def test_create_setup(self): self.path = "{}/testpath".format(os.path.dirname(__file__)) self.setuppath = '{}/setup.py'.format(self.path) os.mkdir(self.path) lib.create_setup(self.path, test=True) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.setuppath)) lib.remove_package(self.path)
def test_create_requirements(self): self.path = 'test_path' self.reqpath = join(self.path, "requirements.txt") os.mkdir(self.path) lib.create_requirements(self.path, self.status) # Check if the file was created successfully self.assertTrue(isfile(self.reqpath)) lib.remove_package(self.path)
def test_create_gitignore(self): self.path = 'test_path' self.gitpath = join(self.path, ".gitignore") os.mkdir(self.path) lib.create_git_ignore(self.path, self.status) # Check if the file was created successfully self.assertTrue(isfile(self.gitpath)) lib.remove_package(self.path)
def test_create_manifest(self): self.path = 'test_path' self.manpath = join(self.path, "MANIFEST.in") os.mkdir(self.path) lib.create_manifest(self.path, self.status) # Check if the file was created successfully self.assertTrue(isfile(self.manpath)) lib.remove_package(self.path)
def test_apa(self): self.path = join(os.path.dirname(__file__), "testpath") self.licpath = join(self.path, "LICENSE") os.mkdir(self.path) lib.apa_lic(self.path, 'testname', 'year', self.status) # Check if the file was created successfully self.assertTrue(isfile(self.licpath)) lib.remove_package(self.path)
def test_apa(self): self.path = "{}/testpath".format(os.path.dirname(__file__)) self.licpath = '{}/LICENSE'.format(self.path) os.mkdir(self.path) lib.apa_lic(self.path, 'testname', 'year', self.status) # Check if the file was created successfully self.assertTrue(os.path.isfile(self.licpath)) lib.remove_package(self.path)
def test_git_init(self): self.path = "{}/testpath".format(os.path.dirname(__file__)) lib.remove_package(self.path) os.mkdir(self.path) status = lib.git_init(self.path, self.status, silent=True) # Check if the repository was created successfully self.assertTrue(status) self.assertTrue(os.path.isdir("{}/.git".format(self.path))) lib.remove_package(self.path)
def test_git_init(self): self.path = join(os.path.dirname(__file__), "testpath") lib.remove_package(self.path) os.mkdir(self.path) status = lib.git_init(self.path, self.status, silent=True) # Check if the repository was created successfully self.assertTrue(status) self.assertTrue(isdir(join(self.path, ".git"))) lib.remove_package(self.path)
def test_venv_init(self): self.path = join(os.path.dirname(__file__), "testpath") lib.remove_package(self.path) os.mkdir(self.path) status = lib.venv_init(self.path, self.status, silent=True) # Check if the virtualenv was created successfully self.assertTrue(status) self.assertTrue(isdir(join(self.path, "testenv"))) lib.remove_package(self.path)
def sphinx_init(self): self.path = "{}/testpath".format(os.path.dirname(__file__)) status = lib.sphinx_init(self.path, "testauthor", "1.0.0", self.status, silent=True) # Check if the sphinx dir was created successfully self.assertTrue(status) self.assertTrue(os.path.isdir("{}/testpath/_build".format(self.path))) self.assertTrue(os.path.isdir("{}/testpath/_static".format(self.path))) self.assertTrue( os.path.isdir("{}/testpath/_templates".format(self.path)) ) lib.remove_package(self.path)
def test_create_tests_package(self): self.test_name = 'sample_tests_pack' self.sub_directory = '{0}/tests'.format(self.test_name) self.initfile = join(self.sub_directory, "__init__.py") self.testlibfile = join(self.sub_directory, "test_lib.py") os.mkdir(self.test_name) lib.create_tests_package(self.test_name, self.status) # Verify creation of directories self.assertTrue(isdir(self.test_name)) self.assertTrue(isdir(self.sub_directory)) # Verify creation of files self.assertTrue(isfile(self.initfile)) self.assertTrue(isfile(self.testlibfile)) lib.remove_package(self.test_name)
def test_create_tests_package(self): self.test_name = 'sample_tests_pack' self.sub_directory = '{0}/tests'.format(self.test_name) self.initfile = '{}/__init__.py'.format(self.sub_directory) self.testlibfile = '{}/test_lib.py'.format(self.sub_directory) os.mkdir(self.test_name) lib.create_tests_package(self.test_name) # Verify creation of directories self.assertTrue(os.path.isdir(self.test_name)) self.assertTrue(os.path.isdir(self.sub_directory)) # Verify creation of files self.assertTrue(os.path.isfile(self.initfile)) self.assertTrue(os.path.isfile(self.testlibfile)) lib.remove_package(self.test_name)
def test_create_package_structure(self): self.test_name = 'sample_package' self.sub_directory = '{0}/{0}'.format(self.test_name) self.initfile = join(self.sub_directory, "__init__.py") self.corefile = join(self.sub_directory, "core.py") self.libfile = join(self.sub_directory, "lib.py") lib.create_package_structure(self.test_name, self.status) # Verify creation of directories self.assertTrue(isdir(self.test_name)) self.assertTrue(isdir(self.sub_directory)) # Verify creation of files self.assertTrue(isfile(self.initfile)) self.assertTrue(isfile(self.corefile)) self.assertTrue(isfile(self.libfile)) # Clean-up the package created lib.remove_package(self.test_name)
def test_create_package_structure(self): self.test_name = 'sample_package' self.sub_directory = '{0}/{0}'.format(self.test_name) self.initfile = '{}/__init__.py'.format(self.sub_directory) self.corefile = '{}/core.py'.format(self.sub_directory) self.libfile = '{}/lib.py'.format(self.sub_directory) lib.create_package_structure(self.test_name) # Verify creation of directories self.assertTrue(os.path.isdir(self.test_name)) self.assertTrue(os.path.isdir(self.sub_directory)) # Verify creation of files self.assertTrue(os.path.isfile(self.initfile)) self.assertTrue(os.path.isfile(self.corefile)) self.assertTrue(os.path.isfile(self.libfile)) # Clean-up the package created lib.remove_package(self.test_name)
def test_create_docs_directory(self): self.test_name = 'sample_directory' self.sub_directory = '{0}/docs'.format(self.test_name) self.conffile = '{}/conf.py'.format(self.sub_directory) self.indexfile = '{}/index.rst'.format(self.sub_directory) self.makefile = '{}/make.bat'.format(self.sub_directory) os.mkdir(self.test_name) lib.create_docs_directory(self.test_name) # Verify creation of directories self.assertTrue(os.path.isdir(self.test_name)) self.assertTrue(os.path.isdir(self.sub_directory)) # Verify creation of files self.assertTrue(os.path.isfile(self.conffile)) self.assertTrue(os.path.isfile(self.indexfile)) self.assertTrue(os.path.isfile(self.makefile)) lib.remove_package(self.test_name)
def test_remove_package(self): self.test_path = 'test_dir' os.mkdir(self.test_path) lib.remove_package(self.test_path) self.assertFalse(isdir(self.test_path))
def main(): """ Entry point for the package, alacrity.exe in win and alacrity in linux :return: None """ # Start the process try: from alacrity import version except ImportError: version = importlib.import_module('version', '../alacrity') # Get version information from version.py v = version.version() parser = argparse.ArgumentParser(description="Alacrity : " "Quickstart your Python " "package from a terminal") parser.add_argument('--make', action='store_true', help="Rebuild " "persistence") parser.add_argument('--debug', action='store_true', help="Display verbose " "debug messages") parser.add_argument('--version', action="version", version=v) parser.add_argument('package_name') args = parser.parse_args() if args.make: lib.rebuild_persistence() if not args.package_name: logging.error(" package_name is a required argument") sys.exit() # Initialize logging depending on debug mode if args.debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.CRITICAL) # Initialise status dictionary status = { 'structure_created': False, 'gitignore_created': False, 'setup_created': False, 'license_created': False, 'manifest_created': False, 'readme_created': False, 'requirements_created': False, 'tests_created': False, 'git_initialized': False, 'venv_created': False, 'sphinx_created': False } try: try: package_name = args.package_name # Check if the package already exists logging.debug("[-] Checking if the package already exists") check_is_file = os.path.isfile( "{0}/{0}/__init__.py".format(package_name)) # Check for clean_make if os.path.isdir(package_name) or check_is_file: logging.debug("[-] Package already exists, " "launching clean make prompt") print(colored.red("[!] A package by that name already exists, " "destroy and clean make? (y/n) : "), end="") choice = input() logging.debug("[-] Choice prompt input : {}".format(choice)) if choice == 'y': logging.debug("[-] Removing existing package") lib.remove_package(package_name) elif choice == 'n': logging.debug("[-] Clean make cancelled") print( colored.red("[!] Please pick a different package " "name, aborting.")) sys.exit() else: logging.error(colored.red(" Invalid choice")) print(colored.red("[!] Invalid choice, aborting")) sys.exit() # Create the initial structure logging.debug("[-] Creating package structure") lib.create_package_structure(package_name, status) # Create starter files logging.debug("[-] Creating starter files in package") author, version = lib.create_starter_files(package_name, status) # Create tests directory logging.debug("[-] Creating tests package in structure") lib.create_tests_package(package_name, status) # Initialize git if required and available logging.debug("[-] Launching git init submodule") lib.git_init(package_name, status) # Initialize venv if required and available logging.debug("[-] Launching venv init submodule") lib.venv_init(package_name, status) # Initialize sphinx docs if required and available logging.debug("[-] Launching sphinx init submodule") lib.sphinx_init(package_name, author, version, status) logging.debug("[-] Launching status reporter submodule") lib.report_status(status) print(colored.green("[|]")) print( colored.green("[*] Package {} was created " "successfully.".format(package_name))) except EOFError: # Catch error thrown by clint.main print(colored.yellow("\n[!] Ctrl+C : Aborting package creation.")) sys.exit() except KeyboardInterrupt: print(colored.yellow("\n[!] Ctrl+C : Aborting package creation.")) # Rollback changes if os.path.isdir(args.package_name): logging.debug("[-] Rolling back committed changes, deleting files") shutil.rmtree(args.package_name) logging.debug("[-] alacrity:ROOT :: quiting") sys.exit()