Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import textwrap 

2 

3 

4def get_module_view_content(): 

5 content = textwrap.dedent( 

6 """\ 

7 from shopyo.api.module import ModuleHelp 

8 # from flask import render_template 

9 # from flask import url_for 

10 # from flask import redirect 

11 # from flask import flash 

12 # from flask import request 

13 

14 # from shopyo.api.html import notify_success 

15 # from shopyo.api.forms import flash_errors 

16 

17 mhelp = ModuleHelp(__file__, __name__) 

18 globals()[mhelp.blueprint_str] = mhelp.blueprint 

19 module_blueprint = globals()[mhelp.blueprint_str] 

20 

21 

22 @module_blueprint.route("/") 

23 def index(): 

24 return mhelp.info['display_string'] 

25 

26 # If "dashboard": "/dashboard" is set in info.json 

27 # 

28 # @module_blueprint.route("/dashboard", methods=["GET"]) 

29 # def dashboard(): 

30 

31 # context = mhelp.context() 

32 

33 # context.update({ 

34 

35 # }) 

36 # return mhelp.render('dashboard.html', **context) 

37 """ 

38 ) 

39 

40 return content 

41 

42 

43def get_dashboard_html_content(): 

44 content = textwrap.dedent( 

45 """\ 

46 {% extends "base/module_base.html" %} 

47 {% set active_page = info['display_string']+' dashboard' %} 

48 {% block pagehead %} 

49 <title></title> 

50 <style> 

51 </style> 

52 {% endblock %} 

53 {% block sidebar %} 

54 {% include info['module_name']+'/blocks/sidebar.html' %} 

55 {% endblock %} 

56 {% block content %} 

57 <br> 

58 

59 <div class="card"> 

60 <div class="card-body"> 

61 

62 </div> 

63 </div> 

64 {% endblock %} 

65 """ 

66 ) 

67 

68 return content 

69 

70 

71def get_global_py_content(): 

72 content = textwrap.dedent( 

73 """\ 

74 

75 # global templates variables in here 

76 # available_everywhere = { 

77 # 

78 # } 

79 

80 # global configs in here, defined by profile 

81 # configs = { 

82 # "development": { 

83 # "CONFIG_VAR": "DEVVALUE" 

84 # }, 

85 # "production": { 

86 # "CONFIG_VAR": "PRODVALUE" 

87 # }, 

88 # "testing": { 

89 # "CONFIG_VAR": "TESTVALUE" 

90 # } 

91 # } 

92 """ 

93 ) 

94 

95 return content 

96 

97 

98def get_cli_content(projname): 

99 content = textwrap.dedent( 

100 f'''\ 

101 """ 

102 file: cli.py 

103 description: Add your custom cli commands here 

104 documentation: https://click.palletsprojects.com/en/7.x/ 

105 

106 You will need to run ``python -m pip install -e .`` to load the setup.py 

107 which contains the entry point to this file before being able to run your 

108 custom commands 

109 

110 Usage ``{projname} [OPTIONS] COMMAND [ARGS]...`` 

111 

112 Example command 'welcome' has been added. 

113 - To get your project version, run ``{projname} --version`` 

114 - Run the sample command as ``{projname} welcome [OPTIONS] NAME`` 

115 """ 

116 

117 from {projname} import __version__ 

118 import click 

119 

120 

121 @click.group() 

122 @click.version_option(__version__) 

123 @click.pass_context 

124 def cli(ctx): 

125 """CLI entry point""" 

126 pass 

127 

128 

129 @cli.command("welcome") 

130 @click.argument("name") 

131 @click.option('--verbose', "-v", is_flag=True, default=False) 

132 def welcome(name, verbose): 

133 """Sample command to welcome users. 

134 

135 NAME will be printed along with the welcome message 

136 """ 

137 click.secho(f"Hi {{name}}. Welcome to {projname}", fg="cyan") 

138 

139 if verbose: 

140 click.echo("See you soon") 

141 ''' 

142 ) 

143 

144 return content 

145 

146 

147def get_init_content(): 

148 content = textwrap.dedent( 

149 """\ 

150 version_info = (1, 0, 0) 

151 __version__ = ".".join([str(v) for v in version_info]) 

152 """ 

153 ) 

154 

155 return content 

156 

157 

158def get_setup_py_content(projname): 

159 content = textwrap.dedent( 

160 f'''\ 

161 """ 

162 A setuptools based setup module. 

163 See: 

164 https://packaging.python.org/guides/distributing-packages-using-setuptools/ 

165 https://github.com/pypa/sampleproject 

166 

167 python setup.py publish to publish 

168 

169 """ 

170 

171 # Always prefer setuptools over distutils 

172 from setuptools import setup 

173 

174 # from setuptools import find_packages 

175 

176 import os 

177 import sys 

178 from {projname} import __version__ # thanks gunicorn 

179 

180 here = os.path.abspath(os.path.dirname(__file__)) 

181 

182 if sys.argv[-1] == "publish": # requests 

183 os.system("python setup.py sdist") # bdist_wheel 

184 os.system("twine upload dist/* --skip-existing") 

185 sys.exit() 

186 

187 # Get the long description from the README file 

188 with open(os.path.join(here, "README.md"), encoding="utf-8") as f: 

189 long_description = f.read() 

190 setup( 

191 name="{projname}", # Required 

192 version=__version__, # Required 

193 description="", # Optional 

194 long_description=long_description, # Optional 

195 long_description_content_type="text/markdown", # Optional (see note above) 

196 url="", # Optional 

197 author="", # Optional 

198 author_email="", # Optional 

199 # Classifiers help users find your project by categorizing it. 

200 # 

201 # For a list of valid classifiers, see https://pypi.org/classifiers/ 

202 classifiers=[ # Optional 

203 # How mature is this project? Common values are 

204 # 3 - Alpha 

205 # 4 - Beta 

206 # 5 - Production/Stable 

207 "Development Status :: 4 - Beta", 

208 # Indicate who your project is intended for 

209 "Intended Audience :: Developers", 

210 # 'Topic :: Weather', 

211 # Pick your license as you wish 

212 "License :: OSI Approved :: MIT License", 

213 # Specify the Python versions you support here. In particular, ensure 

214 # that you indicate whether you support Python 2, Python 3 or both. 

215 # These classifiers are *not* checked by 'pip install'. See instead 

216 # 'python_requires' below. 

217 "Programming Language :: Python :: 3.6", 

218 "Programming Language :: Python :: 3.7", 

219 "Programming Language :: Python :: 3.8", 

220 "Programming Language :: Python :: 3.9", 

221 ], 

222 keywords="", # Optional 

223 # You can just specify package directories manually here if your project is 

224 # simple. Or you can use find_packages(). 

225 # 

226 # Alternatively, if you just want to distribute a single Python file, use 

227 # the `py_modules` argument instead as follows, which will expect a file 

228 # called `my_module.py` to exist: 

229 # 

230 # py_modules=["my_module"], 

231 # 

232 # packages=find_packages(exclude=['contrib', 'docs', 'tests']), # Required 

233 packages=["{projname}"], 

234 include_package_data=True, 

235 python_requires=">=3.6", 

236 install_requires=open( 

237 os.path.join(here, "requirements.txt"), encoding="utf-8" 

238 ) 

239 .read() 

240 .split("\\n"), # Optional 

241 project_urls={{ # Optional 

242 "Bug Reports": "", 

243 "Source": "", 

244 }}, 

245 entry_points={{ 

246 "console_scripts": [ 

247 "{projname}={projname}.cli:cli" 

248 ] 

249 }}, 

250 ) 

251 ''' 

252 ) 

253 

254 return content 

255 

256 

257def get_manifest_ini_content(projname): 

258 content = textwrap.dedent( 

259 """\ 

260 include requirements.txt 

261 include dev_requirements.txt 

262 exclude config.json 

263 recursive-include {projname} * 

264 recursive-exclude {projname}/instance * 

265 recursive-exclude {projname}/static/modules * 

266 recursive-exclude {projname}/.tox * 

267 recursive-exclude __pycache__ * 

268 """ 

269 ) 

270 

271 return content 

272 

273 

274def get_pytest_ini_content(): 

275 content = textwrap.dedent( 

276 """\ 

277 [pytest] 

278 env_files = 

279 .test.prod.env 

280 """ 

281 ) 

282 

283 return content 

284 

285 

