Read Version Number from the Package in setup.cfg
See original GitHub issueHi,
I am trying to make a project to be setup.cfg
project. In the old version, we letted the setup.py
read a version number from a file inside the package.
def get_version() -> dict:
version = {}
with open(Path(__file__).parent / 'sciunit' / 'version.py') as f:
exec(f.read(), version)
return version['__version__']
setup(
...
version=get_version(),
...
)
I am wondering how can I achieve the same thing in setup.cfg file? Is it possible?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Single-sourcing the package version
There are many techniques to maintain a single source of truth for the version number of your project: Read the file in setup.py...
Read more >How can I get the version defined in setup.py (setuptools) in ...
I've seen a case like this where py2exe would put the wrong version number on a package because the package was getting its...
Read more >Configuring setuptools using setup.cfg files
Setuptools allows using configuration files (usually setup.cfg ) to define a package's metadata and other options that are normally supplied to the setup() ......
Read more >Extracting setuptools version numbers from your git repository
Create a new maintenance branch for 1.3: $ git checkout -b maint-1.3 master · Update the setup.cfg file to remove the tag_build and...
Read more >Releasing Your Package
If you didn't you will need to update your setup.cfg file as well as using git tag . Incrementing Version Numbers¶. When you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve answered this question at https://stackoverflow.com/questions/72357031/set-version-of-module-from-a-file-when-configuring-setuptools-using-setup
Method 1:
__version__.py
file at the same level as__init__
of your import package.__version__ = '0.0.2'
__init__.py
, addfrom . __version__ import __version__
.setup.cfg
, useversion = attr: my_package.__version__
Method 2:VERSION
file at the same level as__init__
of your import package.setup.cfg
use:version = file: src/my_package/VERSION
Hi, I had the same question as well.
In the docs, there is the section “Specifying Your Project’s Version”. But it didn’t led me to the only spot I could find that includes the answer, which is “Configuring setup() using setup.cfg files” (specifically, the config example’s
[metadata]
section). I guess it makes sense to link to there from the first section I mentioned?As for the example itself, which is:
Is this really a practical example? As I understand it,
src
here should be the name of an actual Python package. However, the whole example seems to be based on asrc/
project layout. Butsrc/
shouldn’t include a__init__.py
file to make it a package, right?So I assume a better example would be: