Skip to content

Commit

Permalink
Publish (#5)
Browse files Browse the repository at this point in the history
* add test for find track
* fix type hint
* fix test
* add windows run example
* support wheel build
* setup proper long description for pypi
* add classifiers
* update makefile with publish
* add github action to publish
* update contributing
* bump version

Co-authored-by: Radu <[email protected]>
  • Loading branch information
radujica and Radu authored Apr 16, 2020
1 parent e1b236c commit 96ea90a
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 20 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install -r requirements.txt
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ coverage.xml
__pycache__
*.egg-info
dist
build

# this sets up the relevant envvars before running search.py
run.sh
Expand Down
11 changes: 3 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Setup

Currently pipenv focused; can adapt to your dev env.
Check out the Makefile for the common commands.

# activate virtual env where necessary
pipenv shell
Expand All @@ -13,12 +14,6 @@ Currently pipenv focused; can adapt to your dev env.
pipenv lock -r > requirements.txt
pipenv lock --dev -r > requirements-dev.txt

# build for publish
python setup.py sdist
# clean
rm -rf dist tospotify.egg-info
# check before publish
twine check <dist/path>
# publish
twine upload -r pypi <dist/path>
Publishing to pypi is handled through github releases and action,
though version in setup.py needs to be manually bumped.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
prune test*
include README.md
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ lint:
@echo "Running Bandit against source files..."
@bandit -r --ini setup.cfg

build:
@python setup.py sdist
build: clean
@python setup.py sdist bdist_wheel

publish: clean build
@echo "Checking build..."
@twine check dist/*
@echo "Publishing to pypi..."
@twine upload -r pypi dist/*

clean:
rm -rf .pytest_cache .coverage coverage.xml dist tospotify.egg-info build
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ Currently works for m3u files; m3u8 support to come!
existing playlist with this id
### Example
tospotify --verbose "[email protected]" "D:/playlist/name.m3u"
* Linux/MacOS

tospotify --verbose "[email protected]" "D:/playlist/name.m3u"
* Windows*

python -m tospotify "[email protected]" "D:/playlist/name.m3u"
\*`entry_points` does not seem to simply work on Windows


## Requirements
Expand Down
25 changes: 21 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
from setuptools import setup, find_packages
from setuptools import setup


def readme():
with open('README.md') as f:
return f.read()


# TODO: add long_description ~ pypi readme
setup(
name='tospotify',
version='0.1',
version='0.2',
description='Create/update a Spotify playlist from a local m3u playlist',
url='https://github.com/radujica/tospotify',
author='Radu Jica',
author_email='[email protected]',
license='GPL-3.0',
packages=find_packages(),
long_description=readme(),
long_description_content_type='text/markdown',
classifiers=[
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Multimedia :: Sound/Audio',
'Operating System :: OS Independent'
],
packages=['tospotify', 'tospotify.types'],
include_package_data=True,
zip_safe=True,
install_requires=['spotipy', 'm3u8'],
Expand Down
8 changes: 4 additions & 4 deletions test/test_run.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
from unittest.mock import patch

import pytest

from tospotify.run import _parse_path


@patch('os.sep', '/')
@patch('os.getcwd', lambda: '/test/path')
@pytest.mark.parametrize('path,expected', [
('/abs/path', '/abs/path'),
('relative/path', '/test/path/relative/path')
('/abs/path', ['/abs/path']),
('relative/path', ['/test/path', 'relative/path'])
])
def test__parse_path(path, expected):
assert _parse_path(path) == expected
assert _parse_path(path) == os.sep.join(expected)
20 changes: 20 additions & 0 deletions test/test_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from unittest.mock import patch, Mock

import pytest

import tospotify


@patch('tospotify.search._run_query')
@pytest.mark.parametrize('song,_run_query_results,expected', [
('Sting - Every Breath You Take', [None, 'uri1'], 'uri1'),
('Sting - Every Breath You Take', ['uri1', 'uri2'], 'uri1'),
])
def test__find_track(mock__run_query, song, _run_query_results, expected):
mock_song = Mock()
mock_song.title.return_value = song
mock__run_query.side_effect = _run_query_results

actual = tospotify.search._find_track(None, mock_song)

assert actual == expected
2 changes: 1 addition & 1 deletion tospotify/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .search import create_spotify_playlist, update_spotify_playlist


def _parse_args() -> None:
def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description='Create/update a Spotify playlist from a local m3u playlist')
parser.add_argument('spotify_username',
help='Spotify username where playlist should be updated. '
Expand Down

0 comments on commit 96ea90a

Please sign in to comment.