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

Single location for package version number. #29

Closed
wants to merge 3 commits into from
Closed

Conversation

asolis
Copy link
Contributor

@asolis asolis commented May 27, 2022

The current package version is repeated across setup.cfg and sphinx/conf.py configuration.
This creates developer overhead by sync and updating both files while creating documentation and/or packaging.

Suggestion:modify package version should be in just one place and have sphinx and setup.cfg sync with it.
The proposal is to place the __version___ value it in the __init__.py file of the default top-level package name. Accessible by: {{ cookiecutter.package_name }}.__version__

Note: this issue has been combined with creating a top level package folder (Issue #6). Necessary for easy access form setup.cfg and sphinx/conf.py.

Changes:

  1. Create cookiecutter variable {{ cookiecutter.package_name }} by replacing "-" for "_" from project name.
    No sure if that's the most secure way. Let's discuss about it

  2. Create a {{ cookiecutter.package_name }}.init.py with content

    __version__ = "{{ cookiecutter.project_version }}"
  3. Modify setup.cfg to read version from attr: {{ cookiecutter.package_name }}.__version__

  4. Modify conf.py to import {{ cookiecutter.package_name }}`` and read version from {{ cookiecutter.package_name }}.version```

Closes #6
@ToucheSir FYI, brainstorming if there could be an improvement to this feature

@asolis asolis added the enhancement New feature or request label May 27, 2022
@asolis asolis requested a review from goatsweater May 27, 2022 14:14
@asolis asolis assigned asolis and goatsweater and unassigned asolis May 27, 2022
@ToucheSir
Copy link
Contributor

This makes sense to me. It may be possible to centralize version metadata in pyproject.toml, but that is contingent on using Python >= 3.8. Likewise making it available from Sphinx requires either reading the correct TOML field yourself or a third-party library like https://github.com/sphinx-toolbox/sphinx-pyproject.

asolis added 2 commits May 27, 2022 15:04
Updated conf.py to point to the correct ```src``` folder.
 PEP8: solving - E402 module level import not at top of file
@asolis
Copy link
Contributor Author

asolis commented May 27, 2022

I found that this solution is creating a bit of a problem if you want to use it without installing the package editable or not.
In order to read the __version__ from the top-level package, we need to set PYTHONPATH pointing to src. If we do this inside conf.py violates PEP8 : E402 and flake8 won't allow you to commit.
Using pip install is a 'solution' but creates the same problem of checking who is installed. Would like to make it possible via just make docs.

@asolis
Copy link
Contributor Author

asolis commented May 27, 2022

It seems that a possible cleaner solution would be to integrate Sphinx with setup.cfg directly
https://www.sphinx-doc.org/en/master/usage/advanced/setuptools.html

@asolis
Copy link
Contributor Author

asolis commented May 30, 2022

The simplest solution if we decide to keep a top level package is to include conf.py to the list of file exclusions from flake8. It's actually being recommended by the flake8 configuration page. The reason is that sphinx conf.py recommends to modify sys.path dynamically in their file, and PEP E402 doesn't.

Not completely sure if we would like to go for a top-level package template. If that's the decision we could keep this. If we vote for not keeping a top-level package we still should include the conf.py in the exclusion list of flake8, and point to "../src" instead of ".." (I believe that is a typo in the current version of conf.py)

If not top-level package then setup.cfg o pyproject.toml , needs to share the version with sphinx.

@goatsweater
Copy link
Contributor

Setuptools integration is deprecated, and I think we're converging on a solution in #30. Closing this for now and we can reopen if the other solution doesn't pan out.

@goatsweater goatsweater closed this Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

src to project_name
3 participants