Skip to content

Commit

Permalink
feat(DX): PEP517 compatible build in new apps (backport #21704) (#23776)
Browse files Browse the repository at this point in the history
* feat(DX): PEP517 compatible build in new apps (#21704)

* chore: remove setup.py requirements.txt boilerplate

* feat(DX): PEP517 compatible builds on new apps

closes #21612

(cherry picked from commit 8436f77)

# Conflicts:
#	frappe/utils/boilerplate.py

* chore: resolve conflicts

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 13, 2023
1 parent 56f5d0e commit 9daefb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 52 deletions.
3 changes: 1 addition & 2 deletions frappe/tests/test_boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def setUpClass(cls):
cls.git_folder = ".git"

cls.root_paths = [
"requirements.txt",
"README.md",
"setup.py",
"pyproject.toml",
"license.txt",
cls.git_folder,
cls.gitignore_file,
Expand Down
74 changes: 24 additions & 50 deletions frappe/utils/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ def _create_app_boilerplate(dest, hooks, no_git=False):
with open(os.path.join(dest, hooks.app_name, hooks.app_name, "__init__.py"), "w") as f:
f.write(frappe.as_unicode(init_template))

with open(os.path.join(dest, hooks.app_name, "MANIFEST.in"), "w") as f:
f.write(frappe.as_unicode(manifest_template.format(**hooks)))

with open(os.path.join(dest, hooks.app_name, "requirements.txt"), "w") as f:
f.write("# frappe -- https://github.com/frappe/frappe is installed via 'bench init'")
with open(os.path.join(dest, hooks.app_name, "pyproject.toml"), "w") as f:
f.write(frappe.as_unicode(pyproject_template.format(**hooks)))

with open(os.path.join(dest, hooks.app_name, "README.md"), "w") as f:
f.write(
Expand All @@ -132,9 +129,6 @@ def _create_app_boilerplate(dest, hooks, no_git=False):
for key in ("app_publisher", "app_description", "app_license"):
hooks[key] = hooks[key].replace("\\", "\\\\").replace("'", "\\'").replace('"', '\\"')

with open(os.path.join(dest, hooks.app_name, "setup.py"), "w") as f:
f.write(frappe.as_unicode(setup_template.format(**hooks)))

with open(os.path.join(dest, hooks.app_name, hooks.app_name, "hooks.py"), "w") as f:
f.write(frappe.as_unicode(hooks_template.format(**hooks)))

Expand Down Expand Up @@ -279,33 +273,34 @@ def _create_parent_folder_if_not_exists(self):
init_py.touch()


manifest_template = """include MANIFEST.in
include requirements.txt
include *.json
include *.md
include *.py
include *.txt
recursive-include {app_name} *.css
recursive-include {app_name} *.csv
recursive-include {app_name} *.html
recursive-include {app_name} *.ico
recursive-include {app_name} *.js
recursive-include {app_name} *.json
recursive-include {app_name} *.md
recursive-include {app_name} *.png
recursive-include {app_name} *.py
recursive-include {app_name} *.svg
recursive-include {app_name} *.txt
recursive-exclude {app_name} *.pyc"""

init_template = """
__version__ = '0.0.1'
"""

hooks_template = """from . import __version__ as app_version
pyproject_template = """[project]
name = "{app_name}"
authors = [
{{ name = "{app_publisher}", email = "{app_email}"}}
]
description = "{app_description}"
requires-python = ">=3.10"
readme = "README.md"
dynamic = ["version"]
dependencies = [
# "frappe~=15.0.0" # Installed and managed by bench.
]
[build-system]
requires = ["flit_core >=3.4,<4"]
build-backend = "flit_core.buildapi"
# These dependencies are only installed when developer mode is enabled
[tool.bench.dev-dependencies]
# package_name = "~=1.1.0"
"""

app_name = "{app_name}"
hooks_template = """app_name = "{app_name}"
app_title = "{app_title}"
app_publisher = "{app_publisher}"
app_description = "{app_description}"
Expand Down Expand Up @@ -534,27 +529,6 @@ def get_data():
]
"""

setup_template = """from setuptools import setup, find_packages
with open("requirements.txt") as f:
install_requires = f.read().strip().split("\\n")
# get version from __version__ variable in {app_name}/__init__.py
from {app_name} import __version__ as version
setup(
name="{app_name}",
version=version,
description="{app_description}",
author="{app_publisher}",
author_email="{app_email}",
packages=find_packages(),
zip_safe=False,
include_package_data=True,
install_requires=install_requires
)
"""

gitignore_template = """.DS_Store
*.pyc
*.egg-info
Expand Down

0 comments on commit 9daefb6

Please sign in to comment.