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

Improved setup.cfg integration #562

Open
buhtz opened this issue May 6, 2022 · 4 comments
Open

Improved setup.cfg integration #562

buhtz opened this issue May 6, 2022 · 4 comments

Comments

@buhtz
Copy link
Contributor

buhtz commented May 6, 2022

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

@tristanlatr
Copy link
Contributor

tristanlatr commented May 6, 2022

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.

@buhtz
Copy link
Contributor Author

buhtz commented May 6, 2022

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

@tristanlatr
Copy link
Contributor

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.

@buhtz
Copy link
Contributor Author

buhtz commented May 6, 2022

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)

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