Skip to content
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

Evaluate pathlib compatibility for Python < 3.5 #2438

Closed
mrstewar opened this issue Jun 27, 2018 · 7 comments
Closed

Evaluate pathlib compatibility for Python < 3.5 #2438

mrstewar opened this issue Jun 27, 2018 · 7 comments
Labels
Type: Bug 🐛 This issue is a bug.
Milestone

Comments

@mrstewar
Copy link

Running Python 2.7.12 with pipenv installed in user site (pip install --user pipenv) fails because
pathlib.Path.mkdir function doesn't have a exist_ok argument specified.

Actual error (from bottom of full output):
TypeError: mkdir() got an unexpected keyword argument 'exist_ok'

Seems like it's confied to python2 as python2 doesn't have pathlib natively in the standard library and must use a backport.

Full output:
project_dir>pipenv update --dev
Running $ pipenv lock then $ pipenv sync.
Locking [dev-packages] dependencies...
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
"main", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in run_code
exec code in run_globals
File "<user_base>\Scripts\pipenv.exe_main
.py", line 9, in
File "<user_base>\Python\Python27\site-packages\pipenv\vendor\click\core.py", line 722, in call
return self.main(*args, **kwargs)
File "<user_base>\Python27\site-packages\pipenv\vendor\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "<user_base>\Python27\site-packages\pipenv\vendor\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "<user_base>\Python27\site-packages\pipenv\vendor\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "<user_base>\Python27\site-packages\pipenv\vendor\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "<user_base>\Python27\site-packages\pipenv\vendor\click\decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "<user_base>\Python27\site-packages\pipenv\cli.py", line 850, in update
verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror
File "<user_base>\Python27\site-packages\pipenv\core.py", line 1098, in do_lock
dev=settings['dev']
File "<user_base>\Python27\site-packages\pipenv\utils.py", line 1177, in get_vcs_deps
src_dir.mkdir(mode=0o775, exist_ok=True)
TypeError: mkdir() got an unexpected keyword argument 'exist_ok'

pipenv_help.txt

Expected result

Expected the update to run without error

Actual result

Failed as shown at the beginning

Steps to replicate

In pristine project directory (no Pipfile) using python 2.7.12 or greater run:
pipenv install future

You should actually see the problem there as well.

If not, then run "pipenv update"

@mrstewar
Copy link
Author

I poked around a bit more.
I was able to reproduce this bug on both windows and linux pipenv installations.
I also examined the pathlib backport on my system

Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import pathlib
Help on method mkdir in module pathlib:
mkdir(self, mode=511, parents=False) method of pathlib.WindowsPath instance

Possible fix is to use pathlib2 instead of pathlib, looks like it supports the exist_ok argument.

Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import pathlib2
Help on method mkdir in module pathlib2:
mkdir(self, mode=511, parents=False, exist_ok=False) method of pathlib2.WindowsPath instance
Create a new directory at this given path.

@techalchemy
Copy link
Member

We fall back to pathlib2 which we vendor. I guess you have manually installed the old, deprecated pathlib in your global environment. I guess we can use python conditional version checks but the real solution is to stop installing pathlib in your environment.

@uranusjr
Copy link
Member

We do list 3.4 as supported, and the built-in pathlib on 3.4 does not have exist_ok IIRC. I need to fix that.

@uranusjr
Copy link
Member

Or maybe we should use the vendored pathlib2 on 3.4.

@uranusjr uranusjr changed the title pipenv 2018.6.25 for python 2 fails when running "pipenv update --dev" or similar commands -- pathlib.Path.mkdir does NOT have exist_ok argument Evaluate pathlib compatibility for Python < 3.5 Jun 27, 2018
@uranusjr uranusjr added the Type: Bug 🐛 This issue is a bug. label Jun 27, 2018
@mrstewar
Copy link
Author

@techalchemy you were indeed correct about having pathlib installed in my environment. I removed it on both my windows and linux systems and can confirm that this fixed my specific issue. Many thanks for the tip.

@daa
Copy link

daa commented Jun 28, 2018

@uranusjr @techalchemy You may also use ruamel.std.pathlib which uses standard pathlib or pathlib2 when appropriate, for example now pathlib2 is used for python < 3.5.

@techalchemy
Copy link
Member

We already handled this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐛 This issue is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants