How to name output zip without version number in packaging with setuptools - setuptools

Hi I am packaging a module with setuptools. Here is my setup.py
from setuptools import setup, find_packages
setup(
name='my_package',
packages=find_packages(),
install_requires = ['pymongo'],
setup_requires=['pytest-runner','flake8'],
tests_require=['pytest'],
test_suite="tests"
)
After I run python setup.py sdist --format=zip the output zip file is created in dist folder. So far so good. But output file automatically named my_package-0.0.0.zip. I want it to be named just my_package.zip. How can I do that with setuptools?

Related

Can't Import After Publishing Package

I know there's a similar question like this out here but after trying their solution, it still hasn't worked for me.
Project Structure:
README.md
LICENSE
setup.py
rolimons/
└── __init__.py
└── users.py
└── items.py
└── client.py
My setup file contains the following:
from setuptools import find_packages, setup
with open("README.md", encoding="utf-8") as f:
readme = f.read()
setup(
name="rolimons",
version="1.2.5",
author="walker",
description="Rolimons API Wrapper",
long_description=readme,
long_description_content_type="text/markdown",
packages=['rolimons'],
url="https://github.com/wa1ker38552/Rolimons-PY",
install_requires=["requests", "bs4", "requests_html"],
python_requires=">=3.7",
)
I have published the package after following these steps:
Change version in setup.py
python setup.py sdist
twine upload --skip-existing dist/*
After this, I go to a different project and run pip install rolimons --upgrade and after running, it gives an import error stating that it can't find the module.
What am I doing wrong?

How to configure setup.py work with main method?

I made my tool executable and added __name__:main method which I want to give to my setup.py. This is what it looks like:
from setuptools import setup
setup(
name='client',
version='0.0.1',
entry_points={
'console_scripts': [
'client = client.main:main'
]
}
)
I do not have an __init__.py file, because I want to run my tool as a script, not as a package. I am struggling with the following error -> No module named 'client.main:main. How am I supposed to solve this?
The directory level of my tool is:
requests\
client.py
setup.py

Workaround for dependency on a package with a dash in its name

In one of my setuptools-based Python projects I would like to add a dependency to numpy-stl. That package is on PyPI and depends on numpy. Due to a bug, setuptools is unable to install packages with dashes in their names in some circumstances.
This is a minimal setup.py which reproduces the problem:
import setuptools
setuptools.setup(
install_requires=['numpy-stl'])
Running python setup.py develop produces the following output:
running install
running bdist_egg
running egg_info
writing UNKNOWN.egg-info/PKG-INFO
writing top-level names to UNKNOWN.egg-info/top_level.txt
writing dependency_links to UNKNOWN.egg-info/dependency_links.txt
writing requirements to UNKNOWN.egg-info/requires.txt
reading manifest file 'UNKNOWN.egg-info/SOURCES.txt'
writing manifest file 'UNKNOWN.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-x86_64/egg
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
creating build/bdist.macosx-10.9-x86_64/egg
creating build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/PKG-INFO -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/SOURCES.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/dependency_links.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/requires.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
copying UNKNOWN.egg-info/top_level.txt -> build/bdist.macosx-10.9-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/UNKNOWN-0.0.0-py3.5.egg' and adding 'build/bdist.macosx-10.9-x86_64/egg' to it
removing 'build/bdist.macosx-10.9-x86_64/egg' (and everything under it)
Processing UNKNOWN-0.0.0-py3.5.egg
Copying UNKNOWN-0.0.0-py3.5.egg to /Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages
Adding UNKNOWN 0.0.0 to easy-install.pth file
Installed /Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages/UNKNOWN-0.0.0-py3.5.egg
Processing dependencies for UNKNOWN==0.0.0
Searching for numpy-stl
Reading https://pypi.python.org/simple/numpy-stl/
[... installing numpy-stl and some of its dependencies ...]
Installed /Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages/nine-0.3.4-py3.5.egg
Searching for numpy
Best match: numpy stl-1.7.1
Downloading https://pypi.python.org/packages/source/n/numpy-stl/numpy-stl-1.7.1.tar.gz#md5=fa3a9324418b72a6827f266671198fe1
Processing numpy-stl-1.7.1.tar.gz
Writing /var/folders/r3/lpx2z49s5hs8mmh3vzrgxd9c0000gs/T/easy_install-yvi_spnk/numpy-stl-1.7.1/setup.cfg
Running numpy-stl-1.7.1/setup.py -q bdist_egg --dist-dir /var/folders/r3/lpx2z49s5hs8mmh3vzrgxd9c0000gs/T/easy_install-yvi_spnk/numpy-stl-1.7.1/egg-dist-tmp-72gff1lq
File "build/bdist.macosx-10.9-x86_64/egg/stl2/stl.py", line 41
except RuntimeError, (recoverable, e):
^
SyntaxError: invalid syntax
zip_safe flag not set; analyzing archive contents...
tests.__pycache__.test_convert.cpython-35: module references __file__
removing '/Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages/numpy_stl-1.7.1-py3.5.egg' (and everything under it)
creating /Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages/numpy_stl-1.7.1-py3.5.egg
Extracting numpy_stl-1.7.1-py3.5.egg to /Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages
File "/Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages/numpy_stl-1.7.1-py3.5.egg/stl2/stl.py", line 41
except RuntimeError, (recoverable, e):
^
SyntaxError: invalid syntax
numpy-stl 1.7.1 is already the active version in easy-install.pth
Installing stl2ascii script to /Users/michi/Desktop/STL_Plot/stl_plot/venv/bin
Installing stl2bin script to /Users/michi/Desktop/STL_Plot/stl_plot/venv/bin
Installing stl script to /Users/michi/Desktop/STL_Plot/stl_plot/venv/bin
Installed /Users/michi/Desktop/STL_Plot/stl_plot/venv/lib/python3.5/site-packages/numpy_stl-1.7.1-py3.5.egg
error: The 'numpy' distribution was not found and is required by numpy-stl
(venv)michi ~/.../STL_Plot/stl_plot$
After installing nine, setuptools tries to find a numpy distribution and finds numpy-stl, thinking its the package numpy in version stl and installs numpy-stl again. In the end it detects that numpy is still not installed and gives up.
Is this just the way it is, that setuptools projects cannot depend on packages with dashes in their names, which is about 1/4 of the packages on PyPI? Or is there a workaround which allows setuptools to install such dependencies?

Setuptools how to build shared library before package installation

My pacakge has *.py files and *.c files, the *.py files use ctypes to import shared library
built from the c source.
Now I have problem how to write my setup.py.
The setup script needs to build my_c_file.c to my_c_file.so, and then copy it to python libpath.
I want to know the what is the 'should' way?
You should probably have a look at Building C and C++ Extensions with distutils.
If you build a setup.py file around the example below, setuptools should compile your c file into my_c_lib.so and automatically add it to your installed package (untested).
from distutils.core import setup, Extension
c_module = Extension('my_c_lib',
sources = ['my_c_file.c'])
setup (name = 'my_package',
version = '1.0',
description = 'This is a package in which I compile a C library.',
ext_modules = [c_module])

Force py.test to use installed version of module

I have a mixed Python/C++ library with test files mixed in amongst source files in the same directories. The layout looks like
/home/irving/geode
geode
__init__.py
vector
__init__.py
test_vector.py
...
...
Unfortunately, the library is unusable in-place since it lacks .so extension modules. Question: Can I make py.test always use an installed version, even when run from /home/irving/geode or a subdirectory?
The test files have from __future__ import absolute_import, and run fine if executed directly as scripts. For example, if I do
cd geode/vector
./test_vector.py
which does import geode, it finds the installed version. However, if I run py.test in geode/vector, it finds the local copy of geode, and then dies.
I think you have two options:
run py.test --pyargs geode.vector.test_vector to make pytest interpretet the argument as an import path, deriving the file system path from it. This should run the test against the installed version.
move the tests out into a tests directory without an __init__.py file. This way you need to pip install -e . to work in-place or can do python setup.py install and the py.test tests to run tests against the installed version.