Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using use_scm_version write_to in setup.cfg #582

Closed
smarie opened this issue Jun 16, 2021 · 3 comments
Closed

Using use_scm_version write_to in setup.cfg #582

smarie opened this issue Jun 16, 2021 · 3 comments

Comments

@smarie
Copy link
Contributor

smarie commented Jun 16, 2021

I love setuptools_scm, I use it in all my libs. I find the write_to option a great way to have the package find its own __version__, using the trick described here.

I adopted last year a practice to place most of the setup information in setup.cfg, it seems to work very well (following this great example)

Until now I was always still placing use_scm_version={"write_to": f"{name}/_version.py"} in the setup.py because it was not supported in setup.cfg. However the name had to be inserted in both files, which is not convenient (For example: here in setup.py and here in setup.cfg).

Digging aroung in the past issues and PR I found #364 and #181 So I thought that maybe the status had evolved now ? Can I now use

use_scm_version = 
    write_to = foo/_version.py

in setup.cfg ? If this is not the recommended way, let me know !
Thanks a lot

@smarie smarie changed the title Using use_scm_version={"write_to": f"{name}/_version.py"} in setup.cfg Using use_scm_version write_to in setup.cfg Jun 16, 2021
@smarie
Copy link
Contributor Author

smarie commented Jun 16, 2021

There may be a workaround: in setup.py it seems possible to use read_configuration to access information from the setup.cfg. So the setup.py can look like

from setuptools import setup
from setuptools.config import read_configuration

conf_dict = read_configuration("setup.cfg")
PKG_NAME = conf_dict['metadata']['name']

setup(
    use_scm_version={"write_to": f"{PKG_NAME}/_version.py"},
)

Therefore moving the use_scm_version statement in the other file is not really useful anymore.
I'm still wondering if there are alternatives or feedback on this approach.

smarie pushed a commit to smarie/python-genbadge that referenced this issue Jun 16, 2021
…single configuration file for all metadata.
@RonnyPfannschmidt
Copy link
Contributor

use pyproject.toml setuptools will not natively support this and i won`t add a own parser in setuptools_scm

configuring setuptools_scm via pyproject.toml is supported since a while

@smarie
Copy link
Contributor Author

smarie commented Jun 16, 2021

So basically what you're saying is that I should place

[tool.setuptools_scm]
write_to = "pkg/_version.py"

in pyproject.toml.

Well this is great but that does not solve my problem :( since the pkg name has to be written twice: once here in the write_to contents, and once in setup.cfg (to fill the name metadata).

Maybe supporting a write_to=auto option, defaulting to <pkg>/_version.py, could do the trick ? Otherwise, supporting metadata variable names in write_to could be another, much more flexible workaround ? At least the package name is super useful.

Until such a solution is available, for those developers wishing to avoid entering the same folder name twice in two different configuration files, the workaround above seems to work. I tested it on https://github.com/smarie/python-genbadge and both in dev and release mode it works.

Thanks again @RonnyPfannschmidt !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants