Skip to content

Commit

Permalink
Upstream changes, use src layout (#40)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Updates the main branch with the latest changes from upstream
* Applies the flat layout

### Does this PR introduce a breaking change?

Yes. The new src layout will have repercussions on all downstream
projects.

### Other information:

Closes #39
  • Loading branch information
Zeitsperre authored May 8, 2024
2 parents 5789eda + 2f8f0f6 commit 6b81aca
Show file tree
Hide file tree
Showing 24 changed files with 248 additions and 88 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: pip install tox
run: |
python -m pip install tox
- name: Run bake test suite
run: tox -e ${{ matrix.tox-env }}
run:
python -m tox -e ${{ matrix.tox-env }}
- name: Archive package
if: ${{ matrix.tox-env == 'py39' }}
uses: actions/upload-artifact@v2
with:
name: cookie-cutter
path: src/dist
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Ready to contribute? Here's how to set up `cookiecutter-pypackage` for local dev

.. code-block:: bash
$ pip install -rrequirements_dev.txt
$ pip install -r requirements_dev.txt
$ pytest ./tests
If you get any errors while installing cryptography package (something like `#include <openssl/aes.h>`). Please update your pip version and try again:
Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
BAKE_OPTIONS=--no-input

help:
@echo "bake generate project using defaults"
@echo "watch generate project using defaults and watch for changes"
@echo "replay replay last cookiecutter run and watch for changes"
@echo "bake Generate project using defaults"
@echo "help Show this help"
@echo "test Run the tests"
@echo "replay Replay last cookiecutter run and watch for changes"
@echo "watch Generate project using defaults and watch for changes"


bake:
bake: # Generate project using defaults
cookiecutter $(BAKE_OPTIONS) . --overwrite-if-exists

watch: bake
Expand All @@ -14,3 +17,6 @@ watch: bake
replay: BAKE_OPTIONS=--replay
replay: watch
;

test:
pytest
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Cookiecutter_ template for a Python package.
* GitHub repo (fork): https://github.com/Ouranosinc/cookiecutter-pypackage/
* Documentation (upstream): https://cookiecutter-pypackage.readthedocs.io/
* Free software: BSD license
* Discord: https://discord.gg/PWXJr3upUE

Features
--------
Expand Down
5 changes: 3 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"add_pyup_badge": "n",
"make_docs": "y",
"add_translations": "y",
"command_line_interface": ["Click", "Argparse", "No command-line interface"],
"command_line_interface": ["Typer", "Click", "Argparse", "No command-line interface"],
"create_author_file": "y",
"open_source_license": [
"MIT license",
Expand All @@ -23,5 +23,6 @@
"GNU General Public License v3",
"Not open source"
],
"generated_with_cruft": "y"
"generated_with_cruft": "y",
"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}"
}
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import shlex
# import sys
# import os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
13 changes: 5 additions & 8 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ On Windows, activate it like this. You may find that using a Command Prompt wind
> \path\to\env\Scripts\activate
.. note::

If you create your virtual environment folder in a different location within your project folder, be sure to add that path to your .gitignore file.

Install cookiecutter:

Expand All @@ -55,17 +58,15 @@ Use cookiecutter, pointing it at the cookiecutter-pypackage repo:
cookiecutter https://github.com/audreyfeldroy/cookiecutter-pypackage.git
You'll be asked to enter a bunch of values to set the package up.
If you don't know what to enter, stick with the defaults.
You'll be asked to enter various values to set the package up.
If you don't know what to enter, press Enter to stick with the defaults.


Step 3: Create a GitHub Repo
----------------------------

Go to your GitHub account and create a new repo named ``mypackage``, where ``mypackage`` matches the ``[project_slug]`` from your answers to running cookiecutter. This is so that Travis CI and pyup.io can find it when we get to Step 5.

``If your virtualenv folder is within your project folder, be sure to add the virtualenv folder name to your .gitignore file.``

You will find one folder named after the ``[project_slug]``. Move into this folder, and then setup git to use your GitHub repo and upload the code:

.. code-block:: bash
Expand All @@ -77,10 +78,6 @@ You will find one folder named after the ``[project_slug]``. Move into this fold
git remote add origin git@github.com:myusername/mypackage.git
git push -u origin main
.. note::
GitHub has changed the default branch name from 'master' to 'main'. If you are using another Git repository hosting service that uses the Git branch naming defaults, you might need to use 'master' instead of 'main'.
Where ``myusername`` and ``mypackage`` are adjusted for your username and package name.

You'll need a ssh key to push the repo. You can `Generate`_ a key or `Add`_ an existing one.
Expand Down
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def replace_contents(filepath):
remove_file("environment-dev.yml")

if "no" in "{{ cookiecutter.command_line_interface|lower }}":
cli_file = Path("{{ cookiecutter.project_slug }}").joinpath("cli.py")
cli_file = Path("src/{{ cookiecutter.project_slug }}").joinpath("cli.py")
remove_file(cli_file)

