Skip to content

Commit 866d1ec

Browse files
committed
Add __version__ attribute with Makefile-based version management
Implements bugsnag.__version__ for programmatic version checking (PEP 396). Uses Makefile approach (inspired by bugsnag-cocoa) to address performance concerns. Changes: - Added __version__ = '4.8.0' to bugsnag/__init__.py - Hardcoded version='4.8.0' in setup.py - Hardcoded 'version': '4.8.0' in bugsnag/notifier.py - Added Makefile with bump target for automated version updates - Updated CHANGELOG.md with enhancement entry - Updated CONTRIBUTING.md to document Makefile usage - Removed VERSION file and MANIFEST.in (no runtime file I/O overhead) - Updated features/support/env.rb (removed VERSION from test fixtures) Usage: - Users: bugsnag.__version__ returns '4.8.0' - Maintainers: make VERSION=x.y.z bump (updates all 3 files) Benefits: - Zero runtime overhead (no file I/O during import) - bugsnag.__version__ attribute now available - Automated version updates via single Makefile command - Addresses reviewer feedback on performance concerns
1 parent f8a1284 commit 866d1ec

9 files changed

Lines changed: 20 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Changelog
66
### Enhancements
77

88
* Add `__version__` attribute for programmatic version checking
9-
* Implemented VERSION file as single source of truth for version number
109
* `bugsnag.__version__` now returns the installed package version
10+
* Follows PEP 396 specification
1111

1212
## v4.8.0 (2024-07-08)
1313

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ 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 the [`VERSION`](./VERSION) file
100+
* Update the version number using the Makefile
101101
102102
```
103-
echo "4.x.x" > VERSION
103+
make VERSION=4.x.x bump
104104
```
105105
106106
* Update the CHANGELOG.md (add version and date) and README.md if necessary
107107
* Commit and open a pull request into `master`
108108
109109
```
110-
git add VERSION CHANGELOG.md
110+
git add bugsnag/__init__.py setup.py bugsnag/notifier.py CHANGELOG.md
111111
git commit -m "Release v4.x.x"
112112
git push origin release/v4.x.x
113113
```

MANIFEST.in

Lines changed: 0 additions & 7 deletions
This file was deleted.

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.PHONY: bump
2+
3+
bump: ## Bump the version numbers to $VERSION
4+
ifeq ($(VERSION),)
5+
@$(error VERSION is not defined. Run with `make VERSION=number bump`)
6+
endif
7+
@echo Bumping the version number to $(VERSION)
8+
@sed -i.bak "s/__version__ = '.*'/__version__ = '$(VERSION)'/" bugsnag/__init__.py && rm bugsnag/__init__.py.bak
9+
@sed -i.bak "s/version='.*',/version='$(VERSION)',/" setup.py && rm setup.py.bak
10+
@sed -i.bak "s/'version': '.*'/'version': '$(VERSION)'/" bugsnag/notifier.py && rm bugsnag/notifier.py.bak
11+
@echo "Successfully bumped version to $(VERSION)"
12+
@echo "Updated files: bugsnag/__init__.py, setup.py, bugsnag/notifier.py"

VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

bugsnag/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
from bugsnag.configuration import Configuration, RequestConfiguration
42
from bugsnag.notification import Notification
53
from bugsnag.event import Event
@@ -20,13 +18,7 @@
2018
clear_feature_flag, clear_feature_flags,
2119
aws_lambda_handler)
2220

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'
21+
__version__ = '4.8.0'
3022

3123
__all__ = ('Client', 'Event', 'Configuration', 'RequestConfiguration',
3224
'configuration', 'configure', 'configure_request',

bugsnag/notifier.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
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 = {
122
'name': 'Python Bugsnag Notifier',
133
'url': 'https://github.com/bugsnag/bugsnag-python',
14-
'version': _version
4+
'version': '4.8.0'
155
}

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", "VERSION"],
39+
["bugsnag", "setup.py"],
4040
destination,
4141
remove_destination: true # delete destination before copying
4242
)

setup.py

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

13-
import os
1413
from setuptools import setup, find_packages
1514

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-
2015
setup(
2116
name='bugsnag',
22-
version=version,
17+
version='4.8.0',
2318
description='Automatic error monitoring for django, flask, etc.',
2419
long_description=__doc__,
2520
author='Simon Maynard',

0 commit comments

Comments
 (0)