Skip to content

Commit aaf9212

Browse files
committed
Version 1.1.0
1 parent cb8fcbe commit aaf9212

File tree

10 files changed

+52
-59
lines changed

10 files changed

+52
-59
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
## Version 1.1.0
4+
5+
- Add `--setup` flag option to create either `setup.cfg` and `setup.py` or `pyproject.toml` file.
6+
- Deprecate `--pyproject`, `--setupcfg`, and `--setuppy` flags. Use `--setup` flag instead.

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ This is a simple python project initializer. It creates any file and directory s
1717
- [x] publish the package on pypi
1818
- [x] add a command line interface
1919
- [x] test it vanilla
20-
- [ ] Change options setuppy and setupcfg to setup
21-
- [ ] Change options pyproject to make setup a flag. If setup is true, then create setup.py and setup.cfg. If setup is false, then create pyproject.toml
22-
- [ ] Refactor a bit to make the code more readable
20+
- [x] Change options setuppy and setupcfg to setup
21+
- [x] Change options pyproject to make setup a flag. If setup is true, then create setup.py and setup.cfg. If setup is false, then create pyproject.toml
2322
- [ ] Cut the code into smaller functions if possible
24-
- [ ] Add skeleton template for setup.py, setup.cfg, and pyproject.toml with flake8, black and pylint
25-
- [ ] Add pytest to the skeleton template as a dev dependency
2623

2724

2825
## DESCRIPTION

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "pyproject_init"
7-
version = "1.0.2"
7+
version = "1.1.0"
88
requires-python = ">=3.9"
99
dependencies = [
1010
"click",

pyproject_init/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
__title__ = "pyprojectinit"
5-
__version__ = "0.1.0"
5+
__version__ = "1.1.0"
66
__author__ = "Quentin Haenn"
77
__license__ = "MIT"
88
__copyright__ = "Copyright 2024 Quentin Haenn"

pyproject_init/cli.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,42 @@ def cli():
3838

3939

4040
@cli.command()
41-
@click.option("--setuppy", is_flag=True, help="Create a setup.py file")
42-
@click.option("--setupcfg", is_flag=True, help="Create a setup.cfg file")
43-
@click.option("--pyproject", is_flag=True, help="Create a pyproject.toml file")
41+
@click.option("--setup", is_flag=True, help="If set, create a setup.py and a setup.cfg file, if not creates pyproject.toml")
4442
@click.option("--git", is_flag=True, help="Initialize a git repository")
4543
@click.option("--virtualenv", is_flag=True, help="Create a virtualenv")
4644
@click.option("--docker", is_flag=True, help="Create a docker file")
4745
@click.option("--license", default="MIT", help="Choose the license type")
4846
@click.argument("project_name", required=True)
49-
def lib(setuppy, setupcfg, pyproject, git, virtualenv, docker, license, project_name):
47+
def lib(setup, git, virtualenv, docker, license, project_name):
5048
"""
5149
Create a library project
5250
"""
5351
echo("Creating a library project")
5452
project_root = os.getcwd()
5553
initializer = PyprojectInitializer(
56-
project_name, project_root, "lib", setuppy, setupcfg, pyproject, git, virtualenv, docker, license
54+
project_name, project_root, "lib", setup, git, virtualenv, docker, license
5755
)
5856
initializer.init()
5957
echo("Library project created")
6058

6159

6260
@cli.command()
63-
@click.option("--setuppy", is_flag=True, help="Create a setup.py file")
64-
@click.option("--setupcfg", is_flag=True, help="Create a setup.cfg file")
65-
@click.option("--pyproject", is_flag=True, help="Create a pyproject.toml file")
61+
@click.option("--setup",
62+
is_flag=True,
63+
help="If set, create a setup.py and a setup.cfg file, if not creates pyproject.toml")
6664
@click.option("--git", is_flag=True, help="Initialize a git repository")
6765
@click.option("--virtualenv", is_flag=True, help="Create a virtualenv")
6866
@click.option("--docker", is_flag=True, help="Create a docker file")
6967
@click.option("--license", default="MIT", help="Choose the license type")
7068
@click.argument("project_name", required=True)
71-
def app(setuppy, setupcfg, pyproject, git, virtualenv, docker, license, project_name):
69+
def app(setup, git, virtualenv, docker, license, project_name):
7270
"""
7371
Create an application project
7472
"""
7573
echo("Creating an application project")
7674
project_root = os.getcwd()
7775
initializer = PyprojectInitializer(
78-
project_name, project_root, "app", setuppy, setupcfg, pyproject, git, virtualenv, docker, license
76+
project_name, project_root, "app", setup, git, virtualenv, docker, license
7977
)
8078
initializer.init()
8179
echo("Application project created")

pyproject_init/pyproject_initializer.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,35 @@ def __init__(
1515
project_name,
1616
project_root,
1717
project_type,
18-
setuppy_needed=False,
19-
setupcfg_needed=False,
20-
pyproject_needed=False,
18+
setup = False,
2119
git_needed=False,
2220
virtualenv_needed=False,
2321
docker_needed=False,
24-
license="MIT",
22+
license_name="MIT",
2523
):
2624
self.project_name = project_name
27-
self.project_root = project_root # os.getcwd()
25+
self.project_root = project_root
2826
self.project_path = os.path.join(self.project_root, self.project_name)
2927
self.project_type = project_type
30-
self.setuppy = setuppy_needed
31-
self.setupcfg = setupcfg_needed
32-
self.pyproject = pyproject_needed
28+
self.setup = setup
3329
self.git = git_needed
3430
self.virtualenv = virtualenv_needed
3531
self.docker = docker_needed
36-
self.license = license
32+
self.license_name = license_name
3733

3834
def init(self):
3935
"""
4036
Initialize the project
4137
"""
42-
files.create_base_files(self.project_root, self.license, self.setupcfg, self.setuppy, self.pyproject)
38+
files.create_base_files(self.project_root, self.license_name, self.setup)
4339
if self.project_type == "lib":
4440
self.create_lib_project()
4541
elif self.project_type == "app":
4642
self.create_app_project()
4743

4844
if self.git:
4945
self.init_git()
46+
files.create_gitignore(self.project_root, self.project_name)
5047

5148
if self.virtualenv:
5249
self.init_virtualenv()
@@ -70,13 +67,13 @@ def init_git(self):
7067
"""
7168
Initialize the git repository
7269
"""
73-
subprocess.run(["git", "init"], cwd=self.project_root)
70+
subprocess.run(["git", "init"], cwd=self.project_root, check=True)
7471

7572
def init_virtualenv(self):
7673
"""
7774
Initialize the virtual environment
7875
"""
79-
subprocess.run(["python3", "-m", "venv", self.project_name + "-env"], cwd=self.project_root)
76+
subprocess.run(["python3", "-m", "venv", self.project_name + "-env"], cwd=self.project_root, check=True)
8077

8178
def init_docker(self):
8279
"""

pyproject_init/utils/projectfiles.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88

99
def create_base_files(
10-
project_path, license_type="MIT", setupcfg_needed=False, setuppy_needed=False, pyproject_needed=False
11-
):
10+
project_path, license_type="MIT", setup = False):
1211
"""
1312
Create the base files for a project.
1413
1514
This function creates the following base files:
1615
- README.md
17-
- .gitignore
1816
- LICENSE
1917
- pyproject.toml (optional)
2018
- setup.cfg (optional)
@@ -25,13 +23,11 @@ def create_base_files(
2523
"""
2624

2725
_create_readme(project_path)
28-
_create_gitignore(project_path)
2926
_create_license(project_path, license_type)
30-
if setupcfg_needed:
27+
if setup:
3128
_create_setupcfg(project_path, license_type)
32-
if setuppy_needed:
3329
_create_setuppy(project_path, license_type)
34-
if pyproject_needed:
30+
else:
3531
_create_pyproject(project_path)
3632

3733

@@ -51,7 +47,7 @@ def _create_readme(project_path):
5147
readme.write("- License\n")
5248

5349

54-
def _create_gitignore(project_path):
50+
def create_gitignore(project_path, project_name):
5551
"""
5652
_create_gitignore creates the .gitignore file
5753
@@ -66,19 +62,22 @@ def _create_gitignore(project_path):
6662
gitignore.write("# pytest artifacts\n")
6763
gitignore.write("*.pyc\n")
6864
gitignore.write("__pycache__/\n")
65+
gitignore.write(".pytest_cache/\n")
6966
gitignore.write("\n")
7067
gitignore.write("# Coverage\n")
7168
gitignore.write("htmlcov/\n")
7269
gitignore.write(".coverage\n")
73-
gitignore.write(".pytest_cache/\n")
7470
gitignore.write("\n")
7571
gitignore.write("# Distribution\n")
7672
gitignore.write("build/\n")
7773
gitignore.write("dist/\n")
7874
gitignore.write(".eggs/\n")
75+
gitignore.write("*.egg-info\n")
7976
gitignore.write("\n")
8077
gitignore.write("# Documentation source build\n")
8178
gitignore.write("doc/_build\n")
79+
gitignore.write("# Virtual environment\n")
80+
gitignore.write(project_path + project_name + "-env/\n")
8281

8382

8483
def _create_license(project_path, license_type="MIT"):

test/test_cli.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ def test_lib(self, runner, tmp_path):
1919
result = runner.invoke(
2020
lib,
2121
[
22-
"--setuppy",
23-
"--setupcfg",
24-
"--pyproject",
2522
"--git",
2623
"--virtualenv",
2724
"--docker",
@@ -33,12 +30,11 @@ def test_lib(self, runner, tmp_path):
3330
print(result.output)
3431
assert result.exit_code == 0
3532
assert os.path.isdir(os.path.join(tmp_path, "test_project"))
36-
assert os.path.isfile(os.path.join(tmp_path, "setup.py"))
37-
assert os.path.isfile(os.path.join(tmp_path, "setup.cfg"))
3833
assert os.path.isfile(os.path.join(tmp_path, "pyproject.toml"))
3934
assert os.path.isdir(os.path.join(tmp_path, "test_project-env"))
4035
assert os.path.isfile(os.path.join(tmp_path, "Dockerfile"))
4136
assert os.path.isdir(os.path.join(tmp_path, ".git"))
37+
assert os.path.isfile(os.path.join(tmp_path, ".gitignore"))
4238
assert os.path.isfile(os.path.join(tmp_path, "LICENSE"))
4339
assert os.path.isfile(os.path.join(tmp_path, "README.md"))
4440

@@ -48,9 +44,7 @@ def test_app(self, runner, tmp_path):
4844
app,
4945
[
5046
"test_project",
51-
"--setuppy",
52-
"--setupcfg",
53-
"--pyproject",
47+
"--setup",
5448
"--git",
5549
"--virtualenv",
5650
"--docker",
@@ -62,9 +56,9 @@ def test_app(self, runner, tmp_path):
6256
assert os.path.isdir(os.path.join(tmp_path, "test_project"))
6357
assert os.path.isfile(os.path.join(tmp_path, "setup.py"))
6458
assert os.path.isfile(os.path.join(tmp_path, "setup.cfg"))
65-
assert os.path.isfile(os.path.join(tmp_path, "pyproject.toml"))
6659
assert os.path.isdir(os.path.join(tmp_path, "test_project-env"))
6760
assert os.path.isfile(os.path.join(tmp_path, "Dockerfile"))
6861
assert os.path.isdir(os.path.join(tmp_path, ".git"))
62+
assert os.path.isfile(os.path.join(tmp_path, ".gitignore"))
6963
assert os.path.isfile(os.path.join(tmp_path, "LICENSE"))
7064
assert os.path.isfile(os.path.join(tmp_path, "README.md"))

test/test_projectfiles.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_create_readme(self, tmp_path):
2222
assert "- License" in content
2323

2424
def test_create_gitignore(self, tmp_path):
25-
pfiles._create_gitignore(str(tmp_path))
25+
pfiles.create_gitignore(str(tmp_path), "test_project")
2626
gitignore_path = os.path.join(str(tmp_path), ".gitignore")
2727
assert os.path.isfile(gitignore_path)
2828
with open(gitignore_path, "r") as gitignore:
@@ -99,11 +99,15 @@ def test_create_pyproject(self, tmp_path):
9999
assert 'requires = ["setuptools", "wheel"]\n' in content
100100
assert 'build-backend = "setuptools.build_meta"\n' in content
101101

102-
def test_create_base_files(self, tmp_path):
103-
pfiles.create_base_files(str(tmp_path), "MIT", True, True, True)
102+
def test_create_base_files_setup(self, tmp_path):
103+
pfiles.create_base_files(str(tmp_path), "MIT", True)
104104
assert os.path.isfile(os.path.join(tmp_path, "README.md"))
105-
assert os.path.isfile(os.path.join(tmp_path, ".gitignore"))
106105
assert os.path.isfile(os.path.join(tmp_path, "LICENSE"))
107106
assert os.path.isfile(os.path.join(tmp_path, "setup.cfg"))
108107
assert os.path.isfile(os.path.join(tmp_path, "setup.py"))
108+
109+
def test_create_base_files_pyproject(self, tmp_path):
110+
pfiles.create_base_files(str(tmp_path), "MIT", False)
111+
assert os.path.isfile(os.path.join(tmp_path, "README.md"))
112+
assert os.path.isfile(os.path.join(tmp_path, "LICENSE"))
109113
assert os.path.isfile(os.path.join(tmp_path, "pyproject.toml"))

test/test_pyproject.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,30 @@
77

88
class TestPyprojectInitializer:
99
def test_init(self, tmp_path):
10-
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib", True, True, True, True, True, True, "MIT")
10+
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib",True, True, True, True, "MIT")
1111
assert py_test.project_name == "test_project"
1212
assert py_test.project_root == str(tmp_path)
1313
assert py_test.project_path == os.path.join(str(tmp_path), "test_project")
1414
assert py_test.project_type == "lib"
15-
assert py_test.setuppy is True
16-
assert py_test.setupcfg is True
17-
assert py_test.pyproject is True
15+
assert py_test.setup is True
1816
assert py_test.git is True
1917
assert py_test.virtualenv is True
2018
assert py_test.docker is True
21-
assert py_test.license is "MIT"
19+
assert py_test.license_name is "MIT"
2220

2321
def test_init_git(self, tmp_path):
24-
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib", True, True, True, True, True, True, "MIT")
22+
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib", True, True, True, True, "MIT")
2523
py_test.init_git()
2624
assert os.path.isdir(os.path.join(str(tmp_path), ".git"))
2725
subprocess.run(["rm", "-rf", os.path.join(str(tmp_path), ".git")], check=True)
2826

2927
def test_init_virtualenv(self, tmp_path):
30-
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib", True, True, True, True, True, True, "MIT")
28+
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib", True, True, True, True, "MIT")
3129
py_test.init_virtualenv()
3230
assert os.path.isdir(os.path.join(str(tmp_path), "test_project-env"))
3331
subprocess.run(["rm", "-rf", os.path.join(str(tmp_path), "test_project-env")], check=True)
3432

3533
def test_init_docker(self, tmp_path):
36-
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib", True, True, True, True, True, True, "MIT")
34+
py_test = PyprojectInitializer("test_project", str(tmp_path), "lib", True, True, True, True, "MIT")
3735
py_test.init_docker()
3836
assert os.path.isfile(os.path.join(str(tmp_path), "Dockerfile"))

0 commit comments

Comments
 (0)