Skip to content

Commit 50fc285

Browse files
committed
Add 🧰 Tools Recommended section and logit of deleting old dists
1 parent 54c4456 commit 50fc285

File tree

3 files changed

+101
-5
lines changed

3 files changed

+101
-5
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# v1.2.2
2+
3+
![](https://img.shields.io/badge/Version-v1.2.2-green)
4+
5+
## 🔄 Change
6+
7+
- `packaging.sh`: add logit of deleting the old distribution packages.
8+
- `README.md`: add `🧰 Tools Recommended` section.
9+
10+
---
11+
112
# v1.2.1
213

314
![](https://img.shields.io/badge/Version-v1.2.1-green)
@@ -13,6 +24,11 @@
1324

1425
![](https://img.shields.io/badge/Version-v1.2.0-green)
1526

27+
## 🎉 Support manual package maintenance
28+
29+
Including construction, inspection, and publishing to PyPI.
30+
Please refer to steps `6` through `8` in [`README.md`](https://github.com/Ahzyuan/Python-package-template/blob/v1.2.0/README.md) file.
31+
1632
## 🔄 Change
1733

1834
- `setup.py`: keep a minimal setting to ensure editable installation supported

README.md

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 📦 A Project Template for Self-developed Python Package
22

3-
![Package Version](https://img.shields.io/badge/Version-v1.2.1-green)
3+
![Package Version](https://img.shields.io/badge/Version-v1.2.2-green)
44
[![License](https://img.shields.io/badge/License-MIT-khaki)](https://opensource.org/license/MIT)
55
![Pypi Template](https://img.shields.io/badge/PyPI-Package_pattern-yellow?logo=pypi&labelColor=%23FAFAFA)
66

@@ -299,11 +299,14 @@ This repo provides an 𝐨𝐮𝐭-𝐨𝐟-𝐭𝐡𝐞-𝐛𝐨𝐱 𝐩𝐫
299299
> • So firstly, you need to register an account with [`PyPI`](https://pypi.org/) or [`TestPyPI`](https://test.pypi.org/).
300300
> • Also, don't forget to generate a token for uploading your package. See more [here](https://pypi.org/help/#apitoken).
301301
302+
> 📋 **𝖲𝗎𝗀𝗀𝖾𝗌𝗍𝗂𝗈𝗇**
303+
> • You likely have many commits to `PyPI` or `TestPyPI` to familiarize yourself with the process.
304+
> • In this case, you can maintain a **forged `PyPI` server locally**, see `🧰 Tools Recommended -> pypi-server` below.
305+
302306
```bash
303307
# pwd: .../MYPROJECT
304308
305-
# (Option but strongly recommended) upload to testpypi first
306-
# see if anywhere wrong
309+
# (Option but strongly recommended) upload to testpypi firstly to see if anywhere wrong
307310
twine upload --repository testpypi dist/*
308311
309312
# upload to pypi
@@ -348,7 +351,7 @@ This repo provides an 𝐨𝐮𝐭-𝐨𝐟-𝐭𝐡𝐞-𝐛𝐨𝐱 𝐩𝐫
348351
349352
# ---------------------- configure .pypirc ----------------------
350353
# refer to https://packaging.python.org/en/latest/specifications/pypirc/
351-
# <username> should be same as the one you used in keyring
354+
# <username> should be same as the one you use in keyring
352355
cat >~/.pypirc<<EOF
353356
[distutils]
354357
index-servers =
@@ -369,10 +372,81 @@ This repo provides an 𝐨𝐮𝐭-𝐨𝐟-𝐭𝐡𝐞-𝐛𝐨𝐱 𝐩𝐫
369372
370373
</details>
371374
375+
---
376+
372377
> 🥳 𝗖𝗼𝗻𝗴𝗿𝗮𝘁𝘂𝗹𝗮𝘁𝗶𝗼𝗻𝘀!
373378
> • You have successfully published your package to `PyPI`.
374379
> • Now everyone can install it via `pip install my-project -i https://pypi.org/simple`
375-
> • To update your package to a new version, do `rm -r dist`, then repeat steps 5 to 8 above.
380+
> • To update your package to a new version, repeat steps 5 to 8 above.
381+
382+
## 🧰 Tools Recommended
383+
384+
<details>
385+
<summary>①. 𝚙𝚢𝚙𝚒-𝚜𝚎𝚛𝚟𝚎𝚛</summary>
386+
387+
> • A simple `PyPI` server for local use.
388+
> • This is **highly recommended** if you are **testing your CI/CD workflow**.
389+
390+
You likely have many commits to `PyPI` or `TestPyPI` to familiarize yourself with publishing process. Then there exists two problems:
391+
392+
- [`TestPyPI` / `PyPI` project size limit](https://pypi.org/help/#project-size-limit): many commits can exceed project size limit.
393+
- Using `TestPyPI` as the index of `pip install` is not always reliable: especially when your package depends on some packages that are only available on `PyPI` but not on `TestPyPI`.
394+
For example, if your package `mp-project` depends on `ruff`, then `pip install mp-project -i https://test.pypi.org/simple` will fail with `ResolutionImpossible` or `Package not found` in the process of finding and downloading `ruff`, cause `ruff` is only available on `PyPI`.
395+
396+
To solve these problems and fully imitate the bahvior normal `pip install` using `PyPI` index. You can deploy a local `PyPI` server with `pypi-server`.
397+
398+
Here is a quick guide to get started, please check its [repo](https://github.com/pypiserver/pypiserver ) for more details.
399+
400+
401+
```bash
402+
403+
pip install pypiserver
404+
405+
mkdir Path/to/store/packages # path to store distribution packages
406+
407+
pypi-server run \
408+
-i 0.0.0.0 \
409+
-p <port> \ # specify a port to listen
410+
<path-to-store>/.pypiserver_pkgs\
411+
-a . -P . & # disable authentication for intranet use
412+
413+
cat >~/.pypirc<<EOF # add local server to .pypirc
414+
[distutils]
415+
index-servers =
416+
pypi
417+
testpypi
418+
local
419+
420+
[pypi]
421+
repository: https://upload.pypi.org/legacy/
422+
423+
[testpypi]
424+
repository: https://test.pypi.org/legacy/
425+
426+
[local]
427+
repository: http://0.0.0.0:7418
428+
username: none # random string, not important
429+
password: none # random string, not important
430+
EOF
431+
```
432+
433+
OK, then we can use commands below to upload and install packages:
434+
435+
```bash
436+
# pwd: .../package project dir
437+
438+
# upload package to local server
439+
twine upload --repository local dist/*
440+
441+
# install package from local server
442+
pip install <package> \
443+
--trusted-host \
444+
--extra-index-url http://0.0.0.0:<port>/simple/
445+
```
446+
447+
If you want to close the server, using `kill -9 "$(pgrep pypi-server)"`.
448+
449+
</details>
376450

377451
## 📑 To Do
378452

packaging.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ red_output() {
1212
echo -e "\033[31m$1\033[0m"
1313
}
1414

15+
DIR=$(dirname "$(readlink -f "$0")")
16+
17+
if [[ -d "$DIR/dist" ]]; then
18+
rm -r "$DIR/dist"
19+
fi
20+
1521
eval "$(conda shell.bash hook)"
1622

1723
envs=$(conda env list | grep -v "#" | cut -d " " -f1)

0 commit comments

Comments
 (0)