@@ -21,16 +21,17 @@ export default class SetupPy extends React.Component {
2121 intro : null ,
2222 code : "" ,
2323 copied : false ,
24- author : "author " ,
25- authorEmail : "author @pythoncreate.com" ,
24+ author : "Hank " ,
25+ authorEmail : "hank @pythoncreate.com" ,
2626 description : "Description of the project." ,
2727 classifiers : [ ] ,
2828 version : "0.0.1" ,
2929 requirements : "setuptools>=45.0" ,
3030 srcFolder : true ,
3131 versionInPackage : true ,
3232 packageData : false ,
33- packageName : "hello-world"
33+ packageName : "hello-world" ,
34+ entrypoint : false ,
3435 } ;
3536 }
3637
@@ -89,7 +90,7 @@ export default class SetupPy extends React.Component {
8990
9091 if ( this . state . packageData ) {
9192 code . push ( ` include_package_data=True,` ) ;
92- code . push ( ` package_data={"` + this . state . packageName + `": ["src/` + this . state . packageName + `resources/*"]},` ) ;
93+ code . push ( ` package_data={"` + this . state . packageName + `": ["src/` + this . state . packageName + `/ resources/*"]},` ) ;
9394 }
9495
9596 if ( this . state . requirements ) {
@@ -103,7 +104,13 @@ export default class SetupPy extends React.Component {
103104 ) ;
104105 code . push ( ` ],` ) ;
105106 }
106- // code.push(` entry_points={"console_scripts": ["{name}={name}.cli.__main__:main"]},`);
107+
108+ if ( this . state . entrypoint ) {
109+ code . push ( ` entry_points={` ) ;
110+ code . push ( ` "console_scripts": [` ) ;
111+ code . push ( ` "` + this . state . packageName + `"="` + this . state . packageName + `.__main__.main",` )
112+ code . push ( ` ]},` ) ;
113+ }
107114 if ( this . state . classifiers . length > 0 ) {
108115 code . push ( ` classifiers=[` ) ;
109116 this . state . classifiers . forEach (
@@ -116,6 +123,22 @@ export default class SetupPy extends React.Component {
116123 return code . join ( "\n" ) ;
117124 }
118125
126+ filterPackagename ( value ) {
127+ return value . replace ( / [ ^ \w \s - ] / gi, "" ) ;
128+ }
129+
130+ filterAuthorname ( value ) {
131+ return value . replace ( "\"" , "\\\"" ) ;
132+ }
133+
134+ filterEmailAddress ( value ) {
135+ return value . replace ( / [ ^ \w \s ! @ # $ % & ' * + - / \\ = ? ^ _ ` { | } ~ ] / gi, "" ) ;
136+ }
137+
138+ filterDescription ( value ) {
139+ return value . replace ( "\"" , "\\\"" ) ;
140+ }
141+
119142 updatePythonCode ( ) {
120143 this . setState ( { code : this . getPythonCode ( ) } ) ;
121144 this . setState ( { copied : false } ) ;
@@ -129,7 +152,7 @@ export default class SetupPy extends React.Component {
129152 defaultValue = { this . state . version }
130153 variant = "outlined"
131154 onChange = { e => {
132- this . setState ( { author : e . target . value . replace ( / " / g , "\\\"" ) || this . defaultValue } , this . updatePythonCode ) ;
155+ this . setState ( { author : e . target . value || this . defaultValue } , this . updatePythonCode ) ;
133156 } }
134157 />
135158 ) ;
@@ -155,7 +178,7 @@ export default class SetupPy extends React.Component {
155178 defaultValue = { this . state . packageName }
156179 variant = "outlined"
157180 onChange = { e => {
158- this . setState ( { packageName : e . target . value . replace ( / " / g , "\\\"" ) || this . defaultValue } , this . updatePythonCode ) ;
181+ this . setState ( { packageName : this . filterPackagename ( e . target . value ) || this . defaultValue } , this . updatePythonCode ) ;
159182 } }
160183 />
161184 < TextField
@@ -165,7 +188,7 @@ export default class SetupPy extends React.Component {
165188 defaultValue = { this . state . author }
166189 variant = "outlined"
167190 onChange = { e => {
168- this . setState ( { author : e . target . value . replace ( / " / g , "\\\"" ) || this . defaultValue } , this . updatePythonCode ) ;
191+ this . setState ( { author : this . filterAuthorname ( e . target . value ) || this . defaultValue } , this . updatePythonCode ) ;
169192 } }
170193 />
171194 < TextField
@@ -175,7 +198,7 @@ export default class SetupPy extends React.Component {
175198 defaultValue = { this . state . authorEmail }
176199 variant = "outlined"
177200 onChange = { e => {
178- this . setState ( { authorEmail : e . target . value . replace ( / " / g , "\\\"" ) || this . defaultValue } , this . updatePythonCode ) ;
201+ this . setState ( { authorEmail : this . filterEmailAddress ( e . target . value ) || this . defaultValue } , this . updatePythonCode ) ;
179202 } }
180203 />
181204 < TextField
@@ -187,7 +210,7 @@ export default class SetupPy extends React.Component {
187210 rowsMax = { 4 }
188211 variant = "outlined"
189212 onChange = { e => {
190- this . setState ( { description : e . target . value . replace ( / " / g , "\\\"" ) || this . defaultValue } , this . updatePythonCode ) ;
213+ this . setState ( { description : this . filterDescription ( e . target . value ) || this . defaultValue } , this . updatePythonCode ) ;
191214 } }
192215 />
193216 < FormControlLabel
@@ -227,14 +250,26 @@ export default class SetupPy extends React.Component {
227250 label = { < div > Include < strong > package data</ strong > .</ div > }
228251 labelPlacement = "end"
229252 />
253+ < FormControlLabel
254+ control = {
255+ < Switch
256+ checked = { this . state . entrypoint }
257+ onChange = { ( ) => {
258+ this . setState ( { entrypoint : ! this . state . entrypoint } , this . updatePythonCode ) ;
259+ } }
260+ />
261+ }
262+ label = { < div > Add < strong > entrypoint</ strong > .</ div > }
263+ labelPlacement = "end"
264+ />
230265 < TextField
231266 id = "requirements"
232267 label = "Requirements"
233268 multiline
234269 defaultValue = { this . state . requirements }
235270 variant = "outlined"
236271 onChange = { e => {
237- this . setState ( { requirements : e . target . value . replace ( / " / g , "\\\"" ) || this . defaultValue } , this . updatePythonCode ) ;
272+ this . setState ( { requirements : e . target . value || this . defaultValue } , this . updatePythonCode ) ;
238273 } }
239274 />
240275 < Autocomplete
@@ -254,7 +289,7 @@ export default class SetupPy extends React.Component {
254289 </ FormGroup >
255290 </ Grid >
256291 < Grid item xs = { 12 } >
257- < SyntaxHighlighter language = "python" style = { solarizedDark } > { this . state . code } </ SyntaxHighlighter >
292+ < SyntaxHighlighter language = "python" style = { solarizedDark } className = { this . props . classes . syntax } > { this . state . code } </ SyntaxHighlighter >
258293 < CopyToClipboard text = { this . state . code }
259294 onCopy = { ( ) => this . setState ( { copied : true } ) } >
260295 < Button variant = "contained" color = "primary" > { ( this . state . copied ) ? "Copied!" : "Copy" } </ Button >
0 commit comments