Skip to content

Commit

Permalink
Remove the setuptools-scm dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Nov 22, 2023
1 parent e9f0cb6 commit 2947d92
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 87 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ venv
/dist
/build
/docs/_build
ops/version.py

# Smoke test artifacts
*.tar.gz
Expand Down
40 changes: 12 additions & 28 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,38 +154,22 @@ All tool configuration is kept in [project.toml](pyproject.toml).
The build backend is [setuptools](https://pypi.org/project/setuptools/), and
the build frontend is [build](https://pypi.org/project/build/).

The version number is automatically generated from Git metadata using the
[setuptools-scm package](https://pypi.org/project/setuptools-scm/). During the
build process, an ``ops/version.py`` is automatically generated so that if you
are running from an installed package (including an editable install), you can
statically access the version:

```python
import ops
print(ops.__version__)
import ops.version
print(ops.version.version_tuple)
```

[This is pretty awful, and it seems like this cannot be the best way to do this]: #

Importing `ops` outside of an install will fail because the generated version
module does not exist. It can be generated using:

```sh
python -c 'import setuptools_scm;conf=setuptools_scm.Configuration.from_file();setuptools_scm.dump_version(conf.root,setuptools_scm.get_version(),conf.version_file,conf.version_file_template)'
```

# Publishing a Release

To make a release of the ops library, do the following:

1. Visit the [releases page on GitHub](https://github.com/canonical/operator/releases).
2. Click "Draft a new release"
3. The "Release Title" is simply the full version number, in the form <major>.<minor>.<patch>
E.g. 2.3.12
4. Drop notes and a changelog in the description.
5. When you are ready, click "Publish". (If you are not ready, click "Save as Draft".)
1. Open a PR to change [version.py][ops/version.py]'s `version` to the
[appropriate string](https://semver.org/), and get that merged to main.
2. Visit the [releases page on GitHub](https://github.com/canonical/operator/releases).
3. Click "Draft a new release"
4. The "Release Title" is simply the full version number, in the form <major>.<minor>.<patch>
and a brief summary of the main changes in the release
E.g. 2.3.12 Bug fixes for the Juju foobar feature when using Python 3.12
5. Drop notes and a changelog in the description.
6. When you are ready, click "Publish". (If you are not ready, click "Save as Draft".)
7. Open a PR to change [version.py][ops/version.py]'s `version` to the expected
next version, with "+dev" appended (for example, if 3.14.1 is the next expected version, use
`'3.14.1.dev0'`).

This will trigger an automatic build for the Python package and publish it to PyPI (authorization is handled via a [Trusted Publisher](https://docs.pypi.org/trusted-publishers/) relationship).

Expand Down
20 changes: 20 additions & 0 deletions ops/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Package version.
This module is NOT to be used when developing charms using ops.
"""

version: str = '2.9.0.dev0'
32 changes: 1 addition & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,52 +42,22 @@ dev = [
"pyright==1.1.317",
"pytest-operator~=0.23",
"coverage[toml]~=7.0",
"setuptools>=60",
"setuptools-scm>=8.0",
"typing_extensions~=4.2",
]

[project.urls]
"Homepage" = "https://juju.is/docs/sdk"
"Repository" = "https://github.com/canonical/operator"
"Issues" = "https://github.com/canonical/operator/issues"
"Documentation" = "https://ops.readthedocs.org"
"Documentation" = "https://ops.readthedocs.io"
"Changelog" = "https://github.com/canonical/operator/blob/main/CHANGES.md"

[build-system]
requires = [
"setuptools>=60",
"setuptools-scm>=8.0",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_file = "ops/version.py"
version_file_template = """
# Copyright 2020 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# file generated by setuptools_scm - don't change, don't track in version control
\"\"\"Package version.\"\"\"
import typing
version: str = {version!r}
version_tuple: typing.Tuple[typing.Union[int, str], ...] = {version_tuple!r}
"""

[tool.pip-tools]
generate-hashes = true
strip-extras = true
Expand Down
14 changes: 2 additions & 12 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,7 @@ oauthlib==3.2.2 \
packaging==23.2 \
--hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \
--hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7
# via
# pytest
# setuptools-scm
# via pytest
paramiko==2.12.0 \
--hash=sha256:376885c05c5d6aa6e1f4608aac2a6b5b0548b1add40274477324605903d9cd49 \
--hash=sha256:b2df1a6325f6996ef55a8789d0462f5b502ea83b3c990cbb5bbe57345c6812c4
Expand Down Expand Up @@ -652,10 +650,6 @@ rsa==4.9 \
--hash=sha256:90260d9058e514786967344d0ef75fa8727eed8a7d2e43ce9f4bcf1b536174f7 \
--hash=sha256:e38464a49c6c85d7f1351b0126661487a7e0a14a50f1675ec50eb34d4f20ef21
# via google-auth
setuptools-scm==8.0.4 \
--hash=sha256:b47844cd2a84b83b3187a5782c71128c28b4c94cad8bfb871da2784a5cb54c4f \
--hash=sha256:b5f43ff6800669595193fd09891564ee9d1d7dcb196cab4b2506d53a2e1c95c7
# via ops (pyproject.toml)
six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
Expand Down Expand Up @@ -693,7 +687,6 @@ typing-extensions==4.8.0 \
--hash=sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef
# via
# ops (pyproject.toml)
# setuptools-scm
# typing-inspect
typing-inspect==0.9.0 \
--hash=sha256:9ee6fc59062311ef8547596ab6b955e1b8aa46242d854bfc78f4f6b0eff35f9f \
Expand Down Expand Up @@ -794,7 +787,4 @@ websockets==12.0 \
setuptools==68.2.2 \
--hash=sha256:4ac1475276d2f1c48684874089fefcd83bd7162ddaafb81fac866ba0db282a87 \
--hash=sha256:b454a35605876da60632df1a60f736524eb73cc47bbc9f3f1ef1b644de74fd2a
# via
# nodeenv
# ops (pyproject.toml)
# setuptools-scm
# via nodeenv
20 changes: 5 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ commands =
[testenv:lint]
description = Check code against coding style standards
deps = pip-tools
commands_pre =
pip-sync {toxinidir}/requirements-dev.txt
python -c 'import setuptools_scm;conf=setuptools_scm.Configuration.from_file();setuptools_scm.dump_version(conf.root,setuptools_scm.get_version(),conf.version_file,conf.version_file_template)'
commands_pre = pip-sync {toxinidir}/requirements-dev.txt
commands =
# pflake8 wrapper suppports config from pyproject.toml
pflake8 {[vars]all_path}
Expand All @@ -53,9 +51,7 @@ commands =
[testenv:static]
description = Run static type checker
deps = pip-tools
commands_pre =
pip-sync {toxinidir}/requirements-dev.txt
python -c 'import setuptools_scm;conf=setuptools_scm.Configuration.from_file();setuptools_scm.dump_version(conf.root,setuptools_scm.get_version(),conf.version_file,conf.version_file_template)'
commands_pre = pip-sync {toxinidir}/requirements-dev.txt
commands =
pyright {posargs}

Expand All @@ -65,9 +61,7 @@ passenv =
RUN_REAL_PEBBLE_TESTS
PEBBLE
deps = pip-tools
commands_pre =
pip-sync {toxinidir}/requirements-dev.txt
python -c 'import setuptools_scm;conf=setuptools_scm.Configuration.from_file();setuptools_scm.dump_version(conf.root,setuptools_scm.get_version(),conf.version_file,conf.version_file_template)'
commands_pre = pip-sync {toxinidir}/requirements-dev.txt
commands =
coverage run --source={[vars]src_path} \
-m pytest --ignore={[vars]tst_path}smoke -v --tb native {posargs}
Expand All @@ -82,9 +76,7 @@ setenv =
PEBBLE=/tmp/pebble
RUN_REAL_PEBBLE_TESTS=1
deps = pip-tools
commands_pre =
pip-sync {toxinidir}/requirements-dev.txt
python -c 'import setuptools_scm;conf=setuptools_scm.Configuration.from_file();setuptools_scm.dump_version(conf.root,setuptools_scm.get_version(),conf.version_file,conf.version_file_template)'
commands_pre = pip-sync {toxinidir}/requirements-dev.txt
commands =
bash -c "umask 0; (pebble run --http=':4000' --create-dirs &>/dev/null & ) ; sleep 1; pytest -v --tb native test/test_real_pebble.py {posargs} ; killall -y 3m pebble"

Expand All @@ -96,9 +88,7 @@ whitelist_externals = juju
deps =
build
pip-tools
commands_pre =
pip-sync {toxinidir}/requirements-dev.txt
python -c 'import setuptools_scm;conf=setuptools_scm.Configuration.from_file();setuptools_scm.dump_version(conf.root,setuptools_scm.get_version(),conf.version_file,conf.version_file_template)'
commands_pre = pip-sync {toxinidir}/requirements-dev.txt
commands =
# Build a source tarball for ops, and drop it into the root directory of the smoke test charm.
bash -c 'rm -vf ./test/charms/test_smoke/*.tar.gz # Cleanup old builds'
Expand Down

0 comments on commit 2947d92

Please sign in to comment.