Skip to content

Commit 061a5f1

Browse files
09-release
1 parent 9d7e3fa commit 061a5f1

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ __pycache__/
1313

1414
# Pip
1515
*.egg-info
16+
dist/
1617

1718
# Testing
1819
.pytest_cache/

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,56 @@ The code to embed badges can be found on travis and coveralls.
469469
After the CI runs successfully, the badges will be updated.
470470

471471
Checkout the repo at this stage using the [`08-ci`](https://github.com/MichaelKim0407/tutorial-pip-package/tree/08-ci) tag.
472+
473+
## Step 9: Releasing on pypi!
474+
475+
At this point, your library can already be shared with the world,
476+
however it is not on pypi yet.
477+
478+
To release on pypi, there are a few things we need to take care of.
479+
480+
First, add some classifiers for your package in `setup()`.
481+
A full list of classifiers can be found [here](https://pypi.org/pypi?%3Aaction=list_classifiers).
482+
483+
Next, change `__version__` to a standard version string, such as `1.0`.
484+
485+
Next, change the name of your package, if you followed the tutorial thus far,
486+
since `my_pip_package` would be taken by me.
487+
Be creative!
488+
The `name` argument in `setup()` does not need to match the name of the python package,
489+
but it's better to keep them the same so that anyone that installs your library won't be confused.
490+
491+
You may also want to add a `description` in `setup()`.
492+
493+
Once everything is good, we can package the library:
494+
495+
```bash
496+
$ python setup.py sdist
497+
```
498+
499+
If should create a `.tar.gz` file under `dist/`.
500+
You can unzip the file to inspect its contents.
501+
502+
Also, don't forget to add `dist/` to `.gitignore`.
503+
504+
The file is now ready to be uploaded to `pypi`.
505+
Create an account on `pypi`, and store the credentials in `~/.pypirc`:
506+
507+
```
508+
[pypi]
509+
username =
510+
password =
511+
```
512+
513+
Finally, to upload the file:
514+
515+
```bash
516+
$ twine upload dist/{packaged file}.tar.gz
517+
```
518+
519+
Your package should now show up on `pypi` and installable using `pip install`.
520+
521+
It would also be a good idea to create a release on GitHub,
522+
and drop the packaged file as an attachment.
523+
524+
Checkout the repo at this stage using the [`09-release`](https://github.com/MichaelKim0407/tutorial-pip-package/tree/09-release) tag.

my_pip_package/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = 'dev'
1+
__version__ = '1.1'
22

33

44
def hello_world():

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
setup(
2828
name='my_pip_package',
2929
version=__version__,
30+
description='A tutorial for creating pip packages.',
3031

3132
url='https://github.com/MichaelKim0407/tutorial-pip-package',
3233
author='Michael Kim',
@@ -50,4 +51,11 @@
5051
'add=my_pip_package.math:cmd_add',
5152
],
5253
},
54+
55+
classifiers=[
56+
'Intended Audience :: Developers',
57+
58+
'Programming Language :: Python',
59+
'Programming Language :: Python :: 3',
60+
],
5361
)

0 commit comments

Comments
 (0)