#πŸ”’ A good way to write __version__ in your package, pyproject.toml and argparse?

27 messages Β· Page 1 of 1 (latest)

white oar
#

I'm trying to use __version__ to control my package version and I saw so many different ways to provide version information in varies of packages.
Someone use _version.py, and someone put __version__ inside __init__.py. Can anyone guild me through the entire workflow for adding __version__ info into the package, including pyproject.toml and argparse?

slim tigerBOT
#

@white oar

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fresh rock
#

What's your build backend?

#

(paste your pyproject.toml so far)

white oar
#
[build-system]
requires = ['setuptools>=61.0']
build-backend = 'setuptools.build_meta'
[project]
name= "lastree"
version = '1.0.0'
authors = [{name="Jiawei Li", email="[email protected]"}]
description = "A tool box to use for process sfm point cloud of the tree and get the tree structure"
readme = 'README.md'
dependencies = ["numpy", "pandas"]
license = {file = "LICENSE"}
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
    "Operating System :: OS Independent",

]

[project.urls]
Homepage = "https://github.com/jldz9/point_cloud_tree_detection_ex"
Issues = "https://github.com/jldz9/point_cloud_tree_detection_ex/issues"
[project.scripts]
lastree = 'lastree.main:main_cli'
[tool.setuptools.packages.find]
where = ['src']
[tool.setuptools.exclude-package-data]
'*' = ['*.pyc']
'lastree.test' = ['test.py']
[tool.setuptools.package-data]
"lastree.defaults" = ['CONFIG']
#

I choose to create a _version.py and storage __version__ = '1.0.0'

white oar
#

but I'm not sure how to add __version__ to this toml file

fresh rock
#

You need to set

[project]
dynamic = ["version"]

[tools.setuptools.dynamic]
version = {attr: 'lastree._version.__version__'}
white oar
#

Thanks! I'll try this. I saw the link you mentioned about setuptools_scm to get version number from VCS, is that a easy move or need some complex configure on git?

fresh rock
#

Yeah it's nice

#

There's stuff you need to configure for git archives to work

#

I don't use it, but it's popular

white oar
#

Okay, I'll use _version.py for now and try this feature sometime in the future

#

It works! thank you @fresh rock !

white oar
# fresh rock Yeah it's nice

A quick question relate to exclude data in toml,
I use py [tool.setuptools.exclude-package-data] '*' = ['*.pyc'] 'lastree.test' = ['test.py'] to remove __pycache__ and test folder under lastree but it does not seems to work

#

This is my package structure

fresh rock
#

You shouldn't need to exclude pyc files

#

I wouldn't bother excluding your test folder if you use inline tests

#

If you want to exclude it put it outside src

white oar
#

I just have one test.py under it, could easily delete but just curious

#

Yeah, good idea I'll move it to upper level

boreal crown
white oar
slim tigerBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.