Skip to content

Commit

Permalink
Upgrade to Masonite 4 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
girardinsamuel authored Oct 30, 2021
1 parent 35941d1 commit 850e11b
Show file tree
Hide file tree
Showing 75 changed files with 590 additions and 878 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ updates:
labels:
- "configuration"

# Maintain dependencies for GitHub Actions for generated project
- package-ecosystem: "github-actions"
directory: "{{cookiecutter.project_slug}}/"
schedule:
interval: "weekly"
assignees:
- "girardinsamuel"
labels:
- "configuration"

# Maintain dependencies for cookiecutter repo
- package-ecosystem: "pip"
directory: "/"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Cookiecutter Masonite Package

<p align="center">
<img alt="GitHub Workflow Status (branch)" src="https://img.shields.io/github/workflow/status/girardinsamuel/cookiecutter-masonite-package/Test%20Application/master">
<img alt="GitHub Workflow Status (branch)" src="https://img.shields.io/github/workflow/status/girardinsamuel/cookiecutter-masonite-package/Test%20Application">
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/girardinsamuel/cookiecutter-masonite-package">
<img alt="GitHub" src="https://img.shields.io/github/license/girardinsamuel/cookiecutter-masonite-package">
</p>
Expand Down
16 changes: 5 additions & 11 deletions generate_demo_project.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
import sys
from cookiecutter.main import cookiecutter

# display info on the README about this cookiecutter thing
project_description = """Demo package to show Masonite cookiecutter scaffolding result.
**This package has been generated with [Cookiecutter Masonite Package](https://github.com/girardinsamuel/cookiecutter-masonite-package). The badges will display correctly at first Github release and first PyPi publish.**
**To report bugs or request features please use the [Cookiecutter Masonite Package](https://github.com/girardinsamuel/cookiecutter-masonite-package) repo directly.**"""

# Clean old generated masonite demo package which are not cleaned by cookiecutter because hidden
shutil.rmtree("../masonite-demo-package/.github/", ignore_errors=True)

# Get template to use
options = sys.argv
tag = None
template = 'https://github.com/girardinsamuel/cookiecutter-masonite-package.git'
template = "https://github.com/girardinsamuel/cookiecutter-masonite-package.git"

if len(options) == 2:
tag = options[1]

Expand All @@ -32,10 +26,10 @@
checkout=tag,
extra_context={
"project_name": "Demo Package",
"project_description": project_description
}
"project_description": "Demo package to show Masonite package generator.",
},
)

os.chdir("../masonite-demo-package")

# Then commit manually "update with vX.X"
# Then commit manually "update with vX.X"
30 changes: 26 additions & 4 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
#!/usr/bin/env python
import os
import pdb
from requests.utils import requote_uri

TERMINATOR = "\x1b[0m"
WARNING = "\x1b[1;33m [WARNING]: "
INFO = "\x1b[1;33m [INFO]: "
HINT = "\x1b[3;33m"
SUCCESS = "\x1b[1;32m [SUCCESS]: "

pkg_name = "{{ cookiecutter.project_name }}"

PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)


def remove_file(filepath):
os.remove(os.path.join(PROJECT_DIRECTORY, filepath))


if 'Not open source' == '{{ cookiecutter.open_source_license }}':
remove_file('LICENSE')
if "Not open source" == "{{ cookiecutter.open_source_license }}":
remove_file("LICENSE")

# Generate Beyond code banner with https://banners.beyondco.de in README header
pip_name = "{{ cookiecutter.project_slug }}"
package_name = "{{ cookiecutter.project_name }}"
description = "{{ cookiecutter.project_description }}"
package_name_encoded = requote_uri(package_name)
description_encoded = requote_uri(description)
pattern = "topography"
line = f"""<p align="center">
<img src="https://banners.beyondco.de/{package_name_encoded}.png?theme=light&packageManager=pip+install&packageName={pip_name}&pattern={pattern}&style=style_1&description={description_encoded}&md=1&showWatermark=1&fontSize=100px&images=https%3A%2F%2Fgblobscdn.gitbook.com%2Fspaces%2F-L9uc-9XAlqhXkBwrLMA%2Favatar.png">
</p>
"""
with open(os.path.join(PROJECT_DIRECTORY, "README.md"), "r+") as f:
content = f.read()
f.seek(0, 0)
f.write(line.rstrip("\r\n") + "\n" + content)

print(SUCCESS+"Your package is ready to be developed ! => cd {{cookiecutter.project_slug}}/"+TERMINATOR)
print(
SUCCESS
+ "Your package is ready to be developed ! => cd {{cookiecutter.project_slug}}/"
+ TERMINATOR
)
32 changes: 26 additions & 6 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,42 @@
SUCCESS = "\x1b[1;32m [SUCCESS]: "


pkg_name = '{{ cookiecutter.pkg_name }}'
pip_name = '{{ cookiecutter.project_slug }}'
pkg_name = "{{ cookiecutter.pkg_name }}"
pip_name = "{{ cookiecutter.project_slug }}"


if not pip_name.startswith("masonite-"):
print(WARNING + '%s is not a valid Masonite pip package! Reasons: pip package name should start with masonite-.' % pkg_name + TERMINATOR)
print(
WARNING
+ "%s is not a valid Masonite pip package! Reasons: pip package name should start with masonite-."
% pkg_name
+ TERMINATOR
)
sys.exit(1)

if not re.match(r"^[a-z0-9_-]+$", pip_name):
print(WARNING + '%s is not a valid Masonite pip package! Reasons: Python pip package should contain only a-z,0-9,_,-.' % pkg_name + TERMINATOR)
print(
WARNING
+ "%s is not a valid Masonite pip package! Reasons: Python pip package should contain only a-z,0-9,_,-."
% pkg_name
+ TERMINATOR
)
sys.exit(1)

if "masonite" in pkg_name:
print(WARNING + "%s is not a valid Masonite package! Reasons: package name cannot contains masonite as it will be imported from 'masonite.'." % pkg_name + TERMINATOR)
print(
WARNING
+ "%s is not a valid Masonite package! Reasons: package name cannot contains masonite as it will be imported from 'masonite.'."
% pkg_name
+ TERMINATOR
)
sys.exit(1)

if not re.match(r"^[a-z0-9_]+$", pkg_name):
print(WARNING + '%s is not a valid Python package! Reasons: package name should contain a-z,0-9,_ only.' % pkg_name + TERMINATOR)
print(
WARNING
+ "%s is not a valid Python package! Reasons: package name should contain a-z,0-9,_ only."
% pkg_name
+ TERMINATOR
)
sys.exit(1)
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cookiecutter==1.7.2
binaryornot==0.4.4
cookiecutter
binaryornot
pyyaml
flake8
black

# Testing
# ------------------------------------------------------------------------------
pytest-cookies
pytest==6.2.3
pytest==6.2.4
pytest-instafail==0.4.2
masonite>=3.0<4.0
masonite-validation==3.0.14
masonite-logging==1.0.1
pyyaml==5.4.1
flake8==3.9.1
black==21.7b0
https://github.com/MasoniteFramework/masonite4/archive/master.zip
https://github.com/MasoniteFramework/orm/archive/2.0.zip
cryptography
21 changes: 14 additions & 7 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def test_invalid_project_slug_if_no_pip_installable(cookies, context, slug):
assert isinstance(result.exception, FailedHookException)


@pytest.mark.parametrize("slug", ["project-slug", "project", "project_slug", "project-masonite"])
@pytest.mark.parametrize(
"slug", ["project-slug", "project", "project_slug", "project-masonite"]
)
def test_invalid_project_slug_if_no_masonite_namespace(cookies, context, slug):
"""Invalid slug should failed pre-generation hook."""
context.update({"project_slug": slug})
Expand All @@ -122,7 +124,9 @@ def test_package_names_are_valid(cookies, context, pkg):
assert result.exit_code == 0


@pytest.mark.parametrize("pkg", ["project slug", "Project_Slug", "project-slug", "project.slug"])
@pytest.mark.parametrize(
"pkg", ["project slug", "Project_Slug", "project-slug", "project.slug"]
)
def test_invalid_package_name_if_not_python_importable(cookies, context, pkg):
"""Invalid package should failed pre-generation hook."""
context.update({"pkg_name": pkg})
Expand All @@ -131,7 +135,9 @@ def test_invalid_package_name_if_not_python_importable(cookies, context, pkg):
assert isinstance(result.exception, FailedHookException)


@pytest.mark.parametrize("pkg", ["masonite_project", "masoniteproject", "package_masonite"])
@pytest.mark.parametrize(
"pkg", ["masonite_project", "masoniteproject", "package_masonite"]
)
def test_invalid_package_name_if_contains_masonite(cookies, context, pkg):
"""Invalid package should failed pre-generation hook."""
context.update({"pkg_name": pkg})
Expand Down Expand Up @@ -159,9 +165,10 @@ def test_generation_and_run_tests(cookies, context):
result = cookies.bake(extra_context=context)
assert result.exit_code == 0
assert result.project.isdir()
run_inside_dir('cp .env-example .env', str(result.project)) == 0
run_inside_dir('pip install .', str(result.project)) == 0
run_inside_dir('python -m pytest tests', str(result.project)) == 0
run_inside_dir("cp .env-example .env", str(result.project)) == 0
run_inside_dir("pip install -r requirements.txt", str(result.project)) == 0
run_inside_dir("pip install .", str(result.project)) == 0
run_inside_dir("python -m pytest tests", str(result.project)) == 0


def test_flake8_passes(cookies, context):
Expand Down Expand Up @@ -192,6 +199,6 @@ def test_can_import_package_in_masonite_namespace(cookies, context):
for now only packages sources (src/*)"""
result = cookies.bake(extra_context=context)

test_command = "import masonite.{0}".format(context['pkg_name'])
test_command = "import masonite.{0}".format(context["pkg_name"])
run_inside_dir("python -c '{0}'".format(test_command), str(result.project))
assert result is not None
4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/.env-example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_DEBUG=True
APP_ENV=development

APP_KEY=plyUWY8iZnEH9_8WrVjl-LS3B8aRtHK9UAB35fGAq0M=
DB_CONFIG_PATH=tests/integrations/config/database
DB_CONNECTION=sqlite
DB_DATABASE={{cookiecutter.pkg_name}}.db
15 changes: 15 additions & 0 deletions {{cookiecutter.project_slug}}/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

# Maintain dependencies for cookiecutter repo
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
# Allow up to 10 open pull requests for pip dependencies
open-pull-requests-limit: 10
22 changes: 13 additions & 9 deletions {{cookiecutter.project_slug}}/.github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,35 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
python-version: ["3.7", "3.8", "3.9", "3.10"]
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
make init
- name: Test with pytest and Build coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
make coverage
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false

lint:
runs-on: ubuntu-latest
name: Lint
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.6
uses: actions/setup-python@v1
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: 3.8
- name: Intall Flake8
run: |
pip install flake8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ coverage.xml
dist
.env
*.db
masonite.egg-info
src/masonite_{{cookiecutter.pkg_name}}.egg-info
4 changes: 4 additions & 0 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ _Explain how to use your package_

Please read the [Contributing Documentation](CONTRIBUTING.md) here.

## Maintainers

- [{{ cookiecutter.full_name }}](https://www.github.com/{{ cookiecutter.github_username }})

## License

{% if cookiecutter.open_source_license == 'Not open source' -%}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 850e11b

Please sign in to comment.