{"id":25133079,"url":"https://github.com/dev-vivekkumarverma/using-wheel-with-python","last_synced_at":"2025-04-03T01:24:44.940Z","repository":{"id":275949694,"uuid":"927646275","full_name":"dev-vivekkumarverma/using-wheel-with-python","owner":"dev-vivekkumarverma","description":"using wheel for python","archived":false,"fork":false,"pushed_at":"2025-02-05T12:23:56.000Z","size":48944,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-05T13:26:41.883Z","etag":null,"topics":["build-tool","dependency-management","python3","wheel"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dev-vivekkumarverma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-05T09:59:42.000Z","updated_at":"2025-02-05T12:24:00.000Z","dependencies_parsed_at":"2025-02-05T13:36:55.209Z","dependency_job_id":null,"html_url":"https://github.com/dev-vivekkumarverma/using-wheel-with-python","commit_stats":null,"previous_names":["dev-vivekkumarverma/using-wheel-with-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2Fusing-wheel-with-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2Fusing-wheel-with-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2Fusing-wheel-with-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-vivekkumarverma%2Fusing-wheel-with-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev-vivekkumarverma","download_url":"https://codeload.github.com/dev-vivekkumarverma/using-wheel-with-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246918577,"owners_count":20854841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-tool","dependency-management","python3","wheel"],"created_at":"2025-02-08T15:34:08.888Z","updated_at":"2025-04-03T01:24:44.911Z","avatar_url":"https://github.com/dev-vivekkumarverma.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"To automatically add `install_requires` in `setup.py`, you can use a `requirements.txt` file and parse it in `setup.py`. This ensures that your dependencies are consistent across both files. Here's how you can do it:\n\n---\n\n### **Step 1: Create a `requirements.txt` File**\nList your dependencies in `requirements.txt`:\n```txt\npandas\u003e=2.0.0\nnumpy\u003e=1.24.0\nmatplotlib\u003e=3.7.0\nrequests\u003e=2.31.0\n```\n\n---\n\n### **Step 2: Modify `setup.py` to Read `requirements.txt`**\nUpdate your `setup.py` to read the dependencies from `requirements.txt`:\n```python\nfrom setuptools import setup, find_packages\nfrom pathlib import Path\n\n# Read requirements.txt\ndef get_requirements():\n    requirements_file = Path(__file__).parent / \"requirements.txt\"\n    with open(requirements_file, \"r\") as f:\n        return [line.strip() for line in f if line.strip() and not line.startswith(\"#\")]\n\nsetup(\n    name=\"my_project\",\n    version=\"0.1\",\n    packages=find_packages(),\n    install_requires=get_requirements(),  # Automatically add dependencies\n)\n```\n\n---\n\n### **Step 3: Install the Project**\nRun the following command to install the project in editable mode:\n```bash\npip install -e .\n```\n\n---\n\n### **How It Works**\n1. **`get_requirements()` Function**:\n   - Reads the `requirements.txt` file.\n   - Filters out comments (lines starting with `#`) and empty lines.\n   - Returns a list of dependencies.\n\n2. **`install_requires`**:\n   - Passes the list of dependencies to `setup()`.\n\n---\n\n### **Step 4: Keep `requirements.txt` and `setup.py` in Sync**\nWhenever you update `requirements.txt`, the `install_requires` in `setup.py` will automatically reflect the changes.\n\n---\n\n### **Alternative: Use `pip-tools` for Advanced Dependency Management**\nIf your project has complex dependencies (e.g., dev vs. production), you can use `pip-tools` to manage them.\n\n1. **Install `pip-tools`**:\n   ```bash\n   pip install pip-tools\n   ```\n\n2. **Create `requirements.in`**:\n   Add your dependencies to `requirements.in`:\n   ```txt\n   pandas\u003e=2.0.0\n   numpy\u003e=1.24.0\n   matplotlib\u003e=3.7.0\n   requests\u003e=2.31.0\n   ```\n\n3. **Compile `requirements.txt`**:\n   ```bash\n   pip-compile requirements.in --output-file requirements.txt\n   ```\n\n4. **Update `setup.py`**:\n   Use the same `get_requirements()` function as above to read `requirements.txt`.\n\n---\n\n### **Benefits of This Approach**\n- **Single Source of Truth**: Dependencies are defined in one place (`requirements.txt` or `requirements.in`).\n- **Consistency**: Ensures `setup.py` and `requirements.txt` are always in sync.\n- **Flexibility**: Works with both simple and complex dependency setups.\n\n---\n\n### **Full Example**\nHere’s the complete `setup.py`:\n```python\nfrom setuptools import setup, find_packages\nfrom pathlib import Path\n\ndef get_requirements():\n    requirements_file = Path(__file__).parent / \"requirements.txt\"\n    with open(requirements_file, \"r\") as f:\n        return [line.strip() for line in f if line.strip() and not line.startswith(\"#\")]\n\nsetup(\n    name=\"my_project\",\n    version=\"0.1\",\n    packages=find_packages(),\n    install_requires=get_requirements(),\n)\n```\n\nAnd the `requirements.txt`:\n```txt\npandas\u003e=2.0.0\nnumpy\u003e=1.24.0\nmatplotlib\u003e=3.7.0\nrequests\u003e=2.31.0\n```\n\n---\n\n### **Step 5: Test the Setup**\n1. Install the project:\n   ```bash\n   pip install -e .\n   ```\n\n2. Verify the dependencies:\n   ```bash\n   pip freeze\n   ```\n\nYou should see the dependencies (`pandas`, `numpy`, etc.) installed in your environment.\n\n---\n- for adding new requirements\nappend them in `requirement.txt`\n\n-- for first time installation \n\nrun \n```shell\n./pre_requisit.sh\n```\n\n- for creating wheel file and building .whl file\nrun \n```shell\n./runner.sh\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-vivekkumarverma%2Fusing-wheel-with-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev-vivekkumarverma%2Fusing-wheel-with-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-vivekkumarverma%2Fusing-wheel-with-python/lists"}