mirror of https://github.com/scrapy/scrapy.git
Merge pull request #4676 from Gallaecio/startproject-existing-folder
Fix startproject failing for existing folders
This commit is contained in:
commit
ada539a63a
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
import os
|
||||
import string
|
||||
from importlib import import_module
|
||||
from importlib.util import find_spec
|
||||
from os.path import join, exists, abspath
|
||||
from shutil import ignore_patterns, move, copy2, copystat
|
||||
from stat import S_IWUSR as OWNER_WRITE_PERMISSION
|
||||
|
|
@ -42,11 +42,8 @@ class Command(ScrapyCommand):
|
|||
|
||||
def _is_valid_name(self, project_name):
|
||||
def _module_exists(module_name):
|
||||
try:
|
||||
import_module(module_name)
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
spec = find_spec(module_name)
|
||||
return spec is not None and spec.loader is not None
|
||||
|
||||
if not re.search(r'^[_a-zA-Z]\w*$', project_name):
|
||||
print('Error: Project names must begin with a letter and contain'
|
||||
|
|
|
|||
|
|
@ -71,9 +71,14 @@ class ProjectTest(unittest.TestCase):
|
|||
|
||||
def proc(self, *new_args, **popen_kwargs):
|
||||
args = (sys.executable, '-m', 'scrapy.cmdline') + new_args
|
||||
p = subprocess.Popen(args, cwd=self.cwd, env=self.env,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
**popen_kwargs)
|
||||
p = subprocess.Popen(
|
||||
args,
|
||||
cwd=popen_kwargs.pop('cwd', self.cwd),
|
||||
env=self.env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
**popen_kwargs,
|
||||
)
|
||||
|
||||
def kill_proc():
|
||||
p.kill()
|
||||
|
|
@ -93,7 +98,10 @@ class ProjectTest(unittest.TestCase):
|
|||
class StartprojectTest(ProjectTest):
|
||||
|
||||
def test_startproject(self):
|
||||
self.assertEqual(0, self.call('startproject', self.project_name))
|
||||
p, out, err = self.proc('startproject', self.project_name)
|
||||
print(out)
|
||||
print(err, file=sys.stderr)
|
||||
self.assertEqual(p.returncode, 0)
|
||||
|
||||
assert exists(join(self.proj_path, 'scrapy.cfg'))
|
||||
assert exists(join(self.proj_path, 'testproject'))
|
||||
|
|
@ -128,6 +136,25 @@ class StartprojectTest(ProjectTest):
|
|||
self.assertEqual(2, self.call('startproject'))
|
||||
self.assertEqual(2, self.call('startproject', self.project_name, project_dir, 'another_params'))
|
||||
|
||||
def test_existing_project_dir(self):
|
||||
project_dir = mkdtemp()
|
||||
project_name = self.project_name + '_existing'
|
||||
project_path = os.path.join(project_dir, project_name)
|
||||
os.mkdir(project_path)
|
||||
|
||||
p, out, err = self.proc('startproject', project_name, cwd=project_dir)
|
||||
print(out)
|
||||
print(err, file=sys.stderr)
|
||||
self.assertEqual(p.returncode, 0)
|
||||
|
||||
assert exists(join(abspath(project_path), 'scrapy.cfg'))
|
||||
assert exists(join(abspath(project_path), project_name))
|
||||
assert exists(join(join(abspath(project_path), project_name), '__init__.py'))
|
||||
assert exists(join(join(abspath(project_path), project_name), 'items.py'))
|
||||
assert exists(join(join(abspath(project_path), project_name), 'pipelines.py'))
|
||||
assert exists(join(join(abspath(project_path), project_name), 'settings.py'))
|
||||
assert exists(join(join(abspath(project_path), project_name), 'spiders', '__init__.py'))
|
||||
|
||||
|
||||
def get_permissions_dict(path, renamings=None, ignore=None):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue