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

Update templates for new projects #624

Merged
merged 5 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion docs/config/project-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The list of licenses should be composed of [SPDX identifiers](https://spdx.org/l

### Tests

This adds a `tests` directory with [pytest](https://github.com/pytest-dev/pytest) functionality.
This adds a `tests` directory with environments for testing and linting.

=== ":octicons-file-code-16: config.toml"

Expand Down
8 changes: 4 additions & 4 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ hatch run python -c "import sys;print(sys.executable)"

You can also run any [scripts](config/environment/overview.md#scripts) that have been defined.

You'll notice that in the `pyproject.toml` file there are already scripts defined in the `default` environment. Try running the `cov` command, which invokes [pytest](https://github.com/pytest-dev/pytest) with some flags for tracking [coverage](https://github.com/nedbat/coveragepy):
You'll notice that in the `pyproject.toml` file there are already scripts defined in the `default` environment. Try running the `test` command, which invokes [pytest](https://github.com/pytest-dev/pytest) with some default arguments:

```
hatch run cov
hatch run test
```

All additional arguments are passed through to scripts, so for example if you wanted to see the version of `pytest` and which plugins are installed you could do:
All additional arguments are passed through to that script, so for example if you wanted to see the version of `pytest` and which plugins are installed you could do:

```
hatch run cov -VV
hatch run test -VV
```

## Dependencies
Expand Down
7 changes: 4 additions & 3 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ This would create the following structure in your current working directory:

```
hatch-demo
├── hatch_demo
│ ├── __about__.py
│ └── __init__.py
├── src
│ └── hatch_demo
│ ├── __about__.py
│ └── __init__.py
├── tests
│ └── __init__.py
├── LICENSE.txt
Expand Down
4 changes: 2 additions & 2 deletions docs/version.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ The `regex` source requires an option `path` that represents a relative path to

```toml
[tool.hatch.version]
path = "hatch_demo/__about__.py"
path = "src/hatch_demo/__about__.py"
```

=== ":octicons-file-code-16: hatch.toml"

```toml
[version]
path = "hatch_demo/__about__.py"
path = "src/hatch_demo/__about__.py"
```

The default pattern looks for a variable named `__version__` or `VERSION` that is set to a string containing the version, optionally prefixed with the lowercase letter `v`.
Expand Down
14 changes: 9 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ exclude = [
]

[tool.black]
include = '\.pyi?$'
line-length = 120
skip-string-normalization = true
target-version = ["py37"]
Expand All @@ -104,12 +103,17 @@ select = [
"YTT",
]
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
"FBT003",
# Ignore McCabe complexity
"C901",
"S105",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
]
unfixable = [
# Don't touch unused imports
"F401",
]

Expand Down Expand Up @@ -175,8 +179,8 @@ omit = [
]

[tool.coverage.paths]
hatch = ["src", "*/hatch/src"]
hatchling = ["backend/src", "*/hatch/backend/src"]
hatch = ["src/hatch", "*/hatch/src/hatch"]
hatchling = ["backend/src/hatchling", "*/hatch/backend/src/hatchling"]
tests = ["tests", "*/hatch/tests"]

[tool.coverage.report]
Expand Down
73 changes: 68 additions & 5 deletions src/hatch/template/files_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PyProject(File):

[project]
name = "{project_name_normalized}"
dynamic = ["version"]
description = {description!r}
readme = "{readme_file_path}"
requires-python = ">=3.7"
Expand All @@ -88,7 +89,6 @@ class PyProject(File):
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = {dependency_data}
dynamic = ["version"]

[project.urls]{project_url_data}{cli_scripts}

Expand Down Expand Up @@ -136,23 +136,86 @@ def __init__(self, template_config: dict, plugin_config: dict):

[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
"pytest-cov",
]
[tool.hatch.envs.default.scripts]
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov={package_location}{template_config['package_name']} --cov=tests {{args}}"
no-cov = "cov --no-cov {{args}}"
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]

[[tool.hatch.envs.test.matrix]]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]

[envs.lint]
detached = true
dependencies = [
"black",
"mypy",
"ruff",
]
[envs.lint.scripts]
typing = "mypy --install-types --non-interactive {{args:{package_location}{template_config['package_name']} tests}}"
style = [
"ruff {{args:.}}",
"black --check --diff {{args:.}}",
]
fmt = [
"black {{args:.}}",
"ruff --fix {{args:.}}",
"style",
]
all = [
"style",
"typing",
]

[tool.black]
target-version = ["py37"]
line-length = 120
skip-string-normalization = true

[tool.ruff]
target-version = "py37"
line-length = 120
select = ["A", "B", "C", "E", "F", "FBT", "I", "M", "N", "Q", "RUF", "S", "T", "U", "W", "YTT"]
ofek marked this conversation as resolved.
Show resolved Hide resolved
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore McCabe complexity
"C901",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
]
unfixable = [
# Don't touch unused imports
"F401",
]

[tool.ruff.isort]
known-first-party = ["{template_config['package_name']}"]

[tool.coverage.run]
source_pkgs = ["{template_config['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"{package_location}{template_config['package_name']}/__about__.py",
]

[tool.coverage.paths]
{template_config['package_name']} = ["{package_location}{template_config['package_name']}", "*/{template_config['project_name_normalized']}/{package_location}{template_config['package_name']}"]
tests = ["tests", "*/{template_config['project_name_normalized']}/tests"]

[tool.coverage.report]
exclude_lines = [
"no cov",
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/templates/new/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_files(**kwargs):

[project]
name = "{kwargs['project_name_normalized']}"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.7"
Expand All @@ -84,7 +85,6 @@ def get_files(**kwargs):
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = []
dynamic = ["version"]

[project.urls]
Documentation = "https://github.com/unknown/{kwargs['project_name_normalized']}#readme"
Expand Down
73 changes: 68 additions & 5 deletions tests/helpers/templates/new/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get_files(**kwargs):

[project]
name = "{kwargs['project_name_normalized']}"
dynamic = ["version"]
description = '{description}'
readme = "README.md"
requires-python = ">=3.7"
Expand All @@ -94,7 +95,6 @@ def get_files(**kwargs):
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = []
dynamic = ["version"]

[project.urls]
Documentation = "https://github.com/unknown/{kwargs['project_name_normalized']}#readme"
Expand All @@ -106,23 +106,86 @@ def get_files(**kwargs):

[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
"pytest-cov",
]
[tool.hatch.envs.default.scripts]
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/{kwargs['package_name']} --cov=tests {{args}}"
no-cov = "cov --no-cov {{args}}"
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]

[[tool.hatch.envs.test.matrix]]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]

[envs.lint]
detached = true
dependencies = [
"black",
"mypy",
"ruff",
]
[envs.lint.scripts]
typing = "mypy --install-types --non-interactive {{args:src/{kwargs['package_name']} tests}}"
style = [
"ruff {{args:.}}",
"black --check --diff {{args:.}}",
]
fmt = [
"black {{args:.}}",
"ruff --fix {{args:.}}",
"style",
]
all = [
"style",
"typing",
]

[tool.black]
target-version = ["py37"]
line-length = 120
skip-string-normalization = true

[tool.ruff]
target-version = "py37"
line-length = 120
select = ["A", "B", "C", "E", "F", "FBT", "I", "M", "N", "Q", "RUF", "S", "T", "U", "W", "YTT"]
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore McCabe complexity
"C901",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
]
unfixable = [
# Don't touch unused imports
"F401",
]

[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]

[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"src/{kwargs['package_name']}/__about__.py",
]

[tool.coverage.paths]
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]

[tool.coverage.report]
exclude_lines = [
"no cov",
Expand Down
Loading