Exemplo n.º 1
0
 def test_get_simpleDesc_from_template(self):
     """Test Getting the MANIFEST.in file from templates subdirectory"""
     D = {'simpleDesc_rst':'123', 'longDesc':'abcdefghijklmnop', 
           'projName_lower':'myproject', 'github_user_name':'github_user_name',
           'projName':'MyProject'  }
     s = get_file_template( template_dir, 'README.rst', D)
     
     self.assertTrue( s.find('abcdefghijklmnop') >= 0 )
Exemplo n.º 2
0
 def place_template_file(dest_dir, fname):
     """Get template string from template subdirectory, render template
        and save to dest_dir
     """
     s = get_file_template(TEMPLATE_DIR, fname, dataD)
     create_file(dest_dir, fname, contents=s)
Exemplo n.º 3
0
    def save_project_below_this_dir(self, save_dir):
        '''Creates file layout of project'''

        # print warning and exit if proj_license is not recognized
        if self.proj_license not in CLASSIFIER_D:
            self.print_proj_license_error()
            return

        # print warning and exit if status is not recognized
        if self.status not in DEV_STATUS_OPTIONS:
            self.print_proj_status_error()
            return

        print('save_dir =', save_dir)
        print('os.path.abspath( save_dir )=', os.path.abspath(save_dir))

        save_dir = os.path.abspath(save_dir)
        print('save_dir =', save_dir)

        projDir = os.path.join(save_dir, self.projName)
        print('projDir=', projDir)

        codeDir = os.path.join(projDir, self.projName.lower())
        print('codeDir=', codeDir)

        testDir = os.path.join(projDir, self.projName.lower(), 'tests')
        print('testDir=', testDir)

        docsDir = os.path.join(projDir, 'docs')
        print('docsDir=', docsDir)

        examplesDir = os.path.join(projDir, self.projName.lower(), 'examples')
        print('examplesDir=', examplesDir)

        docsStaticDir = os.path.join(docsDir, '_static')
        print('docsStaticDir=', docsStaticDir)

        docsTemplateDir = os.path.join(docsDir, '_templates')
        print('docsTemplateDir=', docsTemplateDir)
        print()

        if os.path.isdir(projDir):
            print('ERROR... %s already exists' % projDir)
            return 'Dir Already Exists'
        else:

            # Update CONFIG file with current personal info
            for gen_id in generalIdL:
                if getattr(self, gen_id, ''):  # if has a value
                    CONFIG.set('generalId', gen_id, getattr(self, gen_id))

            try:
                with open(USER_DATA_CFG_FNAME, 'w') as config_file:
                    CONFIG.write(config_file)
            except:
                pass

            # get dataD dictionary to build file contents strings
            dataD = {}
            for gen_id in generalIdL:
                dataD[gen_id] = getattr(self, gen_id, '')
            for pid in projectInfoL:
                dataD[pid] = getattr(self, pid, '')

            # build specialty dictionary entries
            dataD['projName_lower'] = self.projName.lower()
            dataD['projName'] = self.projName
            dataD['projName_rst'] = self.projName + '\n' + '=' * len(
                self.projName)

            s = self.projName + " Code Functions"
            dataD['projCode_rst'] = s + '\n' + '=' * len(s)

            s = self.projName + " Code Functions"
            dataD['projCode_rst'] = s + '\n' + '=' * len(s)

            s = "Install " + self.projName
            dataD['install_projName_rst'] = s + '\n' + '-' * len(s)
            s = "Running " + self.projName
            dataD['running_projName_rst'] = s + '\n' + '-' * len(s)

            dataD['version'] = self.version
            dataD['author'] = self.author
            dataD['github_user_name'] = self.github_user_name
            dataD['email'] = self.email
            dataD['proj_license'] = self.proj_license
            dataD['status'] = self.status

            dataD['simpleDesc'] = self.simpleDesc
            dataD['simpleDesc_rst'] = self.simpleDesc.title(
            ) + '\n' + '=' * len(self.simpleDesc)

            dataD['longDesc'] = self.longDesc
            dataD['year'] = self.year
            dataD['date_str'] = self.date_str
            dataD['organization'] = self.organization

            if self.proj_license in CLASSIFIER_D:
                dataD['license_classifier'] = CLASSIFIER_D[self.proj_license]
            else:
                dataD['license_classifier'] = 'License :: OSI Approved'

            if self.proj_license in HEADER_D:
                dataD['license_header'] = HEADER_D[self.proj_license] % dataD
            else:
                dataD['license_header'] = ('%(projName)s\nCopyright (C)'+\
                      ' %(year)s  %(organization)s with license:%(proj_license)s') % dataD
            dataD['license_header'] = dataD[
                'license_header'] + '\n-----------------------\n'

            if self.mainPyFileName.endswith('.py'):
                dataD['mainPyFilePrefix'] = self.mainPyFileName[:-3]
            else:
                dataD['mainPyFilePrefix'] = self.mainPyFileName

            dataD['mainPyFileName'] = dataD['mainPyFilePrefix'] + '.py'

            if self.mainDefinesClass == 'Y':
                dataD['func_or_class_name'] = self.mainClassName
                code_contents_str = get_file_template(TEMPLATE_DIR,
                                                      'Module_Class.py', dataD)

                # change Class_Test_File.py to Class_Te_st_File.py so nosetests won't find it
                test_contents_str = get_file_template(TEMPLATE_DIR,
                                                      'Class_Te_st_File.py',
                                                      dataD)
                dataD['example_call'] = 'my_class = ' + dataD[
                    'mainClassName'] + '()'
            else:
                dataD['func_or_class_name'] = self.mainFunctionName
                code_contents_str = get_file_template(TEMPLATE_DIR,
                                                      'Module_Function.py',
                                                      dataD)

                # change Function_Test_File.py to Function_Te_st_File.py so nosetests won't find it
                test_contents_str = get_file_template(
                    TEMPLATE_DIR, 'Function_Te_st_File.py', dataD)
                dataD['example_call'] = 'my_result = ' + dataD[
                    'mainFunctionName'] + '()'

            def make_directory(dirName):
                """Use os.mkdir to make directory.
                   If in test mode, only print test message
                """
                if self.in_test_mode:
                    print("TESTING make dir:", dirName)
                else:
                    print("Making dir:", dirName)
                    os.mkdir(dirName)

            # Start making directories
            make_directory(projDir)
            make_directory(codeDir)
            make_directory(testDir)
            make_directory(docsDir)
            make_directory(docsStaticDir)
            make_directory(docsTemplateDir)
            make_directory(examplesDir)

            def create_file(sdir, file_name, contents=''):
                """Create a file called file_name in directory sdir with
                   contents.
                """
                fname = os.path.join(sdir, file_name)
                if self.in_test_mode:
                    print("TESTING make file:", fname)
                    f = StringIO()
                    contents = text(contents)
                else:
                    print("Making file:", fname)
                    f = open(fname, 'w')
                f.write(contents)
                f.close()

                if not self.in_test_mode:
                    # Make sure permissions on file are good for owner
                    st = os.stat(fname)
                    if file_name.endswith('.py'):
                        # read/write/execute by owner
                        os.chmod(fname, st.st_mode | stat.S_IRWXU)
                    else:
                        # read & write by owner
                        os.chmod(fname,
                                 st.st_mode | stat.S_IREAD | stat.S_IWRITE)

            #create_file( codeDir, '__init__.py', contents='')
            create_file(codeDir,
                        self.mainPyFileName,
                        contents=code_contents_str)

            # NOTE: pytest.org advises AGAINST putting __init__.py into the test dir.
            #  comment the following line if you agree.
            create_file(testDir, '__init__.py',
                        contents='')  # allows "setup.py test" to work
            #  ???????????????????????????????????????????????

            create_file(testDir,
                        'test_' + self.mainPyFileName,
                        contents=test_contents_str)

            #print( 'dataD =',dataD )
            def place_template_file(dest_dir, fname):
                """Get template string from template subdirectory, render template
                   and save to dest_dir
                """
                s = get_file_template(TEMPLATE_DIR, fname, dataD)
                create_file(dest_dir, fname, contents=s)

            place_template_file(codeDir, '__init__.py')
            place_template_file(codeDir, '_version.py')

            place_template_file(projDir, 'setup.cfg')
            place_template_file(projDir, 'README.rst')
            place_template_file(projDir, 'HISTORY.rst')
            place_template_file(projDir, 'AUTHORS.rst')
            place_template_file(projDir, 'MANIFEST.in')
            place_template_file(projDir, 'setup.py')
            place_template_file(projDir, 'build_local_git_history.py')
            place_template_file(projDir, 'metadata_reset.py')
            place_template_file(projDir, 'UPLOAD_TO_PyPI.BAT')

            place_template_file(projDir, '.pypirc')
            #place_template_file( projDir, 'tk_nosy.py' )

            if platform.system() == "Windows":
                create_file(projDir,
                            'tox.ini',
                            contents=get_file_template(TEMPLATE_DIR,
                                                       'tox_windows.ini',
                                                       dataD))
            else:
                create_file(projDir,
                            'tox.ini',
                            contents=get_file_template(TEMPLATE_DIR,
                                                       'tox_linux.ini', dataD))

            place_template_file(examplesDir, 'example_1.py')

            # requirements.txt is empty, just a place-holder to edit later
            place_template_file(projDir, 'requirements.txt')

            # If using GitHub, Travis CI can be used to verify code on check-in
            place_template_file(projDir, '.travis.yml')

            # Get license text from LICENSE_D
            create_file(projDir,
                        'LICENSE.txt',
                        contents=LICENSE_D[self.proj_license] % dataD)

            # Make sphinx doc files
            for fname in [
                    'index.rst', 'Makefile', 'fulltoc.py', 'functions.rst',
                    'conf.py', 'sphinxy.py', 'keyboard_hit.py', 'make.bat',
                    'history.rst', 'build_all_html.py', 'authors.rst',
                    'quickstart.rst', 'copyright.rst',
                    'spelling_correct_wordlist.txt', 'spell_check.bat'
            ]:
                s = get_file_template(DOC_TEMPLATE_DIR, fname, dataD)
                create_file(docsDir, fname, contents=s)

            s = get_file_template(DOC_TEMPLATE_DIR, 'generic_logo.svg', dataD)
            create_file(docsStaticDir, 'generic_logo.svg', contents=s)

            #logoName = os.path.join( docsStaticDir, 'PythonSphinxlogo.png' )
            #save_logo_to_file( logoName, in_test_mode=self.in_test_mode )

            return 'Success'

        return 'Hmmm Unusual Return'
