5

I have a project where I manage the version through git tags. Then, I use setuptools_scm to get this information in my setup.py and also generates a file (_version.py) that gets included when generating the wheel for pip.

This file is not tracked by git since:

  1. it has the same information that can be gathered by git
  2. it would create a circular situation where building the wheel will modify the version which changes the sources and a new version will be generated

Now, when I build the documentation, it becomes natural to fetch this version from _version.py and this all works well locally.

However, when I try to do this within ReadTheDocs, the building of the documentation fails because _version.py is not tracked by git, so ReadTheDocs does not find it when fetching the sources from the repository.


EDIT: I have tried to use the method proposed in the duplicate, which is the same as what setuptools_scm indicate in the documentation, i.e. using in docs/conf.py:

from pkg_resources import get_distribution
__version__ = get_distribution('numeral').version
... # I use __version__ to define Sphinx variables

but I get:

pkg_resources.DistributionNotFound: The 'numeral' distribution was not found and is required by the application

(Again, building the documentation locally works correctly.)


How could I solve this issue without resorting to maintaining the version number in two places?

gerrit
  • 24,025
  • 17
  • 97
  • 170
norok2
  • 25,683
  • 4
  • 73
  • 99
  • Does this answer your question? [readthedocs and setuptools scm version wrong](https://stackoverflow.com/questions/35811267/readthedocs-and-setuptools-scm-version-wrong) – sinoroc Apr 11 '20 at 21:45
  • @sinoroc Thanks for the suggestion, but it seems to be a different issue. I do not get the version **at all**. – norok2 Apr 12 '20 at 11:55
  • 1
    What's your `readthedocs.yml` and how exactly is `_version.py` generated? Do you overwrite `setuptools_scm` defaults? – hoefling Apr 12 '20 at 12:06
  • I have never used a similar setup. But from what I understood of the instructions, the intention seems to be to just ignore the `_version.py` automatically generated by `setuptools_scm` and write your own solution with `import pkg_resources; pkg_resources.get_distribution('myproject').version` instead. Actually nowadays I would use the following: [`import importlib_metadata; importlib_metadata.version('myproject')`](https://docs.python.org/3/library/importlib.metadata.html#distribution-versions). – sinoroc Apr 12 '20 at 15:30
  • On the other hand, is there really anything to do? `readthedocs.org` seems to fetch version numbers from the _git_ tags, similar to how `setuptools_scm` does it, so both should end up with the same version number, and it should be all fine. Am I misunderstanding something? Could you clarify the following bit: "_Now, when I build the documentation, it becomes natural to fetch this version from `_version.py`_"? – sinoroc Apr 12 '20 at 16:30
  • @sinoroc I meant that I was expecting read-the-docs to build my package and hence to have `_version.py` somewhere. Anyway I solved the issue, thanks for the hints and investigating this for me :-) – norok2 Apr 12 '20 at 17:56
  • @hoefling I do not have a `readthedocs.yml`. `_version.py` is generated via `use_scm_version=dict(write_to=...)` in `setup.py` (by `setuptools_scm`). I am learning now that `readthedocs.yml` is the preferred way of configuring the service. I was expecting this to pop out during the sign-up process. – norok2 Apr 12 '20 at 18:02

1 Answers1

4

Eventually the issue was that ReadTheDocs did not have the option to build my package active by default and I was expecting this to happen.

All I had to do was to enable "Install Project" in the Advanced Settings / Default Settings.

norok2
  • 25,683
  • 4
  • 73
  • 99