Repository: beetbox/beets (language: python)

Issue:
Update /usr/bin shebangs to Python3?
### Problem

YouTuber found error because beets calls for Python3 but actually requires python36+.

https://youtu.be/_-WeZhlU0_I?t=492

Probably this code needs to change:

https://github.com/beetbox/beets/search?q=%2Fusr%2Fbin

**Open question**: Specify Python36 in the shebangs? I bet this would cause compatibility issues with shells that only have generic python3 installed with no subversion number (3.**6**).

### Setup

* OS: Linux


Discussion / hints:

I'll have to rewatch the video at home, but the first thing that comes up is: He's installing beets 1.4.9. Video is from 1 year ago. Why? Wasn't anything newer out this time? I think 1.6.0 even...will check! He doesnt install a distro package but directly via pip3

The shebang of the file he's editing is created by setuptools (on pip install) btw, not hardcoded!

If files have a shebang specified manually

/usr/bin/env python

usually is the correct way, thus everything your github code search link shows seems to be correct. Mostly things not handled by setuptools are found.


> [](https://github.com/beetbox/beets/search?q=%2Fusr%2Fbin)
> 
> **Open question**: Specify Python36 in the shebangs? I bet this would cause compatibility issues with shells that only have generic python3 installed with no subversion number (3.**6**).

No. In particular, manually making these lines specific to minor Python versions will fail with any other supported python which is not 3.6 (i.e. 3.7). We could change it to `python3`.

However, I think none of the scripts that this search turns up are actually relevant to users: Almost all of them are developer tools, except for the `beet` "executable". However, even that isn't actually used as far as I can tell (In fact, could we even remove it?), since we install the script via `entry_points` in `setup.py`, which generates a stub file that should refer to the correct python version which has beets installed (check `cat $(which beet)` on your system).

I haven't watched the video, but that sounds more like a botched-up Python/beets installation.
I didn't watch again on big screen yet but:

Video is from June 15th, 2021

He's using Python 3.8

At that time the latest release (on pip where he installs from) most probably was: https://github.com/beetbox/beets/releases/tag/v1.5.0

Update: Sorry, must have been the one before: 1.4.9. So what we see in the video is the latest version available on this day being pulled from pypi correctly.

In the release notes I find this, no idea if this has anything to do with his "Python 3.8 seems to be too new for beets" assumption: 



```
Fixes:

Adapt to breaking changes in Python's ast module in Python 3.8.
```

Not enough time / too lazy to look through the changes/commits from 1.4.9 to 1.5.0

If we figure that problem is fixed by now we could post below that video to help potential new beets user because video watchers could get the false impression that beets is difficult to install and requires hackish approaches like shown in the video....again: It's 1,5 years old, not tooooo old to believe things shown could still be true....

HTH
> However, even that isn't actually used as far as I can tell (In fact, could we even remove it?), since we install the script via `entry_points` in `setup.py`, which generates a stub file that should refer to the correct python version which has beets installed (check `cat $(which beet)` on your system).

All correct! It might be a good idea to remove this… it has been vaguely nice for testing without installing in the past, but even I don't do that anymore (`pip install -e` is a much better option).
Sounds like the issue is:

1. Remove /usr/bin/python shebangs from code that no longer needs it (/beet)
2. Update shebangs to python3 for remaining code. Even if it's dev/test code, that's important for devs and testing.
3. The issue in the OP is apparently solved already.

> /usr/bin/env python
> 
> usually is the correct way, thus everything your github code search link shows seems to be correct. Mostly things not handled by setuptools are found.

Isn't explicit better than implicit? python (no 3) is the PEP way to do it, but some [disagree](https://discuss.python.org/t/pep-394-clarify-bullet-for-usr-bin-env-python/7953).

https://peps.python.org/pep-0394/

> For scripts that are only expected to be run in an activated virtual environment, shebang lines can be written as #!/usr/bin/env python, as this instructs the script to respect the active virtual environment.
> Sounds like the issue is:
> 1. Remove /usr/bin/python shebangs from code that no longer needs it (/beet)

It does need the shebang; what I was asking is whether we can remove the script entirely (since it appeared unused to me, but as @sampsyo highlighted, there might still be a usecase for developers. However, it is unclear whether anyone uses it).

> 2. Update shebangs to python3 for remaining code. Even if it's dev/test code, that's important for devs and testing.

Sounds good.

> > /usr/bin/env python
> > usually is the correct way, thus everything your github code search link shows seems to be correct. Mostly things not handled by setuptools are found.
> 
> Isn't explicit better than implicit? python (no 3) is the PEP way to do it, but some [disagree](https://discuss.python.org

Without having researched this in detail, `python3` seems safest to me, too (even though should really be phasing out Python 2 anyway).

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I'm for removing `beet` executable. Most probably it's unused, if not we point them to  `pip install -e`

Anything else to do here @RollingStar you wann take over here and state the todos? Thanks :-))
I don't think I understand it well enough to state the todos.
Here's what a potential PR should probably do:

* Remove the included `beet` executable.
* Grep for `bin\/env python` and change all other random scripts we have lying around (there are a few) to use `python3` instead of `python`.
I had a look over PEP 394, and I agree that changing `env python` to `env python3` makes sense.  I didn't realize that the `beet` script in the repo simply goes unused; if that should be removed, I'm happy to do it.  I'll open a (single) PR for both of these.

Fix patch:
diff --git a/beet b/beet
deleted file mode 100755
index abf55ec274..0000000000
--- a/beet
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env python
-
-# This file is part of beets.
-# Copyright 2016, Adrian Sampson.
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-
-
-import beets.ui
-
-if __name__ == '__main__':
-    beets.ui.main()
diff --git a/docs/changelog.rst b/docs/changelog.rst
index a245cc623e..bdf221e413 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -14,6 +14,7 @@ Bug fixes:
 For packagers:
 
 * The minimum supported Python version is now 3.8.
+* The `beet` script has been removed from the repository.
 
 Other changes:
 


Test patch:
diff --git a/test/rsrc/convert_stub.py b/test/rsrc/convert_stub.py
index 14282c8ce6..cba693c4ec 100755
--- a/test/rsrc/convert_stub.py
+++ b/test/rsrc/convert_stub.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 """A tiny tool used to test the `convert` plugin. It copies a file and appends
 a specified text tag.
diff --git a/test/testall.py b/test/testall.py
index b96815eb89..27d852a77b 100755
--- a/test/testall.py
+++ b/test/testall.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # This file is part of beets.
 # Copyright 2016, Adrian Sampson.