-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to tomlkit for parsing and writing #3191
Conversation
Maybe we can drop prettytoml/contoml from the vendors directory at this point? |
That would be very nice, those libraries are so annoying |
Nice failure...
There are spaces between the |
@techalchemy :( toml keeps them but tomlkit suppresses them. |
All CI passed! 🎆 |
I cannot believe this is passing. 🎉 |
I want to make sure we aren't using this in |
506f1d9
to
b3aa66b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, looks good to me so whenever @uranusjr confirms I am guessing we can merge this, thanks for your efforts on the toml patches and cleanup -- this is going to make life a lot easier
1b807fa
to
65d7090
Compare
I found a weird bug handling comments. Please don't merge until I fix this. Thanks |
Marking as WIP for now |
what is the weird handling? |
Seems a bug of tomlkit, trying to figure out how to update vendors and patch scripts. I have filed bugs in upstream python-poetry/tomlkit#29 python-poetry/tomlkit#30 if anyone is interested in. |
@techalchemy @uranusjr Can you guys have another look on the latest changes and we are good to go. |
[packages.requests] | ||
version = "*" | ||
""".strip() | ||
f.write(contents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely related to this PR, but it just occurred to me that we need a test to make sure we are reading Pipfile and Pipfile.lock with the correct encoding. It is likely best to have an abstraction around this in Project
too (something like with project.open_pipfile('w') as f:
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had this in Project
-- did it go away?
Thanks for the quick response from tomlkit and I just updated tomlkit to 0.5.2 and cleaned some patching stuff. |
88ad74c
to
1f7c9ef
Compare
Vendoring updates are somewhat complicated, I often take my local copy of pipenv, clone the entire thing to export PIPENV_DIR=$(cwd)
cd /tmp
git clone "$PIPENV_DIR" pipenv
cd pipenv/pipenv/vendor
pip install -t . --no-deps --upgrade <pkgname>==<pkgversion>
rm -rf *.dist-info
git checkout -- <pkgname>.LICENSE <pkgdir>/LICENSE # depends on which got deleted
git add <pkgname>...
git commit -m "Temp commit for updating patches"
cp -R "${PIPENV_DIR}/pipenv/vendor/<pkgname>/files-you-want" pipenv/vendor/<pkgname>/
git diff -p pipenv/vendor/<pkgname> > "${PIPENV_DIR}/tasks/vendoring/patches/vendor/pkgname-whatever.patch" I've literally never documented that before so we should probably record that... |
@techalchemy Yeah, it really took me much time to figure it out. I managed to do it by invoke run. |
pipenv/vendor/tomlkit/items.py
Outdated
try: | ||
from enum import Enum | ||
except ImportError: | ||
from pipenv.vendor.backports.enum import Enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses try-catch, but there’s a lru_cache
block that uses if-else. I would recommend unifying the style (probably to try-catch; it seems to be recommended).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lru_cache
is got from the original code, I will change to if
to adapt the style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the if/else
approach is actually there on purpose, and shoudln't be removed blindly...
The decisions I made about where to use try/except
vs if/else
aren't stylistic, they have real consequences. We vendor a large number of critical items and we also use a number of runtime hacks that affect sys.path
. try/except
is not an acceptable approach if you specifically need functionality provided by a backport or a vendored package in situations where something might actually succeed if you import it. Things that come to mind:
- pathlib (there is a garbage python 2 backport of a package called pathlib, if you try/except this you will wrongly allow imports of the wrong
pathlib
which is not api compliant with the standard library TemporaryDirectory
-- Not all backports use weakrefs, this will literally break everything about pipenv- I've actually seen people importing things across python versions, across site packages/user site/local environment and having completely out of date versions from actually the wrong version of python 3
- scandir in the vendored format is modified to excluded binaries
tl;dr don't mess with things unless you know the consequences of it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in most cases, like the Enum
case, it doesn't matter at all
if and when @uranusjr is ok with this I can verify the patches and we can merge |
I want to verify that this and #3196 will play nicely together before merging either of them so that’s the next step |
Thank you for contributing to Pipenv!
The issue
Incomplete implementation of #3177
The fix
dump_dict
method.toml
.prettytoml/contoml
from vendors.The checklist
news/
directory to describe this fix with the extension.bugfix
,.feature
,.behavior
,.doc
..vendor
. or.trivial
(this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.