Skip to content

Commit

Permalink
Merge pull request #172 from metaodi/develop
Browse files Browse the repository at this point in the history
Release 4.2.0
  • Loading branch information
metaodi authored Aug 8, 2024
2 parents 5463019 + 0e60038 commit d4fe54d
Show file tree
Hide file tree
Showing 22 changed files with 539 additions and 220 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Build osmapi
name: Test osmapi package
on:
pull_request:
push:
branches: [master, develop]
jobs:
build:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
Expand All @@ -13,10 +13,10 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -28,5 +28,5 @@ jobs:
pip install -r test-requirements.txt
pip install -e .
- name: Build the package
run: ./build.sh
- name: Test the package
run: ./test.sh
55 changes: 42 additions & 13 deletions .github/workflows/publish_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,57 @@
name: Upload Python Package

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
release:
types: [created]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
sudo apt-get install pandoc
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r test-requirements.txt
pip install -e .
- name: Test the package
run: ./test.sh

deploy:
runs-on: ubuntu-latest
needs: [test]
environment: release
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
pip install setuptools wheel build
- name: Build
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

## [4.2.0] - 2024-08-08
### Added
- Add a new `timeout` parameter to `OsmApi` which allows to set a timeout in seconds (default is 30s) for the API requests (see issue #170, thanks [Mateusz Konieczny](https://github.com/matkoniecz))

### Changed
- Only include `discussion` key in result of `ChangesetGet` if `include_discussion=True` (see issue #163, thanks [Mateusz Konieczny](https://github.com/matkoniecz))
- Update OAuth example in README using [cli-oauth2](https://github.com/Zverik/cli-oauth2) (see PR #169, thanks [Ilya Zverev](https://github.com/Zverik))

## [4.1.0] - 2024-03-19
### Added
- OAuth 2.0 example in README and in the `examples` directory
Expand Down Expand Up @@ -349,7 +357,8 @@ Miroslav Šedivý
- `Fixed` for any bug fixes.
- `Security` to invite users to upgrade in case of vulnerabilities.

[Unreleased]: https://github.com/metaodi/osmapi/compare/v4.1.0...HEAD
[Unreleased]: https://github.com/metaodi/osmapi/compare/v4.2.0...HEAD
[4.2.0]: https://github.com/metaodi/osmapi/compare/v4.1.0...v4.2.0
[4.1.0]: https://github.com/metaodi/osmapi/compare/v4.0.0...v4.1.0
[4.0.0]: https://github.com/metaodi/osmapi/compare/v3.1.0...v4.0.0
[3.1.0]: https://github.com/metaodi/osmapi/compare/v3.0.0...v3.1.0
Expand Down
54 changes: 15 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,66 +71,42 @@ Note: Each line in the password file should have the format _user:password_

### OAuth authentication

Username/Password authentication will be deprecated in 2024 (see [official OWG announcemnt](https://www.openstreetmap.org/user/pnorman/diary/401157) for details).
Username/Password authentication will be deprecated in July 2024
(see [official OWG announcemnt](https://blog.openstreetmap.org/2024/04/17/oauth-1-0a-and-http-basic-auth-shutdown-on-openstreetmap-org/) for details).
In order to use this library in the future, you'll need to use OAuth 2.0.

To use OAuth 2.0, you must register an application with an OpenStreetMap account, either on the [development server](https://master.apis.dev.openstreetmap.org/oauth2/applications) or on the [production server](https://www.openstreetmap.org/oauth2/applications).
To use OAuth 2.0, you must register an application with an OpenStreetMap account, either on the
[development server](https://master.apis.dev.openstreetmap.org/oauth2/applications)
or on the [production server](https://www.openstreetmap.org/oauth2/applications).
Once this registration is done, you'll get a `client_id` and a `client_secret` that you can use to authenticate users.

Example code using [`requests-oauth2client`](https://pypi.org/project/requests-oauth2client/):
Example code using [`cli-oauth2`](https://github.com/Zverik/cli-oauth2) on the development server, replace `OpenStreetMapDevAuth` with `OpenStreetMapAuth` to use the production server:

```python
from requests_oauth2client import OAuth2Client, OAuth2AuthorizationCodeAuth
import requests
import webbrowser
import osmapi
import os
from oauthcli import OpenStreetMapDevAuth

client_id = "<client_id>"
client_secret = "<client_secret>"

# special value for redirect_uri for non-web applications
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
auth = OpenStreetMapDevAuth(
client_id, client_secret, ['read_prefs', 'write_map']
).auth_code()

authorization_base_url = "https://master.apis.dev.openstreetmap.org/oauth2/authorize"
token_url = "https://master.apis.dev.openstreetmap.org/oauth2/token"

oauth2client = OAuth2Client(
token_endpoint=token_url,
authorization_endpoint=authorization_base_url,
redirect_uri=redirect_uri,
client_id=client_id,
client_secret=client_secret,
code_challenge_method=None,
)

# open OSM website to authrorize user using the write_api and write_notes scope
scope = ["write_api", "write_notes"]
az_request = oauth2client.authorization_request(scope=scope)
print(f"Authorize user using this URL: {az_request.uri}")
webbrowser.open(az_request.uri)

# create a new requests session using the OAuth authorization
auth_code = input("Paste the authorization code here: ")
auth = OAuth2AuthorizationCodeAuth(
oauth2client,
auth_code,
redirect_uri=redirect_uri,
)
oauth_session = requests.Session()
oauth_session.auth = auth

# use the custom session
api = osmapi.OsmApi(
api="https://api06.dev.openstreetmap.org",
session=oauth_session
session=auth.session
)

with api.Changeset({"comment": "My first test"}) as changeset_id:
print(f"Part of Changeset {changeset_id}")
node1 = api.NodeCreate({"lon": 1, "lat": 1, "tag": {}})
print(node1)
```

An alternative way using the `requests-oauthlib` library can be found
[in the examples](https://github.com/metaodi/osmapi/blob/develop/examples/oauth2.py).

## Note about imports / automated edits

Scripted imports and automated edits should only be carried out by those with experience and understanding of the way the OpenStreetMap community creates maps, and only with careful **planning** and **consultation** with the local community.
Expand Down
2 changes: 1 addition & 1 deletion docs/osmapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h1 class="modulename">

<details>
<summary>View Source</summary>
<div class="codehilite"><pre><span></span><span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;4.1.0&quot;</span>
<div class="codehilite"><pre><span></span><span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;4.2.0&quot;</span>

<span class="kn">from</span> <span class="nn">.OsmApi</span> <span class="kn">import</span> <span class="o">*</span> <span class="c1"># noqa</span>
<span class="kn">from</span> <span class="nn">.errors</span> <span class="kn">import</span> <span class="o">*</span> <span class="c1"># noqa</span>
Expand Down
Loading

0 comments on commit d4fe54d

Please sign in to comment.