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

Simplify single source #1580

Merged
merged 50 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
342f9eb
updated single_source_version with a much simpler page -- essentially
ChrisBarker-NOAA Jul 25, 2024
ce0d4bc
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 25, 2024
6cd1b9b
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 25, 2024
dbac235
Added links to build tools
ChrisBarker-NOAA Jul 25, 2024
438198f
swap prefer for require
ChrisBarker-NOAA Jul 25, 2024
51e2c23
replace text about __version__
ChrisBarker-NOAA Jul 25, 2024
6d4aeb3
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 26, 2024
49e743d
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 26, 2024
0598c69
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 26, 2024
2a32499
updated the __version__ description
ChrisBarker-NOAA Jul 26, 2024
d1cbce9
a few suggestions from the PR discussion
ChrisBarker-NOAA Jul 30, 2024
0fc5aca
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
7d60695
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
28c8bcb
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
00d8645
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
50a588f
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
db4e988
minor formatting edit
ChrisBarker-NOAA Jul 30, 2024
83c7f24
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 31, 2024
a1df94c
a few more edits from the PR comments, and adding it back to the inde…
ChrisBarker-NOAA Jul 31, 2024
ba32cc6
added single_source page back in -- not sure if it's the right section.
ChrisBarker-NOAA Jul 31, 2024
476f916
updated single_source_version with a much simpler page -- essentially
ChrisBarker-NOAA Jul 25, 2024
0512c22
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 25, 2024
892d045
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 25, 2024
6db49ef
Added links to build tools
ChrisBarker-NOAA Jul 25, 2024
afa38c4
swap prefer for require
ChrisBarker-NOAA Jul 25, 2024
b9bb45d
replace text about __version__
ChrisBarker-NOAA Jul 25, 2024
6359083
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 26, 2024
e6b0ed9
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 26, 2024
54906da
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 26, 2024
398b4fb
updated the __version__ description
ChrisBarker-NOAA Jul 26, 2024
e7d2369
a few suggestions from the PR discussion
ChrisBarker-NOAA Jul 30, 2024
0ff8c16
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
8529ada
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
840474d
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
61dc0b8
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
f932935
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 30, 2024
ae2ad09
minor formatting edit
ChrisBarker-NOAA Jul 30, 2024
01f66a9
Update source/single_source_version.rst
ChrisBarker-NOAA Jul 31, 2024
9d353a7
a few more edits from the PR comments, and adding it back to the inde…
ChrisBarker-NOAA Jul 31, 2024
1aae700
added single_source page back in -- not sure if it's the right section.
ChrisBarker-NOAA Jul 31, 2024
6d72810
Merge branch 'simplify_single_source' of https://github.com/ChrisBark…
ChrisBarker-NOAA Aug 1, 2024
f130e81
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 1, 2024
0aefb9e
Update source/discussions/single_source_version.rst
ChrisBarker-NOAA Aug 21, 2024
2aee101
Merge branch 'pypa:main' into simplify_single_source
ChrisBarker-NOAA Aug 21, 2024
3b05459
normalized the page file name
ChrisBarker-NOAA Aug 22, 2024
c335757
Update source/discussions/single-source-version.rst
ChrisBarker-NOAA Aug 22, 2024
b35bd14
Update source/discussions/single-source-version.rst
ChrisBarker-NOAA Aug 22, 2024
e0cb805
Update source/discussions/single-source-version.rst
ChrisBarker-NOAA Aug 22, 2024
b120a51
Make the single-sourcing discussion label unique
webknjaz Aug 24, 2024
4d7e33a
🇺🇦 Set the last-reviewed date in the single-sourced version discussion
webknjaz Aug 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/discussions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ specific topic. If you're just trying to get stuff done, see
package-formats
src-layout-vs-flat-layout
setup-py-deprecated
single-source-version
47 changes: 47 additions & 0 deletions source/discussions/single-source-version.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. _`Single sourcing the version discussion`:

===================================
Single-sourcing the Project Version
===================================

:Page Status: Complete
:Last Reviewed: 2024-08-24

One of the challenges in building packages is that the version string can be required in multiple places.

* It needs to be specified when building the package (e.g. in :file:`pyproject.toml`)
This will make it available in the installed package’s metadata, from where it will be accessible at runtime using ``importlib.metadata.version("distribution_name")``.

* A package may set a module attribute (e.g., ``__version__``) to provide an alternative means of runtime access to the version of the imported package. If this is done, the value of the attribute and that used by the build system to set the distribution's version should be kept in sync in :ref:`the build systems's recommended way <Build system version handling>`.

* If the code is in in a version control system (VCS), e.g. Git, the version may appear in a *tag* such as ``v1.2.3``.

To ensure that version numbers do not get out of sync, it is recommended that there is a single source of truth for the version number.

In general, the options are:

1) If the code is in a version control system (VCS), e.g. Git, then the version can be extracted from the VCS.

2) The version can be hard-coded into the :file:`pyproject.toml` file -- and the build system can copy it into other locations it may be required.

3) The version string can be hard-coded into the source code -- either in a special purpose file, such as :file:`_version.txt`, or as a attribute in a module, such as :file:`__init__.py`, and the build system can extract it at build time.


Consult your build system's documentation for their recommended method.

.. _Build system version handling:

Build System Version Handling
-----------------------------

The following are links to some build system's documentation for handling version strings.

* `Flit <https://flit.pypa.io/en/stable/>`_

* `Hatchling <https://hatch.pypa.io/1.9/version/>`_

* `PDM <https://pdm-project.org/en/latest/reference/pep621/#__tabbed_1_2>`_

* `Setuptools <https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata>`_

- `setuptools_scm <https://setuptools-scm.readthedocs.io/en/latest/>`_
Loading