Repository: pymedusa/Medusa

Issue:
Docker python 3
Hi,

today I tested docker for new 0.3.0 version, but its still based on python 2.7.15 not on python 3.
Can you please update dockerfile, so it can run on python 3 as well please?

If Im doing something wrong, can you please point me to the right direction here?

Thanks

With regards Sparhawk


Discussion:
What's the rush? It's not quite tested well enough and even still what's the difference to an end user???
> 
> 
> What's the rush? It's not quite tested well enough and even still what's the difference to an end user???

one word.. speed

I tested it without docker and at least for me its much quicker..
I'll test tomorrow and see 
Python erroring out on importlib which is weird as it's included in python3.6
```
Error processing line 1 of /app/medusa/ext/configparser.pth:

  Traceback (most recent call last):
    File "/usr/lib/python3.6/site.py", line 168, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  ModuleNotFoundError: No module named 'importlib'

Remainder of file ignored
Traceback (most recent call last):
  File "/app/medusa/start.py", line 8, in <module>
    from medusa.__main__ import main
  File "/app/medusa/medusa/__init__.py", line 24, in <module>
    initialize()
  File "/app/medusa/medusa/init/__init__.py", line 33, in initialize
    _configure_guessit()
  File "/app/medusa/medusa/init/__init__.py", line 179, in _configure_guessit
    import guessit
  File "/app/medusa/ext/guessit/__init__.py", line 8, in <module>
    from .api import guessit, GuessItApi
  File "/app/medusa/ext/guessit/api.py", line 20, in <module>
    from .rules import rebulk_builder
  File "/app/medusa/ext/guessit/rules/__init__.py", line 11, in <module>
    from .properties.episodes import episodes
  File "/app/medusa/ext/guessit/rules/properties/episodes.py", line 14, in <module>
    from .title import TitleFromPosition
  File "/app/medusa/ext/guessit/rules/properties/title.py", line 11, in <module>
    from .language import SubtitlePrefixLanguageRule, SubtitleSuffixLanguageRule, SubtitleExtensionRule
  File "/app/medusa/ext/guessit/rules/properties/language.py", line 10, in <module>
    import babelfish
  File "/app/medusa/ext/babelfish/__init__.py", line 20, in <module>
    from .converters import (LanguageConverter, LanguageReverseConverter, LanguageEquivalenceConverter, CountryConverter,
  File "/app/medusa/ext/babelfish/converters/__init__.py", line 6, in <module>
    from pkg_resources import iter_entry_points, EntryPoint
  File "/app/medusa/lib/pkg_resources/__init__.py", line 77, in <module>
    __import__('pkg_resources.extern.packaging.requirements')
  File "/app/medusa/lib/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
    from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/app/medusa/lib/pkg_resources/extern/__init__.py", line 43, in load_module
    __import__(extant)
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 4715, in <module>
    _escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 1261, in setParseAction
    self.parseAction = list(map(_trim_arity, list(fns)))
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 1043, in _trim_arity
    this_line = extract_stack(limit=2)[-1]
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 1027, in extract_stack
    frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset]
  File "/usr/lib/python3.6/traceback.py", line 211, in extract_stack
    stack = StackSummary.extract(walk_stack(f), limit=limit)
  File "/usr/lib/python3.6/traceback.py", line 364, in extract
    f.line
  File "/usr/lib/python3.6/traceback.py", line 286, in line
    self._line = linecache.getline(self.filename, self.lineno).strip()
  File "/usr/lib/python3.6/linecache.py", line 16, in getline
    lines = getlines(filename, module_globals)
  File "/usr/lib/python3.6/linecache.py", line 47, in getlines
    return updatecache(filename, module_globals)
  File "/usr/lib/python3.6/linecache.py", line 142, in updatecache
    size, mtime = stat.st_size, stat.st_mtime
AttributeError: 'list' object has no attribute 'st_size'
Error processing line 1 of /app/medusa/ext/configparser.pth:

  Traceback (most recent call last):
    File "/usr/lib/python3.6/site.py", line 168, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  ModuleNotFoundError: No module named 'importlib'

Remainder of file ignored
Traceback (most recent call last):
  File "/app/medusa/start.py", line 8, in <module>
    from medusa.__main__ import main
  File "/app/medusa/medusa/__init__.py", line 24, in <module>
    initialize()
  File "/app/medusa/medusa/init/__init__.py", line 33, in initialize
    _configure_guessit()
  File "/app/medusa/medusa/init/__init__.py", line 179, in _configure_guessit
    import guessit
  File "/app/medusa/ext/guessit/__init__.py", line 8, in <module>
    from .api import guessit, GuessItApi
  File "/app/medusa/ext/guessit/api.py", line 20, in <module>
    from .rules import rebulk_builder
  File "/app/medusa/ext/guessit/rules/__init__.py", line 11, in <module>
    from .properties.episodes import episodes
  File "/app/medusa/ext/guessit/rules/properties/episodes.py", line 14, in <module>
    from .title import TitleFromPosition
  File "/app/medusa/ext/guessit/rules/properties/title.py", line 11, in <module>
    from .language import SubtitlePrefixLanguageRule, SubtitleSuffixLanguageRule, SubtitleExtensionRule
  File "/app/medusa/ext/guessit/rules/properties/language.py", line 10, in <module>
    import babelfish
  File "/app/medusa/ext/babelfish/__init__.py", line 20, in <module>
    from .converters import (LanguageConverter, LanguageReverseConverter, LanguageEquivalenceConverter, CountryConverter,
  File "/app/medusa/ext/babelfish/converters/__init__.py", line 6, in <module>
    from pkg_resources import iter_entry_points, EntryPoint
  File "/app/medusa/lib/pkg_resources/__init__.py", line 77, in <module>
    __import__('pkg_resources.extern.packaging.requirements')
  File "/app/medusa/lib/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
    from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/app/medusa/lib/pkg_resources/extern/__init__.py", line 43, in load_module
    __import__(extant)
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 4715, in <module>
    _escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 1261, in setParseAction
    self.parseAction = list(map(_trim_arity, list(fns)))
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 1043, in _trim_arity
    this_line = extract_stack(limit=2)[-1]
  File "/app/medusa/lib/pkg_resources/_vendor/pyparsing.py", line 1027, in extract_stack
    frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset]
  File "/usr/lib/python3.6/traceback.py", line 211, in extract_stack
    stack = StackSummary.extract(walk_stack(f), limit=limit)
  File "/usr/lib/python3.6/traceback.py", line 364, in extract
    f.line
  File "/usr/lib/python3.6/traceback.py", line 286, in line
    self._line = linecache.getline(self.filename, self.lineno).strip()
  File "/usr/lib/python3.6/linecache.py", line 16, in getline
    lines = getlines(filename, module_globals)
  File "/usr/lib/python3.6/linecache.py", line 47, in getlines
    return updatecache(filename, module_globals)
  File "/usr/lib/python3.6/linecache.py", line 142, in updatecache
    size, mtime = stat.st_size, stat.st_mtime
AttributeError: 'list' object has no attribute 'st_size'
```
@a10kiloham
You're using an old/outdated Medusa version. `/app/medusa/ext/configparser.pth` doesn't exist in the current release.
Ok it runs. Doesn't seem to be much faster in my case. Also some bugs - can't open the "Health & Info" page. It get stuck on 
```
Loading…
If this is taking too long,
click here to show the page.
{{ $route.meta.header }}
```

Also on the individual shows page, it loses everything about the show above the Seasons tables - it just says Loading... where normally the art and information would be.

If you want to test here's a sample Dockerfile to use:

```
FROM lsiobase/alpine.python:3.9
MAINTAINER a10kiloham

# set version label
ARG BUILD_DATE
ARG VERSION
LABEL build_version="Version:- ${VERSION} Build-date:- ${BUILD_DATE}"

RUN apk add --no-cache python3 && \
    python3 -m ensurepip && \
    rm -r /usr/lib/python*/ensurepip && \
    pip3 install --upgrade pip setuptools && \
    if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
    rm /usr/bin/python && \
    ln -sf /usr/bin/python3 /usr/bin/python && \
    rm -r /root/.cache

# install packages
RUN \
 apk add --no-cache \
        --repository http://nl.alpinelinux.org/alpine/edge/community \
        mediainfo

# install app
COPY . /app/medusa/

# copy local files
COPY .docker/root/ /

# ports and volumes
EXPOSE 8081
VOLUME /config /downloads /tv /anime
```
Clear your browser cache with CTRL + F5.
i submitted a PR but would suggest more testing. I'll try it for a week or so and see how it feels
https://github.com/pymedusa/Medusa/pull/6424

Resolving patch:
diff --git a/medusa/__main__.py b/medusa/__main__.py
--- a/medusa/__main__.py
+++ b/medusa/__main__.py
@@ -474,9 +474,20 @@ def initialize(self, console_logging=True):
 
             # current commit hash
             app.CUR_COMMIT_HASH = check_setting_str(app.CFG, 'General', 'cur_commit_hash', '')
+            # set current commit hash from environment variable, if needed
+            # use this to inject the commit hash information on immutable installations (e.g. Docker containers)
+            commit_hash_env = os.environ.get('MEDUSA_COMMIT_HASH')
+            if commit_hash_env and app.CUR_COMMIT_HASH != commit_hash_env:
+                app.CUR_COMMIT_HASH = commit_hash_env
 
             # current commit branch
             app.CUR_COMMIT_BRANCH = check_setting_str(app.CFG, 'General', 'cur_commit_branch', '')
+            # set current commit branch from environment variable, if needed
+            # use this to inject the branch information on immutable installations (e.g. Docker containers)
+            commit_branch_env = os.environ.get('MEDUSA_COMMIT_BRANCH')
+            if commit_branch_env and app.CUR_COMMIT_BRANCH != commit_branch_env:
+                app.CUR_COMMIT_BRANCH = commit_branch_env
+
             app.ACTUAL_CACHE_DIR = check_setting_str(app.CFG, 'General', 'cache_dir', 'cache')
 
             # fix bad configs due to buggy code
diff --git a/medusa/helpers/__init__.py b/medusa/helpers/__init__.py
--- a/medusa/helpers/__init__.py
+++ b/medusa/helpers/__init__.py
@@ -1471,6 +1471,9 @@ def memory_usage(pretty=True):
     usage = ''
     if memory_usage_tool == 'resource':
         usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
+        if platform.system() == 'Linux':
+            # resource.RUSAGE_SELF is in KB on Linux
+            usage *= 1024
     elif memory_usage_tool == 'psutil':
         usage = Process(os.getpid()).memory_info().rss
     else:


Test patch: