mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-30 23:47:31 +03:00 
			
		
		
		
	Don't check for Jupyter in global scope and fix check (#3213)
Resolves #3208. Prevent interactions with other libraries (pandas) that also access `get_ipython().config` and its parameters. See #3208 for details. I don't fully understand why this happens, but in spaCy, we can at least make sure we avoid calling into this method. <!--- Provide a general summary of your changes in the title. --> ## Description <!--- Use this section to describe your changes. If your changes required testing, include information about the testing environment and the tests you ran. If your test fixes a bug reported in an issue, don't forget to include the issue number. If your PR is still a work in progress, that's totally fine – just include a note to let us know. --> ### Types of change <!-- What type of change does your PR cover? Is it a bug fix, an enhancement or new feature, or a change to the documentation? --> ## Checklist <!--- Before you submit the PR, go over this checklist and make sure you can tick off all the boxes. [] -> [x] --> - [x] I have submitted the spaCy Contributor Agreement. - [x] I ran the tests, and all new and existing tests passed. - [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
This commit is contained in:
		
							parent
							
								
									b34bc9d2e9
								
							
						
					
					
						commit
						e9a6dbe4f3
					
				|  | @ -9,10 +9,9 @@ from ..util import prints, is_in_jupyter | |||
| 
 | ||||
| 
 | ||||
| _html = {} | ||||
| IS_JUPYTER = is_in_jupyter() | ||||
| 
 | ||||
| 
 | ||||
| def render(docs, style='dep', page=False, minify=False, jupyter=IS_JUPYTER, | ||||
| def render(docs, style='dep', page=False, minify=False, jupyter=False, | ||||
|            options={}, manual=False): | ||||
|     """Render displaCy visualisation. | ||||
| 
 | ||||
|  | @ -39,7 +38,7 @@ def render(docs, style='dep', page=False, minify=False, jupyter=IS_JUPYTER, | |||
|     parsed = [converter(doc, options) for doc in docs] if not manual else docs | ||||
|     _html['parsed'] = renderer.render(parsed, page=page, minify=minify).strip() | ||||
|     html = _html['parsed'] | ||||
|     if jupyter:  # return HTML rendered by IPython display() | ||||
|     if jupyter or is_in_jupyter():  # return HTML rendered by IPython display() | ||||
|         from IPython.core.display import display, HTML | ||||
|         return display(HTML(html)) | ||||
|     return html | ||||
|  |  | |||
|  | @ -222,15 +222,15 @@ def get_package_path(name): | |||
| def is_in_jupyter(): | ||||
|     """Check if user is running spaCy from a Jupyter notebook by detecting the | ||||
|     IPython kernel. Mainly used for the displaCy visualizer. | ||||
| 
 | ||||
|     RETURNS (bool): True if in Jupyter, False if not. | ||||
|     """ | ||||
|     # https://stackoverflow.com/a/39662359/6400719 | ||||
|     try: | ||||
|         cfg = get_ipython().config | ||||
|         if cfg['IPKernelApp']['parent_appname'] == 'ipython-notebook': | ||||
|             return True | ||||
|         shell = get_ipython().__class__.__name__ | ||||
|         if shell == "ZMQInteractiveShell": | ||||
|             return True  # Jupyter notebook or qtconsole | ||||
|     except NameError: | ||||
|         return False | ||||
|         return False  # Probably standard Python interpreter | ||||
|     return False | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user