当前位置:网站首页>Teach you how to package and release the mofish Library
Teach you how to package and release the mofish Library
2022-06-27 14:47:00 【Python advanced】
Click on the above “Python Crawler and data mining ”, Focus on
reply “ Books ” You can get a gift Python From the beginning to the advanced stage 10 This ebook
today
Japan
chicken
soup
Business women don't know how to die , Across the river, you still sing backyard flowers .
Hello everyone , I'm Pippi .
One 、 Preface
A few days ago, boss Wu recommended me a fishing house , Turned out to be Python library , I was surprised , Feeling should be absent from sting .

You know, he has written an article about fishing before , Interested partners , You can go to : Hands teach you how to use Python Create a fishing countdown interface .
Now he made this fishing into a Python library , Articles have been published about the use of this library , You can go to : Take stock of a named fishing Python library , Let's fish together !
I saw in the comment area 【 I little interesting 】 Big guy's message , As shown in the figure below :

It probably means to write your own code , Encapsulated into Python library , Everyone can use that , Here is the arrangement for , This article is about how to package and publish , Let's see !
Two 、 Code
First prepare the code , This code , Previous articles have been shared , No more details here , The code is here .
# -*- coding: utf-8 -*-
import datetime
import click
from zhdate import ZhDate as lunar_date
def get_week_day(date):
week_day_dict = {
0: ' Monday ',
1: ' Tuesday ',
2: ' Wednesday ',
3: ' Thursday ',
4: ' Friday ',
5: ' Saturday ',
6: ' Sunday ',
}
day = date.weekday()
return week_day_dict[day]
def time_parse(today):
distance_big_year = (lunar_date(today.year, 1, 1).to_datetime().date() - today).days
distance_big_year = distance_big_year if distance_big_year > 0 else (
lunar_date(today.year + 1, 1, 1).to_datetime().date() - today).days
distance_5_5 = (lunar_date(today.year, 5, 5).to_datetime().date() - today).days
distance_5_5 = distance_5_5 if distance_5_5 > 0 else (
lunar_date(today.year + 1, 5, 5).to_datetime().date() - today).days
distance_8_15 = (lunar_date(today.year, 8, 15).to_datetime().date() - today).days
distance_8_15 = distance_8_15 if distance_8_15 > 0 else (
lunar_date(today.year + 1, 8, 15).to_datetime().date() - today).days
distance_year = (datetime.datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d").date() - today).days
distance_year = distance_year if distance_year > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-01-01", "%Y-%m-%d").date() - today).days
distance_4_5 = (datetime.datetime.strptime(f"{today.year}-04-05", "%Y-%m-%d").date() - today).days
distance_4_5 = distance_4_5 if distance_4_5 > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-04-05", "%Y-%m-%d").date() - today).days
distance_5_1 = (datetime.datetime.strptime(f"{today.year}-05-01", "%Y-%m-%d").date() - today).days
distance_5_1 = distance_5_1 if distance_5_1 > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-05-01", "%Y-%m-%d").date() - today).days
distance_10_1 = (datetime.datetime.strptime(f"{today.year}-10-01", "%Y-%m-%d").date() - today).days
distance_10_1 = distance_10_1 if distance_10_1 > 0 else (
datetime.datetime.strptime(f"{today.year + 1}-10-01", "%Y-%m-%d").date() - today).days
time_ = [
{"v_": 5 - 1 - today.weekday(), "title": " Over the weekend "}, # From the weekend
{"v_": distance_year, "title": " New year's Day "}, # From New Year's day
{"v_": distance_big_year, "title": " The Chinese New Year "}, # Distance from the Chinese New Year
{"v_": distance_4_5, "title": " Qingming Festival "}, # Distance from Qingming
{"v_": distance_5_1, "title": " labor day "}, # Distance labor
{"v_": distance_5_5, "title": " The Dragon Boat Festival "}, # From the Dragon Boat Festival
{"v_": distance_8_15, "title": " Mid-Autumn Festival "}, # From the Mid Autumn Festival
{"v_": distance_10_1, "title": " National Day "}, # It's national day
]
time_ = sorted(time_, key=lambda x: x['v_'], reverse=False)
return time_
@click.command()
def cli():
""" Hello , Fisherman , I'm tired of work , Don't forget to fish !"""
from colorama import init, Fore
init(autoreset=True) # initialization , And set the color settings to restore automatically
print()
today = datetime.date.today()
now_ = f"{today.year} year {today.month} month {today.day} Japan "
week_day_ = get_week_day(today)
print(f'\t\t {Fore.GREEN}{now_} {week_day_}')
str_ = '''
Hello , Fisherman , I'm tired of work , Don't forget to fish !
If you have nothing to do, get up and go to the tea room, go to the corridor and walk on the roof , Don't always sit on the station .
Drink more water , The money belongs to the boss , But life is your own !
'''
print(f'{Fore.RED}{str_}')
time_ = time_parse(today)
for t_ in time_:
print(f'\t\t {Fore.RED} distance {t_.get("title")} also : {t_.get("v_")} God ')
tips_ = '''
[ Friendship tips ] Third class hospital ICU The average cost of lying down for a day is about 10000 yuan .
You're a day late ICU, It's like making an extra $10000 for your family . Less work , Fish more .\n
'''
print(f'{Fore.RED}{tips_}')
print(f'\t\t\t\t\t\t\t{Fore.YELLOW} Fishing do ')
if __name__ == '__main__':
cli()click Library usage
Notice that our file code above uses click library .
Python There's a built-in Argparse Standard library for creating command line , But it's a little cumbersome to use ,Click Compared with Argparse It can be said that it is a small Witch to see a great witch .
install
pip install clickclick Simple use
An introductory example of official documents :
import click
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo('Hello %s!' % name)
if __name__ == '__main__':
hello()@click.command()Make functionhelloBecome a command line interface .@click.optionThe first parameter of specifies the name of the command line option .click.echoMethods andpythonBuilt inprintThe method is similar .
Usage method :
Print 10 individual Boss pi .
$ python hello.py --count 10 --name Boss pi # Appoint count and name Value
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !
Hello Boss pi !setuptool Packaging releases
Installation dependency
pip install setuptools
pip install twinePackage and upload
python setup.py sdist
twine upload dist/* Sign in pypi Account and publish python library
setup.py Example
from setuptools import setup, find_packages
description = ' Hello , Fisherman , I'm tired of work , Don't forget to fish ! If you have nothing to do, get up and go to the tea room, go to the corridor and walk on the roof , Don't always sit on the station . Drink more water , The money belongs to the boss , But life is your own !'
setup(
name='mofish', # Library name
version='1.0.0', # Version number
description=description, # Short introduction
long_description_content_type='text/markdown',
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Internet',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Clustering',
'Topic :: System :: Distributed Computing',
'Topic :: System :: Monitoring',
'Topic :: System :: Systems Administration',
],
python_requires='>=3.7', # py Version restrictions
author='PY-GZKY', # author
author_email='[email protected]', # mail
url='https://github.com/PY-GZKY/Mofish', # git
license='MIT', # Open source licenses
packages=find_packages(), # package
include_package_data=True,
entry_points="""
[console_scripts]
moyu=src.main:cli
""", # Start the command line script file
install_requires=[
'click>=6.7',
'zhdate'
], # Limit the version of the installation Library
)Install and use
pip install mofish
moyuCode warehouse address :
https://github.com/PY-GZKY/Mofish
summary
Hello everyone , I'm Pippi . This article is mainly to give you an inventory of Python library , Based on this library , This article introduces how to encapsulate your own code into Python library , Package and upload , And publish it to pypi, Everyone in the back can use your library .
Finally thanks 【 Boss Wu 】 The thought and code support given by the boss , thank 【 I little interesting 】 The needs of the boss .
[ Friendship tips ] Third class hospital ICU The average cost of lying down for a day is about 10000 yuan . You're a day late ICU, It's like making an extra $10000 for your family . Less work , Fish more .

friends , Practice it quickly ! If in the process of learning , Any problems encountered , Welcome to add my friend , I'll pull you in Python The learning exchange group discusses learning together .

------------------- End -------------------
Excellent articles in the past are recommended :

Welcome to give the thumbs-up , Leaving a message. , forward , Reprint , Thank you for your company and support
Want to join Python Learning group, please reply in the background 【 The group of 】
All rivers and mountains are always in love , Order one 【 Looking at 】 OK?
/ Today's message topic /
Just a word or two ~
边栏推荐
- Too many requests at once, and the database is in danger
- OpenSSF安全计划:SBOM将驱动软件供应链安全
- Talk about redis transactions
- 每日3题(2):检查二进制字符串字段
- Abnormal analysis of pcf8591 voltage measurement data
- AI begets the moon, and thousands of miles share the literary heart
- 机械硬盘和ssd固态硬盘的原理对比分析
- Leetcode 724. Find the central subscript of the array (yes, once)
- [daily 3 questions (3)] maximum number of balls in the box
- 解析Activity启动-生命周期角度
猜你喜欢

How to set the compatibility mode of 360 speed browser

基于Vue+Node+MySQL的美食菜谱食材网站设计与实现

Redis持久化
![[business security 03] password retrieval business security and interface parameter account modification examples (based on the metinfov4.0 platform)](/img/29/73c381f14a09ecaf36a98d67d76720.png)
[business security 03] password retrieval business security and interface parameter account modification examples (based on the metinfov4.0 platform)

【业务安全03】密码找回业务安全以及接口参数账号修改实例(基于metinfov4.0平台)

Massive data! Second level analysis! Flink+doris build a real-time data warehouse scheme

Atomic operation class
![[business security-02] business data security test and example of commodity order quantity tampering](/img/0f/c4d4dd72bed206bbe3e15e32456e2c.png)
[business security-02] business data security test and example of commodity order quantity tampering

Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training

OpenSSF安全计划:SBOM将驱动软件供应链安全
随机推荐
Pychart installation and setup
Design and implementation of food recipe and ingredients website based on vue+node+mysql
[business security-04] universal user name and universal password experiment
OpenSSF安全计划:SBOM将驱动软件供应链安全
Gaode map IP positioning 2.0 backup
What are the operating modes of the live app? What mode should we choose?
Talk about redis transactions
Jupiter core error
2022-06-27日报:Swin Transformer、ViT作者等共话:好的基础模型是CV研究者的朴素追求
Leetcode 724. Find the central subscript of the array (yes, once)
巧用redis实现点赞功能,它不比mysql香吗?
Acwing game 57
Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
ThreadLocal之强、弱、軟、虛引用
易周金融 | Q1手机银行活跃用户规模6.5亿;理财子公司布局新兴领域
【业务安全-04】万能用户名及万能密码实验
How to select cross-border e-commerce multi merchant system
Julia1.1 installation instructions
清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!...
Make a ThreadLocal (source code) that everyone can understand