Skip to main content

Un esempio di progetto con namespace

Project description

My Project 2 ( python setup.py sdist bdist_wheel )

Questo è un esempio super banale di un pacchetto Python.

Pubblicare il Pacchetto in un Repository Pubblico (PyPI)

Per pubblicare un pacchetto organizzato come my_project_2 ho seguito i seguenti passi:

  1. Mi sono registrato su PyPI

  2. Ho installato twine: pip install twine

  3. Ho creato un pacchetto distribuibile: source distribution e una wheel mettendo in my_project_2 setup.py e utilizzando setuptools python setup.py sdist bdist_wheel

  4. Caricare i pacchetti su PyPI: twine upload dist/*

Source Distribution e Wheel

Una Source Distribution cioè una distribuzione del codice sorgente, è un pacchetto che contiene il codice sorgente del progetto insieme ai file per la sua costruzione e installazione. I file tipicamente inclusi sono:

Il codice sorgente del progetto Il file setup.py file di documentazione

La source distribution è utile perché permette agli utenti di costruire e installare il pacchetto su diverse piattaforme e ambienti.

La si crea con: python setup.py sdist

Questo comando genera un archivio (come un file .tar.gz o .zip) nella directory dist.

Una Wheel è un formato di distribuzione binaria per pacchetti Python. Contiene tutti i file necessari per installare il pacchetto in una forma precompilata, il che rende l'installazione molto più veloce rispetto alla source distribution. Le wheel sono specifiche per la piattaforma e la versione di Python.

python setup.py bdist_wheel

Namespace del Progetto

Per evitare conflitti di nomi su PyPI, è una buona idea usare un namespace unico per il tuo progetto. Un metodo comune è usare il tuo username o il nome della tua organizzazione come prefisso del namespace.

Supponiamo che il tuo username sia tuo_username. Puoi organizzare il tuo progetto in modo da usare questo prefisso come namespace.

Esempio di Namespace

Ecco come puoi strutturare il tuo progetto con un namespace:

my_project_2/ ├── tuo_username/ │   └── my_project_2/ │   ├── packages/ │   │   ├── my_package_1/ │   │   │   ├── arithmetic.py │   │   │   ├── geometry.py │   │   │   ├── init.py │   │   └── my_package_2/ │   │   ├── init.py │   ├── scripts/ │   │   ├── main.py │   └── tests/ │   ├── init.py │   ├── test_geometry.py ├── README.md ├── setup.py

inoltre setup.py:

from setuptools import setup, find_packages

setup( name='tuo_username_my_project_2', version='0.1', packages=find_packages(), install_requires=[], author='Il Tuo Nome', author_email='tuo.email@example.com', description='Un esempio di progetto con namespace', long_description=open('README.md').read(), long_description_content_type='text/markdown', url='https://github.com/tuo_username/my_project_2', classifiers=[ 'Programming Language :: Python :: 3', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', ], python_requires='>=3.6', )

Quando esegui pip install my_project, pip cerca il pacchetto my_project su PyPI (o su un repository specificato). Se trova il pacchetto, pip scarica e installa la versione disponibile. La procedura di installazione dipende dai file di distribuzione disponibili per il pacchetto:

Wheel (.whl): Se è disponibile una wheel compatibile con la piattaforma e la versione di Python in uso, pip scarica e installa la wheel. L'installazione da wheel è molto veloce perché la wheel contiene già i file precompilati. Source Distribution (.tar.gz, .zip): Se una wheel non è disponibile, pip scarica e installa la source distribution. Questo processo può richiedere più tempo poiché potrebbe essere necessario compilare codice o eseguire script di installazione aggiuntivi.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stenka_razin_my_project_2-0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stenka_razin_my_project_2-0.1-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file stenka_razin_my_project_2-0.1.tar.gz.

File metadata

  • Download URL: stenka_razin_my_project_2-0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for stenka_razin_my_project_2-0.1.tar.gz
Algorithm Hash digest
SHA256 7377f91930e1e2161dd1e04a8de8320de61a86acd0552547c4e241e718b45b35
MD5 237e122dcad0748a72a2f4d3d8caa5fd
BLAKE2b-256 954cc984e8271133e3413c34e415c0c383399c6b1e24b370ad8ecf1dcabf20e0

See more details on using hashes here.

File details

Details for the file stenka_razin_my_project_2-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for stenka_razin_my_project_2-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 424ecdd8fd8ef52f3ebd5bc72e0d0555498a10b270168551e65f843da9bd3b2f
MD5 b92af37a08ab85f70c080340d3b83717
BLAKE2b-256 89c31d2b0f8b8551540c6a3cac19028172098c5db0211cc69f4693097b7d825f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page