-
- 添加文档字符串与注释后的完整代码
"""
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
)
"""
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__))
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',
platforms='any',
packages=['flask_share'],
zip_safe=False,
test_suite='test_flask_share', 测试包或模块
include_package_data=True,
install_requires=['Flask'],
keywords='flask extension development',
classifiers=[
'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
graft flask_share/static
include LICENSE test_flask_share.py
-
- 编写单元测试
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('<div class="socail-share"', data))
-
- setup.cfg
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App