pydoctor icon indicating copy to clipboard operation
pydoctor copied to clipboard

Improved setup.cfg integration

Open buhtz opened this issue 3 years ago • 4 comments

I don't know in which PEP or somewhere else this is specified but it works well except with pydoctor. It would be great if pydoctor would be enhanced that way when using setup.cfg for its configuration.

The __init__.py of my project specifies all project related meta data like this

# Name of the application
__name__ = 'Buhtzology'

# Version informations
__major__ = 0
__minor__ = 0
__micro__ = 1
__pre_n__ = 1
__pre__ = f'a{__pre_n__}'
__version__ = f'{__major__}.{__minor__}.{__micro__}{__pre__}'

# contact details
__author__ = 'Christian Buhtz'
__author_email__ = '[email protected]'
__maintainer__ = __author__
__maintainer_email__ = __author_email__
__website__ = 'https://codeberg.org/buhtz/buhtzology'

# misc details
__license__ = 'GPL3'

Because of that I can use variables/placeholders in the setup.cfg without repeating the values

[metadata]
name = attr: buhtzology.__name__
version = attr: buhtzology.__version__
author = attr: buhtzology.__author__
author_email = attr: buhtzology.__email__
maintainer = attr: buhtzology.__maintainer__
maintainer_email = attr: buhtzology.__maintainer_email__
description = The authors own toolbox.
long_desription = file: README.md, LICENSE
keywords = data science, pandas, toolbox
license = attr: buhtzology.__license__
license_files = LICENSE.txt
url = attr: buhtzology.__website__

But it doesn't work for pydoctor section in setup.cfg

[tool:pydoctor]
project-name=attr: buhtzology.__name__
make-html=True
html-output=docs/html
docformat=epytext

The value for project-name is not translated image

buhtz avatar May 06 '22 09:05 buhtz

Hello, @Codeberg-AsGithubAlternative-buhtz,

Thanks for the proposition. I think it wouldn’t be too hard to add support for the “attr” keyword in the config field. Using setuptools to parse the config file is not an option, so we’ll have to do the processing manually if we’re going to support this.

tristanlatr avatar May 06 '22 12:05 tristanlatr

Or maybe you see an alternative mechanism to get meta data like version number from a centralized location (__init__.py in my case)?

buhtz avatar May 06 '22 19:05 buhtz

There is no way currently to do this kind of maneuver. Usually people use a wrapper to call pydoctor, either with tox, makefile, or something else. So having support for attr would be good.

tristanlatr avatar May 06 '22 19:05 tristanlatr

Currently i am using a "simple" script that depends on a project with "modern" src-layout.

#!/usr/bin/env python3
"""Generate the documentation with pydoctor.

The applications metadata is extracted from the project itself and given to
pydoctor via commandline arguments. The script assume a project folder in
src-layout and need to run in the docs folder."""

import pathlib
import importlib

DOC_FOLDER = 'docs'

# Make sure the script runs inside the docs folder.
cwd = pathlib.Path.cwd()
if cwd.name != DOC_FOLDER:
    raise RuntimeError(
        f'The script need to run inside the {DOC_FOLDER} folder!')

# Get name of project and name of package
pkg_name = cwd.parent / 'src'
pkg_name = list(filter(lambda p: 'egg-info' not in str(p), pkg_name.glob('*')))
if len(pkg_name) != 1:
    raise ValueError(f'Something unexpected in src-folder. {pkg_name}')
pkg_path = pkg_name[0]
pkg_name = pkg_path.name
prj_name = cwd.parent.name

# get more project meta-data
pkg = importlib.import_module(pkg_name)

# Build commandline arguments
args = [
    f'--project-name={pkg.__name__}',
    f'--project-version={pkg.__version__}',
    f'--project-url={pkg.__website__}',
    f'--html-viewsource-base={pkg.__repository_url__}',
    '--docformat=epytext',
    '--make-html',
    f'--html-output=html',
    f'--project-base-dir=..',
    f'{pkg_path}'
    ]

# Run pydoctor
import pydoctor
import pydoctor.driver
pydoctor.driver.main(args)

buhtz avatar May 06 '22 20:05 buhtz