Skip to content

Commit c667dbd

Browse files
committed
Initial commit
1 parent c778ed6 commit c667dbd

8 files changed

Lines changed: 166 additions & 7 deletions

File tree

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/python
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
3+
4+
### Python ###
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]
@@ -20,6 +24,7 @@ parts/
2024
sdist/
2125
var/
2226
wheels/
27+
pip-wheel-metadata/
2328
share/python-wheels/
2429
*.egg-info/
2530
.installed.cfg
@@ -49,7 +54,7 @@ coverage.xml
4954
*.py,cover
5055
.hypothesis/
5156
.pytest_cache/
52-
cover/
57+
pytestdebug.log
5358

5459
# Translations
5560
*.mo
@@ -70,9 +75,9 @@ instance/
7075

7176
# Sphinx documentation
7277
docs/_build/
78+
doc/_build/
7379

7480
# PyBuilder
75-
.pybuilder/
7681
target/
7782

7883
# Jupyter Notebook
@@ -83,9 +88,7 @@ profile_default/
8388
ipython_config.py
8489

8590
# pyenv
86-
# For a library or package, you might want to ignore these files since the code is
87-
# intended to run in multiple environments; otherwise, check them in:
88-
# .python-version
91+
.python-version
8992

9093
# pipenv
9194
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@@ -134,5 +137,4 @@ dmypy.json
134137
# pytype static type analyzer
135138
.pytype/
136139

137-
# Cython debug symbols
138-
cython_debug/
140+
# End of https://www.toptal.com/developers/gitignore/api/python

.idea/runConfigurations/All_tests.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [year] [fullname]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include *.txt
2+
recursive-include tests *.py
3+
recursive-include .idea/runConfigurations *.xml

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,70 @@
11
# Python Package Example
22
This repository contains a basic python package example with the aim of showing how a good python package should look like.
33

4+
Install:
5+
```
6+
pip install helloworld
7+
```
8+
Install locally:
9+
```
10+
git clone https://github.com/mkmenta/python-package-example.git
11+
cd python-package-example
12+
pip install -e .
13+
```
14+
If you are developing, you should run `pip install -e .` every time you change `setup.py` or the dependencies etc. to make sure that everything works.
15+
16+
Usage example:
17+
```python
18+
from helloworld import say_hello
19+
20+
# Generate "Hello world!"
21+
say_hello()
22+
23+
# Generate "Hello mkmenta!"
24+
say_hello("mkmenta")
25+
```
26+
27+
### Developing
28+
To install the package along with the tools you need to develop it run the following (local installation with the `"dev"` extras:
29+
```
30+
git clone https://github.com/mkmenta/python-package-example.git
31+
cd python-package-example
32+
pip install -e ."[dev]"
33+
```
34+
### A note about requirements
35+
The requirements needed to **run** the package should go in the `install_requires` argument of `setup()` in the `setup.py`.
36+
37+
The requirements needed to **develop** the package should go in the `extras_require` argument dict (under the `"dev"` key) of `setup()` in the `setup.py`.
38+
39+
This is preferred to a `requirements.txt` file, because this is code and it can be understood directly during the installation of the package itself.
40+
41+
The `requirements.txt` should be used to recreate enviroments with specific versions (e.g.`requests==2.22.0`), not to share software.
42+
43+
### Building and distribution
44+
Build without installi i.e. build wheel:
45+
```
46+
python3 setup.py bdist_wheel
47+
```
48+
49+
Source distribution:
50+
```
51+
python3 setup.py sdist
52+
```
53+
For the source distribution, remember to:
54+
- Check out the warnings of `python3 setup.py sdist`.
55+
- Check that every file from the repo is packed in the tar file (`tar tzf dist/helloworld-X.X.X.tar.gz`) as written in the `MANIFEST.in`. A useful tool is `check-manifest`.
56+
57+
### Uploading to PyPI
58+
```
59+
python3 setup.py bdist_wheel sdist
60+
twine upload dist/*
61+
```
62+
63+
### Other useful stuff
64+
- This repo is prepared for PyCharm and it has some run configurations (in `.idea/runConfigurations`).
65+
466
## References
567
- Mark Smith - Publish a (Perfect) Python Package on PyPI ([video](https://www.youtube.com/watch?v=GIF3LaRqgXo&list=WL&index=9&t=779s))
68+
- `.gitignore` file from [gitignore.io](gitignore.io)
69+
- License from [choosealicense.com](choosealicense.com)
70+
- PyPI classifiers from https://pypi.org/classifiers/

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from setuptools import setup
2+
3+
with open("README.md", "r") as f:
4+
long_description = f.read()
5+
6+
setup(
7+
name="helloworld-mkmenta",
8+
version="0.0.1",
9+
description="Say hello!",
10+
long_description=long_description,
11+
long_description_content_type="text/markdown",
12+
url="https://github.com/mkmenta/python-package-example",
13+
author="Mikel Menta Garde",
14+
author_email="thisisnotmyemail@gmail.com",
15+
py_modules=["helloworld"],
16+
package_dir={"": "src"},
17+
# You can take classifiers from https://pypi.org/classifiers/
18+
classifiers=[
19+
"Programming Language :: Python :: 3 :: Only",
20+
"Programming Language :: Python :: 3.6",
21+
"License :: OSI Approved :: MIT License",
22+
"Operating System :: OS Independent"
23+
],
24+
# TODO: it would be cool to show some install_requires usage
25+
extras_require={
26+
"dev": ["pytest>=3.7"]
27+
}
28+
)

src/helloworld.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from hashlib import blake2b
2+
3+
4+
def say_hello(name=None):
5+
if name is None:
6+
return "Hello world!"
7+
8+
h = blake2b(digest_size=20)
9+
h.update(name.encode())
10+
if h.hexdigest() == 'df543254a1110b5d32d96028cf4b1df9ea96ebbb':
11+
return "I'm on the radioooooo!!!"
12+
13+
return f"Hello {name}!"

tests/test_helloworld.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from helloworld import say_hello
2+
3+
4+
def test_helloworld_no_params():
5+
assert say_hello() == "Hello world!"
6+
7+
def test_helloworld_with_param():
8+
assert say_hello("mkmenta") == "Hello mkmenta!"

0 commit comments

Comments
 (0)