Closed mr-orange closed 10 years ago
If you don't register entry_points, you can't use babelfish. You should be able to register base converters anyway, I'll look into it.
Thanks.
Il giorno 08/dic/2013, alle ore 19:11, Antoine Bertin < notifications@github.com> ha scritto:
If you don't register entry_points, you can't use babelfish. You should be able to register base converters anyway, I'll look into it.
— Reply to this email directly or view it on GitHubhttps://github.com/Diaoul/babelfish/issues/9#issuecomment-30087229 .
You can always create a fake distribution and register given entry points in the setup.py, it'll work as well.
import pkg_resources
def get_exec_path():
current_filepath = os.path.splitext(os.path.abspath(__file__))[0]
current_modpath = os.path.join(os.sep, __name__.replace('.', os.sep))
return current_filepath.replace(current_modpath, '')
def register_language_converters():
# Create fake distrubtion:
distrib = pkg_resources.Distribution(location=os.path.join(get_exec_path(), 'subliminal'), project_name='subliminal', version='0.0.1')
ep = { 'babelfish.language_converters': [ 'alpha2 = babelfish.converters.alpha2:Alpha2Converter',
'alpha3b = babelfish.converters.alpha3b:Alpha3BConverter',
'alpha3t = babelfish.converters.alpha3t:Alpha3TConverter',
'name = babelfish.converters.name:NameConverter',
'scope = babelfish.converters.scope:ScopeConverter',
'type = babelfish.converters.type:LanguageTypeConverter',
'opensubtitles = babelfish.converters.opensubtitles:OpenSubtitlesConverter'],
'babelfish.country_converters': ['name = babelfish.converters.countryname:CountryNameConverter']
}
distrib._ep_map = pkg_resources.EntryPoint.parse_map(ep, distrib)
pkg_resources.working_set.add(disturb)
Celestial02 I need to use subliminal modules without user installation, because I need to integrate subliminal 0.8 in my sickbeard fork.
I can't force anyone to register the entry points only to use subliminal...
On Mon, Dec 9, 2013 at 11:22 AM, celestian02 notifications@github.comwrote:
You can always create a fake distribution and register given entry points in the setup.py, it'll work as well.
— Reply to this email directly or view it on GitHubhttps://github.com/Diaoul/babelfish/issues/9#issuecomment-30120424 .
That's exactly what I'm saying... I had the same issue. This is the workaround I have implemented to use babelfish as a thirdy party library that is in my app folder.
Could you share the method you used? Thanks.
On Mon, Dec 9, 2013 at 11:32 AM, celestian02 notifications@github.comwrote:
That's exactly what I'm saying... I had the same issue. This is the workaround I have implemented to use babelfish as a thirdy party library that is in my app folder.
— Reply to this email directly or view it on GitHubhttps://github.com/Diaoul/babelfish/issues/9#issuecomment-30121070 .
That's the code I pasted...
I've just tried but it's not working for me.... The code need to be in setup.py? then i have to run setup.py?
Which one of your repo would you like it to be included in?
Sickbeard pistachitos
Il giorno 09/dic/2013, alle ore 12:11, celestian02 notifications@github.com ha scritto:
Which one of your repo would you like it to be included in?
— Reply to this email directly or view it on GitHubhttps://github.com/Diaoul/babelfish/issues/9#issuecomment-30123388 .
https://github.com/Pistachitos/Sick-Beard
this one right?
Nope is this: https://github.com/mr-orange/Sick-Beard/tree/Pistachitos
Could you send me the print of babelfish.language.LANGUAGE_CONVERTERS in your system? Probably i can get the lib working overwriting this dictionary.
I can make a pull request if you still need some help
What pr want you send me?
On Mon, Dec 9, 2013 at 1:58 PM, celestian02 notifications@github.comwrote:
I can make a pull request if you still need some help
— Reply to this email directly or view it on GitHubhttps://github.com/Diaoul/babelfish/issues/9#issuecomment-30129771 .
Required code for babel fish to import correctly and subliminal to work.
yes thanks... I've just created Pistachitos-subliminal_v0.8 branch with all required library... send me a pr on that branch. The branch probably will not running because some methods need to be changed in subtitles.py.
On Mon, Dec 9, 2013 at 2:00 PM, celestian02 notifications@github.comwrote:
Required code for babel fish to import correctly and subliminal to work.
— Reply to this email directly or view it on GitHubhttps://github.com/Diaoul/babelfish/issues/9#issuecomment-30129875 .
@Diaoul In the end found a way to init babelfish module without a proper setup.... I Installed the module via proper setup.py install... then copied only the entry_point.txt in the egg dir created by the setup.... deleted the module installed, deleted the egg dir associated to module... copied from babelfish.zip the library module without installing, finally copied the entry_point.txt in babelfish module dir.... It seem to working... Did You see any problem on this?
Code proposed by @celestian02 is working, but project_name
needs to be different than every existing package distributions in the environment for the fake distribution do be loaded.
In the case of additional customer converters (for instance, subliminal), you can also add some code that I had intentionally removed to make it simpler for mr-orange to automatically scan for modules in a folder and discover additional ep automatically:
def get_exec_path():
current_filepath = os.path.splitext(os.path.abspath(__file__))[0]
current_modpath = os.path.join(os.sep, __name__.replace('.', os.sep))
return current_filepath.replace(current_modpath, '')
def list_modules(pkg, exclude=None):
exclude = exclude or []
pkg_path = os.path.join(get_exec_path(), pkg.replace('.', os.sep))
return [i for i in os.listdir(pkg_path) if i.endswith('.py') and i not in exclude]
def register_language_converters():
# Create fake distrubtion:
distrib = pkg_resources.Distribution(location=os.path.join(get_exec_path(), 'subliminal'), project_name='subliminalr', version='0.0.1')
ep = { 'babelfish.language_converters': [ 'alpha2 = babelfish.converters.alpha2:Alpha2Converter',
'alpha3b = babelfish.converters.alpha3b:Alpha3BConverter',
'alpha3t = babelfish.converters.alpha3t:Alpha3TConverter',
'name = babelfish.converters.name:NameConverter',
'scope = babelfish.converters.scope:ScopeConverter',
'type = babelfish.converters.type:LanguageTypeConverter',
'opensubtitles = babelfish.converters.opensubtitles:OpenSubtitlesConverter'],
'babelfish.country_converters': ['name = babelfish.converters.countryname:CountryNameConverter']
}
logger.debug('Searching for available language converters...')
# Scan converters directory and add found converters:
for i in list_modules(__name__, exclude='__init__.py'):
module = importlib.import_module('.' + os.path.splitext(i)[0], __name__)
for c in inspect.getmembers(module, predicate=lambda o: inspect.isclass(o) and issubclass(o, LanguageConverter) and o not in [LanguageConverter, LanguageReverseConverter]):
try:
ep['babelfish.language_converters'].append('%s = %s:%s' % (os.path.splitext(i)[0], c[1].__module__, c[1].__name__))
logger.debug('Registered language converter %r' % unicode(c[0]))
except Exception, e:
logger.error('Could not register language converter %r (%s)' % (unicode(c[0]), e))
distrib._ep_map = pkg_resources.EntryPoint.parse_map(ep, distrib)
pkg_resources.working_set.add(distrib)
Is resolved thank you guys.
Il giorno 13/dic/2013, alle ore 16:32, celestian02 notifications@github.com ha scritto:
In the case of Subliminal, you can also add some code that I had intentionally removed to make it simpler for mr-orange to automatically scan for modules in a folder and add ep automatically:
def get_exec_path(): current_filepath = os.path.splitext(os.path.abspath(file))[0] current_modpath = os.path.join(os.sep, name.replace('.', os.sep)) return current_filepath.replace(current_modpath, '') def list_modules(pkg, exclude=None): exclude = exclude or [] pkg_path = os.path.join(get_exec_path(), pkg.replace('.', os.sep)) return [i for i in os.listdir(pkg_path) if i.endswith('.py') and i not in exclude] def register_language_converters():
distrib = pkg_resources.Distribution(location=os.path.join(get_exec_path(),
'subliminal'), project_name='subliminalr', version='0.0.1') ep = { 'babelfish.language_converters': [ 'alpha2 = babelfish.converters.alpha2:Alpha2Converter', 'alpha3b = babelfish.converters.alpha3b:Alpha3BConverter', 'alpha3t = babelfish.converters.alpha3t:Alpha3TConverter', 'name = babelfish.converters.name:NameConverter', 'scope = babelfish.converters.scope:ScopeConverter', 'type = babelfish.converters.type:LanguageTypeConverter', 'opensubtitles = babelfish.converters.opensubtitles:OpenSubtitlesConverter'], 'babelfish.country_converters': ['name = babelfish.converters.countryname:CountryNameConverter'] }
logger.debug('Searching for available language converters...')
# Scan converters directory and add found converters:
for i in list_modules(__name__, exclude='__init__.py'):
module = importlib.import_module('.' + os.path.splitext(i)[0], __name__)
for c in inspect.getmembers(module, predicate=lambda o:
inspect.isclass(o) and issubclass(o, LanguageConverter) and o not in [LanguageConverter, LanguageReverseConverter]): try: ep['babelfish.language_converters'].append('%s = %s:%s' % (os.path.splitext(i)[0], c[1].module, c[1].name)) logger.debug('Registered language converter %r' % unicode(c[0])) except Exception, e: logger.error('Could not register language converter %r (%s)' % (unicode(c[0]), e))
distrib._ep_map = pkg_resources.EntryPoint.parse_map(ep, distrib)
pkg_resources.working_set.add(distrib)
— Reply to this email directly or view it on GitHubhttps://github.com/Diaoul/babelfish/issues/9#issuecomment-30517619 .
Is resolved thank you guys.
Closing issue then. Feel free to reopen if this still happens to you.
Hi Diaoul I'm trying to play with babelfish code for future import on sb. Trying the code in docs and I have this problem:
language = babelfish.Language('por', 'BR') language return:
Traceback (most recent call last): File "<pyshell#7>", line 1, in
language
File "C:\Python27\lib\site-packages\babelfish\language.py", line 150, in repr
return '<Language [%s]>' % self
File "C:\Python27\lib\site-packages\babelfish\language.py", line 154, in str
s = self.alpha2
File "C:\Python27\lib\site-packages\babelfish\language.py", line 132, in getattr
raise AttributeError(name)
AttributeError: alpha2
I've installed babelfish without using setup but copying babelfish directory in my python site-packaged directory....I know this is not the best way to install but in this way I can test if the library can work without problem in sickbeard.
thanks.
Mr_Orange.