Repository: frappe/frappe

Issue:
Creation of unnecessary __init__.py files
<!--
Welcome to the Frappe Framework issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to Frappe
    - For questions and general support, use https://stackoverflow.com/questions/tagged/frappe
    - For documentation issues, refer to https://frappeframework.com/docs/user/en or the developer cheetsheet https://github.com/frappe/frappe/wiki/Developer-Cheatsheet
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
4. If you think you know what the reason for the bug is, share it with us. Maybe put in a PR 😉
-->

## Description of the issue
I am using multiple self created pages inside my application. Since version 14, I encountered some issues with the automatic creation of `__init__.py` files in the pages directory. Each of my pages have multiple sub-directories to manage the files. One example page looks like this:
```
dashboard/
├── admin_card.js
├── config
│   ├── defaults.js
│   └── __init__.py        <-- not needed
├── dashboard.js
├── dashboard_widget.js
├── index.html
├── index.js
├── index.py
├── __init__.py
├── interface
│   ├── dashboard.py
│   └── __init__.py        <-- maybe not needed
└── styles
    ├── index.scss
    └── __init__.py        <-- not needed
```
But during `bench migrate`, frappe will automatically create `__init__.py` files in all of my sub directories. Since the init files are only needed for python modules, I want to get rid of them everywhere else.

## Context information (for bug reports)

**Output of `bench version`**
```
erpnext 14.63.1
frappe 14.66.2
```

## Steps to reproduce the issue

1. Create a new page with multiple sub directories
2. `bench migrate`
3. `__init__.py` files will be generated in each sub directory.

### Observed result
`__init__.py` files are generated in every sub directoy.

### Expected result
`__init__.py` files should only be generated on the top-level directory of the page.

### Stacktrace / full error message
/

## Additional information
I think the issue is caused by the function `get_pages_from_path` in `router.py`. My suggestion is to just create the init-file inside the top-level directory. It could be easier to move this functionality out of the function get_pages_from_path, since regarding it's name it should only get the pages without creating anything.

Creation of unnecessary __init__.py files
<!--
Welcome to the Frappe Framework issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to Frappe
    - For questions and general support, use https://stackoverflow.com/questions/tagged/frappe
    - For documentation issues, refer to https://frappeframework.com/docs/user/en or the developer cheetsheet https://github.com/frappe/frappe/wiki/Developer-Cheatsheet
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
4. If you think you know what the reason for the bug is, share it with us. Maybe put in a PR 😉
-->

## Description of the issue
I am using multiple self created pages inside my application. Since version 14, I encountered some issues with the automatic creation of `__init__.py` files in the pages directory. Each of my pages have multiple sub-directories to manage the files. One example page looks like this:
```
dashboard/
├── admin_card.js
├── config
│   ├── defaults.js
│   └── __init__.py        <-- not needed
├── dashboard.js
├── dashboard_widget.js
├── index.html
├── index.js
├── index.py
├── __init__.py
├── interface
│   ├── dashboard.py
│   └── __init__.py        <-- maybe not needed
└── styles
    ├── index.scss
    └── __init__.py        <-- not needed
```
But during `bench migrate`, frappe will automatically create `__init__.py` files in all of my sub directories. Since the init files are only needed for python modules, I want to get rid of them everywhere else.

## Context information (for bug reports)

**Output of `bench version`**
```
erpnext 14.63.1
frappe 14.66.2
```

## Steps to reproduce the issue

1. Create a new page with multiple sub directories
2. `bench migrate`
3. `__init__.py` files will be generated in each sub directory.

### Observed result
`__init__.py` files are generated in every sub directoy.

### Expected result
`__init__.py` files should only be generated on the top-level directory of the page.

### Stacktrace / full error message
/

## Additional information
I think the issue is caused by the function `get_pages_from_path` in `router.py`. My suggestion is to just create the init-file inside the top-level directory. It could be easier to move this functionality out of the function get_pages_from_path, since regarding it's name it should only get the pages without creating anything.



Discussion:

Resolving patch:
diff --git a/frappe/website/router.py b/frappe/website/router.py
--- a/frappe/website/router.py
+++ b/frappe/website/router.py
@@ -110,10 +110,6 @@ def get_pages_from_path(start, app, app_path):
 	start_path = os.path.join(app_path, start)
 	if os.path.exists(start_path):
 		for basepath, folders, files in os.walk(start_path):  # noqa: B007
-			# add missing __init__.py
-			if "__init__.py" not in files and frappe.conf.get("developer_mode"):
-				open(os.path.join(basepath, "__init__.py"), "a").close()
-
 			for fname in files:
 				fname = frappe.utils.cstr(fname)
 				if "." not in fname:
@@ -128,7 +124,6 @@ def get_pages_from_path(start, app, app_path):
 						os.path.join(basepath, fname), app, start, basepath, app_path, fname
 					)
 					pages[page_info.route] = page_info
-					# print frappe.as_json(pages[-1])
 
 	return pages
 


Test patch: