ofek / hatch-vcs

Hatch plugin for versioning with your preferred VCS
MIT License
110 stars 15 forks source link

getting the package version on a separate branch (gh-pages) in an editable install #39

Closed raamana closed 1 year ago

raamana commented 1 year ago

I am adopting hatch and hatch-vcs for everything, and so far am able to release many of my packages. One issue I ran into is when I am generating docs via Sphinx to be deployed onto github pages. I do this by running Sphinx make html locally, and then pushing the html to the gh-pages. Now that pkg/_version.py is removed from the repo, I won't have access to it on gh-pages locally, in an editable install. I am wondering if you have any solution or tips for this.

For now I can get around the issue by manually setting the version tag inside the docs/conf.py, but ideally I want it to be automatic reflecting what has been built/distributed by hatch to pypi. Thanks.

RonnyPfannschmidt commented 1 year ago

the recommendaton from setuptools_scm is to use importlib metadata to get the version metadata from the installed package

ofek commented 1 year ago

Can you explain why the file was removed from the repo and also how it was working before?

raamana commented 1 year ago

the recommendaton from setuptools_scm is to use importlib metadata to get the version metadata from the installed package

Hi @RonnyPfannschmidt , can you point me to an example if you know of any?

@ofek , here is an example of the setup I have: https://github.com/raamana/visualqc/blob/2b828ad97cf849ee4bd16d3bedba62cb5661e0b8/pyproject.toml#L72

before I had setup.py and versioneer.py, which relied on the visualqc/_version.py to provide the version info when I do

from visualqc import __version__

I git rm visualqc/_version.py and added it to .gitignore when moving to pyproject.toml, as suggested somewhere. Perhaps I shouldn't?

ofek commented 1 year ago

You can still do that https://github.com/ofek/hatch-vcs#build-hook

raamana commented 1 year ago

I think this would work for me inside docs/conf.py on gh-pages, although I'd have to uninstall and reinstall the latest editable version to get it to match with hatch version on master

from importlib.metadata import version
version = version(project)

thanks guys.