开源发布准备
-
- 添加文档字符串与注释后的完整代码
""" Flask-Share # ~~~~~~~~~~~~~~ Create social share component in Jinja2 tempalte based on share.js. :copyright: (c) 2017 by Gavin Li. :license: MIT, see LICENSE for more details. """ import re from flask import current_app, url_for, Markup, Blueprint, request class Share(object): @staticmethod def load(css\_url=None, js\_url=None): """ Load share.js resourse. :param css\_url: if set, will be used as css url :param js\_url: if set, will be used as js url :param serve\_local: if set to True, the local resource will be used """ @staticmethod def create( title='', sites=None, mobile\_sites=None,align='left',addtion\_class=''): """ Create a share component. :param title: the prompt displayed on the left of the share component. :param sites: a string that consist of sites, separate by comma. :param mobile\_sites: a string that consist of sites, separate by comma. supported site name: weibo, wechat, douban, facebook, twitter, google, linkedin, qq, qzone." for example: weibo,wechat, qq. :param mobile\_sites: the sites displayed on mobile. :param align: the align of the share component,default to '`left`'. :param addition\_class: the style class added to the share component. """
-
- 编写 README 与文档
- 小项目 直接用 README概括所有的必需的说明
- 大项目 比较复杂的,多文件组织文档内容
将项目部署到 Read the Docs上
Sphinx + Github + Readthedocs的工作流编写和部署文档
-
- 定义 python 包的元数据:(
setup.py
)
- 定义 python 包的元数据:(
""" Flask-Share Create social share component in Jinja2 template based on share.js. :copyright: (c) 2022 by Gavin li. :license: MIT, see LICENSE for more details. """ form os import path from codecs import open form setuptools import setup basedir = path.abspath(path.dirname(__file__)) # Get the long description from the README file with open(path.join(basedir,'README.md'), encoding='utf-8') as f: long_description = f.read() setup( name='Flask-Share', # 包名称 version='0.1.0', # 版本 url='https://github.com/lghpython/flask-share', license='MIT', author='xxx' author_email='xx@xx.com', description='xxx', long_description=long_description, long_description_content_type='text/markdown', # 默认渲染格式为 rst platforms='any', packages=['flask\_share'], # 包含的包列表,包括子包,可用find\_pakages() zip_safe=False, test_suite='test\_flask\_share', 测试包或模块 include_package_data=True, install_requires=['Flask'], # 安装依赖 keywords='flask extension development', # 项目关键词 classifiers=[ # 分类词, 在 PyPI 中设置分类 'DevelopmentStatus::3-Alpha', 'Environment::WebEnvironment', 'IntendedAudience::Developers', 'License::OSIApproved::MITLicense', 'ProgrammingLanguage::Python', 'ProgrammingLanguage::Python::2', 'ProgrammingLanguage::Python::2.7', 'ProgrammingLanguage::Python::3', 'ProgrammingLanguage::Python::3.3', 'ProgrammingLanguage::Python::3.4', 'ProgrammingLanguage::Python::3.5', 'ProgrammingLanguage::Python::3.6', 'Topic::Internet::WWW/HTTP::DynamicContent', 'Topic::SoftwareDevelopment::Libraries::PythonModules'] ], )
-
- 指定打包其他文件: MANIFEST.in
需要在 setup()方法中设置: include_package_data=True
- 指定打包其他文件: MANIFEST.in
graft flask_share/static include LICENSE test_flask_share.py # exclude 用来排除匹配文件 # recursive-include 递归匹配 # recursive-exclude 递归排除匹配 # graft 目录 包含目录下所有 # prune 目录 配出目录下所有
-
- 编写单元测试
import unittest from flask import Flask, render_template_string, current_app from flask_share import Share class ShareTestCase(unittest.TestCase): def setUp(self): self.mobile_agent={{'HTTP\_USER\_AGENT':'Mozilla/5.0(iPhone;CPUiPhoneOS9\_1likeMacOSX)\ AppleWebKit/601.1.46(KHTML,likeGecko)Version/9.0Mobile/13B143Safari/601.1'}} app = Flask(__name__) app.testing=True self.share=Share(app) @app.route('/') def index(): return render_template_string('{{share.load() }}\n {{share.create() }}') # 推送上下文 self.context=app.app_context() self.context.push() self.client - app.test_client() def tearDown(self): self.context.pop() def test\_create\_on\_mobile(self): current_app.config['SHARE\_HIDE\_ON\_MOBILE'] = True response = self.client.get('/', environ_base=self.mobile_agent) data = response.get_data(as_text=True) self.assertIn('social-share.min.js', data) self.assertNotIn(', data))
-
- setup.cfg
原文链接:https://blog.csdn.net/weixin_45566993/article/details/123343724?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165934458816781667869865%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165934458816781667869865&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-6-123343724-null-null.nonecase&utm_term=%E8%87%AA%E5%BB%BAcdn
原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/7631