I used the Upload Python Package workflow on GitHub to upload the module stored in the repository to PyPI.
As you can see at the link above, I followed the tutorial given by packaging.python.org, to be more specific I used setup.py instead of setup.cfg.
Anyway an error occurred during the last deploy, which gave me the following error:
Run python -m build
python -m build
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.10.4/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.4/x64/lib
running egg_info
creating src/classevivaAPI.egg-info
writing src/classevivaAPI.egg-info/PKG-INFO
writing dependency_links to src/classevivaAPI.egg-info/dependency_links.txt
writing top-level names to src/classevivaAPI.egg-info/top_level.txt
writing manifest file ‘src/classevivaAPI.egg-info/SOURCES.txt’
error: package directory ‘src/classevivaAPI’ does not exist
* Creating venv isolated environment…
* Installing packages in isolated environment… (selenium>=4.1.3, setuptools>=42)
* Getting dependencies for sdist…
ERROR Backend subproccess exited when trying to invoke get_requires_for_build_sdist
Error: Process completed with exit code 1.
In particular I was wondering what does the following line mean:
ERROR Backend subproccess exited when trying to invoke get_requires_for_build_sdist
Have you ever had the same problem? Do you know how to solve it and upload my package? Thank you in advance.
Okay, let\’s break down this error and figure out how to get your Python package uploaded to PyPI. The error message, combined with the traceback, provides some good clues.\n\n**Understanding the Error**\n\nThe core issue is:\n\n* `error: package directory \’src/classevivaAPI\’ does not exist`\n\nThis means that your `setup.py` file is trying to include a package named `classevivaAPI` located in the `src` directory, but that directory (or the `classevivaAPI` subdirectory within it) doesn\’t actually exist in your repository\’s structure.\n\n* `ERROR Backend subproccess exited when trying to invoke get_requires_for_build_sdist`\n\nThis error indicates that the `build` process, specifically when preparing to create a source distribution (`sdist`), failed because it couldn\’t find the necessary dependencies or structure based on your `setup.py` configuration. The root cause of this is the missing package directory. The `get_requires_for_build_sdist` hook is trying to figure out what your project needs to build a source distribution, and it\’s failing because of the misconfiguration.\n\n**Common Causes and Solutions**\n\nHere\’s a breakdown of the most likely causes and how to fix them:\n\n1. **Incorrect `packages` or `py_modules` in `setup.py`:**\n\n * **The Problem:** Your `setup.py` file likely has an incorrect `packages` or `py_modules` argument in the `setup()` function. These arguments tell the packaging tools which directories/files to include in your package. It\’s pointing to a location that doesn\’t exist.\n * **The Solution:**\n\n * **If you are using a `src` layout (recommended):**\n Your project structure should look like this:\n\n “`\n my_project/\n ├── src/\n │ └── classevivaAPI/\n │ ├── __init__.py\n │ └── … your other .py files\n ├── setup.py\n └── README.md (or other project files)\n “`\n\n In `setup.py`, you should have:\n\n “`python\n from setuptools import setup, find_packages\n\n setup(\n name=\’classevivaAPI\’,\n version=\’…\’,\n packages=find_packages(where=\’src\’), # Important!\n package_dir={\’\’: \’src\’}, #This line is important!\n …\n )\n “`\n\n **Explanation:** `find_packages(where=\’src\’)` automatically finds all packages within the `src` directory. `package_dir={\’\’: \’src\’}` tells setuptools that the root package is located in the `src` directory.\n * **If your package is in the top-level directory:**\n\n Your project structure should look like this:\n\n “`\n my_project/\n ├── classevivaAPI/\n │ ├── __init__.py\n │ └── … your other .py files\n ├── setup.py\n └── README.md (or other project files)\n “`\n\n In `setup.py`, you should have:\n\n “`python\n from setuptools import setup, find_packages\n\n setup(\n name=\’classevivaAPI\’,\n version=\’…\’,\n packages=find_packages(), # Important!\n …\n )\n “`\n **Explanation:** `find_packages()` automatically finds all packages in the current directory.\n * **If you\’re using `py_modules`:**\n\n `py_modules` is used for single-file modules (not recommended for larger projects). If you\’re trying to package a directory, `packages` is the correct approach. However, if you *really* have a single file module:\n\n “`python\n from setuptools import setup\n\n setup(\n name=\’classevivaAPI\’,\n version=\’…\’,\n py_modules=[\’classevivaAPI\’], # Replace with your actual module name (without .py)\n …\n )\n “`\n\n In this case, you should have a single file `classevivaAPI.py` in the same directory as `setup.py`. This is generally *not* the recommended structure.\n\n2. **Missing `__init__.py`:**\n\n * **The Problem:** Every directory that you want to be treated as a Python package *must* contain an `__init__.py` file (even if it\’s empty).\n * **The Solution:** Make sure you have an `__init__.py` file in your `classevivaAPI` directory (and any other subdirectories that should be packages).\n\n3. **Typos:**\n\n * **The Problem:** A simple typo in the `name`, `packages`, or `py_modules` arguments can cause this.\n * **The Solution:** Double-check your `setup.py` file very carefully for typos.\n\n4. **Incorrect Directory Structure (related to `src` layout):**\n\n * **The Problem:** You specified a `src` layout in `setup.py` but your files are not actually inside the `src` folder, or are not structured correctly inside it.\n * **The Solution:** Ensure your project directory structure matches what you specified in the `setup.py`. Refer to the examples in point 1.\n\n**Steps to Debug and Fix**\n\n1. **Examine Your Project Structure:** Carefully look at the directory structure of your repository. Does it match what you *think* it should be? Is there a `src` directory? Is `classevivaAPI` a directory containing `__init__.py`?\n\n2. **Inspect `setup.py`:** Paste the relevant section of your `setup.py` (specifically the `setup()` function call) into your response so I can review it.\n\n3. **Test Locally:** Before pushing to GitHub, try building your package locally:\n\n “`bash\n python -m build\n “`\n\n This will run the same build process that\’s failing in your GitHub Actions workflow, and it will give you more immediate feedback. Run this from the root directory of your project (where `setup.py` is located).\n\n4. **Update GitHub Workflow (if necessary):** Once you\’ve fixed the problem locally, commit and push your changes to your repository. The GitHub Actions workflow should then run successfully.\n\n**Example `setup.py` (with `src` layout):**\n\n“`python\nfrom setuptools import setup, find_packages\n\nsetup(\n name=\’classevivaAPI\’,\n version=\’0.1.0\’, # Replace with your version\n description=\’A Python library for Classeviva API\’, # Replace with your description\n long_description=open(\’README.md\’).read(), #Optional but recommended\n long_description_content_type=\’text/markdown\’, #Optional but recommended\n author=\’Your Name\’, #Replace with your name\n author_email=\’your.email@example.com\’, #Replace with your email\n url=\’https://github.com/yourusername/classevivaAPI\’, #Replace with your repository URL\n packages=find_packages(where=\’src\’),\n package_dir={\’\’: \’src\’},\n install_requires=[\n \’selenium>=4.1.3\’, # Example dependency. List your actual dependencies here\n ],\n classifiers=[\n \’Development Status :: 3 – Alpha\’, # Choose a suitable development status\n \’Intended Audience :: Developers\’,\n \’License :: OSI Approved :: MIT License\’, # Choose your license\n \’Programming Language :: Python :: 3\’,\n \’Programming Language :: Python :: 3.6\’,\n \’Programming Language :: Python :: 3.7\’,\n \’Programming Language :: Python :: 3.8\’,\n \’Programming Language :: Python :: 3.9\’,\n \’Programming Language :: Python :: 3.10\’,\n ],\n)\n“`\n\n**Key Points:**\n\n* Use `find_packages()` to automatically discover your packages.\n* Ensure your directory structure matches your `setup.py` configuration.\n* Test locally before pushing to GitHub.\n* Pay close attention to the traceback; it tells you exactly where the problem is.\n\nLet me know the contents of your `setup.py` and a description of your directory structure, and I can give you more specific advice. Good luck!\n