286def get_tox_ini_content(projname): 

287 content = textwrap.dedent( 

288 f"""\ 

289 [tox] 

290 envlist = 

291 py39 

292 py38 

293 py37 

294 py36 

295 skip_missing_interpreters=true 

296 

297 [testenv] 

298 changedir = {projname} 

299 deps = 

300 -rrequirements.txt 

301 -rdev_requirements.txt 

302 commands = python -m pytest {{posargs}} 

303 """ 

304 ) 

305 

306 return content 

307 

308 

309def get_dev_req_content(): 

310 content = textwrap.dedent( 

311 """\ 

312 flake8==3.8.4 

313 black==20.8b1 

314 isort==5.6.4 

315 Sphinx==3.2.1 

316 pytest==6.1.1 

317 pytest-order==0.9.5 

318 tox==3.21.0 

319 pytest-cov==2.11.1 

320 codecov==2.1.11 

321 factory-boy==3.2.0 

322 freezegun==1.1.0 

323 pytest-dotenv 

324 """ 

325 ) 

326 

327 return content 

328 

329 

330def get_gitignore_content(): 

331 content = textwrap.dedent( 

332 """\ 

333 # Byte-compiled / optimized / DLL files 

334 __pycache__/ 

335 *.py[cod] 

336 *$py.class 

337 

338 # C extensions 

339 *.so 

340 

341 # Distribution / packaging 

342 .Python 

343 build/ 

344 develop-eggs/ 

345 dist/ 

346 downloads/ 

347 eggs/ 

348 .eggs/ 

349 lib/ 

350 lib64/ 

351 parts/ 

352 sdist/ 

353 var/ 

354 wheels/ 

355 *.egg-info/ 

356 .installed.cfg 

357 *.egg 

358 MANIFEST 

359 

360 # PyInstaller 

361 # Usually these files are written by a python script from a template 

362 # before PyInstaller builds the exe, so as to inject date/other infos into it. 

363 *.manifest 

364 *.spec 

365 

366 # Installer logs 

367 pip-log.txt 

368 pip-delete-this-directory.txt 

369 

370 # Unit test / coverage reports 

371 htmlcov/ 

372 .tox/ 

373 .coverage 

374 .coverage.* 

375 .cache 

376 nosetests.xml 

377 coverage.xml 

378 *.cover 

379 .hypothesis/ 

380 .pytest_cache/ 

381 

382 # Translations 

383 *.mo 

384 *.pot 

385 

386 # Django stuff: 

387 *.log 

388 local_settings.py 

389 db.sqlite3 

390 

391 # Flask stuff: 

392 instance/ 

393 .webassets-cache 

394 

395 # Scrapy stuff: 

396 .scrapy 

397 

398 # Sphinx documentation 

399 _build/ 

400 

401 # PyBuilder 

402 target/ 

403 

404 # Jupyter Notebook 

405 .ipynb_checkpoints 

406 

407 # pyenv 

408 .python-version 

409 

410 # celery beat schedule file 

411 celerybeat-schedule 

412 

413 # SageMath parsed files 

414 *.sage.py 

415 

416 # Environments 

417 .env 

418 .venv 

419 env/ 

420 venv/ 

421 ENV/ 

422 env.bak/ 

423 venv.bak/ 

424 

425 # Spyder project settings 

426 .spyderproject 

427 .spyproject 

428 

429 # Rope project settings 

430 .ropeproject 

431 

432 # mkdocs documentation 

433 /site 

434 

435 # mypy 

436 .mypy_cache/ 

437 

438 # shopyo 

439 test.db 

440 testing.db 

441 shopyo.db 

442 

443 # pycharm 

444 .idea/ 

445 

446 # win 

447 *.exe 

448 *.cs 

449 *.bat 

450 *.vbs 

451 

452 # vscode 

453 .vscode 

454 workspace.code-workspace 

455 

456 # modules in static since present in modules 

457 shopyo/static/modules/ 

458 

459 # ignore secrets 

460 config.json 

461 """ 

462 ) 

463 

464 return content 

465 

466 

467def get_index_rst_content(projname): 

