Skip to content

Commit 0c2b011

Browse files
author
Bart Hazen
committed
Add supporting for enabling an entrypoint and fix formatting.
1 parent 6f36f33 commit 0c2b011

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

src/components/Navigator/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const styles = (theme) => ({
6262
});
6363

6464
function Navigator(props) {
65-
const { classes, ...other } = props;
65+
const { classes, location, ...other } = props;
6666

6767
return (
6868
<Drawer variant="permanent" {...other}>
@@ -93,13 +93,13 @@ function Navigator(props) {
9393
{id}
9494
</ListItemText>
9595
</ListItem>
96-
{children.map(({ id: childId, href, icon, active }) => (
96+
{children.map(({ id: childId, href, icon }) => (
9797
<ListItem
9898
key={childId}
9999
button
100100
component="a"
101101
href={href}
102-
className={clsx(classes.item, active && classes.itemActiveItem)}
102+
className={clsx(classes.item, location === href && classes.itemActiveItem)}
103103
>
104104
<ListItemIcon className={classes.itemIcon}>{icon}</ListItemIcon>
105105
<ListItemText

src/pages/SetupPy/index.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

src/scenes/Main/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ const styles = {
157157
minHeight: 'auto',
158158
},
159159
},
160+
syntax: {
161+
fontSize: '1.3em',
162+
},
160163
app: {
161164
flex: 1,
162165
display: 'flex',
@@ -190,12 +193,16 @@ function Paperbase(props) {
190193
<Navigator
191194
PaperProps={{ style: { width: drawerWidth } }}
192195
variant="temporary"
196+
location={props.location.pathname}
193197
open={mobileOpen}
194198
onClose={handleDrawerToggle}
195199
/>
196200
</Hidden>
197201
<Hidden xsDown implementation="css">
198-
<Navigator PaperProps={{ style: { width: drawerWidth } }} />
202+
<Navigator
203+
PaperProps={{ style: { width: drawerWidth } }}
204+
location={props.location.pathname}
205+
/>
199206
</Hidden>
200207
</nav>
201208
<div className={classes.app}>

0 commit comments

Comments
 (0)