FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/pythonFiles/rope/refactor/topackage.py at master · modulexcite/pythonVSCode · GitHub
modulexcite
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
pythonFiles
/
rope
/
refactor
/
topackage.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (27 loc) · 1.24 KB
Breadcrumbs
pythonVSCode
/
pythonFiles
/
rope
/
refactor
/
topackage.py
Copy path
File metadata and controls
32 lines (27 loc) · 1.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import
rope
.
refactor
.
importutils
from
rope
.
base
.
change
import
ChangeSet
,
ChangeContents
,
MoveResource
, \
CreateFolder
class
ModuleToPackage
(
object
):
def
__init__
(
self
,
project
,
resource
):
self
.
project
=
project
self
.
resource
=
resource
def
get_changes
(
self
):
changes
=
ChangeSet
(
'Transform <%s> module to package'
%
self
.
resource
.
path
)
new_content
=
self
.
_transform_relatives_to_absolute
(
self
.
resource
)
if
new_content
is
not
None
:
changes
.
add_change
(
ChangeContents
(
self
.
resource
,
new_content
))
parent
=
self
.
resource
.
parent
name
=
self
.
resource
.
name
[:
-
3
]
changes
.
add_change
(
CreateFolder
(
parent
,
name
))
parent_path
=
parent
.
path
+
'/'
if
not
parent
.
path
:
parent_path
=
''
new_path
=
parent_path
+
'%s/__init__.py'
%
name
if
self
.
resource
.
project
==
self
.
project
:
changes
.
add_change
(
MoveResource
(
self
.
resource
,
new_path
))
return
changes
def
_transform_relatives_to_absolute
(
self
,
resource
):
pymodule
=
self
.
project
.
get_pymodule
(
resource
)
import_tools
=
rope
.
refactor
.
importutils
.
ImportTools
(
self
.
project
)
return
import_tools
.
relatives_to_absolutes
(
pymodule
)
Back
|
FazBrowse Home
|
New Git URL