[PYTHON] Get the package version to register with PyPI from Git

Overview

When registering a package on PyPI, you need to pass the version argument to the setup function called by setup.py. Until now, this version information was edited manually, but since I pulled it from the Git tag, I will write it as a memorandum.

setuptools_scm setuptools_scm is a library that pulls information from the version control system and sets setup.py. If you use this, you can calculate and set the version number based on the tag information. There is also a function to automatically add the tracked package data to the package.

When setting the version number using setuptools_scm, pass the following parameters to the setup function of setup.py.

setup.py


from setuptools import setup

setup(
    use_scm_version=True,
    setup_requires=[
        "setuptools_scm"
    ],
    ... #Other items omitted
)

Now, when you do python setup.py sdist, the version number will be calculated properly. The calculation method of the version number follows the following rules.

See the manual for more information.

Add package data

To add the tracked package data automatically, add ʻinclude_package_data = True` to the setup function. In other words

setup.py


from setuptools import setup

setup(
    use_scm_version=True,
    include_package_data=True,
    setup_requires=[
        "setuptools_scm"
    ],
    ... #Other items omitted
)

Let. If there are data files that you are tracking but do not want to include in the package, It can be specified by exclude_package_data. See Manual for details.

Recommended Posts

Get the package version to register with PyPI from Git
Get only the source code of the PyPI package with pip from the command line
How to get the Python version
[Python] Get Python package information with PyPI API
Get the contents of git diff from python
Get the latest Linux kernel version with Arch Linux
Get the GNOME version
Try to get the contents of Word with Golang
Manage the package version number of requirements.txt with pip-tools
One liner to get the nth commit hash in Git
Try to get the function list of Python> os package
A memorandum to register the library written in Hy in PyPI
Memo to get the value on the html-javascript side with jupyter
Minimum knowledge to get started with the Python logging module
How to register on pypi
Steps to install a Git cloned package locally with pip
How to register a package on PyPI (as of September 2017)
I want to install a package from requirements.txt with poetry
How to get into the python development environment with Vagrant
[Shell] How to get the remote default branch in Git
I tried to get various information from the codeforces API
[Introduction to Python] How to get data with the listdir function
Get the source of the page to load infinitely with python.
Getting Started with Poetry From installation to execution and version control
Repeat with While. Scripts to Tweet and search from the terminal
[September 2020 version] Explains the procedure to use Gmail API with Python
How to get followers and followers from python using the Mastodon API
Switch the package to be installed for each environment with poetry
How to get the directory where the EXE built with Pyinstaller exists
I tried to get started with Bitcoin Systre on the weekend
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
Change the active version in Pyenv from anaconda to plain Python
From "drawing" to "writing" the configuration diagram: Try drawing the AWS configuration diagram with Diagrams
The fastest way to get camera images regularly with python opencv
PhytoMine-I tried to get the genetic information of plants with Python
Link to get started with python
Create folders from '01' to '12' with python
Get the weather with Python requests
Get the weather with Python requests 2
Get one column from DataFrame with DataFrame
How to get started with Scrapy
How to get started with Python
How to get started with Django
Get the value from the [Django] Form
Register as a package on PyPI
Get the address from the zip code
Python version to get unused ports
Review from git init to git push
[Completed version] Try to find out the number of residents in the town from the address list with Python
I made an npm package to get the ID of the IC card with Raspberry Pi and PaSoRi
[Yahoo! Weather Replacement Version] How to get weather information with LINE Notify + Python
Learning record (4th day) #How to get the absolute path from the relative path
How to get the date and time difference in seconds with python
Semi-automatically generate a description of the package to be registered on PyPI
Deb package development with Git: (Part 1) Creating a stray package with the minimum configuration
I tried to get the authentication code of Qiita API with Python.
Get the number of visits to each page with ReportingAPI + Cloud Functions
I tried to learn the angle from sin and cos with chainer
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
Get the list of packages for the specified user from the packages registered on PyPI
Get the song name from the title of the video you tried to sing