if "Not open source" == "{{ cookiecutter.open_source_license }}":
Expand Down
1 change: 0 additions & 1 deletion hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@

# Exit to cancel project
sys.exit(1)
1
22 changes: 11 additions & 11 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
alabaster
build
cookiecutter
coverage
flit
pre-commit
pytest-cookies
pytest
tox>=4.0
twine
watchdog>=0.9.0
alabaster>=0.7.13
build>=1.2.1
cookiecutter>=2.6.0
coverage>=7.5.1
flit>=3.9.0
pre-commit>=3.5.0
pytest-cookies>=0.7.0
pytest>=8.2.0
tox>=4.15.0
twine>=5.0.0
watchdog>=4.0.0
3 changes: 3 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclude = [
"*cookiecutter.project_slug*"
]
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ search = version='{current_version}'
replace = version='{new_version}'

[tool:pytest]
addopts = --verbose
addopts =
--verbose
markers =
precommit: mark tests that can only be run with precommit present
precommit: mark tests that can only be run with precommit present
testpaths = tests
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
packages=[],
version='0.1.0',
description='Cookiecutter template for a Python package',
author='Audrey Roy Greenfeld',
author='Audrey M. Roy Greenfeld',
license='BSD',
author_email='aroy@alum.mit.edu',
url='https://github.com/audreyr/cookiecutter-pypackage',
author_email='audrey@feldroy.com',
url='https://github.com/audreyfeldroy/cookiecutter-pypackage',
keywords=['cookiecutter', 'template', 'package', ],
python_requires='>=3.8',
classifiers=[
Expand All @@ -20,10 +20,12 @@
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development',
Expand Down
23 changes: 18 additions & 5 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ def test_year_compute_in_license_file(cookies):

def project_info(result):
"""Get toplevel dir, project_slug, and project dir from baked cookies"""
project_path = str(result.project_path)
project_slug = os.path.split(project_path)[-1]
project_dir = os.path.join(project_path, project_slug)
assert result.exception is None
assert result.project_path.is_dir()

project_path = result.project_path
project_slug = project_path.name
project_dir = project_path.joinpath("src").joinpath(project_slug)
return project_path, project_slug, project_dir


Expand All @@ -79,9 +82,13 @@ def test_bake_with_defaults(cookies):
assert result.exception is None

found_toplevel_files = [f.name for f in result.project_path.iterdir()]
assert "LICENSE" in found_toplevel_files
assert "Makefile" in found_toplevel_files
assert "README.rst" in found_toplevel_files
assert "environment-dev.yml" in found_toplevel_files
assert "pyproject.toml" in found_toplevel_files
assert "python_boilerplate" in found_toplevel_files
assert "src" in found_toplevel_files
assert "python_boilerplate" in next(result.project_path.joinpath("src").iterdir()).name
assert "tests" in found_toplevel_files
assert "tox.ini" in found_toplevel_files

Expand Down Expand Up @@ -235,6 +242,11 @@ def test_bake_not_open_source(cookies):
assert "License" not in result.project_path.joinpath("README.rst").read_text()


def _running_tox():
return os.getenv("TOX", False)


@pytest.mark.skipif("not _running_tox()", reason="Not running on tox")
def test_using_pytest(cookies):
with bake_in_temp_dir(cookies, extra_context={"use_pytest": "y"}) as result:
assert result.project_path.is_dir()
Expand All @@ -244,6 +256,7 @@ def test_using_pytest(cookies):
text = test_file_path.read_text()
assert "import pytest" in text
# Test the new pytest target
assert run_inside_dir("pip install --editable .", str(result.project_path)) == 0
assert run_inside_dir("pytest", str(result.project_path)) == 0


Expand Down Expand Up @@ -292,7 +305,7 @@ def test_bake_with_no_console_script(cookies):
assert "[project.scripts]" not in setup_file.read()


@pytest.mark.parametrize("option", ["Click", "Argparse"])
@pytest.mark.parametrize("option", ["Click", "Argparse", "Typer"])
def test_bake_with_console_options_script_files(cookies, option):
context = {"command_line_interface": option}
result = cookies.bake(
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ commands =
setenv =
PYTEST_ADDOPTS = "--color=yes"
PYTHONPATH = {toxinidir}
TOX = 1
deps =
-r{toxinidir}/requirements_dev.txt
download = True
Expand Down
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ target/
# Jupyter Notebook
.ipynb_checkpoints

# Dask worker cache
dask-worker-space/

# pyenv
.python-version

Expand Down
84 changes: 84 additions & 0 deletions {{cookiecutter.project_slug}}/CODE_OF_CONDUCT.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
====================================
Contributor Covenant Code of Conduct
====================================

Our Pledge
----------

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

Our Standards
-------------

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

Our Responsibilities
--------------------

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

Scope
-----

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

Enforcement
-----------

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

Attribution
-----------

This Code of Conduct is adapted from the `Contributor Covenant`_, version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

.. _`Contributor Covenant`: https://www.contributor-covenant.org
Loading

0 comments on commit 6b81aca

Please sign in to comment.