468 content = textwrap.dedent( 

469 f"""\ 

470 Welcome to {projname} docs! 

471 ============================ 

472 

473 Write project description here 

474 

475 .. toctree:: 

476 :maxdepth: 9 

477 

478 Docs <docs> 

479 

480 Indices and tables 

481 ================== 

482 

483 * :ref:`genindex` 

484 * :ref:`modindex` 

485 * :ref:`search` 

486 """ 

487 ) 

488 

489 return content 

490 

491 

492def get_docs_rst_content(projname): 

493 content = textwrap.dedent( 

494 """\ 

495 .. :tocdepth:: 5 

496 

497 Documentation 

498 ============= 

499 

500 Sphinx is included in dev_requirements.txt 

501 

502 .. code:: bash 

503 

504 cd docs 

505 sphinx-build . _build 

506 

507 to generate html pages in docs 

508 """ 

509 ) 

510 

511 return content 

512 

513 

514def get_sphinx_conf_py(projname): 

515 content = textwrap.dedent( 

516 f"""\ 

517 # Configuration file for the Sphinx documentation builder. 

518 # 

519 # This file only contains a selection of the most common options. For a full 

520 # list see the documentation: 

521 # https://www.sphinx-doc.org/en/master/usage/configuration.html 

522 

523 # -- Path setup -------------------------------------------------------------- 

524 # 

525 # If extensions (or modules to document with autodoc) are in another directory, 

526 # add these directories to sys.path here. If the directory is relative to the 

527 # documentation root, use os.path.abspath to make it absolute, like shown here. 

528 # 

529 # import os 

530 # import sys 

531 # sys.path.insert(0, os.path.abspath('.')) 

532 # 

533 # -- Project information ----------------------------------------------------- 

534 

535 project = "{projname}" 

536 author = "" 

537 

538 # -- General configuration --------------------------------------------------- 

539 

540 # Add any Sphinx extension module names here, as strings. They can be 

541 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 

542 # ones. 

543 extensions = [ 

544 "sphinx.ext.autodoc", 

545 "sphinx.ext.viewcode", 

546 "sphinx.ext.autosectionlabel", 

547 "sphinx.ext.napoleon", 

548 ] 

549 

550 # Add any paths that contain templates here, relative to this directory. 

551 templates_path = ["_templates"] 

552 

553 # List of patterns, relative to source directory, that match files and 

554 # directories to ignore when looking for source files. 

555 # This pattern also affects html_static_path and html_extra_path. 

556 exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] 

557 

558 

559 # -- Options for HTML output ------------------------------------------------- 

560 html_context = {{ 

561 "project_links": [ 

562 "Source Code", 

563 "https://github.com/<name>/<project>", 

564 "Issue Tracker", 

565 "https://github.com/<name>/<project>/issues", 

566 ] 

567 }} 

568 html_logo = "shopyo.ico" 

569 

570 html_sidebars = {{ 

571 "**": ["about.html", "relations.html", "navigation.html", "searchbox.html"] 

572 }} 

573 

574 # The theme to use for HTML and HTML Help pages. See the documentation for 

575 # a list of builtin themes. 

576 # 

577 html_theme = "alabaster" 

578 html_theme_options = {{ 

579 "github_repo": "<name>/<project>", 

580 "fixed_sidebar": "true", 

581 }} 

582 

583 # Add any paths that contain custom static files (such as style sheets) here, 

584 # relative to this directory. They are copied after the builtin static files, 

585 # so a file named "default.css" will overwrite the builtin "default.css". 

586 html_static_path = ["_static"] 

587 """ 

588 ) 

589 

590 return content 

591 

592 

593def get_sphinx_makefile(): 

594 content = textwrap.dedent( 

595 """\ 

596 # Minimal makefile for Sphinx documentation 

597 # 

598 

599 # You can set these variables from the command line, and also 

600 # from the environment for the first two. 

601 SPHINXOPTS ?= 

602 SPHINXBUILD ?= sphinx-build 

603 SOURCEDIR = . 

604 BUILDDIR = _build 

605 

606 # Put it first so that "make" without argument is like "make help". 

607 help: 

608 @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 

609 

610 .PHONY: help Makefile 

611 

612 # Catch-all target: route all unknown targets to Sphinx using the new 

613 # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 

614 %: Makefile 

615 @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 

616 

617 """ 

618 ) 

619 

620 return content