Skip to content

Commit f8a1284

Browse files
committed
Add __version__ attribute using VERSION file as single source of truth
This implements the requested feature to expose bugsnag.__version__ for programmatic version checking, as per PEP 396. Changes: - Created VERSION file containing current version (4.8.0) - Updated bugsnag/__init__.py to read from VERSION and expose __version__ - Updated setup.py to read version from VERSION file - Updated bugsnag/notifier.py to read version from VERSION file - Added MANIFEST.in to include VERSION in package distributions - Updated CHANGELOG.md with enhancement entry - Updated CONTRIBUTING.md to document simplified release process Benefits: - Single source of truth for version number (no more manual updates in 3 places) - bugsnag.__version__ now available for programmatic access - Graceful fallback to 'unknown' if VERSION file is missing
1 parent a699b7d commit f8a1284

8 files changed

Lines changed: 61 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
## TBD
5+
6+
### Enhancements
7+
8+
* Add `__version__` attribute for programmatic version checking
9+
* Implemented VERSION file as single source of truth for version number
10+
* `bugsnag.__version__` now returns the installed package version
11+
412
## v4.8.0 (2024-07-08)
513

614
### Enhancements

CONTRIBUTING.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,21 @@ If you're on the core team, you can release Bugsnag as follows:
9797
git checkout -b release/v4.x.x
9898
```
9999
100-
* Update the version number in [`setup.py`](./setup.py) and `bugsnag/notifier.py`(./bugsnag/notifier.py)
101-
* Update the CHANGELOG.md and README.md if necessary
100+
* Update the version number in the [`VERSION`](./VERSION) file
101+
102+
```
103+
echo "4.x.x" > VERSION
104+
```
105+
106+
* Update the CHANGELOG.md (add version and date) and README.md if necessary
102107
* Commit and open a pull request into `master`
108+
109+
```
110+
git add VERSION CHANGELOG.md
111+
git commit -m "Release v4.x.x"
112+
git push origin release/v4.x.x
113+
```
114+
103115
* Merge the PR when it's been reviewed
104116
* Create a release on GitHub, tagging the new version `v4.x.x`
105117
* Push the release to PyPI

MANIFEST.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include VERSION
2+
include README.md
3+
include LICENSE.txt
4+
include CHANGELOG.md
5+
include UPGRADING.md
6+
include CONTRIBUTING.md
7+
include SECURITY.md

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.8.0

bugsnag/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from bugsnag.configuration import Configuration, RequestConfiguration
24
from bugsnag.notification import Notification
35
from bugsnag.event import Event
@@ -18,6 +20,14 @@
1820
clear_feature_flag, clear_feature_flags,
1921
aws_lambda_handler)
2022

23+
# Read version from VERSION file
24+
_version_file = os.path.join(os.path.dirname(__file__), '..', 'VERSION')
25+
try:
26+
with open(_version_file, 'r') as f:
27+
__version__ = f.read().strip()
28+
except Exception:
29+
__version__ = 'unknown'
30+
2131
__all__ = ('Client', 'Event', 'Configuration', 'RequestConfiguration',
2232
'configuration', 'configure', 'configure_request',
2333
'add_metadata_tab', 'clear_request_config', 'notify',
@@ -27,4 +37,4 @@
2737
'OnBreadcrumbCallback', 'leave_breadcrumb', 'add_on_breadcrumb',
2838
'remove_on_breadcrumb', 'FeatureFlag', 'add_feature_flag',
2939
'add_feature_flags', 'clear_feature_flag', 'clear_feature_flags',
30-
'aws_lambda_handler')
40+
'aws_lambda_handler', '__version__')

bugsnag/notifier.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import os
2+
3+
# Read version from VERSION file
4+
_version_file = os.path.join(os.path.dirname(__file__), '..', 'VERSION')
5+
try:
6+
with open(_version_file, 'r') as f:
7+
_version = f.read().strip()
8+
except Exception:
9+
_version = 'unknown'
10+
111
_NOTIFIER_INFORMATION = {
212
'name': 'Python Bugsnag Notifier',
313
'url': 'https://github.com/bugsnag/bugsnag-python',
4-
'version': '4.8.0'
14+
'version': _version
515
}

features/support/env.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def current_ip
3636
FileUtils.mkdir(destination) unless File.exist?(destination)
3737

3838
FileUtils.cp_r(
39-
["bugsnag", "setup.py"],
39+
["bugsnag", "setup.py", "VERSION"],
4040
destination,
4141
remove_destination: true # delete destination before copying
4242
)

setup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
and solve your bugs as fast as possible.
1111
"""
1212

13+
import os
1314
from setuptools import setup, find_packages
1415

16+
# Read version from VERSION file
17+
with open(os.path.join(os.path.dirname(__file__), 'VERSION'), 'r') as f:
18+
version = f.read().strip()
19+
1520
setup(
1621
name='bugsnag',
17-
version='4.8.0',
22+
version=version,
1823
description='Automatic error monitoring for django, flask, etc.',
1924
long_description=__doc__,
2025
author='Simon Maynard',
@@ -48,6 +53,6 @@
4853
test_suite='tests',
4954
install_requires=['webob'],
5055
extras_require={
51-
'flask': ['flask', 'blinker']
52-
},
56+
'flask': []
57+
}
5358
)

0 commit comments

Comments
 (0)