def label(classifiers): """Takes a list of classifiers gathered by the project.prompt_classifiers() function and adds them to the setup.py file.""" if os.path.isfile('.pythong'): try: config_data = read_config('.pythong') # TODO: fix dict so I can do config_data.project.classifiers, # so that I can add cool stuff to the config later that is # not about the project? dunno if necessary config_data['classifiers'] = classifiers write_config('.pythong', config_data) print "Modified .pythong config file with new classifiers." if ask_yes_no("Do you want to rebuild your setup.py from your new" " config file? All manual changes will be erased.", default=False): try: write_setup_files(config_data['project_dir']) print "Setup files written." except: print "Problem writing setup files." except OSError: print "Can't open .pythong file in current directory." else: print "No .pythong file in current directory."
def prompt_new_project(name=None, snap=False): """ sampleproject = dict( encoding="utf8", version="0.0.1", shortname="pythong", description="This is a description that has words", classifiers=["thong", "wearing", "pythonistas"], keywords=["more", "thong", "keywords"], author="ryansb", email="*****@*****.**", url="github.com", license="MIT", requires=["nose", "pyramid"] ) """ project = dict() if not name: name = prompt_input("Project name: ") if os.path.isdir(name): print "A project with that name already exists here." if not ask_yes_no("Would you like to convert your existing setup.py " "to use distribute?"): exit(1) project.update(determine_directories(name, os.getcwd(), snap)) # Files project['manifest'] = join(project['project_dir'], "MANIFEST.in") project['setup_file'] = join(project['project_dir'], "setup.py") project['init_file'] = join(project['source_dir'], "__init__.py") if project.get('tests_dir'): project['test_init_file'] = join(project['tests_dir'], "__init__.py") project['test_file'] = join(project['tests_dir'], name + "_tests.py") project['files'] = [project['manifest'], project['setup_file'], project['init_file']] if project.get('tests_dir'): project['files'].extend([project['test_init_file'], project['test_file']]) # Create project skeleton print "Creating structure for new Python project {}.".format( project.get("name")) # Create directories for dirname in project.get("directories", []): try: os.mkdir(dirname) except OSError as e: if e.errno != 17: raise e # Create files for f in project.get("files", []): try: project['init_file'] = open(f, 'w').close() except OSError as e: if e.errno != 17: raise e # Create setup.py file # first, set sane defaults project.update(dict( encoding="utf8", version="0.1.0", shortname=project.get("name", "horsewithnoname"), description="A new project", classifiers=[], keywords=[], author="", email="", url="", license="", requires=[])) if not snap and ask_yes_no("Would you like help creating a setup.py " "file?"): project.update(dict( encoding=prompt_input("Encoding [utf8]: ", default='utf8'), version=prompt_input("Version [0.1.0]: ", default='0.1.0'), shortname=prompt_input("Short name [%s]: " % project.get("name"), default=project.get("name")), description=prompt_input("Description [A new project]: ", default='A new project'), classifiers=prompt_classifiers(), keywords=[x.strip() for x in prompt_input("Keywords (comma delimited): ", default="").split(',')], author=prompt_input("Author: "), email=prompt_input("Author email: "), url=prompt_input("Project URL: "), license=prompt_input("License: "), requires=[x.strip() for x in prompt_input("Requirements (separate with commas): ", default="").split(',')])) if os.path.exists(project['setup_file']) \ and os.path.getsize(project['setup_file']) != 0: os.rename(project['setup_file'], project['setup_file'] + '.old') else: print "Generating skeletal setup files." try: write_config(os.path.join(project['project_dir'], '.pythong'), project) print "Configuration file written." except: print "Problem writing config file." try: write_setup_files(project['project_dir']) print "Setup files written." except: print "Problem writing setup files."
def prompt_new_project(name=None, snap=False): """ sampleproject = dict( encoding="utf8", version="0.0.1", shortname="pythong", description="This is a description that has words", classifiers=["thong", "wearing", "pythonistas"], keywords=["more", "thong", "keywords"], author="ryansb", email="*****@*****.**", url="github.com", license="MIT", requires=["nose", "pyramid"] ) """ project = dict() if not name: name = prompt_input("Project name: ") if os.path.isdir(name): print "A project with that name already exists here." if not ask_yes_no("Would you like to convert your existing setup.py " "to use distribute?"): exit(1) project.update(determine_directories(name, os.getcwd(), snap)) # Files project['manifest'] = join(project['project_dir'], "MANIFEST.in") project['setup_file'] = join(project['project_dir'], "setup.py") project['init_file'] = join(project['source_dir'], "__init__.py") if project.get('tests_dir'): project['test_init_file'] = join(project['tests_dir'], "__init__.py") project['test_file'] = join(project['tests_dir'], name + "_tests.py") project['files'] = [ project['manifest'], project['setup_file'], project['init_file'] ] if project.get('tests_dir'): project['files'].extend( [project['test_init_file'], project['test_file']]) # Create project skeleton print "Creating structure for new Python project {}.".format( project.get("name")) # Create directories for dirname in project.get("directories", []): try: os.mkdir(dirname) except OSError as e: if e.errno != 17: raise e # Create files for f in project.get("files", []): try: project['init_file'] = open(f, 'w').close() except OSError as e: if e.errno != 17: raise e # Create setup.py file # first, set sane defaults project.update( dict(encoding="utf8", version="0.1.0", shortname=project.get("name", "horsewithnoname"), description="A new project", classifiers=[], keywords=[], author="", email="", url="", license="", requires=[])) if not snap and ask_yes_no("Would you like help creating a setup.py " "file?"): project.update( dict(encoding=prompt_input("Encoding [utf8]: ", default='utf8'), version=prompt_input("Version [0.1.0]: ", default='0.1.0'), shortname=prompt_input("Short name [%s]: " % project.get("name"), default=project.get("name")), description=prompt_input("Description [A new project]: ", default='A new project'), classifiers=prompt_classifiers(), keywords=[ x.strip() for x in prompt_input("Keywords (comma delimited): ", default="").split(',') ], author=prompt_input("Author: "), email=prompt_input("Author email: "), url=prompt_input("Project URL: "), license=prompt_input("License: "), requires=[ x.strip() for x in prompt_input("Requirements (separate with commas): ", default="").split(',') ])) if os.path.exists(project['setup_file']) \ and os.path.getsize(project['setup_file']) != 0: os.rename(project['setup_file'], project['setup_file'] + '.old') else: print "Generating skeletal setup files." try: write_config(os.path.join(project['project_dir'], '.pythong'), project) print "Configuration file written." except: print "Problem writing config file." try: write_setup_files(project['project_dir']) print "Setup files written." except: print "Problem writing setup files."