Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

Commit f2e670f

Browse files
authored
cleanups (#19)
1 parent f8d027e commit f2e670f

5 files changed

Lines changed: 35 additions & 93 deletions

File tree

project_name/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from .base import BaseClass, base_function
2-
3-
__all__ = ["BaseClass", "base_function"]

project_name/__main__.py

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,6 @@
1-
import argparse # pragma: no cover
2-
3-
from . import BaseClass, base_function # pragma: no cover
4-
5-
6-
def main() -> None: # pragma: no cover
7-
"""
8-
The main function executes on commands:
9-
`python -m project_name` and `$ project_name `.
10-
11-
This is your program's entry point.
12-
13-
You can change this function to do whatever you want.
14-
Examples:
15-
* Run a test suite
16-
* Run a server
17-
* Do some other stuff
18-
* Run a command line application (Click, Typer, ArgParse)
19-
* List all available tasks
20-
* Run an application (Flask, FastAPI, Django, etc.)
21-
"""
22-
parser = argparse.ArgumentParser(
23-
description="project_name.",
24-
epilog="Enjoy the project_name functionality!",
25-
)
26-
# This is required positional argument
27-
parser.add_argument(
28-
"name",
29-
type=str,
30-
help="The username",
31-
default="author_name",
32-
)
33-
# This is optional named argument
34-
parser.add_argument(
35-
"-m",
36-
"--message",
37-
type=str,
38-
help="The Message",
39-
default="Hello",
40-
required=False,
41-
)
42-
parser.add_argument(
43-
"-v",
44-
"--verbose",
45-
action="store_true",
46-
help="Optionally adds verbosity",
47-
)
48-
args = parser.parse_args()
49-
print(f"{args.message} {args.name}!")
50-
if args.verbose:
51-
print("Verbose mode is on.")
52-
53-
print("Executing main function")
54-
base = BaseClass()
55-
print(base.base_method())
56-
print(base_function())
57-
print("End of main function")
1+
"""Entry point for project_name."""
582

3+
from .cli import main # pragma: no cover
594

605
if __name__ == "__main__": # pragma: no cover
616
main()

project_name/base.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,5 @@
1313
and then choose `flask` as template.
1414
"""
1515

16-
17-
class BaseClass:
18-
def base_method(self) -> str:
19-
"""
20-
Base method.
21-
"""
22-
return "hello from BaseClass"
23-
24-
def __call__(self) -> str:
25-
return self.base_method()
26-
27-
28-
def base_function() -> str:
29-
"""
30-
Base function.
31-
"""
32-
return "hello from base function"
16+
# example constant variable
17+
NAME = "project_name"

project_name/cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""CLI interface for project_name project.
2+
3+
Be creative! do whatever you want!
4+
5+
- Install click or typer and create a CLI app
6+
- Use builtin argparse
7+
- Start a web application
8+
- Import things from your .base module
9+
"""
10+
11+
12+
def main(): # pragma: no cover
13+
"""
14+
The main function executes on commands:
15+
`python -m project_name` and `$ project_name `.
16+
17+
This is your program's entry point.
18+
19+
You can change this function to do whatever you want.
20+
Examples:
21+
* Run a test suite
22+
* Run a server
23+
* Do some other stuff
24+
* Run a command line application (Click, Typer, ArgParse)
25+
* List all available tasks
26+
* Run an application (Flask, FastAPI, Django, etc.)
27+
"""
28+
print("This will do something")

tests/test_base.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
import pytest
1+
from project_name.base import NAME
22

3-
from project_name import BaseClass, base_function
43

5-
given = pytest.mark.parametrize
6-
7-
8-
@given("fn", [BaseClass(), base_function])
9-
def test_parameterized(fn):
10-
assert "hello from" in fn()
11-
12-
13-
def test_base_function():
14-
assert base_function() == "hello from base function"
15-
16-
17-
def test_base_class():
18-
assert BaseClass().base_method() == "hello from BaseClass"
4+
def test_base():
5+
assert NAME == "project_name"

0 commit comments

Comments
 (0)