FactoryBoy / factory_boy

A test fixtures replacement for Python
https://factoryboy.readthedocs.io/
MIT License
3.52k stars 398 forks source link

3.2.0: build_sphinx setuptools target fails #865

Closed kloczek closed 3 years ago

kloczek commented 3 years ago

Looks like in copy.py is missing path to factory_boy module code.

[tkloczko@barrel factory_boy-3.2.0]$ /usr/bin/python3 setup.py build_sphinx -b man
running build_sphinx
Running Sphinx v4.0.2

Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/factory_boy-3.2.0/factory/__init__.py", line 76, in <module>
    __version__ = version("factory_boy")
  File "/usr/lib64/python3.8/importlib/metadata.py", line 530, in version
    return distribution(distribution_name).version
  File "/usr/lib64/python3.8/importlib/metadata.py", line 503, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib64/python3.8/importlib/metadata.py", line 177, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: factory_boy

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 323, in eval_config_file
    exec(code, namespace)
  File "/home/tkloczko/rpmbuild/BUILD/factory_boy-3.2.0/docs/conf.py", line 12, in <module>
    import factory
  File "/home/tkloczko/rpmbuild/BUILD/factory_boy-3.2.0/factory/__init__.py", line 80, in <module>
    __version__ = pkg_resources.get_distribution("factory_boy").version
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 482, in get_distribution
    dist = get_provider(dist)
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 358, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 901, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 787, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'factory_boy' distribution was not found and is required by the application
kloczek commented 3 years ago

Looks like in project root there is no factory_boy directory. Probably renama factory to factory_boy could solve that issue (but I'm not sure).

rbarrois commented 3 years ago

Thanks for the report!

Indeed, it might be confusing: factory_boy uses the factory_boy distribution name, but installs the factory package.

However, I'm surprised at the way you're trying to build the doc: we use make doc to that end (which ends up calling sphinx-build with the right flags)

kloczek commented 3 years ago

Thanks for the report!

Indeed, it might be confusing: factory_boy uses the factory_boy distribution name, but installs the factory package.

However, I'm surprised at the way you're trying to build the doc: we use make doc to that end (which ends up calling sphinx-build with the right flags)

That is how I'm generating man pages for all my rpm packages with python mopduules and that way should be somehow supported as factory_boy source tree is using setuptools 😋 It is all about using some standards 🤪

rbarrois commented 3 years ago

That's indeed interesting; do you have some pointer to the docs of that entrypoint / CLI? It's the first time I hear about it, so I don't know where to start looking to comply to said standards :/

kloczek commented 3 years ago

That way is build-in in setuptools module. Just try to execute python setup.py --help-commands in your project root directory to see full set of setuptools commands

rbarrois commented 3 years ago

It's actually provided by Sphinx: https://www.sphinx-doc.org/en/master/usage/advanced/setuptools.html

However, I see no issue running the command locally:

$ python -m venv venv
$ . ./venv/bin/activate
$ pip install -e .[dev,doc]
# ...
$ python setup.py build_sphinx -b man
running build_sphinx
...
Writing... factoryboy.1 { introduction reference orms recipes fuzzy examples internals changelog credits ideas } done
build succeeded.

The manual pages are in build/sphinx/man.
rbarrois commented 3 years ago

As a side note, how do you setup your work environment? The factory/__init__.py file expects the package to be installed in the current environment, that's why we start with a pip install --editable ..

kloczek commented 3 years ago

All what is needed is run egg_info before bnuild documentation (yes that is equivalent of the p install -e . which is simpletr and lighter than using pip). With that it builds correctly:

+ /usr/bin/python3 setup.py build_sphinx -b man --build-dir build/sphinx
running build_sphinx
Running Sphinx v4.1.2
making output directory... done
loading intersphinx inventory from https://docs.python.org/objects.inv...
loading intersphinx inventory from https://docs.djangoproject.com/en/dev/_objects/...
loading intersphinx inventory from https://docs.sqlalchemy.org/en/latest/objects.inv...
intersphinx inventory has moved: https://docs.python.org/objects.inv -> https://docs.python.org/3/objects.inv
intersphinx inventory has moved: https://docs.sqlalchemy.org/en/latest/objects.inv -> https://docs.sqlalchemy.org/en/14/objects.inv
building [mo]: targets for 0 po files that are out of date
building [man]: all manpages
updating environment: [new config] 11 added, 0 changed, 0 removed
reading sources... [100%] reference
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
writing... python-factory-boy.3 { introduction reference orms recipes fuzzy examples internals changelog credits ideas } done
build succeeded.

The manual pages are in build/sphinx/man.

Closing

rbarrois commented 3 years ago

Oh, that's a nice fix, thanks for letting us know how you fixed it!

kloczek commented 3 years ago

BTW you can change: https://github.com/FactoryBoy/factory_boy/commit/00bd29292bd99aca4b8659bece464ed30c200c22#diff-7b3ed02bc73dc06b7db906cf97aa91dec2b2eb21f2d92bc5caa761df5bbc168fR442-R443 tu just:

python setup.py egg_info make_sphinx -b <output_format>

With that Makefile is not needed :)