Skip to content

Commit 20784ce

Browse files
half way through restucturing
1 parent d85495c commit 20784ce

31 files changed

Lines changed: 912 additions & 574 deletions

File tree

build_gh_pages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# -- to be nicely served by gh-pages
1010

1111

12-
GHPAGESDIR=../IntroToPython.gh-pages
12+
GHPAGESDIR=../ProgrammingInPython.gh-pages
1313

1414
# make sure gh-pages dir is there -- exit if not
1515
if [ ! -d $GHPAGESDIR ]; then

source/exercises/index.rst

Lines changed: 0 additions & 146 deletions
This file was deleted.
4.22 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# list of words that don't get capitalized
2+
is
3+
or
4+
a
5+
the
6+
it
7+
to
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
A really simple script just to demonstrate packaging
5+
"""
6+
7+
import sys, os
8+
import capital_mod
9+
import main
10+
11+
12+
if __name__ == "__main__":
13+
main.main()
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
A really simple module, just to demonstrate packaging
5+
"""
6+
7+
from pathlib import Path
8+
9+
10+
def load_special_words(data_file_name, words=None):
11+
"""
12+
Loads the special words (those that don't get capitalized)
13+
14+
from the data file in the package
15+
16+
data file is a text file with one work per line
17+
the # charactor is a comment -- everything after it will be ignored
18+
19+
"""
20+
words = set() if words is None else words
21+
with open(data_file_name) as data_file:
22+
for line in data_file:
23+
word = line.split('#')[0].strip()
24+
if word:
25+
words.add(word.lower())
26+
return words
27+
28+
def get_datafile_name():
29+
"""
30+
return the default data file that comes with the package
31+
"""
32+
return Path(__file__).parent / "cap_data.txt"
33+
34+
## load up the special words on import
35+
special_words = load_special_words(get_datafile_name())
36+
37+
def capitalize_line(instr, special_words=special_words):
38+
"""
39+
capitalizes the input string
40+
41+
:param instr: the string to capitalize it should be a single sentence.
42+
:type instr: string
43+
44+
:param special_words: set of words that should not be capitalized
45+
defaults to the words in the encosed data file
46+
:type special_words: set of str
47+
48+
:returns: a capitalized version of instr
49+
"""
50+
new_words = []
51+
for word in instr.split():
52+
new = word.capitalize() if word not in special_words else word
53+
new_words.append(new)
54+
# capitalize the first word:
55+
56+
if new_words:
57+
new_words[0] = new_words[0].capitalize()
58+
return " ".join(new_words)
59+
60+
# return " ".join(word.capitalize() for word in instr.split()
61+
# if word not in special_words)
62+
63+
64+
def capitalize(infilename, outfilename):
65+
"""
66+
reads the contents of infilename, and writes it to outfilename, but with
67+
every word capitalized
68+
69+
note: very primitive -- it will mess some files up!
70+
71+
this is called by the capitalize script
72+
73+
:param infilename: The file name you want to process
74+
:type infilename: string
75+
76+
:param outfilename: the name of the new file that will be created
77+
:type outfilename: string
78+
79+
:returns: None
80+
81+
:raises: IOError if infilename doesn't exist.
82+
"""
83+
infile = open(infilename, 'U')
84+
outfile = open(outfilename, 'w')
85+
86+
for line in infile:
87+
outfile.write(capitalize_line(line))
88+
outfile.write("\n")
89+
90+
return None
91+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
here is a simple main() module -- to demonstrate setuptools entrypoints
5+
"""
6+
7+
import sys, os
8+
import capital_mod
9+
10+
help = """
11+
capitalize script
12+
13+
capitalize file_to_process [output_file_name]
14+
15+
capitalizes (title case) each line in a passed in file
16+
"""
17+
18+
def main():
19+
"""
20+
startup function for running a capitalize as a script
21+
"""
22+
try:
23+
infilename = sys.argv[1]
24+
except IndexError:
25+
print("you need to pass in a file name to process")
26+
print(help)
27+
sys.exit()
28+
try:
29+
outfilename = sys.argv[2]
30+
except IndexError:
31+
root, ext = os.path.splitext(infilename)
32+
outfilename = root + "_cap" + ext
33+
34+
# do the real work:
35+
print("Capitalizing: %s and storing it in %s"%(infilename, outfilename))
36+
37+
capital_mod.capitalize(infilename, outfilename)
38+
39+
print("I'm done")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This is a really simple Text file.
2+
It is here so that I can test the capitalize script.
3+
4+
And that's only there to try out packaging.
5+
6+
So there.

0 commit comments

Comments
 (0)