diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index a203147..18236ad 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -9,17 +9,19 @@ jobs: env: SPOTIPY_CLIENT_ID: ${{ secrets.SPOTIPY_CLIENT_ID }} SPOTIPY_CLIENT_SECRET: ${{ secrets.SPOTIPY_CLIENT_SECRET }} - PYTHON_VERSION: "3.10" + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ env.PYTHON_VERSION }} + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: - python-version: ${{ env.PYTHON_VERSION }} + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[test] + pip install . - name: Run non user endpoints integration tests run: | python -m unittest discover -v tests/integration/non_user_endpoints diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..ba917fd --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" # Lint can be done on latest Python only + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install .[test] + - name: Check pep8 with flake8 + run: | + flake8 . --count --show-source --statistics + - name: Check sorted imports with isort + run: | + isort . -c diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/unit_tests.yml similarity index 63% rename from .github/workflows/pythonapp.yml rename to .github/workflows/unit_tests.yml index 5f2ffc8..9b823cb 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/unit_tests.yml @@ -1,6 +1,6 @@ -name: Tests +name: Unit tests -on: [push, pull_request] +on: [push] jobs: build: @@ -18,12 +18,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[test] - - name: Lint with flake8 - run: | - pip install -Iv enum34==1.1.6 # https://bitbucket.org/stoneleaf/enum34/issues/27/enum34-118-broken - pip install flake8 - flake8 . --count --show-source --statistics + pip install . - name: Run unit tests run: | python -m unittest discover -v tests/unit diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d4993a..b96d378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,10 @@ Rebasing master onto v3 doesn't require a changelog update. - Added FAQ entry for inaccessible playlists - Type annotations to `spotipy.cache_handler` +### Changed + +- Split test and lint workflows + ### Fixed - Audiobook integration tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53605fb..737fbba 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ $ source env/bin/activate ### Lint -To automatically fix the code style: +To automatically fix some of the code style: pip install autopep8 autopep8 --in-place --aggressive --recursive . @@ -42,7 +42,11 @@ To verify the code style: To make sure if the import lists are stored correctly: pip install isort - isort . -c -v + isort . -c + +Sort them automatically with: + + isort . ### Changelog diff --git a/docs/conf.py b/docs/conf.py index 4892717..81dbaef 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,8 +10,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/examples/add_saved_episodes.py b/examples/add_saved_episodes.py index 5acc177..8e34f94 100644 --- a/examples/add_saved_episodes.py +++ b/examples/add_saved_episodes.py @@ -4,6 +4,7 @@ Usage: add_saved_episodes.py -e episode_id episode_id ... """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/add_saved_shows.py b/examples/add_saved_shows.py index ef16258..1bbaf9d 100644 --- a/examples/add_saved_shows.py +++ b/examples/add_saved_shows.py @@ -4,6 +4,7 @@ Usage: add_saved_shows.py -s show_id show_id ... """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/app.py b/examples/app.py index c4fd379..f60a81b 100644 --- a/examples/app.py +++ b/examples/app.py @@ -24,8 +24,10 @@ Run app.py """ import os -from flask import Flask, session, request, redirect + +from flask import Flask, redirect, request, session from flask_session import Session + import spotipy app = Flask(__name__) diff --git a/examples/artist_albums.py b/examples/artist_albums.py index 493bfc2..de241cb 100644 --- a/examples/artist_albums.py +++ b/examples/artist_albums.py @@ -1,8 +1,8 @@ import argparse import logging -from spotipy.oauth2 import SpotifyClientCredentials import spotipy +from spotipy.oauth2 import SpotifyClientCredentials logger = logging.getLogger('examples.artist_albums') logging.basicConfig(level='INFO') diff --git a/examples/artist_discography.py b/examples/artist_discography.py index 0952b08..b9011ed 100644 --- a/examples/artist_discography.py +++ b/examples/artist_discography.py @@ -2,8 +2,8 @@ import argparse import logging -from spotipy.oauth2 import SpotifyClientCredentials import spotipy +from spotipy.oauth2 import SpotifyClientCredentials logger = logging.getLogger('examples.artist_discography') logging.basicConfig(level='INFO') diff --git a/examples/artist_recommendations.py b/examples/artist_recommendations.py index 238db92..390cc9e 100644 --- a/examples/artist_recommendations.py +++ b/examples/artist_recommendations.py @@ -4,7 +4,6 @@ import logging import spotipy from spotipy.oauth2 import SpotifyClientCredentials - logger = logging.getLogger('examples.artist_recommendations') logging.basicConfig(level='INFO') diff --git a/examples/audio_analysis_for_track.py b/examples/audio_analysis_for_track.py index 9f13e1f..91b01fb 100644 --- a/examples/audio_analysis_for_track.py +++ b/examples/audio_analysis_for_track.py @@ -1,11 +1,11 @@ # shows audio analysis for the given track -from spotipy.oauth2 import SpotifyClientCredentials import json -import spotipy -import time import sys +import time +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) diff --git a/examples/audio_features.py b/examples/audio_features.py index c81b23d..c5a12d9 100644 --- a/examples/audio_features.py +++ b/examples/audio_features.py @@ -1,11 +1,11 @@ # shows acoustic features for tracks for the given artist -from spotipy.oauth2 import SpotifyClientCredentials import json -import spotipy -import time import sys +import time +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) diff --git a/examples/audio_features_analysis.py b/examples/audio_features_analysis.py index 20aa86d..ada1846 100644 --- a/examples/audio_features_analysis.py +++ b/examples/audio_features_analysis.py @@ -1,12 +1,12 @@ -import spotipy -from spotipy.oauth2 import SpotifyClientCredentials - +import matplotlib.pyplot as plt # Import the extra necessary libraries for this example # These libraries are not included in the default packages import pandas as pd -import matplotlib.pyplot as plt import seaborn as sns +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + # Set up Spotify credentials client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) diff --git a/examples/audio_features_for_track.py b/examples/audio_features_for_track.py index ddebda6..729d171 100644 --- a/examples/audio_features_for_track.py +++ b/examples/audio_features_for_track.py @@ -1,11 +1,11 @@ # shows acoustic features for tracks for the given artist -from spotipy.oauth2 import SpotifyClientCredentials import json -import spotipy -import time import sys +import time +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) diff --git a/examples/check_show_is_saved.py b/examples/check_show_is_saved.py index eeeb56d..5da3b0f 100644 --- a/examples/check_show_is_saved.py +++ b/examples/check_show_is_saved.py @@ -4,6 +4,7 @@ Usage: check_show_is_saved -s show_id show_id ... """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/client_credentials_flow.py b/examples/client_credentials_flow.py index cd7e56c..47b73a4 100644 --- a/examples/client_credentials_flow.py +++ b/examples/client_credentials_flow.py @@ -1,7 +1,8 @@ -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy from pprint import pprint +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) diff --git a/examples/delete_saved_episodes.py b/examples/delete_saved_episodes.py index b62f4f0..349bb75 100644 --- a/examples/delete_saved_episodes.py +++ b/examples/delete_saved_episodes.py @@ -4,6 +4,7 @@ Usage: delete_saved_episodes.py -e episode_id episode_id ... """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/follow_playlist.py b/examples/follow_playlist.py index 59e1f5e..598e950 100644 --- a/examples/follow_playlist.py +++ b/examples/follow_playlist.py @@ -1,6 +1,7 @@ # Follow a playlist import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/get_audiobook_chapters_info.py b/examples/get_audiobook_chapters_info.py index abbf37a..094c818 100644 --- a/examples/get_audiobook_chapters_info.py +++ b/examples/get_audiobook_chapters_info.py @@ -4,6 +4,7 @@ Usage: get_audiobooks_chapters_info.py -a audiobook_id """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/get_audiobooks_info.py b/examples/get_audiobooks_info.py index 72fe18d..5e8f010 100644 --- a/examples/get_audiobooks_info.py +++ b/examples/get_audiobooks_info.py @@ -4,9 +4,11 @@ Usage: get_audiobooks_info.py -a audiobook_id audiobook_id ... """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth + def get_args(): parser = argparse.ArgumentParser(description='Get information for a list of audiobooks') # Defaults set to The Great Gatsby, The Chronicles of Narnia and Dune diff --git a/examples/headless.py b/examples/headless.py index d9f4278..b354a60 100644 --- a/examples/headless.py +++ b/examples/headless.py @@ -1,5 +1,4 @@ import spotipy - from spotipy.oauth2 import SpotifyOAuth # set open_browser=False to prevent Spotipy from attempting to open the default browser diff --git a/examples/multiple_accounts.py b/examples/multiple_accounts.py new file mode 100644 index 0000000..6323053 --- /dev/null +++ b/examples/multiple_accounts.py @@ -0,0 +1,10 @@ +from pprint import pprint + +import spotipy +import spotipy.util as util + +while True: + username = input("Type the Spotify user ID to use: ") + token = util.prompt_for_user_token(username, show_dialog=True) + sp = spotipy.Spotify(token) + pprint(sp.me()) diff --git a/examples/personalized_playlist.py b/examples/personalized_playlist.py index 4d7234c..f0e062a 100644 --- a/examples/personalized_playlist.py +++ b/examples/personalized_playlist.py @@ -1,11 +1,11 @@ -import spotipy -from spotipy.oauth2 import SpotifyOAuth - # Import the extra necessary libraries for this example # These libraries are not included in the default packages import pandas as pd from sklearn.cluster import KMeans +import spotipy +from spotipy.oauth2 import SpotifyOAuth + # Set up Spotify credentials sp = spotipy.Spotify(auth_manager=SpotifyOAuth( client_id="YOUR_APP_CLIENT_ID", diff --git a/examples/player.py b/examples/player.py index 82a12ed..85a5cbd 100644 --- a/examples/player.py +++ b/examples/player.py @@ -1,8 +1,9 @@ -import spotipy -from spotipy.oauth2 import SpotifyOAuth from pprint import pprint from time import sleep +import spotipy +from spotipy.oauth2 import SpotifyOAuth + scope = "user-read-playback-state,user-modify-playback-state" sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) diff --git a/examples/playlist_all_non_local_tracks.py b/examples/playlist_all_non_local_tracks.py index 48797fb..cbfd905 100644 --- a/examples/playlist_all_non_local_tracks.py +++ b/examples/playlist_all_non_local_tracks.py @@ -1,6 +1,6 @@ # get all non-local tracks of a playlist -from spotipy.oauth2 import SpotifyClientCredentials import spotipy +from spotipy.oauth2 import SpotifyClientCredentials # playlist id of global top 50 PlaylistExample = '37i9dQZEVXbMDoHDwVN2tF' diff --git a/examples/playlist_tracks.py b/examples/playlist_tracks.py index 00ae96b..86e29a1 100644 --- a/examples/playlist_tracks.py +++ b/examples/playlist_tracks.py @@ -1,8 +1,10 @@ -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy from pprint import pprint -sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials()) +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + +auth_manager = SpotifyClientCredentials() +sp = spotipy.Spotify(auth_manager=auth_manager) pl_id = 'spotify:playlist:5RIbzhG2QqdkaP24iXLnZX' offset = 0 diff --git a/examples/read_a_playlist.py b/examples/read_a_playlist.py index 9697f4a..4034f6e 100644 --- a/examples/read_a_playlist.py +++ b/examples/read_a_playlist.py @@ -1,7 +1,8 @@ -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import json +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) diff --git a/examples/remove_tracks_from_playlist.py b/examples/remove_tracks_from_playlist.py index 59625cc..91a7e8e 100644 --- a/examples/remove_tracks_from_playlist.py +++ b/examples/remove_tracks_from_playlist.py @@ -5,7 +5,6 @@ import sys import spotipy from spotipy.oauth2 import SpotifyOAuth - if len(sys.argv) > 2: playlist_id = sys.argv[1] track_ids = sys.argv[2:] diff --git a/examples/search.py b/examples/search.py index a504635..0c0e09a 100644 --- a/examples/search.py +++ b/examples/search.py @@ -1,9 +1,10 @@ # shows artist info for a URN or URL -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy -import sys import pprint +import sys + +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials search_str = sys.argv[1] if len(sys.argv) > 1 else 'Radiohead' sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials()) diff --git a/examples/show_album.py b/examples/show_album.py index f689b5e..b43fd7c 100644 --- a/examples/show_album.py +++ b/examples/show_album.py @@ -1,10 +1,11 @@ # shows album info for a URN or URL -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import sys from pprint import pprint +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + if len(sys.argv) > 1: urn = sys.argv[1] else: diff --git a/examples/show_artist.py b/examples/show_artist.py index 5b270ac..64bd40b 100644 --- a/examples/show_artist.py +++ b/examples/show_artist.py @@ -1,10 +1,11 @@ # shows artist info for a URN or URL -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import sys from pprint import pprint +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + if len(sys.argv) > 1: urn = sys.argv[1] else: diff --git a/examples/show_artist_top_tracks.py b/examples/show_artist_top_tracks.py index 7f2df16..622b253 100644 --- a/examples/show_artist_top_tracks.py +++ b/examples/show_artist_top_tracks.py @@ -1,10 +1,11 @@ # shows artist info for a URN or URL # scope is not required for this function -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import sys +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + if len(sys.argv) > 1: urn = sys.argv[1] else: diff --git a/examples/show_artist_tracks.py b/examples/show_artist_tracks.py index 372e7ca..bc84adc 100644 --- a/examples/show_artist_tracks.py +++ b/examples/show_artist_tracks.py @@ -2,10 +2,11 @@ # usage: python tracks.py [artist name] -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import sys +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) diff --git a/examples/show_featured_artists.py b/examples/show_featured_artists.py index 0e01dc6..1471c12 100644 --- a/examples/show_featured_artists.py +++ b/examples/show_featured_artists.py @@ -2,11 +2,12 @@ # usage: featured_artists.py spotify:album:[album urn] -from spotipy.oauth2 import SpotifyClientCredentials import sys -import spotipy from pprint import pprint +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + if len(sys.argv) > 1: urn = sys.argv[1] else: diff --git a/examples/show_related.py b/examples/show_related.py index c1ebb8b..c8e6287 100644 --- a/examples/show_related.py +++ b/examples/show_related.py @@ -1,13 +1,15 @@ # shows related artists for the given seed artist -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import sys +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + artist_name = sys.argv[1] if len(sys.argv) > 1 else 'weezer' auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) result = sp.search(q=f'artist:{artist_name}', type='artist') + try: name = result['artists']['items'][0]['name'] uri = result['artists']['items'][0]['uri'] diff --git a/examples/show_track_info.py b/examples/show_track_info.py index 13a709e..bad288b 100644 --- a/examples/show_track_info.py +++ b/examples/show_track_info.py @@ -1,10 +1,11 @@ # shows track info for a URN or URL -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import sys from pprint import pprint +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + if len(sys.argv) > 1: urn = sys.argv[1] else: diff --git a/examples/show_tracks.py b/examples/show_tracks.py index 986ed8f..f2e3c2d 100644 --- a/examples/show_tracks.py +++ b/examples/show_tracks.py @@ -3,10 +3,11 @@ given a list of track IDs show the artist and track name ''' -from spotipy.oauth2 import SpotifyOAuth -import spotipy import argparse +import spotipy +from spotipy.oauth2 import SpotifyOAuth + def get_args(): parser = argparse.ArgumentParser(description='Print artist and track name given a list of track IDs') diff --git a/examples/show_user.py b/examples/show_user.py index 30c3041..34d4c9e 100644 --- a/examples/show_user.py +++ b/examples/show_user.py @@ -1,9 +1,10 @@ # Shows artist info for a URN or URL -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy -import sys import pprint +import sys + +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials username = sys.argv[1] if len(sys.argv) > 1 else 'plamere' auth_manager = SpotifyClientCredentials() diff --git a/examples/simple_artist_albums.py b/examples/simple_artist_albums.py index 8b99ce6..06bd411 100644 --- a/examples/simple_artist_albums.py +++ b/examples/simple_artist_albums.py @@ -1,5 +1,5 @@ -from spotipy.oauth2 import SpotifyClientCredentials import spotipy +from spotipy.oauth2 import SpotifyClientCredentials birdy_uri = 'spotify:artist:2WX2uTcsvV5OnS0inACecP' diff --git a/examples/simple_artist_top_tracks.py b/examples/simple_artist_top_tracks.py index 6943d41..709f9bf 100644 --- a/examples/simple_artist_top_tracks.py +++ b/examples/simple_artist_top_tracks.py @@ -1,5 +1,5 @@ -from spotipy.oauth2 import SpotifyClientCredentials import spotipy +from spotipy.oauth2 import SpotifyClientCredentials lz_uri = 'spotify:artist:36QJpDe2go2KgaRleHCDTp' diff --git a/examples/simple_me.py b/examples/simple_me.py index b01759b..b10113d 100644 --- a/examples/simple_me.py +++ b/examples/simple_me.py @@ -1,6 +1,7 @@ -import spotipy from pprint import pprint +import spotipy + def main(): spotify = spotipy.Spotify(auth_manager=spotipy.SpotifyOAuth()) diff --git a/examples/simple_search_artist.py b/examples/simple_search_artist.py index e0b0e1e..0c50b9f 100644 --- a/examples/simple_search_artist.py +++ b/examples/simple_search_artist.py @@ -1,5 +1,5 @@ -from spotipy.oauth2 import SpotifyClientCredentials import spotipy +from spotipy.oauth2 import SpotifyClientCredentials auth_manager = SpotifyClientCredentials() sp = spotipy.Spotify(auth_manager=auth_manager) diff --git a/examples/simple_search_artist_image_url.py b/examples/simple_search_artist_image_url.py index 945c384..faa4a53 100644 --- a/examples/simple_search_artist_image_url.py +++ b/examples/simple_search_artist_image_url.py @@ -1,8 +1,8 @@ # Shows the name of the artist/band and their image by giving a link import sys -from spotipy.oauth2 import SpotifyClientCredentials import spotipy +from spotipy.oauth2 import SpotifyClientCredentials sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials()) diff --git a/examples/title_chain.py b/examples/title_chain.py index 30ce5a6..9ba342f 100644 --- a/examples/title_chain.py +++ b/examples/title_chain.py @@ -1,7 +1,8 @@ -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import random +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + ''' generates a list of songs where the first word in each subsequent song matches the last word of the previous song. diff --git a/examples/track_recommendations.py b/examples/track_recommendations.py index 6172e9b..563c568 100644 --- a/examples/track_recommendations.py +++ b/examples/track_recommendations.py @@ -1,6 +1,7 @@ +import random + import spotipy from spotipy.oauth2 import SpotifyOAuth -import random # Set up Spotify credentials sp = spotipy.Spotify(auth_manager=SpotifyOAuth( diff --git a/examples/user_playlists.py b/examples/user_playlists.py index 51905a3..69960f2 100644 --- a/examples/user_playlists.py +++ b/examples/user_playlists.py @@ -1,6 +1,7 @@ # Shows a user's playlists (need to be authenticated via oauth) import sys + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/user_public_playlists.py b/examples/user_public_playlists.py index 59f0eb9..62bd26a 100644 --- a/examples/user_public_playlists.py +++ b/examples/user_public_playlists.py @@ -3,6 +3,7 @@ # import sys + import spotipy from spotipy.oauth2 import SpotifyClientCredentials diff --git a/examples/user_saved_episodes.py b/examples/user_saved_episodes.py index 4a10682..56dfa51 100644 --- a/examples/user_saved_episodes.py +++ b/examples/user_saved_episodes.py @@ -4,6 +4,7 @@ Usage: user_saved_episodes -l -o """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/examples/user_saved_shows.py b/examples/user_saved_shows.py index ea60f4a..ebe9e0c 100644 --- a/examples/user_saved_shows.py +++ b/examples/user_saved_shows.py @@ -4,6 +4,7 @@ Usage: user_saved_shows -l -o """ import argparse + import spotipy from spotipy.oauth2 import SpotifyOAuth diff --git a/setup.py b/setup.py index 0ce4071..0421f81 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,13 @@ memcache_cache_reqs = [ ] extra_reqs = { - 'memcache': memcache_cache_reqs + 'memcache': [ + 'pymemcache>=3.5.2' + ], + 'test': [ + 'flake8>=7.1.1', + 'isort>=5.13.2' + ] } setup( diff --git a/spotipy/__init__.py b/spotipy/__init__.py index bb2e201..96f013b 100644 --- a/spotipy/__init__.py +++ b/spotipy/__init__.py @@ -2,5 +2,5 @@ from .cache_handler import * # noqa from .client import * # noqa from .exceptions import * # noqa from .oauth2 import * # noqa -from .util import * # noqa from .scope import * # noqa +from .util import * # noqa diff --git a/spotipy/cache_handler.py b/spotipy/cache_handler.py index 065f4ee..0bbc800 100644 --- a/spotipy/cache_handler.py +++ b/spotipy/cache_handler.py @@ -7,9 +7,10 @@ import os from abc import ABC, abstractmethod from json import JSONEncoder from typing import TypedDict + import redis -from redis import RedisError import redis.client +from redis import RedisError from .util import CLIENT_CREDS_ENV_VARS diff --git a/spotipy/client.py b/spotipy/client.py index a2e6231..c3d0201 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -6,14 +6,13 @@ import json import logging import re import warnings +from collections import defaultdict import requests from spotipy.exceptions import SpotifyException from spotipy.util import Retry -from collections import defaultdict - logger = logging.getLogger(__name__) diff --git a/spotipy/oauth2.py b/spotipy/oauth2.py index a81bd9c..4f1b4d5 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -9,20 +9,20 @@ __all__ = [ import base64 import logging import os +import re import time +import urllib.parse as urllibparse import webbrowser +from http.server import BaseHTTPRequestHandler, HTTPServer +from typing import Iterable +from urllib.parse import parse_qsl, urlparse import requests -import urllib.parse as urllibparse -from http.server import BaseHTTPRequestHandler, HTTPServer -from urllib.parse import parse_qsl, urlparse from spotipy.cache_handler import CacheFileHandler, CacheHandler from spotipy.exceptions import SpotifyOauthError, SpotifyStateError -from spotipy.util import CLIENT_CREDS_ENV_VARS, get_host_port from spotipy.scope import Scope -from typing import Iterable -import re +from spotipy.util import CLIENT_CREDS_ENV_VARS, get_host_port logger = logging.getLogger(__name__) diff --git a/spotipy/scope.py b/spotipy/scope.py index 79a4adc..b5b4bf7 100644 --- a/spotipy/scope.py +++ b/spotipy/scope.py @@ -2,8 +2,8 @@ __all__ = ["Scope"] -from enum import Enum import re +from enum import Enum from typing import Iterable, Set diff --git a/spotipy/util.py b/spotipy/util.py index 37ccbc7..8400a54 100644 --- a/spotipy/util.py +++ b/spotipy/util.py @@ -5,8 +5,8 @@ from spotipy.scope import Scope __all__ = ["CLIENT_CREDS_ENV_VARS", "get_host_port", "normalize_scope", "Retry"] import logging -from types import TracebackType from collections.abc import Iterable +from types import TracebackType import urllib3 diff --git a/tests/helpers.py b/tests/helpers.py index c95d368..39321f0 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,4 +1,5 @@ import base64 + import requests diff --git a/tests/integration/non_user_endpoints/test.py b/tests/integration/non_user_endpoints/test.py index bf15545..aebcb21 100644 --- a/tests/integration/non_user_endpoints/test.py +++ b/tests/integration/non_user_endpoints/test.py @@ -1,12 +1,10 @@ -from spotipy import ( - Spotify, - SpotifyClientCredentials, - SpotifyException -) -import spotipy import unittest + import requests +import spotipy +from spotipy import Spotify, SpotifyClientCredentials, SpotifyException + class AuthTestSpotipy(unittest.TestCase): """ diff --git a/tests/integration/user_endpoints/test.py b/tests/integration/user_endpoints/test.py index eaa3f28..ab7cba1 100644 --- a/tests/integration/user_endpoints/test.py +++ b/tests/integration/user_endpoints/test.py @@ -1,14 +1,9 @@ import os - -from spotipy import ( - CLIENT_CREDS_ENV_VARS as CCEV, - Spotify, - SpotifyException, - SpotifyOAuth, - SpotifyPKCE, - CacheFileHandler -) import unittest + +from spotipy import CLIENT_CREDS_ENV_VARS as CCEV +from spotipy import (CacheFileHandler, Spotify, SpotifyException, SpotifyOAuth, + SpotifyPKCE) from tests import helpers diff --git a/tests/unit/test_oauth.py b/tests/unit/test_oauth.py index 2efdfc4..90cc555 100644 --- a/tests/unit/test_oauth.py +++ b/tests/unit/test_oauth.py @@ -1,14 +1,13 @@ import io import json import unittest - import unittest.mock as mock import urllib.parse as urllibparse from spotipy import SpotifyOAuth, SpotifyPKCE -from spotipy.oauth2 import SpotifyClientCredentials, SpotifyOauthError -from spotipy.oauth2 import SpotifyStateError -from spotipy import MemoryCacheHandler, CacheFileHandler +from spotipy.cache_handler import CacheFileHandler, MemoryCacheHandler +from spotipy.oauth2 import (SpotifyClientCredentials, SpotifyOauthError, + SpotifyStateError) patch = mock.patch DEFAULT = mock.DEFAULT @@ -323,8 +322,8 @@ class TestSpotifyPKCE(unittest.TestCase): self.assertTrue(auth.code_challenge) def test_code_verifier_and_code_challenge_are_correct(self): - import hashlib import base64 + import hashlib auth = SpotifyPKCE("CLID", "REDIR") auth.get_pkce_handshake_parameters() self.assertEqual(auth.code_challenge, diff --git a/tests/unit/test_scopes.py b/tests/unit/test_scopes.py index 441c793..051b260 100644 --- a/tests/unit/test_scopes.py +++ b/tests/unit/test_scopes.py @@ -1,6 +1,7 @@ from unittest import TestCase -from spotipy.scope import Scope + from spotipy.oauth2 import SpotifyAuthBase +from spotipy.scope import Scope class SpotipyScopeTest(TestCase): diff --git a/tox.ini b/tox.ini index bbf780f..daba9d2 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py3{8,9,10,11,12} [testenv] deps= requests -commands=python -m unittest discover -v tests +commands=python -m unittest discover -v tests/unit [flake8] max-line-length = 99 exclude=