mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 01:48:04 +03:00 
			
		
		
		
	Port over #2949
This commit is contained in:
		
							parent
							
								
									ec5ee9e616
								
							
						
					
					
						commit
						c62d06ea5c
					
				| 
						 | 
					@ -5,6 +5,7 @@ import sys
 | 
				
			||||||
import ujson
 | 
					import ujson
 | 
				
			||||||
import itertools
 | 
					import itertools
 | 
				
			||||||
import locale
 | 
					import locale
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from thinc.neural.util import copy_array
 | 
					from thinc.neural.util import copy_array
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,7 +85,7 @@ def getattr_(obj, name, *default):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def symlink_to(orig, dest):
 | 
					def symlink_to(orig, dest):
 | 
				
			||||||
    if is_python2 and is_windows:
 | 
					    if is_windows:
 | 
				
			||||||
        import subprocess
 | 
					        import subprocess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        subprocess.call(["mklink", "/d", path2str(orig), path2str(dest)], shell=True)
 | 
					        subprocess.call(["mklink", "/d", path2str(orig), path2str(dest)], shell=True)
 | 
				
			||||||
| 
						 | 
					@ -92,6 +93,15 @@ def symlink_to(orig, dest):
 | 
				
			||||||
        orig.symlink_to(dest)
 | 
					        orig.symlink_to(dest)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def symlink_remove(link):
 | 
				
			||||||
 | 
					    # https://stackoverflow.com/q/26554135/6400719
 | 
				
			||||||
 | 
					    if os.path.isdir(path2str(link)) and is_windows:
 | 
				
			||||||
 | 
					        # this should only be on Py2.7 and windows
 | 
				
			||||||
 | 
					        os.rmdir(path2str(link))
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        os.unlink(path2str(link))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def is_config(python2=None, python3=None, windows=None, linux=None, osx=None):
 | 
					def is_config(python2=None, python3=None, windows=None, linux=None, osx=None):
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        python2 in (None, is_python2)
 | 
					        python2 in (None, is_python2)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										38
									
								
								spacy/tests/test_cli.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								spacy/tests/test_cli.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,38 @@
 | 
				
			||||||
 | 
					# coding: utf-8
 | 
				
			||||||
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import pytest
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					from spacy.compat import symlink_to, symlink_remove, path2str
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@pytest.fixture
 | 
				
			||||||
 | 
					def target_local_path():
 | 
				
			||||||
 | 
					    return Path("./foo-target")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@pytest.fixture
 | 
				
			||||||
 | 
					def link_local_path():
 | 
				
			||||||
 | 
					    return Path("./foo-symlink")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@pytest.fixture(scope="function")
 | 
				
			||||||
 | 
					def setup_target(request, target_local_path, link_local_path):
 | 
				
			||||||
 | 
					    if not target_local_path.exists():
 | 
				
			||||||
 | 
					        os.mkdir(path2str(target_local_path))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # yield -- need to cleanup even if assertion fails
 | 
				
			||||||
 | 
					    # https://github.com/pytest-dev/pytest/issues/2508#issuecomment-309934240
 | 
				
			||||||
 | 
					    def cleanup():
 | 
				
			||||||
 | 
					        symlink_remove(link_local_path)
 | 
				
			||||||
 | 
					        os.rmdir(path2str(target_local_path))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    request.addfinalizer(cleanup)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_create_symlink_windows(setup_target, target_local_path, link_local_path):
 | 
				
			||||||
 | 
					    assert target_local_path.exists()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    symlink_to(link_local_path, target_local_path)
 | 
				
			||||||
 | 
					    assert link_local_path.exists()
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user