@@ -13,8 +13,6 @@ class AddCommand(EnvCommand, InitCommand):
13
13
arguments = [argument ("name" , "Packages to add." , multiple = True )]
14
14
options = [
15
15
option ("dev" , "D" , "Add package as development dependency." ),
16
- option ("git" , None , "The url of the Git repository." , flag = False ),
17
- option ("path" , None , "The path to a dependency." , flag = False ),
18
16
option (
19
17
"extras" ,
20
18
"E" ,
@@ -58,17 +56,11 @@ def handle(self):
58
56
packages = self .argument ("name" )
59
57
is_dev = self .option ("dev" )
60
58
61
- if (self .option ("git" ) or self .option ("path" ) or self .option ("extras" )) and len (
62
- packages
63
- ) > 1 :
59
+ if self .option ("extras" ) and len (packages ) > 1 :
64
60
raise ValueError (
65
- "You can only specify one package "
66
- "when using the --git or --path options"
61
+ "You can only specify one package " "when using the --extras option"
67
62
)
68
63
69
- if self .option ("git" ) and self .option ("path" ):
70
- raise RuntimeError ("--git and --path cannot be used at the same time" )
71
-
72
64
section = "dependencies"
73
65
if is_dev :
74
66
section = "dev-dependencies"
@@ -83,32 +75,27 @@ def handle(self):
83
75
for name in packages :
84
76
for key in poetry_content [section ]:
85
77
if key .lower () == name .lower ():
78
+ pair = self ._parse_requirements ([name ])[0 ]
79
+ if "git" in pair or pair .get ("version" ) == "latest" :
80
+ continue
81
+
86
82
raise ValueError ("Package {} is already present" .format (name ))
87
83
88
- if self .option ("git" ) or self .option ("path" ):
89
- requirements = {packages [0 ]: "" }
90
- else :
91
- requirements = self ._determine_requirements (
92
- packages , allow_prereleases = self .option ("allow-prereleases" )
93
- )
94
- requirements = self ._format_requirements (requirements )
84
+ requirements = self ._determine_requirements (
85
+ packages , allow_prereleases = self .option ("allow-prereleases" )
86
+ )
95
87
96
- # validate requirements format
97
- for constraint in requirements .values ():
98
- parse_constraint (constraint )
88
+ for _constraint in requirements :
89
+ if "version" in _constraint :
90
+ # Validate version constraint
91
+ parse_constraint (_constraint ["version" ])
99
92
100
- for name , _constraint in requirements .items ():
101
93
constraint = inline_table ()
102
- constraint ["version" ] = _constraint
103
-
104
- if self .option ("git" ):
105
- del constraint ["version" ]
106
-
107
- constraint ["git" ] = self .option ("git" )
108
- elif self .option ("path" ):
109
- del constraint ["version" ]
94
+ for name , value in _constraint .items ():
95
+ if name == "name" :
96
+ continue
110
97
111
- constraint ["path" ] = self . option ( "path" )
98
+ constraint [name ] = value
112
99
113
100
if self .option ("optional" ):
114
101
constraint ["optional" ] = True
@@ -135,7 +122,7 @@ def handle(self):
135
122
if len (constraint ) == 1 and "version" in constraint :
136
123
constraint = constraint ["version" ]
137
124
138
- poetry_content [section ][name ] = constraint
125
+ poetry_content [section ][_constraint [ " name" ] ] = constraint
139
126
140
127
# Write new content
141
128
self .poetry .file .write (content )
@@ -152,7 +139,7 @@ def handle(self):
152
139
153
140
installer .dry_run (self .option ("dry-run" ))
154
141
installer .update (True )
155
- installer .whitelist (requirements )
142
+ installer .whitelist ([ r [ "name" ] for r in requirements ] )
156
143
157
144
try :
158
145
status = installer .run ()
0 commit comments