我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用main.main()。
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) pagedown.init_app(app) login_manager.init_app(app) if not app.debug and not app.testing and not app.config['SSL_DISABLE']: from flask.ext.sslify import SSLify sslify = SSLify(app) from main import main as main_blueprint app.register_blueprint(main_blueprint) from auth import auth as auth_blueprint app.register_blueprint(auth_blueprint,url_prefix='/auth') db.init_app(app) return app
def run(title, base_batch_size, base_labeled_batch_size, base_lr, n_labels, data_seed, **kwargs): LOG.info('run title: %s', title) ngpu = torch.cuda.device_count() adapted_args = { 'batch_size': base_batch_size * ngpu, 'labeled_batch_size': base_labeled_batch_size * ngpu, 'lr': base_lr * ngpu, 'labels': 'data-local/labels/cifar10/{}_balanced_labels/{:02d}.txt'.format(n_labels, data_seed), } context = RunContext(__file__, "{}_{}".format(n_labels, data_seed)) main.args = parse_dict_args(**adapted_args, **kwargs) main.main(context)
def run(title, base_batch_size, base_labeled_batch_size, base_lr, data_seed, **kwargs): LOG.info('run title: %s', title) ngpu = torch.cuda.device_count() adapted_args = { 'batch_size': base_batch_size * ngpu, 'labeled_batch_size': base_labeled_batch_size * ngpu, 'lr': base_lr * ngpu, 'labels': 'data-local/labels/ilsvrc2012/128000_balanced_labels/{:02d}.txt'.format(data_seed), } context = RunContext(__file__, data_seed) main.args = parse_dict_args(**adapted_args, **kwargs) main.main(context)
def run_all(): main.main(is_interactive=False, k_opt=32, des_opt=constants.ORB_FEAT_OPTION, svm_kernel=cv2.SVM_RBF)
def test_batch_empty(): for batch_size in range(1, 10): assert len( list(main.batch([], batch_size=batch_size))) == 0
def test_batch_single(): for batch_size in range(1, 10): batched = tuple(main.batch([1], batch_size=batch_size)) assert batched == ((1,),)
def test_single_image_returns_text(cloud_config): vision_api_client = main.VisionApi() image_path = _TEST_IMAGE_URI.format(cloud_config.storage_bucket) texts = vision_api_client.detect_text([image_path]) assert image_path in texts _, document = main.extract_description(texts[image_path]) assert "daughter" in document assert "Bennet" in document assert "hat" in document
def test_single_nonimage_returns_error(): vision_api_client = main.VisionApi() texts = vision_api_client.detect_text(['README.md']) assert "README.md" not in texts
def test_text_returns_entities(): text = "Holmes and Watson walked to the cafe." text_analyzer = main.TextAnalyzer() entities = text_analyzer.nl_detect(text) assert entities etype, ename, salience, wurl = text_analyzer.extract_entity_info( entities[0]) assert ename == 'holmes' assert wurl == 'http://en.wikipedia.org/wiki/Sherlock_Holmes'
def test_main(remote_resource, tmpdir, capsys): images_path = str(tmpdir.mkdir('images')) # First, pull down some test data zip_path = remote_resource('language/ocr_nl-images-small.zip', tmpdir) # Extract it to the image directory with zipfile.ZipFile(zip_path) as zfile: zfile.extractall(images_path) main.main(images_path, str(tmpdir.join('ocr_nl.db'))) stdout, _ = capsys.readouterr() assert re.search(r'google was found with count', stdout)
def test_dependents(): text = "I am eating a delicious banana" analysis = main.analyze_syntax(text) tokens = analysis.get('tokens', []) assert [0, 1, 5] == main.dependents(tokens, 2) assert [3, 4] == main.dependents(tokens, 5)
def test_phrase_text_for_head(): text = "A small collection of words" analysis = main.analyze_syntax(text) tokens = analysis.get('tokens', []) assert "words" == main.phrase_text_for_head(tokens, text, 4)
def test_find_triples(): text = "President Obama won the noble prize" analysis = main.analyze_syntax(text) tokens = analysis.get('tokens', []) triples = main.find_triples(tokens) for triple in triples: assert (1, 2, 5) == triple
def test_obama_example(resource, capsys): main.main(resource('obama_wikipedia.txt')) stdout, _ = capsys.readouterr() lines = stdout.split('\n') assert re.match( r'.*Obama\b.*\| received\b.*\| national attention\b', lines[1])
def create_app(config_name=None,main=True) : if config_name is None : config_name = 'default' app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) db.init_app(app) moment.init_app(app) login_manager.init_app(app) from .api_1_0 import api app.register_blueprint(api ,url_prefix='/api/v1.0') return app
def create_app(config_name='default'): app = Flask(__name__) app.config.from_object(config[config_name]) db.init_app(app) bootstrap.init_app(app) login_manager.init_app(app) pagedown.init_app(app) # babel.init_app(app) Gravatar(app, size=64) from auth import auth as auth_blueprint from main import main as main_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') app.register_blueprint(main_blueprint, static_folder='static') @app.template_test('current_link') def is_current_link(link): return link == request.path # @babel.localeselector # def get_locale(): # return current_user.locale return app # @app.route('/upload', methods=['GET', 'POST']) # def upload(): # if request.method == 'POST': # f = request.files['file'] # basepath = path.abspath(path.dirname(__file__)) # upload_path = path.join(basepath, 'static/uploads') # f.save(upload_path + '/' + secure_filename(f.filename)) # return redirect(url_for('upload')) # return render_template('upload.html')
def prepare_grid_benchmark(input_grid, nb_executions): for i in range(nb_executions): process = Process(target=algorithm.main, args=(False,), kwargs={'old_pop':False, 'timer':None, 'nloop':config.NGEN, 'timed':False, 'input_grid':input_grid}) processes_pool.append((process, input_grid))
def main(args): print "nb_parallel_executions", args.nb_parallel_executions print "nb_executions_per_grid_size", args.nb_executions_per_grid_size prepare_grid_benchmark("test_4pieces.txt", args.nb_executions_per_grid_size) # our algorithm currently does not solve 3x3 puzzle prepare_grid_benchmark("test_9pieces.txt", args.nb_executions_per_grid_size) # prepare_grid_benchmark("test_16pieces.txt", args.nb_executions_per_grid_size) print "\nlaunching benchmark..." launch_benchmark(args.nb_parallel_executions) print "\ncomputing stats from benchmark records..." compute_stats_from_records()
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) db.init_app(app) login_manager.init_app(app) pagedown.init_app(app) assets.init_app(app) if config_name == "testing": assets._named_bundles = {} # quick fix for flask testng and flask assets js = Bundle('js/index.js',filters='jsmin', output='gen/packed.js') assets.register('js_all', js) css = Bundle('css/index.css',filters='cssmin',output='css/min.css') assets.register('css_all', css) from main import main as main_blueprint app.register_blueprint(main_blueprint) from auth import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') from admin import admin as admin_blueprint app.register_blueprint(admin_blueprint, url_prefix='/admin') from api_1_0 import api as api_1_0_blueprint app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0') return app
def create_app(config_name): app = Flask(__name__, instance_relative_config=1) app.config.from_object(config_name) app.config.from_pyfile("config.py") from model import db db.init_app(app) from utilities import cache cache.init_app(app) from admin import admin admin.init_app(app) from security import security security.init_app(app) from main import main as main_blueprint app.register_blueprint(main_blueprint) return app
def main(): #figure out our directories global DATADIR, CODEDIR # first try to get the path from the solarwolf package. try: import solarwolf if type(solarwolf.__path__) == list: localpath = os.path.abspath(solarwolf.__path__[0]) else: localpath = os.path.abspath(solarwolf.__path__._path[0]) except ImportError: localpath = os.path.split(os.path.abspath(sys.argv[0]))[0] testdata = localpath testcode = os.path.join(localpath, '.') if os.path.isdir(os.path.join(testdata, 'data')): DATADIR = testdata if os.path.isdir(testcode): CODEDIR = testcode #apply our directories and test environment os.chdir(DATADIR) sys.path.insert(0, CODEDIR) checkdependencies() #install pychecker if debugging try: import game if game.DEBUG >= 2: import pychecker.checker print('Pychecker Enabled') except ImportError: pass #run game and protect from exceptions try: import main, pygame main.main(sys.argv) except KeyboardInterrupt: print('Keyboard Interrupt (Control-C)...') except: #must wait on any threading if game.thread: game.threadstop = 1 while game.thread: pygame.time.wait(10) print('waiting on thread...') exception_handler() if game.DEBUG: raise