Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023 Updates #20

Merged
merged 13 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ jobs:
strategy:
matrix:
include:
- tox-env: py37
python-version: "3.7"
- tox-env: py38
python-version: "3.8"
- tox-env: py39
python-version: "3.9"
- tox-env: pypy3
python-version: pypy3
python-version: "pypy3.9"
Zeitsperre marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.9.1
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"make_docs": "y",
"command_line_interface": ["Click", "Argparse", "No command-line interface"],
"create_author_file": "y",
"open_source_license": ["MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"],
"open_source_license": ["MIT", "BSD-3-Clause", "ISC", "Apache-2.0", "GPL-3.0-or-later", "Not open source"],
"generated_with_cruft": "y"
}
24 changes: 24 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ def remove_folder(folderpath):
Path(PROJECT_DIRECTORY).joinpath(folderpath).rmdir()


def replace_contents(filepath):
replacements = {
"__PYTHON_VERSION__": 'matrix.python-version',
"__GITHUB_TOKEN__": 'secrets.GITHUB_TOKEN',
'__TOX_ENV__': 'matrix.tox-env',
"__PYPI_API_TOKEN__": "secrets.PYPI_API_TOKEN",
"__TESTPYPI_API_TOKEN__": "secrets.TEST_PYPI_API_TOKEN"
}

lines = []
with open(filepath) as infile:
for line in infile:
for src, target in replacements.items():
line = line.replace(src, " ".join(["${ {".replace(" ", ""), target, "} }".replace(" ", "")]))
lines.append(line)
with open(filepath, 'w') as outfile:
for line in lines:
outfile.write(line)


if __name__ == "__main__":

if "{{ cookiecutter.create_author_file }}" != "y":
Expand All @@ -33,3 +53,7 @@ def remove_folder(folderpath):

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

for f in Path(".github/workflows").glob("*.yml"):
replace_contents(f)
4 changes: 2 additions & 2 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
if not re.match(MODULE_REGEX, module_name):
print('ERROR: The project slug (%s) is not a valid Python module name. Please do not use a - and use _ instead' % module_name)

#Exit to cancel project
sys.exit(1)
# Exit to cancel project
sys.exit(1)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ replace = version='{new_version}'
[tool:pytest]
addopts = --verbose
markers =
requires_precommit: mark tests that can only be run with precommit present
precommit: mark tests that can only be run with precommit present
42 changes: 15 additions & 27 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import subprocess
import sys
from contextlib import contextmanager
from pathlib import Path

import yaml
import datetime
import pytest
from cookiecutter.utils import rmtree

from click.testing import CliRunner

import importlib
import importlib.util


@contextmanager
Expand All @@ -35,6 +35,7 @@ def bake_in_temp_dir(cookies, *args, **kwargs):
:param cookies: pytest_cookies.Cookies,
cookie to be baked and its temporal files will be removed
"""
kwargs.update(template=Path(__file__).parents[1].as_posix())
result = cookies.bake(*args, **kwargs)
try:
yield result
Expand Down Expand Up @@ -93,7 +94,7 @@ def test_bake_and_run_tests(cookies):
print("test_bake_and_run_tests path", str(result.project))


@pytest.mark.requires_precommit
@pytest.mark.precommit
def test_bake_and_run_pre_commit(cookies):
with bake_in_temp_dir(cookies) as result:
assert result.project.isdir()
Expand All @@ -120,17 +121,6 @@ def test_bake_with_apostrophe_and_run_tests(cookies):
run_inside_dir("python setup.py test", str(result.project)) == 0


def test_bake_without_travis_pypi_setup(cookies):
with bake_in_temp_dir(
cookies, extra_context={"use_pypi_deployment_with_travis": "n"}
) as result:
result_travis_config = yaml.load(
result.project.join(".travis.yml").open(), Loader=yaml.FullLoader
)
assert "deploy" not in result_travis_config
assert "python" == result_travis_config["language"]


def test_bake_without_docs(cookies):
with bake_in_temp_dir(cookies, extra_context={"make_docs": "n"}) as result:
found_toplevel_files = [f.basename for f in result.project.listdir()]
Expand Down Expand Up @@ -166,12 +156,11 @@ def test_make_help(cookies):

def test_bake_selecting_license(cookies):
license_strings = {
"MIT license": "MIT ",
"BSD license": "Redistributions of source code must retain the "
+ "above copyright notice, this",
"ISC license": "ISC License",
"Apache Software License 2.0": "Licensed under the Apache License, Version 2.0",
"GNU General Public License v3": "GNU GENERAL PUBLIC LICENSE",
"MIT": "MIT",
"BSD-3-Clause": "Redistributions of source code must retain the above copyright notice, this",
"ISC": "ISC License",
"Apache-2.0": "Licensed under the Apache License, Version 2.0",
"GPL-3.0-or-later": "GNU GENERAL PUBLIC LICENSE",
}
for license, target_string in license_strings.items():
with bake_in_temp_dir(
Expand Down Expand Up @@ -232,7 +221,7 @@ def test_not_using_pytest(cookies):

def test_bake_with_no_console_script(cookies):
context = {"command_line_interface": "No command-line interface"}
result = cookies.bake(extra_context=context)
result = cookies.bake(extra_context=context, template=Path(__file__).parents[1].as_posix())
project_path, project_slug, project_dir = project_info(result)
found_project_files = os.listdir(project_dir)
assert "cli.py" not in found_project_files
Expand All @@ -242,10 +231,10 @@ def test_bake_with_no_console_script(cookies):
assert "entry_points" not in setup_file.read()


@pytest.mark.parametrize("option", ["click", "argparse"])
@pytest.mark.parametrize("option", ["Click", "Argparse"])
def test_bake_with_console_options_script_files(cookies, option):
context = {"command_line_interface": option}
result = cookies.bake(extra_context=context)
result = cookies.bake(extra_context=context, template=Path(__file__).parents[1].as_posix())
project_path, project_slug, project_dir = project_info(result)
found_project_files = os.listdir(project_dir)
assert "cli.py" in found_project_files
Expand All @@ -255,10 +244,9 @@ def test_bake_with_console_options_script_files(cookies, option):
assert "entry_points" in setup_file.read()


@pytest.mark.parametrize("option", ["click", "argparse"])
def test_bake_with_console_options_script_cli(cookies, option):
context = {"command_line_interface": option}
result = cookies.bake(extra_context=context)
def test_bake_with_console_options_script_click(cookies):
context = {"command_line_interface": "Click"}
result = cookies.bake(extra_context=context, template=Path(__file__).parents[1].as_posix())
project_path, project_slug, project_dir = project_info(result)
module_path = os.path.join(project_dir, "cli.py")
module_name = ".".join([project_slug, "cli"])
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/.coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
service_name: github
repo_token: YOURTOKENHERE
# repo_token: YOURTOKENHERE
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Generic issue template
description: For detailing generic/uncategorized issues in {{ cookiecutter.project_name }}

body:
- type: textarea
id: generic-issue
attributes:
label: Generic Issue
description: Please fill in the following information fields as needed.
value: |
* {{ cookiecutter.project_slug }} version:
* Python version:
* Operating System:

### Description
<!--Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.-->

### What I Did
<!--Paste the command(s) you ran and the output.
If there was a crash, please include the traceback below.-->
```
$ pip install foo --bar
```

### What I Received
<!--Paste the output or the stack trace of the problem you experienced here.-->
```
Traceback (most recent call last):
File "/path/to/file/script.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-9e1622b385b6>", line 1, in <module>
1/0
ZeroDivisionError: division by zero
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Bug report
description: Help us improve {{ cookiecutter.project_name }}
labels: [ "bug" ]

body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: setup-information
attributes:
label: Setup Information
description: |
What software versions are you running? Example:
- {{ cookiecutter.project_slug }} version: 0.55.0-gamma
- Python version: 4.2
- Operating System: Nutmeg Linux 12.34 | macOS 11.0 "Redmond"
value: |
- {{ cookiecutter.project_slug }} version:
- Python version:
- Operating System:
- type: textarea
id: description
attributes:
label: Description
description: Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.
- type: textarea
id: steps-to-reproduce
attributes:
label: Steps To Reproduce
description: Paste the command(s) you ran and the output. If there was a crash, please include the traceback below.
- type: textarea
id: additional-context
attributes:
label: Additional context
description: Add any other context about the problem here.
- type: checkboxes
id: submit-pr
attributes:
label: Contribution
description: Do you intend to submit a fix for this bug? (The {{ cookiecutter.project_name }} developers will help with code compliance)
options:
- label: I would be willing/able to open a Pull Request to address this bug.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Feature request
description: Suggest an idea for {{ cookiecutter.project_name }}
labels: [ "enhancement" ]

body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this feature request!
- type: textarea
id: problem
attributes:
label: Addressing a Problem?
description: Is your feature request related to a problem? Please describe it.
- type: textarea
id: potential-solution
attributes:
label: Potential Solution
description: Describe the solution you'd like to see implemented.
- type: textarea
id: additional-context
attributes:
label: Additional context
description: Add any other context about the feature request here.
- type: checkboxes
id: submit-pr
attributes:
label: Contribution
description: Do you intend to submit a fix for this bug? (The {{ cookiecutter.project_name }} developers will help with code compliance)
options:
- label: I would be willing/able to open a Pull Request to contribute this feature.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Question/Support
description: Ask for help from the developers
labels: [ "support" ]

body:
- type: textarea
id: setup-information
attributes:
label: Setup Information
description: |
What software versions are you running? Example:
- {{ cookiecutter.project_slug }} version: 0.55.0-gamma
- Python version: 4.2
- Operating System: Nutmeg Linux 12.34 | macOS 11.0 "Redmond"
value: |
- {{ cookiecutter.project_slug }} version:
- Python version:
- Operating System:
- type: textarea
id: description
attributes:
label: Context
description: Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: First Pull Request

on:
pull_request_target:
types:
- opened

jobs:
welcome:
name: Welcome
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
// Get a list of all issues created by the PR opener
// See: https://octokit.github.io/rest.js/#pagination
const creator = context.payload.sender.login
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
creator,
state: 'all'
})
const issues = await github.paginate(opts)

for (const issue of issues) {
if (issue.number === context.issue.number) {
continue
}

if (issue.pull_request) {
return // Creator is already a contributor.
}
}

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `**Welcome**, new contributor!

It appears that this is your first Pull Request. To give credit where it's due, we ask that you add your information to the \`AUTHORS.rst\` and \`.zenodo.json\`.:
- [ ] The relevant author information has been added to \`AUTHORS.rst\` and \`.zenodo.json\`.

Please make sure you've read our [contributing guide](CONTRIBUTING.rst). We look forward to reviewing your Pull Request shortly ✨`
})
Loading