Package: pipenv-setup
Pipenv-SetupA beautiful python package development tool: sync dependencies inPipfileorPipfile.locktosetup.py.Never need again to change dependencies manually insetup.py, and enjoy the same
dependency locking or semantic versioning.Or just check whethersetup.pyandPipfileare consistent and sync dependency when
necessary.InstallationCreate a command line entry pointpipenv-setup, and addpipenv-setupas adevpackage inPipfile:pipenvinstall--devpipenv-setupAdditionally, starting with the3.2.0release,blackandautopep8can be
included as package extras:pipenvinstall--dev"pipenv-setup[black]"# alternatively: pipenv-setup[autopep8]Notepipenv-setup<3.2includes pinned versions ofblackandautopep8as dependencies. However, most
projects manageblackrequirements independently frompipenv-setup; accordingly,blackis no
longer a requirement ofpipenv-setupafter3.2.0(instead, include it as an extra as shown
above).FeaturesBeautiful pipenv flavored help$ pipenv-setupSync tosetup.pysupports 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-setupsync
packagee1839a8islocal,omittedinsetup.py
setup.pysuccessfullyupdated23packagesfromPipfile.locksyncedtosetup.pyAnd things will be where they should be:# setup.pysetup(...,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-setupsync--dev
setup.pysuccessfullyupdated1defaultpackagesfromPipfile.locksyncedtosetup.py1devpackagesfromPipfile.locksyncedtosetup.py# produced setup.pysetup(...,extras_require={"dev":["pytest==1.1.3",]},install_requires=["xml-subsetter==0.0.1"],)produce beautifulBlackenedsetup.pyfileTemplategeneration with
filled dependencies in the absence of a setup file.$pipenv-setupsync
setup.pynotfoundundercurrentdirectory
Creatingboilerplatesetup.py...
setup.pywassuccessfullygenerated23packagessyncedfromPipfile.locktosetup.py
PleaseedittherequiredfieldsinthegeneratedfileNote: by default,pipenv-setupsyncs lockfile instead of pipfileSyncPipfilevs.Pipfile.lockProvide--pipfileflag to syncPipfileinstead ofPipfile.lock.pipenv-setupwill perform a liquid sync using semantic versioning taken fromPipfile(instead of
using frozen pinned versions fromPipfile.lock):$pipenv-setupsync--pipfile
setup.pywassuccessfullyupdated23packagessyncedfromPipfiletosetup.pyChecks Onlyrun$ pipenv-setup checkchecks four itemslocal package in default pipfile packagesPackage version requirements ininstall_requiresin setup.py that potentially violates PipfilePackage version requirements independency_linksin setup.py that differs from PipfileDefault package in pipfile missing ininstall_requiresordependency_linksin setup.pyexits with non-zero code when conflict found (can be used in travis-ci)here is a somewhat extreme example:$pipenv-setupcheck
package'numpy'hasversionstring:>=1.2insetup.py,whichpotentiallyviolates>=1.5inpipfile
package'pywinusb'hasversionstring:==0.4.2insetup.py,whichisdisjointfrom~=0.3.0inpipfile
package'records'hasversionstring:>=0.4.2,<0.5insetup.py,whichisdisjointfrom>0.5.0inpipfile
package'django'hasbranch/version1.11.5independency_links,whichisdifferentthan1.11.4listedinpipfile
package'requests'inpipfilebutnotininstall_requires
package'e682b37'hasaurlinpipfilebutnotindependency_links(exitswith1)provide--ignore-localflag to allow local packages in pipfile$pipenv-setupchecklocalpackagefoundindefaultdependency:e1839a8.
Doyoumeantomakeitdevdependency(exitswith1)$pipenv-setupcheck--ignore-local
Noversionconflictormissingpackages/dependenciesfoundinsetup.py!(exitswith0)provide--strictflag to only pass identical version requirementsBy defaultpipenv-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-setupcheck--strict
package'pywinusb'hasversionstring:==0.4.2insetup.py,whichspecifiesasubsetof*inpipfile
package'django'hasversionstring:>=0.5insetup.py,whichisdisjointfrom~=0.3.0inpipfile
package'records'hasversionstring:==0.5.2insetup.py,whichspecifiesasubsetof>0.5.0inpipfile
package'requests'hasversionstring:==2.18.4insetup.py,whichspecifiesasubsetof*inpipfile(exitswith1)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 mutableref(e.g. - git branch name instead of a tag or commit sha)Because these resolve to an immutable pointer (e.g. - commit sha) insetup.py, the
dependency will no longer match betweensetup.pyandPipfile. However,Pipfile.lockwill contain the same resolved pointer assetup.py.Pre-commit integrationYou can runpipenv-setupautomatically using apre-commithook. To get
started, add this configuration to your.pre-commit-config.yaml:-repo:https://github.com/Madoshakalaka/pipenv-setuprev:"3.2.0"# pick a git hash / tag to point tohooks:-id:pipenv-setupThis configuration will will executepipenv-setup sync --pipfileon changes toPipfile,Pipfile.lock, andsetup.py.You can also customize the default args ("--pipfile"). For example, to synchronize--devextras:-repo:# ...hooks:-id:pipenv-setupargs:[--dev,--pipfile]If using the hook during CI (or in another environment separate from ablack/autopep8installation), you can include the appropriate auto-formatter with the hook:-repo:# ...hooks:-id:pipenv-setupadditional_dependencies:[".[black]"]ContributingIf you'd like to contribute topipenv-setup, seeContribution Guide