diff --git a/.github/scripts/install.sh b/.github/scripts/install.sh index 5cd76712..a585594c 100755 --- a/.github/scripts/install.sh +++ b/.github/scripts/install.sh @@ -6,8 +6,9 @@ if ! python3 -m pip --version; then curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py sudo python3 get-pip.py sudo python3 -m pip install --upgrade setuptools - sudo python3 -m pip install nox + sudo python3 -m pip install nox twine else sudo python3 -m pip install --upgrade setuptools python3 -m pip install nox + python3 -m pip install --prefer-binary twine fi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index a0ea83af..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2020 Google LLC -# -# 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. - -# A workflow that pushes artifacts to Sonatype -name: Publish - -on: - push: - tags: - - '*' - repository_dispatch: - types: [publish] - -jobs: - publish: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Python - uses: "actions/setup-python@v1" - with: - python-version: "3.6" - - - name: Install dependencies - run: ./.github/scripts/install.sh - - - name: Run distribution - run: python3 -m nox -e distribution - - - name: Deploy to PyPi - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.PYPI_PASSWORD }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bebedf46..f5704229 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,11 +19,21 @@ on: jobs: release: runs-on: ubuntu-latest + env: + PYTHONDONTWRITEBYTECODE: 1 steps: + - name: Setup Python + uses: "actions/setup-python@v1" + with: + python-version: "3.9" - name: Checkout uses: actions/checkout@v2 with: token: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO }} + - name: Install dependencies + run: ./.github/scripts/install.sh + - name: Run distribution + run: python3 -m nox -e distribution - name: Semantic Release uses: cycjimmy/semantic-release-action@v2 with: @@ -31,7 +41,10 @@ jobs: "@semantic-release/commit-analyzer" "@semantic-release/release-notes-generator" "@google/semantic-release-replace-plugin" - "@semantic-release/git - "@semantic-release/github + "@semantic-release/exec" + "@semantic-release/git" + "@semantic-release/github" env: GH_TOKEN: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO }} + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} diff --git a/.releaserc b/.releaserc index 981e4031..15fa5beb 100644 --- a/.releaserc +++ b/.releaserc @@ -11,8 +11,11 @@ plugins: to: "__version__ = \"${nextRelease.version}\"" - files: - "./setup.py" - from: "version=\".*\"" - to: "version=\"${nextRelease.version}\"" + from: 'version=".*"' + to: 'version="${nextRelease.version}"' + - - "@semantic-release/exec" + - prepareCmd: "python3 setup.py sdist && python3 -m twine check dist/*" + publishCmd: "python3 -m twine upload dist/*" - - "@semantic-release/git" - assets: - "./googlemaps/__init__.py" diff --git a/googlemaps/__init__.py b/googlemaps/__init__.py index 2bf13650..937db7ee 100644 --- a/googlemaps/__init__.py +++ b/googlemaps/__init__.py @@ -15,7 +15,7 @@ # the License. # -__version__ = "4.4.4" +__version__ = "4.4.5" from googlemaps.client import Client from googlemaps import exceptions diff --git a/googlemaps/directions.py b/googlemaps/directions.py index b38a4cdf..353145cc 100644 --- a/googlemaps/directions.py +++ b/googlemaps/directions.py @@ -33,7 +33,7 @@ def directions(client, origin, destination, :param destination: The address or latitude/longitude value from which you wish to calculate directions. You can use a place_id as destination - by putting 'place_id:' as a preffix in the passing parameter. + by putting 'place_id:' as a prefix in the passing parameter. :type destination: string, dict, list, or tuple :param mode: Specifies the mode of transport to use when calculating diff --git a/googlemaps/distance_matrix.py b/googlemaps/distance_matrix.py index 1d848253..a30cbe09 100755 --- a/googlemaps/distance_matrix.py +++ b/googlemaps/distance_matrix.py @@ -26,17 +26,19 @@ def distance_matrix(client, origins, destinations, transit_routing_preference=None, traffic_model=None, region=None): """ Gets travel distance and time for a matrix of origins and destinations. - :param origins: One or more locations and/or latitude/longitude values, - from which to calculate distance and time. If you pass an address as - a string, the service will geocode the string and convert it to a + :param origins: One or more addresses, Place IDs, and/or latitude/longitude + values, from which to calculate distance and time. Each Place ID string + must be prepended with 'place_id:'. If you pass an address as a string, + the service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. :type origins: a single location, or a list of locations, where a location is a string, dict, list, or tuple - :param destinations: One or more addresses and/or lat/lng values, to - which to calculate distance and time. If you pass an address as a - string, the service will geocode the string and convert it to a - latitude/longitude coordinate to calculate directions. + :param destinations: One or more addresses, Place IDs, and/or lat/lng values + , to which to calculate distance and time. Each Place ID string must be + prepended with 'place_id:'. If you pass an address as a string, the + service will geocode the string and convert it to a latitude/longitude + coordinate to calculate directions. :type destinations: a single location, or a list of locations, where a location is a string, dict, list, or tuple diff --git a/googlemaps/places.py b/googlemaps/places.py index e288dc91..91c14dfe 100644 --- a/googlemaps/places.py +++ b/googlemaps/places.py @@ -501,6 +501,7 @@ def places_autocomplete( input_text, session_token=None, offset=None, + origin=None, location=None, radius=None, language=None, @@ -525,6 +526,12 @@ def places_autocomplete( service will match on 'Goo'. :type offset: int + :param origin: The origin point from which to calculate straight-line distance + to the destination (returned as distance_meters). + If this value is omitted, straight-line distance will + not be returned. + :type origin: string, dict, list, or tuple + :param location: The latitude/longitude value for which you wish to obtain the closest, human-readable address. :type location: string, dict, list, or tuple @@ -558,6 +565,7 @@ def places_autocomplete( input_text, session_token=session_token, offset=offset, + origin=origin, location=location, radius=radius, language=language, @@ -611,6 +619,7 @@ def _autocomplete( input_text, session_token=None, offset=None, + origin=None, location=None, radius=None, language=None, @@ -629,6 +638,8 @@ def _autocomplete( params["sessiontoken"] = session_token if offset: params["offset"] = offset + if origin: + params["origin"] = convert.latlng(origin) if location: params["location"] = convert.latlng(location) if radius: diff --git a/setup.py b/setup.py index f7089df2..bda02c1f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="googlemaps", - version="4.4.4", + version="4.4.5", description="Python client library for Google Maps Platform", long_description=readme + changelog, long_description_content_type="text/markdown", diff --git a/tests/test_distance_matrix.py b/tests/test_distance_matrix.py index a906f8ce..6946782e 100644 --- a/tests/test_distance_matrix.py +++ b/tests/test_distance_matrix.py @@ -84,7 +84,10 @@ def test_mixed_params(self): content_type="application/json", ) - origins = ["Bobcaygeon ON", [41.43206, -81.38992]] + origins = [ + "Bobcaygeon ON", [41.43206, -81.38992], + "place_id:ChIJ7cv00DwsDogRAMDACa2m4K8" + ] destinations = [ (43.012486, -83.6964149), {"lat": 42.8863855, "lng": -78.8781627}, @@ -95,7 +98,8 @@ def test_mixed_params(self): self.assertEqual(1, len(responses.calls)) self.assertURLEqual( "https://maps.googleapis.com/maps/api/distancematrix/json?" - "key=%s&origins=Bobcaygeon+ON%%7C41.43206%%2C-81.38992&" + "key=%s&origins=Bobcaygeon+ON%%7C41.43206%%2C-81.38992%%7C" + "place_id%%3AChIJ7cv00DwsDogRAMDACa2m4K8&" "destinations=43.012486%%2C-83.6964149%%7C42.8863855%%2C" "-78.8781627" % self.key, responses.calls[0].request.url, @@ -181,3 +185,34 @@ def test_lang_param(self): "destinations=San+Francisco%%7CVictoria+BC" % self.key, responses.calls[0].request.url, ) + @responses.activate + def test_place_id_param(self): + responses.add( + responses.GET, + "https://maps.googleapis.com/maps/api/distancematrix/json", + body='{"status":"OK","rows":[]}', + status=200, + content_type="application/json", + ) + + origins = [ + 'place_id:ChIJ7cv00DwsDogRAMDACa2m4K8', + 'place_id:ChIJzxcfI6qAa4cR1jaKJ_j0jhE', + ] + destinations = [ + 'place_id:ChIJPZDrEzLsZIgRoNrpodC5P30', + 'place_id:ChIJjQmTaV0E9YgRC2MLmS_e_mY', + ] + + matrix = self.client.distance_matrix(origins, destinations) + + self.assertEqual(1, len(responses.calls)) + self.assertURLEqual( + "https://maps.googleapis.com/maps/api/distancematrix/json?" + "key=%s&" + "origins=place_id%%3AChIJ7cv00DwsDogRAMDACa2m4K8%%7C" + "place_id%%3AChIJzxcfI6qAa4cR1jaKJ_j0jhE&" + "destinations=place_id%%3AChIJPZDrEzLsZIgRoNrpodC5P30%%7C" + "place_id%%3AChIJjQmTaV0E9YgRC2MLmS_e_mY" % self.key, + responses.calls[0].request.url, + ) diff --git a/tests/test_places.py b/tests/test_places.py index 5316fe8e..50781773 100644 --- a/tests/test_places.py +++ b/tests/test_places.py @@ -212,6 +212,7 @@ def test_autocomplete(self): "Google", session_token=session_token, offset=3, + origin=self.location, location=self.location, radius=self.radius, language=self.language, @@ -223,6 +224,7 @@ def test_autocomplete(self): self.assertEqual(1, len(responses.calls)) self.assertURLEqual( "%s?components=country%%3Aau&input=Google&language=en-AU&" + "origin=-33.86746%%2C151.20709&" "location=-33.86746%%2C151.20709&offset=3&radius=100&" "strictbounds=true&types=geocode&key=%s&sessiontoken=%s" % (url, self.key, session_token),