当前位置:网站首页>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 ~
边栏推荐
- Synchronized and lock escalation
- Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training
- 基于WEB平台的阅读APP设计与实现
- 优雅的自定义 ThreadPoolExecutor 线程池
- Notes learning summary
- In the past, domestic mobile phones were arrogant in pricing and threatened that consumers would like to buy or not, but now they have plummeted by 2000 for sale
- Calcul de la confidentialité Fate - Prévisions hors ligne
- 每日3题(1):找到最近的有相同 X 或 Y 坐标的点
- Multithreading Basics (III)
- At a time of oversupply of chips, China, the largest importer, continued to reduce imports, and the United States panicked
猜你喜欢

Step by step expansion of variable parameters in class templates

ReentrantLock、ReentrantReadWriteLock、StampedLock

All you want to know about large screen visualization is here

SQL parsing practice of Pisa proxy

Using redis skillfully to realize the like function, isn't it more fragrant than MySQL?
![[PHP code injection] common injectable functions of PHP language and utilization examples of PHP code injection vulnerabilities](/img/19/9827a5e8becfc9d5bf2f51bddf803e.png)
[PHP code injection] common injectable functions of PHP language and utilization examples of PHP code injection vulnerabilities

Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and the mobile phone can easily read literature

Privacy computing fat offline prediction

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

【PHP代码注入】PHP语言常见可注入函数以及PHP代码注入漏洞的利用实例
随机推荐
阅读别人的代码,是一种怎样的体验
Privacy computing fat offline prediction
Why must Oracle cloud customers self test after the release of Oracle cloud quarterly update?
What are the operating modes of the live app? What mode should we choose?
ThreadLocal之强、弱、软、虚引用
请求一下子太多了,数据库危
海量数据!秒级分析!Flink+Doris构建实时数仓方案
Massive data! Second level analysis! Flink+doris build a real-time data warehouse scheme
Redis持久化
Getting to know cloud native security for the first time: the best guarantee in the cloud Era
Volatile and JMM
机械硬盘和ssd固态硬盘的原理对比分析
Hyperledger Fabric 2. X custom smart contract
基于WEB平台的阅读APP设计与实现
优雅的自定义 ThreadPoolExecutor 线程池
直播app运营模式有哪几种,我们该选择什么样的模式?
Design and implementation of reading app based on Web Platform
Li Kou's 81st biweekly match
Synchronized与锁升级
关于 SAP UI5 参数 $$updateGroupId 前面两个 $ 符号的含义