Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent accidental publish Python pacakge using setup.py

Tags:

python

Is there a way to prevent accidental publication of private package such as "private": true in NPM?

like image 383
pjxiao Avatar asked May 11 '14 13:05

pjxiao


People also ask

Does Python package require setup py?

A Python file that relies only on the standard library can be redistributed and reused without the need to use setuptools. But for projects that consist of multiple files, need additional libraries, or need a specific version of Python, setuptools will be required.

What is setup py bdist_wheel?

python setup.py bdist_wheel. This will build any C extensions in the project and then package those and the pure Python code into a . whl file in the dist directory.

What can I use instead of distutils?

Most Python users will not want to use this module directly, but instead use the cross-version tools maintained by the Python Packaging Authority. In particular, setuptools is an enhanced alternative to distutils that provides: support for declaring project dependencies.

Is setup py deprecated?

setuptools in Python setuptools is a library which is built on top of distutils that has been deprecated (and up for removal as of Python 3.12).


1 Answers

You can add something like this to the top of your setup.py script:

import sys

for arg in sys.argv:
    if arg in ('upload', 'register', 'testarg'):
        print('This setup is not designed to be uploaded or registered.')
        sys.exit(-1)

You can test it works safely by doing:

python setup.py testarg

This should display a message and immediately exit.

like image 64
Hugh Perkins Avatar answered Oct 08 '22 00:10

Hugh Perkins