当前位置:网站首页>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 ~
边栏推荐
- E-week finance Q1 mobile banking has 650million active users; Layout of financial subsidiaries in emerging fields
- Step by step expansion of variable parameters in class templates
- Domestic database disorder
- 图书管理系统
- 海外仓知识科普
- Strong, weak, soft and virtual references of ThreadLocal
- 高德地图IP定位2.0备份
- AbortController的使用
- Use GCC to generate an abstract syntax tree "ast" and dump it to Dot file and visualization
- Leetcode 724. Find the central subscript of the array (yes, once)
猜你喜欢

Synchronized与锁升级

enable_ if

海量数据!秒级分析!Flink+Doris构建实时数仓方案

American chips are hit hard again, and another chip enterprise after Intel will be overtaken by Chinese chips

Hyperledger Fabric 2. X custom smart contract

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

Reflection learning summary

Computer screen splitting method
![[WUSTCTF2020]girlfriend](/img/a8/33fe5feb7bcbb73ba26a94d226cc4d.png)
[WUSTCTF2020]girlfriend

OpenSSF安全计划:SBOM将驱动软件供应链安全
随机推荐
初识云原生安全:云时代的最佳保障
Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
【PHP代码注入】PHP语言常见可注入函数以及PHP代码注入漏洞的利用实例
Daily 3 questions (1): find the nearest point with the same X or Y coordinate
Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
Web chat room system based on SSM
Top ten Devops best practices worthy of attention in 2022
[an Xun cup 2019]attack
阅读别人的代码,是一种怎样的体验
Abnormal analysis of pcf8591 voltage measurement data
Redis CacheClient
Is there any discount for opening an account now? Is it safe to open an account online?
[business security-04] universal user name and universal password experiment
QT 如何在背景图中将部分区域设置为透明
volatile与JMM
How to change a matrix into a triple in R language (i.e. three columns: row, col, value)
Sword finger offer II 039 Histogram maximum rectangular area monotonic stack
数学建模经验分享:国赛美赛对比/选题参考/常用技巧
June 27, 2022 Daily: swin transformer, Vit authors and others said: a good basic model is the simple pursuit of CV researchers
What kind of experience is it to read other people's code