Exemplo n.º 4
0
 def place_template_file(dest_dir, fname ):
     """Get template string from template subdirectory, render template
        and save to dest_dir
     """
     s = get_file_template( TEMPLATE_DIR, fname, dataD )
     create_file( dest_dir, fname, contents=s )
Exemplo n.º 5
0
    def save_project_below_this_dir(self, save_dir):
        '''Creates file layout of project'''

        # print warning and exit if proj_license is not recognized
        if self.proj_license not in CLASSIFIER_D:
            self.print_proj_license_error()
            return

        # print warning and exit if status is not recognized
        if self.status not in DEV_STATUS_OPTIONS:
            self.print_proj_status_error()
            return

        print( 'save_dir =',save_dir )
        print( 'os.path.abspath( save_dir )=',os.path.abspath( save_dir ) )

        save_dir =  os.path.abspath( save_dir )
        print( 'save_dir =',save_dir )

        projDir = os.path.join( save_dir, self.projName )
        print( 'projDir=',projDir )

        codeDir = os.path.join( projDir, self.projName.lower() )
        print( 'codeDir=',codeDir )

        testDir = os.path.join( projDir, self.projName.lower(), 'tests' )
        print( 'testDir=',testDir )

        docsDir = os.path.join( projDir, 'docs' )
        print( 'docsDir=',docsDir )

        examplesDir = os.path.join( projDir, self.projName.lower(), 'examples' )
        print( 'examplesDir=',examplesDir )

        docsStaticDir = os.path.join( docsDir, '_static' )
        print( 'docsStaticDir=',docsStaticDir )

        docsTemplateDir = os.path.join( docsDir, '_templates' )
        print( 'docsTemplateDir=',docsTemplateDir )
        print()

        if os.path.isdir( projDir ):
            print( 'ERROR... %s already exists'%projDir )
            return 'Dir Already Exists'
        else:

            # Update CONFIG file with current personal info
            for gen_id in generalIdL:
                if getattr(self, gen_id, ''): # if has a value
                    CONFIG.set('generalId', gen_id, getattr(self, gen_id))

            try:
                with open(USER_DATA_CFG_FNAME, 'w') as config_file:
                    CONFIG.write( config_file )
            except:
                pass


            # get dataD dictionary to build file contents strings
            dataD = {}
            for gen_id in generalIdL:
                dataD[gen_id] = getattr(self, gen_id, '')
            for pid in projectInfoL:
                dataD[pid] = getattr(self, pid, '')

            # build specialty dictionary entries
            dataD['projName_lower'] = self.projName.lower()
            dataD['projName'] = self.projName
            dataD['projName_rst'] = self.projName + '\n' + '='*len(self.projName)

            s = self.projName + " Code Functions"
            dataD['projCode_rst'] = s + '\n' + '='*len(s)

            s = self.projName + " Code Functions"
            dataD['projCode_rst'] = s + '\n' + '='*len(s)

            s = "Install " + self.projName
            dataD['install_projName_rst'] = s + '\n' + '-'*len(s)
            s = "Running " + self.projName
            dataD['running_projName_rst'] = s + '\n' + '-'*len(s)

            dataD['version'] = self.version
            dataD['author'] = self.author
            dataD['github_user_name'] = self.github_user_name
            dataD['email'] = self.email
            dataD['proj_license'] = self.proj_license
            dataD['status'] = self.status

            dataD['simpleDesc'] = self.simpleDesc
            dataD['simpleDesc_rst'] = self.simpleDesc.title() + '\n' + '='*len(self.simpleDesc)

            dataD['longDesc'] = self.longDesc
            dataD['year'] = self.year
            dataD['date_str'] = self.date_str
            dataD['organization'] = self.organization

            if self.proj_license in CLASSIFIER_D:
                dataD['license_classifier'] = CLASSIFIER_D[self.proj_license]
            else:
                dataD['license_classifier'] = 'License :: OSI Approved'


            if self.proj_license in  HEADER_D:
                dataD['license_header'] = HEADER_D[self.proj_license] % dataD
            else:
                dataD['license_header'] = ('%(projName)s\nCopyright (C)'+\
                      ' %(year)s  %(organization)s with license:%(proj_license)s') % dataD
            dataD['license_header'] =  dataD['license_header'] + '\n-----------------------\n'

            if self.mainPyFileName.endswith('.py'):
                dataD['mainPyFilePrefix'] = self.mainPyFileName[:-3]
            else:
                dataD['mainPyFilePrefix'] = self.mainPyFileName

            dataD['mainPyFileName'] = dataD['mainPyFilePrefix'] + '.py'

            if self.mainDefinesClass=='Y':
                dataD['func_or_class_name'] = self.mainClassName
                code_contents_str = get_file_template( TEMPLATE_DIR, 'Module_Class.py', dataD )

                # change Class_Test_File.py to Class_Te_st_File.py so nosetests won't find it
                test_contents_str = get_file_template( TEMPLATE_DIR, 'Class_Te_st_File.py', dataD )
                dataD['example_call'] = 'my_class = ' + dataD['mainClassName'] + '()'
            else:
                dataD['func_or_class_name'] = self.mainFunctionName
                code_contents_str = get_file_template( TEMPLATE_DIR, 'Module_Function.py', dataD )

                # change Function_Test_File.py to Function_Te_st_File.py so nosetests won't find it
                test_contents_str = get_file_template( TEMPLATE_DIR, 'Function_Te_st_File.py', dataD )
                dataD['example_call'] = 'my_result = ' + dataD['mainFunctionName'] + '()'

            def make_directory( dirName ):
                """Use os.mkdir to make directory.
                   If in test mode, only print test message
                """
                if self.in_test_mode:
                    print( "TESTING make dir:", dirName )
                else:
                    print( "Making dir:",dirName )
                    os.mkdir( dirName )

            # Start making directories
            make_directory( projDir )
            make_directory( codeDir )
            make_directory( testDir )
            make_directory( docsDir )
            make_directory( docsStaticDir )
            make_directory( docsTemplateDir )
            make_directory( examplesDir )

            def create_file( sdir, file_name, contents=''):
                """Create a file called file_name in directory sdir with
                   contents.
                """
                fname = os.path.join( sdir, file_name )
                if self.in_test_mode:
                    print( "TESTING make file:", fname )
                    f = StringIO()
                    contents = text(contents)
                else:
                    print( "Making file:", fname )
                    f = open(fname, 'w')
                f.write(contents)
                f.close()

                if not self.in_test_mode:
                    # Make sure permissions on file are good for owner
                    st = os.stat(fname)
                    if file_name.endswith('.py'):
                        # read/write/execute by owner
                        os.chmod(fname, st.st_mode | stat.S_IRWXU)
                    else:
                        # read & write by owner
                        os.chmod(fname, st.st_mode | stat.S_IREAD | stat.S_IWRITE)

            #create_file( codeDir, '__init__.py', contents='')
            create_file( codeDir, self.mainPyFileName, contents=code_contents_str)

            # NOTE: pytest.org advises AGAINST putting __init__.py into the test dir.
            #  comment the following line if you agree.
            create_file( testDir, '__init__.py', contents='') # allows "setup.py test" to work
            #  ???????????????????????????????????????????????

            create_file( testDir, 'test_'+self.mainPyFileName, contents=test_contents_str)

            #print( 'dataD =',dataD )
            def place_template_file(dest_dir, fname ):
                """Get template string from template subdirectory, render template
                   and save to dest_dir
                """
                s = get_file_template( TEMPLATE_DIR, fname, dataD )
                create_file( dest_dir, fname, contents=s )

            place_template_file( codeDir, '__init__.py' )
            place_template_file( codeDir, '_version.py' )

            place_template_file( projDir, 'setup.cfg' )
            place_template_file( projDir, 'README.rst' )
            place_template_file( projDir, 'HISTORY.rst' )
            place_template_file( projDir, 'AUTHORS.rst' )
            place_template_file( projDir, 'MANIFEST.in' )
            place_template_file( projDir, 'setup.py' )
            place_template_file( projDir, 'history_from_github_api.py')
            place_template_file( projDir, 'metadata_reset.py' )

            place_template_file( projDir, '.pypirc' )
            #place_template_file( projDir, 'tk_nosy.py' )

            if platform.system() == "Windows":
                create_file( projDir, 'tox.ini', contents=get_file_template(
                             TEMPLATE_DIR, 'tox_windows.ini', dataD ) )
            else:
                create_file( projDir, 'tox.ini', contents=get_file_template(
                             TEMPLATE_DIR, 'tox_linux.ini', dataD ) )


            place_template_file( examplesDir, 'example_1.py' )

            # requirements.txt is empty, just a place-holder to edit later
            place_template_file( projDir, 'requirements.txt' )

            # If using GitHub, Travis CI can be used to verify code on check-in
            place_template_file( projDir, '.travis.yml' )

            # Get license text from LICENSE_D
            create_file( projDir, 'LICENSE.txt', contents=LICENSE_D[self.proj_license]%dataD )

            # Make sphinx doc files
            for fname in ['index.rst', 'Makefile', 'fulltoc.py', 'functions.rst',
                          'conf.py', 'sphinxy.py', 'keyboard_hit.py', 'make.bat',
                          'history.rst', 'build_all_html.py', 'authors.rst',
                          'quickstart.rst', 'copyright.rst']:
                s = get_file_template( DOC_TEMPLATE_DIR, fname, dataD )
                create_file( docsDir, fname, contents=s )

            
            s = get_file_template( DOC_TEMPLATE_DIR, 'generic_logo.svg', dataD )
            create_file( docsStaticDir, 'generic_logo.svg', contents=s )
            
            
            #logoName = os.path.join( docsStaticDir, 'PythonSphinxlogo.png' )
            #save_logo_to_file( logoName, in_test_mode=self.in_test_mode )

            return 'Success'

        return 'Hmmm Unusual Return'
Exemplo n.º 6
0
 def test_get_manifest_from_template(self):
     """Test Getting the MANIFEST.in file from templates subdirectory"""
     D = {'projName_lower':'myproject'}
     s = get_file_template( template_dir, 'MANIFEST.in', D )
     self.assertTrue( s.find('graft myproject') >= 0 )