sync Pipfile/Pipfile.lock to setup.py
Project description
Pipenv-Setup
A beautiful python package development tool: sync dependencies in Pipfile or Pipfile.lock to setup.py.
Never need again to change dependencies manually in setup.py, and enjoy the same
dependency locking or semantic versioning.
Or just check whether setup.py and Pipfile are consistent and sync dependency when
necessary.
Installation
Create a command line entry point pipenv-setup, and add pipenv-setup as a dev
package in Pipfile:
pipenv install --dev pipenv-setup
Additionally, starting with the
3.2.0 release,
black and autopep8 can be
included as package extras:
pipenv install --dev "pipenv-setup[black]" # alternatively: pipenv-setup[autopep8]
Note
pipenv-setup<3.2 includes pinned versions of black and autopep8 as dependencies. However, most
projects manage black requirements independently from pipenv-setup; accordingly, black is no
longer a requirement of pipenv-setup after 3.2.0 (instead, include it as an extra as shown
above).
Features
Beautiful pipenv flavored help
$ pipenv-setup
Sync to setup.py
-
supports assorted package configuration. You can have a pipfile as ugly as you want:
[package] requests = { extras = ['socks'] } records = '>0.5.0' django = { git = 'https://github.com/django/django.git', ref = '1.11.4', editable = true } "e682b37" = {file = "https://github.com/divio/django-cms/archive/release/3.4.x.zip"} "e1839a8" = {path = ".", editable = true} pywinusb = { version = "*", os_name = "=='nt'", index="pypi"}pipenv-setupwill still figure things out:$ pipenv-setup sync package e1839a8 is local, omitted in setup.py setup.py successfully updated 23 packages from Pipfile.lock synced to setup.py
And things will be where they should be:
# setup.py setup(..., install_requires=[ "certifi==2017.7.27.1", "chardet==3.0.4", "pywinusb==0.4.2; os_name == 'nt'", ..., "xlrd==1.1.0", "xlwt==1.3.0", ], dependency_links=[ "git+https://github.com/django/django.git@1.11.4#egg=django", "https://github.com/divio/django-cms/archive/release/3.4.x.zip", ], )
-
provide
--devflag to sync development packages withextras_require:$ pipenv-setup sync --dev setup.py successfully updated 1 default packages from Pipfile.lock synced to setup.py 1 dev packages from Pipfile.lock synced to setup.py
# produced setup.py setup(..., extras_require={"dev": ["pytest==1.1.3",]}, install_requires=["xml-subsetter==0.0.1"], )
-
produce beautiful Blackened
setup.pyfile -
Template generation with filled dependencies in the absence of a setup file.
$ pipenv-setup sync setup.py not found under current directory Creating boilerplate setup.py... setup.py was successfully generated 23 packages synced from Pipfile.lock to setup.py Please edit the required fields in the generated file
Note: by default,
pipenv-setupsyncs lockfile instead of pipfile
Sync Pipfile vs. Pipfile.lock
Provide --pipfile flag to sync Pipfile instead of Pipfile.lock.
pipenv-setup
will perform a liquid sync using semantic versioning taken from Pipfile (instead of
using frozen pinned versions from Pipfile.lock):
$ pipenv-setup sync --pipfile
setup.py was successfully updated
23 packages synced from Pipfile to setup.py
Checks Only
run $ pipenv-setup check
-
checks four items
- local package in default pipfile packages
- Package version requirements in
install_requiresin setup.py that potentially violates Pipfile - Package version requirements in
dependency_linksin setup.py that differs from Pipfile - Default package in pipfile missing in
install_requiresordependency_linksin setup.py
-
exits with non-zero code when conflict found (can be used in travis-ci)
-
here is a somewhat extreme example:
$ pipenv-setup check package 'numpy' has version string: >=1.2 in setup.py, which potentially violates >=1.5 in pipfile package 'pywinusb' has version string: ==0.4.2 in setup.py, which is disjoint from ~=0.3.0 in pipfile package 'records' has version string: >=0.4.2,<0.5 in setup.py, which is disjoint from >0.5.0 in pipfile package 'django' has branch/version 1.11.5 in dependency_links, which is different than 1.11.4 listed in pipfile package 'requests' in pipfile but not in install_requires package 'e682b37' has a url in pipfile but not in dependency_links (exits with 1)
-
provide
--ignore-localflag to allow local packages in pipfile$ pipenv-setup check local package found in default dependency: e1839a8. Do you mean to make it dev dependency (exits with 1)
$ pipenv-setup check --ignore-local No version conflict or missing packages/dependencies found in setup.py! (exits with 0)
-
provide
--strictflag to only pass identical version requirementsBy default
pipenv-setup checkpasses when the versionsetup.pyspecifies is "compatible" withPipfile, i.e. is a subset of it. For example, a Pipfile specifyingdjango~=1.1withsetup.pyrequiringdjango==1.2is such a case.Provide
--strictto allow only identical requirements; i.e. forPipfile'sdjango~=1.1,setup.pymust requiredjango>=1.1,<2.0Example output:
$ pipenv-setup check --strict package 'pywinusb' has version string: ==0.4.2 in setup.py, which specifies a subset of * in pipfile package 'django' has version string: >=0.5 in setup.py, which is disjoint from ~=0.3.0 in pipfile package 'records' has version string: ==0.5.2 in setup.py, which specifies a subset of >0.5.0 in pipfile package 'requests' has version string: ==2.18.4 in setup.py, which specifies a subset of * in pipfile (exits with 1)
-
provide
--lockfileflag to checksetup.pyagainstPipfile.lockinstead ofPipfileBy default,
pipenv-setup checkcompares the dependencies fromsetup.pyagainst the dependencies listed inPipfile. This works well for most cases, but there are some exceptions that break this strategy, including (but not necessarily limited to):- VCS dependencies with a mutable
ref(e.g. - git branch name instead of a tag or commit sha)- Because these resolve to an immutable pointer (e.g. - commit sha) in
setup.py, the dependency will no longer match betweensetup.pyandPipfile. However,Pipfile.lockwill contain the same resolved pointer assetup.py.
- Because these resolve to an immutable pointer (e.g. - commit sha) in
- VCS dependencies with a mutable
Pre-commit integration
You can run pipenv-setup automatically using a pre-commit hook. To get
started, add this configuration to your .pre-commit-config.yaml:
- repo: https://github.com/Madoshakalaka/pipenv-setup
rev: "3.2.0" # pick a git hash / tag to point to
hooks:
- id: pipenv-setup
This configuration will will execute pipenv-setup sync --pipfile on changes to Pipfile,
Pipfile.lock, and setup.py.
You can also customize the default args ("--pipfile"). For example, to synchronize --dev extras:
- repo: # ...
hooks:
- id: pipenv-setup
args: [--dev, --pipfile]
If using the hook during CI (or in another environment separate from a black / autopep8
installation), you can include the appropriate auto-formatter with the hook:
- repo: # ...
hooks:
- id: pipenv-setup
additional_dependencies: [".[black]"]
Contributing
If you'd like to contribute to pipenv-setup, see Contribution Guide
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pipenv-setup-3.2.0.tar.gz.
File metadata
- Download URL: pipenv-setup-3.2.0.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0def7ec3363f58b38a43dc59b2078fcee67b47301fd51a41b8e34e6f79812b1a
|
|
| MD5 |
6e064cb7d09642c9e7ce4643e5abc21f
|
|
| BLAKE2b-256 |
29545756347bce0bd4067f884add5af48361ae56c7e17159c0b60ac1d31c52a7
|
File details
Details for the file pipenv_setup-3.2.0-py3-none-any.whl.
File metadata
- Download URL: pipenv_setup-3.2.0-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ceda7145a3088494d8ca68fded4b0473022dc62eb786a021c137632c44298b5
|
|
| MD5 |
7921ac4170afa62c8d94113f8bae1ed3
|
|
| BLAKE2b-256 |
fdeae96585cc7c6a4db1ac0c3f3cd197c69245e64b21b347467369e421a90ed2
|