Skip to content

Commit 64e9cda

Browse files
authored
Merge pull request the-library-code#30 from kshepherd/user-agent-and-version
Maintain version centrally, fix non-compliant User-Agent default value
2 parents 1d58e0d + ce2eb1b commit 64e9cda

File tree

9 files changed

+38
-23
lines changed

9 files changed

+38
-23
lines changed

MAINTAINING.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ These notes are for maintenance of the Git / PyPI source and releases / versions
77
All the tasks we need to do, in order, when releasing a new version:
88

99
1. **Check the main branch!** - we should have all the changes we want to include merged/picked and tested
10-
2. **Update setup.py** - this might include other dependency or project description changes, but usually will just be a case of incrementing the version number, e.g. `0.1.9` -> `0.1.10`. Note the new number.
11-
3. **Update publish.sh** - this simple publish script performs the publish to PyPI and will need the new version number
12-
4. **Update CHANGELOG.md** - new versions go at the top of the file. See previous release blocks for formatting. I include a 'thanks' or 'reported by' attribution for PRs contributed or issues reported. The new version number from `setup.py` is used for the heading and the (future) PyPI URL
10+
2. **Update version number** - edit `dspace_rest_client/__init__.py` and update the version. Usually, this will just be a case of incrementing the version number, e.g. `0.1.9` -> `0.1.10`.
11+
3. **Update CHANGELOG.md** - new versions go at the top of the file. See previous release blocks for formatting. I include a 'thanks' or 'reported by' attribution for PRs contributed or issues reported. The new version number is used for the heading and the (future) PyPI URL
1312
4. **Commit release preparation** - once you are happy with the steps above, commit with a message like 'Prepare release 0.1.10'
1413
5. **Push branch** - making sure github is up to date, (in future: CI)
1514
6. **Clear out build and dist directories**: OPTIONAL, but nice to start with a clean Python build environment before making this new version
16-
7. **Run publish script** - this will run `setup.py` to build a new version then upload to PyPI with twine - you will need an API token and publish access in PyPI to do this.
17-
18-
TODO: If we just keep a `version` file around or base builds on a version number extracted from tag name, some of these steps can be more easily automated or derived instead of updated by hand, but for now it's all pretty simple.
15+
7. **Run publish script** - with version number as an argument, e.g. `./publish.sh 0.1.10`. This will run `setup.py` to build a new version then upload to PyPI with twine - you will need an API token and publish access in PyPI to do this.

console.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from dspace_rest_client.client import DSpaceClient
2-
from dspace_rest_client.models import Community, Collection, Item, Bundle, Bitstream
2+
# Import models as needed
3+
#from dspace_rest_client.models import Community, Collection, Item, Bundle, Bitstream
34
import code
4-
import logging
55
import os
66

7-
# The DSpace client will look for the same environment variables but we can also look for them here explicitly
7+
# The DSpace client will look for the same environment variables, but we can also look for them here explicitly
88
# and as an example
99
url = 'http://localhost:8080/server/api'
1010
if 'DSPACE_API_ENDPOINT' in os.environ:

dspace_rest_client/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import *
2+
__version__ = '0.1.12'

dspace_rest_client/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import os
2424
from uuid import UUID
2525
from .models import *
26+
from . import __version__
2627

2728
__all__ = ['DSpaceClient']
2829

@@ -56,7 +57,7 @@ class DSpaceClient:
5657
API_ENDPOINT = 'http://localhost:8080/server/api'
5758
SOLR_ENDPOINT = 'http://localhost:8983/solr'
5859
SOLR_AUTH = None
59-
USER_AGENT = 'DSpace Python REST Client'
60+
USER_AGENT = f'DSpace-Python-REST-Client/{__version__}'
6061
if 'DSPACE_API_ENDPOINT' in os.environ:
6162
API_ENDPOINT = os.environ['DSPACE_API_ENDPOINT']
6263
LOGIN_URL = f'{API_ENDPOINT}/authn/login'

dspace_rest_client/models.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@
99
1010
@author Kim Shepherd <[email protected]>
1111
"""
12-
import code
1312
import json
14-
import logging
15-
16-
import requests
17-
from requests import Request
18-
import os
19-
from uuid import UUID
2013

2114
__all__ = ['DSpaceObject', 'HALResource', 'ExternalDataObject', 'SimpleDSpaceObject', 'Community',
2215
'Collection', 'Item', 'Bundle', 'Bitstream', 'User', 'Group']

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Instantiate DSpace client
2525
# Note the 'fake_user_agent' setting here -- this will set a string like the following, to get by Cloudfront:
2626
# Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
27-
# The default is to *not* fake the user agent, and instead use the default of DSpace Python REST Client.
27+
# The default is to *not* fake the user agent, and instead use the default of DSpace-Python-REST-Client/x.y.z
2828
# To specify a custom user agent, set the USER_AGENT env variable and leave/set fake_user_agent as False
2929
d = DSpaceClient(api_endpoint=url, username=username, password=password, fake_user_agent=True)
3030

example_gets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"""
88

99
from dspace_rest_client.client import DSpaceClient
10-
from dspace_rest_client.models import Community, Collection, Item, Bundle, Bitstream
10+
# Import models as below if needed
11+
#from dspace_rest_client.models import Community, Collection, Item, Bundle, Bitstream
1112

1213
# Example variables needed for authentication and basic API requests
1314
# SET THESE TO MATCH YOUR TEST SYSTEM BEFORE RUNNING THE EXAMPLE SCRIPT
@@ -23,7 +24,7 @@
2324
# Instantiate DSpace client
2425
# Note the 'fake_user_agent' setting here -- this will set a string like the following, to get by Cloudfront:
2526
# Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
26-
# The default is to *not* fake the user agent, and instead use the default of DSpace Python REST Client.
27+
# The default is to *not* fake the user agent, and instead use the default of DSpace-Python-REST-Client/x.y.z.
2728
# To specify a custom user agent, set the USER_AGENT env variable and leave/set fake_user_agent as False
2829
d = DSpaceClient(api_endpoint=url, username=username, password=password, fake_user_agent=True)
2930

publish.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
11
#!/bin/bash
2-
python setup.py bdist_wheel
3-
twine upload --repository dspace-rest-client dist/dspace_rest_client-0.1.12-py3-none-any.whl
2+
3+
version=$1
4+
5+
if ! [[ $version =~ ^[0-9]+\.+[0-9]+\.[0-9]+$ ]]; then
6+
echo "Usage: publish.sh <version>"
7+
echo "Version must match the form x.y.z where all parts are numbers e.g. 0.1.13"
8+
exit 1
9+
fi
10+
11+
echo "Building dspace_rest_client version ${version}"
12+
if ! python setup.py bdist_wheel; then
13+
echo "Error: Failed to build the package"
14+
exit 1
15+
fi
16+
17+
echo "Uploading dspace_rest_client version ${version}"
18+
if ! twine upload --repository dspace-rest-client dist/dspace_rest_client-0.1.13-py3-none-any.whl; then
19+
echo "Error: Failed to upload to PyPI"
20+
exit 1
21+
fi
22+
23+
echo "...done"
24+
exit 0

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import setuptools
2+
from dspace_rest_client import __version__
23

34
with open("README.md", "r") as fh:
45
long_description = fh.read()
56

67
setuptools.setup(
78
name="dspace-rest-client",
8-
version="0.1.12",
9+
version=__version__,
910
author="Kim Shepherd",
1011
author_email="[email protected]",
1112
description="A DSpace 7 REST API client library",

0 commit comments

Comments
 (0)