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
816c5103
Unverified
Commit
816c5103
authored
Aug 08, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the self:update command
parent
489ee37c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
55 deletions
+65
-55
poetry/console/commands/self/update.py
+65
-55
No files found.
poetry/console/commands/self/update.py
View file @
816c5103
...
@@ -23,7 +23,21 @@ class SelfUpdateCommand(Command):
...
@@ -23,7 +23,21 @@ class SelfUpdateCommand(Command):
from
poetry.__version__
import
__version__
from
poetry.__version__
import
__version__
from
poetry.repositories.pypi_repository
import
PyPiRepository
from
poetry.repositories.pypi_repository
import
PyPiRepository
from
poetry.semver
import
Version
from
poetry.semver
import
Version
from
poetry.utils._compat
import
Path
from
poetry.utils._compat
import
decode
from
poetry.utils._compat
import
decode
from
poetry.utils.appdirs
import
expanduser
home
=
Path
(
expanduser
(
"~"
))
poetry_home
=
home
/
".poetry"
current_file
=
Path
(
__file__
)
try
:
current_file
.
relative_to
(
poetry_home
)
except
ValueError
:
raise
RuntimeError
(
"Poetry has not been installed with the recommended installer. Aborting."
)
version
=
self
.
argument
(
"version"
)
version
=
self
.
argument
(
"version"
)
if
not
version
:
if
not
version
:
...
@@ -84,38 +98,66 @@ class SelfUpdateCommand(Command):
...
@@ -84,38 +98,66 @@ class SelfUpdateCommand(Command):
def
update
(
self
,
release
):
def
update
(
self
,
release
):
from
poetry.utils._compat
import
Path
from
poetry.utils._compat
import
Path
from
poetry.utils.helpers
import
temporary_directory
from
poetry.utils.appdirs
import
expanduser
home
=
Path
(
expanduser
(
"~"
))
poetry_home
=
home
/
".poetry"
poetry_bin
=
poetry_home
/
"bin"
poetry_lib
=
poetry_home
/
"lib"
poetry_lib_backup
=
poetry_home
/
"lib.backup"
version
=
release
.
version
version
=
release
.
version
self
.
line
(
"Updating to <info>{}</info>"
.
format
(
version
))
self
.
line
(
"Updating to <info>{}</info>"
.
format
(
version
))
prefix
=
sys
.
prefix
if
poetry_lib
.
exists
():
base_prefix
=
getattr
(
sys
,
"base_prefix"
,
None
)
# Backing up the current lib directory
real_prefix
=
getattr
(
sys
,
"real_prefix"
,
None
)
if
poetry_lib_backup
.
exists
():
shutil
.
rmtree
(
str
(
poetry_lib_backup
))
prefix_poetry
=
self
.
_bin_path
(
Path
(
prefix
),
"poetry"
)
if
prefix_poetry
.
exists
():
shutil
.
copytree
(
str
(
poetry_lib
),
str
(
poetry_lib_backup
))
pip
=
self
.
_bin_path
(
prefix_poetry
.
parent
.
parent
,
"pip"
)
.
resolve
()
shutil
.
rmtree
(
str
(
poetry_lib
))
elif
(
base_prefix
try
:
and
base_prefix
!=
prefix
self
.
_update
(
release
,
poetry_lib
)
and
self
.
_bin_path
(
Path
(
base_prefix
),
"poetry"
)
.
exists
()
except
Exception
as
e
:
):
# Reverting changes
pip
=
self
.
_bin_path
(
Path
(
base_prefix
),
"pip"
)
if
poetry_lib_backup
.
exists
():
elif
real_prefix
:
if
poetry_lib
.
exists
():
pip
=
self
.
_bin_path
(
Path
(
real_prefix
),
"pip"
)
shutil
.
rmtree
(
str
(
poetry_lib
))
else
:
pip
=
self
.
_bin_path
(
Path
(
prefix
),
"pip"
)
shutil
.
copytree
(
str
(
poetry_lib_backup
),
str
(
poetry_lib
))
if
not
pip
.
exists
():
message
=
(
raise
RuntimeError
(
"Unable to determine poetry's path"
)
"An error occured when updating Poetry. "
"The changes have been rolled back."
)
if
self
.
output
.
is_debug
():
message
+=
" Original error: {}"
.
format
(
e
)
raise
RuntimeError
(
message
)
finally
:
if
poetry_lib_backup
.
exists
():
shutil
.
rmtree
(
str
(
poetry_lib_backup
))
self
.
line
(
""
)
self
.
line
(
"<info>Poetry</> (<comment>{}</>) "
"is installed now. Great!"
.
format
(
version
)
)
def
_update
(
self
,
release
,
lib
):
from
poetry.utils._compat
import
Path
from
poetry.utils.helpers
import
temporary_directory
with
temporary_directory
(
prefix
=
"poetry-update-"
)
as
temp_dir
:
with
temporary_directory
(
prefix
=
"poetry-update-"
)
as
temp_dir
:
temp_dir
=
Path
(
temp_dir
)
temp_dir
=
Path
(
temp_dir
)
dist
=
temp_dir
/
"dist"
dist
=
temp_dir
/
"dist"
self
.
line
(
" - Getting dependencies"
)
self
.
line
(
" - Getting dependencies"
)
self
.
process
(
self
.
process
(
str
(
pip
),
sys
.
executable
,
"-m"
,
"pip"
,
"install"
,
"install"
,
"-U"
,
"-U"
,
"poetry=={}"
.
format
(
release
.
version
),
"poetry=={}"
.
format
(
release
.
version
),
...
@@ -142,39 +184,7 @@ class SelfUpdateCommand(Command):
...
@@ -142,39 +184,7 @@ class SelfUpdateCommand(Command):
shutil
.
copy
(
str
(
file
),
str
(
dest
))
shutil
.
copy
(
str
(
file
),
str
(
dest
))
os
.
unlink
(
str
(
file
))
os
.
unlink
(
str
(
file
))
wheel_data
=
dist
/
"poetry-{}.dist-info"
.
format
(
version
)
/
"WHEEL"
shutil
.
copytree
(
dist
,
str
(
lib
))
with
wheel_data
.
open
()
as
f
:
wheel_data
=
Parser
()
.
parsestr
(
f
.
read
())
tag
=
wheel_data
[
"Tag"
]
# Repack everything and install
self
.
line
(
" - Updating <info>poetry</info>"
)
shutil
.
make_archive
(
str
(
temp_dir
/
"poetry-{}-{}"
.
format
(
version
,
tag
)),
format
=
"zip"
,
root_dir
=
str
(
dist
),
)
os
.
rename
(
str
(
temp_dir
/
"poetry-{}-{}.zip"
.
format
(
version
,
tag
)),
str
(
temp_dir
/
"poetry-{}-{}.whl"
.
format
(
version
,
tag
)),
)
self
.
process
(
str
(
pip
),
"install"
,
"--upgrade"
,
"--no-deps"
,
str
(
temp_dir
/
"poetry-{}-{}.whl"
.
format
(
version
,
tag
)),
)
self
.
line
(
""
)
self
.
line
(
"<info>poetry</> (<comment>{}</>) "
"successfully installed!"
.
format
(
version
)
)
def
process
(
self
,
*
args
):
def
process
(
self
,
*
args
):
return
subprocess
.
check_output
(
list
(
args
),
stderr
=
subprocess
.
STDOUT
)
return
subprocess
.
check_output
(
list
(
args
),
stderr
=
subprocess
.
STDOUT
)
...
...
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