Skip to content

Commit 94ac045

Browse files
committed
Create the project
- Add tools - Add source code - Add tests
1 parent f09019e commit 94ac045

File tree

13 files changed

+284
-0
lines changed

13 files changed

+284
-0
lines changed

.flake8

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[flake8]
2+
application-import-names = helloworld
3+
jobs = 4
4+
max-line-length = 160
5+
enable-extensions = G
6+
# Best way to select all installed plugins so far ...
7+
select = E,F,W,A,B,C,D,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,X,Y,Z
8+
ignore = E501,E203,W503
9+
show-source = true
10+
format = html
11+
htmldir = flake-report
12+
exclude =
13+
__pycache__
14+
devenv
15+
venv

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Dev tools
2+
/devenv/
3+
/venv/
4+
5+
# Python
6+
__pycache__
7+
*.pyc
8+
/src/*.egg-info/
9+
/build/
10+
/dist/
11+
12+
# Generated
13+
/flake-report/
14+
/coverage-report/
15+
/tests.xml
16+
/.coverage
17+
18+
# Vscodium
19+
/.vscode/*
20+
!/.vscode/settings.json
21+

.vscode/settings.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"files.exclude": {
3+
"devenv/": true,
4+
"venv/": true,
5+
"**/__pycache__/": true,
6+
},
7+
"python.pythonPath": "venv/bin/python",
8+
"python.autoComplete.extraPaths": [
9+
"${workspaceFolder}/src/"
10+
],
11+
"python.formatting.provider": "black",
12+
"python.formatting.blackArgs": [
13+
"-l",
14+
"160"
15+
],
16+
"editor.formatOnSave": true,
17+
"python.linting.pylintEnabled": false,
18+
"python.linting.flake8Enabled": true,
19+
"python.linting.flake8Args": [
20+
"--ignore=E501,E203,W503"
21+
],
22+
"python.linting.flake8CategorySeverity.N": "Error",
23+
"python.linting.flake8CategorySeverity.S": "Error",
24+
"python.linting.flake8CategorySeverity.P": "Error",
25+
}

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
PYTHON_VERSION := 3.7.3
2+
3+
.PHONY: install watch publish clean test coverage flake8
4+
5+
all: clean test coverage flake8
6+
7+
devenv:
8+
./tools/python-install.sh install $(PYTHON_VERSION) devenv/
9+
10+
venv: requirements.txt
11+
virtualenv -p devenv/bin/python3 venv --no-site-packages
12+
./venv/bin/pip install -r requirements.txt
13+
touch venv
14+
15+
clean:
16+
rm -rf flake-report coverage-report .coverage tests.xml
17+
18+
flake8:
19+
flake8 src/
20+
21+
coverage:
22+
pytest --cov=helloworld src/
23+
coverage html --directory=coverage-report
24+
coverage report
25+
26+
tests:
27+
pytest --junitxml=tests.xml src/
28+
29+
install:
30+
test -n "$(VIRTUAL_ENV)"
31+
python3 setup.py install
32+
#python3 setup.py install_data
33+
34+
watch:
35+
test -n "$(VIRTUAL_ENV)"
36+
rerun -d src -p "*.py" -x "make install >/dev/null 2>&1"
37+
38+
publish:
39+
test -n "$(VIRTUAL_ENV)"
40+
python3 setup.py sdist bdist_wheel
41+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# helloworld
2+
3+
This is just a sample helloworld project which aims to provide some good (at least not so bad) praticies to start a new project.
4+
5+
Basically, you can clone this repository and run `sed -i 's/helloworld/YOURPROJECTNAME/g'` ;)
6+
7+
## Setup a development environment
8+
9+
If you target a python version which is not bundled by your distribution (for example, I want to use python 3.7 and I'm working on Debian9 which bundles python 3.5), you can install the needed python from the source with `make devenv`. Then we need to create a *virtualenv* with the needed libraries from `requirements.txt` with `make venv`.
10+
11+
12+
```sh
13+
$ make devenv
14+
$ ./devenv/bin/python3 --version
15+
Python 3.7.3
16+
$ make venv
17+
$ source venv/bin/activate
18+
(venv) $ which python
19+
$PWD/venv/bin/python
20+
$ python --version
21+
Python 3.7.3
22+
```
23+
24+
The `make devenv` command will simply call the `tools/python-install.sh` script that will:
25+
- download the source from [Python.org](https://python.org)
26+
- Install needed *apt* packages to compile python
27+
- Compile python and install in the workspace
28+
29+
This script can be used to install multiple versions of python in the `devenv/` folder to use [Tox](https://tox.readthedocs.io/en/latest/)
30+
31+
32+
## Coding and testing
33+
34+
[VSCodium](https://github.com/VSCodium/vscodium) is a good editor and the Python support is pretty nice.
35+
Some workspace settings in `.vscode/settings.json` are configured for example to work with the *virtual environment*.
36+
37+
[Flake8](https://pypi.org/project/flake8/) is configured with some plugins to report many warnings/errors (and VSCodium is configured to show them).
38+
39+
[Black](https://pypi.org/project/black/) code formatter will automatically format source code on save using *VSCodium*.
40+
41+
42+
Some usefull `make` targets:
43+
- The `make install` command will install the project in the *virtualenv*.
44+
- The `make watch` will automatically install the project when the source code changes (you need to install `rerun`).
45+
- To run the tests, use `make test` which generated a *junit-like* report.
46+
- *Coverage* and *Flake8* reports are generated with `make coverage` and `make flake8`
47+
- The `make all` target will run the unit tests and generate a *Coverage* report and a *Flake8* report.
48+
- Finally the `make publish` will build and publish the project on [PyPI](https://pypi.org/).

requirements.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Dev tools
2+
setuptools
3+
setuptools-scm
4+
pytest
5+
pytest-xdist
6+
pytest-cov
7+
tox
8+
coverage
9+
rope
10+
black
11+
twine
12+
13+
## Flake8 & plugins
14+
flake8
15+
flake8-html
16+
pep8-naming
17+
flake8-builtins
18+
flake8-blind-except
19+
flake8-comprehensions
20+
flake8-string-format
21+
flake8-pep3101
22+
flake8-bugbear

setup.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
from setuptools import setup
4+
5+
6+
def readfile(file):
7+
with open(file) as f:
8+
return f.read()
9+
10+
11+
setup(
12+
name="helloworld",
13+
license="Apache License 2.0",
14+
author="Sébastien MB",
15+
author_email="seb@essembeh.org",
16+
description="Simple python3 hello world",
17+
long_description=readfile("README.md"),
18+
long_description_content_type="text/markdown",
19+
use_scm_version={"version_scheme": "post-release"},
20+
setup_requires=["setuptools_scm"],
21+
package_dir={"": "src"},
22+
packages=["helloworld"],
23+
entry_points={"console_scripts": ["helloworld = helloworld.__main__:main"]},
24+
classifiers=[
25+
"Development Status :: 4 - Beta",
26+
"Topic :: Utilities",
27+
"License :: OSI Approved :: Apache Software License",
28+
"Programming Language :: Python :: 3.4",
29+
"Programming Language :: Python :: 3.5",
30+
"Programming Language :: Python :: 3.6",
31+
"Programming Language :: Python :: 3.7",
32+
],
33+
)

src/helloworld/__init__.py

Whitespace-only changes.

src/helloworld/__main__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from argparse import ONE_OR_MORE, ArgumentParser
2+
3+
from helloworld.core import User
4+
5+
6+
def main():
7+
parser = ArgumentParser(prog="helloworld", description="Simple hello world python sample")
8+
parser.add_argument(dest="users", nargs=ONE_OR_MORE, type=User, help="your name")
9+
args = parser.parse_args()
10+
for user in args.users:
11+
print("Hello {u.name}!".format(u=user))
12+
13+
14+
if __name__ == "__main__":
15+
main()

src/helloworld/core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class User:
2+
def __init__(self, name: str):
3+
self.__name = name
4+
5+
@property
6+
def name(self):
7+
return self.__name

0 commit comments

Comments
 (0)