Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
bf061f93
Unverified
Commit
bf061f93
authored
May 24, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix get-poetry.py script for Homebrew Python and other installations
parent
4fbf1641
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
7 deletions
+43
-7
get-poetry.py
+43
-7
No files found.
get-poetry.py
View file @
bf061f93
...
@@ -27,6 +27,7 @@ import tempfile
...
@@ -27,6 +27,7 @@ import tempfile
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
from
email.parser
import
Parser
from
email.parser
import
Parser
from
functools
import
cmp_to_key
from
glob
import
glob
from
glob
import
glob
try
:
try
:
...
@@ -88,7 +89,7 @@ def style(fg, bg, options):
...
@@ -88,7 +89,7 @@ def style(fg, bg, options):
STYLES
=
{
STYLES
=
{
'info'
:
style
(
'green'
,
None
,
None
),
'info'
:
style
(
'green'
,
None
,
None
),
'comment'
:
style
(
'yellow'
,
None
,
None
),
'comment'
:
style
(
'yellow'
,
None
,
None
),
'error'
:
style
(
'
white'
,
'red'
,
None
)
'error'
:
style
(
'
red'
,
None
,
None
)
}
}
...
@@ -102,6 +103,7 @@ def colorize(style, text):
...
@@ -102,6 +103,7 @@ def colorize(style, text):
return
'{}{}
\033
[0m'
.
format
(
STYLES
[
style
],
text
)
return
'{}{}
\033
[0m'
.
format
(
STYLES
[
style
],
text
)
@contextmanager
@contextmanager
def
temporary_directory
(
*
args
,
**
kwargs
):
def
temporary_directory
(
*
args
,
**
kwargs
):
try
:
try
:
...
@@ -145,13 +147,24 @@ class Installer:
...
@@ -145,13 +147,24 @@ class Installer:
metadata
=
json
.
loads
(
r
.
read
()
.
decode
())
metadata
=
json
.
loads
(
r
.
read
()
.
decode
())
r
.
close
()
r
.
close
()
def
_compare_versions
(
x
,
y
):
mx
=
self
.
VERSION_REGEX
.
match
(
x
)
my
=
self
.
VERSION_REGEX
.
match
(
y
)
vx
=
tuple
(
int
(
p
)
for
p
in
mx
.
groups
()[:
3
])
+
(
mx
.
group
(
5
),)
vy
=
tuple
(
int
(
p
)
for
p
in
my
.
groups
()[:
3
])
+
(
my
.
group
(
5
),)
if
vx
<
vy
:
return
-
1
elif
vx
>
vy
:
return
1
return
0
print
(
''
)
print
(
''
)
releases
=
sorted
(
releases
=
sorted
(
metadata
[
'releases'
]
.
keys
(),
metadata
[
'releases'
]
.
keys
(),
key
=
lambda
r
:
(
key
=
cmp_to_key
(
_compare_versions
)
'.'
.
join
(
self
.
VERSION_REGEX
.
match
(
r
)
.
groups
()[:
3
]),
self
.
VERSION_REGEX
.
match
(
r
)
.
group
(
5
)
)
)
)
if
self
.
_version
and
self
.
_version
not
in
releases
:
if
self
.
_version
and
self
.
_version
not
in
releases
:
...
@@ -188,7 +201,7 @@ class Installer:
...
@@ -188,7 +201,7 @@ class Installer:
return
self
.
install
(
version
)
return
self
.
install
(
version
)
except
subprocess
.
CalledProcessError
as
e
:
except
subprocess
.
CalledProcessError
as
e
:
print
(
colorize
(
'error'
,
'An error has occured: {}'
.
format
(
str
(
e
))))
print
(
colorize
(
'error'
,
'An error has occured: {}'
.
format
(
str
(
e
))))
print
(
e
.
output
)
print
(
e
.
output
.
decode
()
)
return
e
.
returncode
return
e
.
returncode
...
@@ -197,10 +210,30 @@ class Installer:
...
@@ -197,10 +210,30 @@ class Installer:
with
temporary_directory
(
prefix
=
'poetry-installer-'
)
as
dir
:
with
temporary_directory
(
prefix
=
'poetry-installer-'
)
as
dir
:
dist
=
os
.
path
.
join
(
dir
,
'dist'
)
dist
=
os
.
path
.
join
(
dir
,
'dist'
)
print
(
' - Getting dependencies'
)
print
(
' - Getting dependencies'
)
try
:
self
.
call
(
self
.
call
(
self
.
CURRENT_PYTHON
,
'-m'
,
'pip'
,
'install'
,
'poetry=={}'
.
format
(
version
),
self
.
CURRENT_PYTHON
,
'-m'
,
'pip'
,
'install'
,
'poetry=={}'
.
format
(
version
),
'--target'
,
dist
'--target'
,
dist
)
)
except
subprocess
.
CalledProcessError
as
e
:
if
'must supply either home or prefix/exec-prefix'
in
e
.
output
.
decode
():
# Homebrew Python and possible other installations
# We workaround this issue by temporarily changing
# the --user directory
os
.
environ
[
'PYTHONUSERBASE'
]
=
dir
self
.
call
(
self
.
CURRENT_PYTHON
,
'-m'
,
'pip'
,
'install'
,
'poetry=={}'
.
format
(
version
),
'--user'
,
'--ignore-installed'
)
# Finding site-package directory
lib
=
os
.
path
.
join
(
dir
,
'lib'
)
lib_python
=
list
(
glob
(
os
.
path
.
join
(
lib
,
'python*'
)))[
0
]
site_packages
=
os
.
path
.
join
(
lib_python
,
'site-packages'
)
shutil
.
copytree
(
site_packages
,
dist
)
else
:
raise
print
(
' - Vendorizing dependencies'
)
print
(
' - Vendorizing dependencies'
)
...
@@ -210,7 +243,10 @@ class Installer:
...
@@ -210,7 +243,10 @@ class Installer:
# Everything, except poetry itself, should
# Everything, except poetry itself, should
# be put in the _vendor directory
# be put in the _vendor directory
for
file
in
glob
(
os
.
path
.
join
(
dist
,
'*'
)):
for
file
in
glob
(
os
.
path
.
join
(
dist
,
'*'
)):
if
os
.
path
.
basename
(
file
)
.
startswith
(
'poetry'
):
if
(
os
.
path
.
basename
(
file
)
.
startswith
(
'poetry'
)
or
os
.
path
.
basename
(
file
)
==
'__pycache__'
):
continue
continue
dest
=
os
.
path
.
join
(
vendor_dir
,
os
.
path
.
basename
(
file
))
dest
=
os
.
path
.
join
(
vendor_dir
,
os
.
path
.
basename
(
file
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment