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 24efb28..06c819d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,10 @@ Add your changes below. - category_playlists - Added FAQ entry for inaccessible playlists +### Changed + +- Split test and lint workflows + ### Fixed - Audiobook integration tests - Edited docstrings for certain functions in client.py for functions that are no longer in use and have been replaced. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11558a0..054f1e0 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 69d9943..b81df9b 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 821f3fb..ca2a340 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 ce89b6e..42f26e6 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 aeb3003..68e4576 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 d1af3ca..79939c2 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 1bef5e9..177ed37 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 client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) diff --git a/examples/audio_features.py b/examples/audio_features.py index 4657a97..dbc1c4f 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 client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_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 e345ca6..ce47bf8 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 client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_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 856bf5e..d6c7788 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 + client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_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 index 03f4732..6323053 100644 --- a/examples/multiple_accounts.py +++ b/examples/multiple_accounts.py @@ -1,8 +1,8 @@ +from pprint import pprint + import spotipy import spotipy.util as util -from pprint import pprint - while True: username = input("Type the Spotify user ID to use: ") token = util.prompt_for_user_token(username, show_dialog=True) 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 7ca38dd..73b7b28 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(client_credentials_manager=SpotifyOAuth(scope=scope)) diff --git a/examples/playlist_all_non_local_tracks.py b/examples/playlist_all_non_local_tracks.py index e0bcb21..54a0465 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 360f974..6e756ff 100644 --- a/examples/playlist_tracks.py +++ b/examples/playlist_tracks.py @@ -1,7 +1,8 @@ -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy from pprint import pprint +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) pl_id = 'spotify:playlist:5RIbzhG2QqdkaP24iXLnZX' diff --git a/examples/read_a_playlist.py b/examples/read_a_playlist.py index a6b5676..a5ccc7e 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 + client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_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 cf81208..69306bc 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 if len(sys.argv) > 1: search_str = sys.argv[1] diff --git a/examples/show_album.py b/examples/show_album.py index 8f5e617..7847ec7 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 72f18cc..d07bf22 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 97d2f92..599c2d8 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 33e943e..ad690b0 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 + client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_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 8791404..3865bd6 100644 --- a/examples/show_related.py +++ b/examples/show_related.py @@ -1,9 +1,10 @@ # shows related artists for the given seed artist -from spotipy.oauth2 import SpotifyClientCredentials -import spotipy import sys +import spotipy +from spotipy.oauth2 import SpotifyClientCredentials + if len(sys.argv) > 1: artist_name = sys.argv[1] else: diff --git a/examples/show_track_info.py b/examples/show_track_info.py index 353172c..4a63e61 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 9ea31ef..ceb8249 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 9c010ea..b3cb853 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 if len(sys.argv) > 1: username = sys.argv[1] diff --git a/examples/simple_artist_albums.py b/examples/simple_artist_albums.py index 3f8323d..55c9733 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 caf5fed..7ab9620 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 a89ca42..c1ea7d7 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 client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) diff --git a/examples/simple_search_artist_image_url.py b/examples/simple_search_artist_image_url.py index f1b8eb3..eab4354 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(client_credentials_manager=SpotifyClientCredentials()) diff --git a/examples/title_chain.py b/examples/title_chain.py index 6cf3b8e..0785e7a 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 0231f36..cae7cc0 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 52824fa..c1ac288 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/cache_handler.py b/spotipy/cache_handler.py index ffe539f..7b3b2c3 100644 --- a/spotipy/cache_handler.py +++ b/spotipy/cache_handler.py @@ -11,10 +11,11 @@ import errno import json import logging import os -from spotipy.util import CLIENT_CREDS_ENV_VARS from redis import RedisError +from spotipy.util import CLIENT_CREDS_ENV_VARS + logger = logging.getLogger(__name__) diff --git a/spotipy/client.py b/spotipy/client.py index b14f9a5..cdb2da2 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 c17b4e8..14b2b6d 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -11,14 +11,14 @@ import base64 import logging import os import time +import urllib.parse as urllibparse import warnings import webbrowser - -import requests -import urllib.parse as urllibparse from http.server import BaseHTTPRequestHandler, HTTPServer from urllib.parse import parse_qsl, urlparse +import requests + from spotipy.cache_handler import CacheFileHandler, CacheHandler from spotipy.exceptions import SpotifyOauthError, SpotifyStateError from spotipy.util import CLIENT_CREDS_ENV_VARS, get_host_port, normalize_scope diff --git a/spotipy/util.py b/spotipy/util.py index 2d9e012..069a75c 100644 --- a/spotipy/util.py +++ b/spotipy/util.py @@ -9,10 +9,10 @@ import os import warnings from types import TracebackType -import spotipy - import urllib3 +import spotipy + LOGGER = logging.getLogger(__name__) CLIENT_CREDS_ENV_VARS = { 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 366e24c..bc4e7c3 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 9c7c1d4..cb9e8c9 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, - prompt_for_user_token, - Spotify, - SpotifyException, - SpotifyImplicitGrant, - SpotifyPKCE -) import unittest + +from spotipy import CLIENT_CREDS_ENV_VARS as CCEV +from spotipy import (Spotify, SpotifyException, SpotifyImplicitGrant, + SpotifyPKCE, prompt_for_user_token) from tests import helpers diff --git a/tests/unit/test_oauth.py b/tests/unit/test_oauth.py index 10e1062..c737a65 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, SpotifyImplicitGrant, SpotifyPKCE +from spotipy import SpotifyImplicitGrant, SpotifyOAuth, SpotifyPKCE from spotipy.cache_handler import MemoryCacheHandler -from spotipy.oauth2 import SpotifyClientCredentials, SpotifyOauthError -from spotipy.oauth2 import SpotifyStateError +from spotipy.oauth2 import (SpotifyClientCredentials, SpotifyOauthError, + SpotifyStateError) patch = mock.patch DEFAULT = mock.DEFAULT @@ -487,8 +486,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/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=