8000 first steps to handling nested subpaths · pythonanywhere/helper_scripts@e687d7f · GitHub
[go: up one dir, main page]

Skip to content

Commit e687d7f

Browse files
committed
first steps to handling nested subpaths
1 parent 5ab3394 commit e687d7f

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

pythonanywhere/django_project.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,19 @@ def run_startproject(self, nuke):
7373

7474
def find_django_files(self):
7575
try:
76-
for subfolder in self.project_path.iterdir():
77-
if subfolder.is_dir():
78-
if 'settings.py' in os.listdir(subfolder):
79-
self.settings_path = subfolder / 'settings.py'
80-
if 'manage.py' in os.listdir(self.project_path):
81-
self.manage_py_path = self.project_path / 'manage.py'
76+
for subpath in self.project_path.iterdir():
77+
if subpath.is_dir():
78+
if 'settings.py' in os.listdir(subpath):
79+
self.settings_path = subpath / 'settings.py'
80+
else:
81+
for subsubpath in subpath.iterdir():
82+
if subsubpath.is_dir():
83+
if 'settings.py' in os.listdir(subsubpath):
84+
self.settings_path = subsubpath / 'settings.py'
85+
86+
for subdir in [self.project_path] + [c for c in self.project_path.iterdir() if c.is_dir()]:
87+
if 'manage.py' in os.listdir(subdir):
88+
self.manage_py_path = subdir / 'manage.py'
8289

8390
except FileNotFoundError:
8491
raise SanityException('Could not find your settings.py')

tests/test_django_project.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,19 @@ def non_nested_submodule():
216216
cwd=submodule_path
217217
)
218218
yield submodule_path
219+
subprocess.check_call(['git', 'submodule', 'update', '--init', '--recursive'])
220+
221+
222+
@pytest.fixture
223+
def more_nested_submodule():
224+
subprocess.check_call(['git', 'submodule', 'update', '--init', '--recursive'])
225+
submodule_path = Path(__file__).parents[1] / 'submodules' / 'example-django-project'
219226
subprocess.check_call(
220-
['git', 'checkout', 'master'],
227+
['git', 'checkout', 'morenested'],
221228
cwd=submodule_path
222229
)
223-
230+
yield submodule_path
231+
subprocess.check_call(['git', 'submodule', 'update', '--init', '--recursive'])
224232

225233

226234

@@ -240,6 +248,20 @@ def test_non_nested(self, fake_home, non_nested_submodule):
240248
assert project.manage_py_path == expected_manage_py
241249

242250

251+
def test_nested(self, fake_home, more_nested_submodule):
252+
project = DjangoProject('mydomain.com')
253+
shutil.copytree(more_nested_submodule, project.project_path)
254+
expected_settings_path = project.project_path / 'mysite/mysite/settings.py'
255+
assert expected_settings_path.exists()
256+
expected_manage_py = project.project_path / 'mysite/manage.py'
257+
assert expected_manage_py.exists()
258+
259+
project.find_django_files()
260+
261+
assert project.settings_path == expected_settings_path
262+
assert project.manage_py_path == expected_manage_py
263+
264+
243265
def test_raises_if_empty_project_folder(self, fake_home):
244266
project = DjangoProject('mydomain.com')
245267
with pytest.raises(SanityException) as e:
@@ -270,6 +292,7 @@ def test_raises_if_manage_py_not_found(self, fake_home, non_nested_submodule):
270292
assert 'Could not find your manage.py' in str(e.value)
271293

272294

295+
273296
class TestUpdateSettingsFile:
274297

275298
def test_adds_STATIC_and_MEDIA_config_to_settings(self):

tests/test_pa_autoconfigure_django.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def test_actually_works_against_example_repo(self, fake_home, virtualenvs_folder
7979

8080

8181
def xtest_todos():
82-
assert not 'mysite hard-coded'
83-
assert not 'existing-project sanity checks eg settings.py not found, requirements empty'
82+
assert not 'correct working dir / sys.path for nested projects'
83+
assert not 'existing-project sanity checks eg requirements empty'
8484
assert not 'nuke option shouldnt barf if nothing to nuke'
8585
assert not 'SECRET_KEY'
8686
assert not 'database stuff?'

0 commit comments

Comments
 (0)
0