]> khamidou — GitHub mirrors - pycco.git/commitdiff
Fixing up pocco to work with files that dont have an extension and adding the setup...
authorNick Fitzgerald <fitzgen@gmail.com>
Wed, 30 Jun 2010 04:18:53 +0000 (21:18 -0700)
committerNick Fitzgerald <fitzgen@gmail.com>
Wed, 30 Jun 2010 04:18:53 +0000 (21:18 -0700)
pocco [moved from pocco.py with 93% similarity]
setup.py [new file with mode: 0644]

diff --git a/pocco.py b/pocco
similarity index 93%
rename from pocco.py
rename to pocco
index 667238edd9cfd852cb332034258751d2538d595c..10affd7f0b1136ec7e53cf6b10ebe2620e4ba0f9 100755 (executable)
--- a/pocco.py
+++ b/pocco
@@ -45,12 +45,13 @@ def generate_documentation(source):
 #
 def parse(source, code):
     lines = code.split("\n")
-    if lines[0].startswith("#!"):
-        lines.pop(0)
     sections = []
     language = get_language(source)
     has_code = docs_text = code_text = ""
 
+    if lines[0].startswith("#!"):
+        lines.pop(0)
+
     def save(docs, code):
         sections.append({
             "docs_text": docs,
@@ -148,12 +149,26 @@ for ext, l in languages.items():
 
 # Get the current language we're documenting, based on the extension.
 def get_language(source):
-    return languages[ source[source.rindex("."):] ]
+    try:
+        return languages[ source[source.rindex("."):] ]
+    except ValueError:
+        source = open(source, "r")
+        code = source.read()
+        source.close()
+        lang = lexers.guess_lexer(code).name.lower()
+        for l in languages.values():
+            if l["name"] == lang:
+                return l
+        else:
+            raise ValueError("Can't figure out the language!")
 
 # Compute the destination HTML path for an input source file path. If the source
 # is `lib/example.py`, the HTML will be at `docs/example.html`
 def destination(filepath):
-    name = filepath.replace(filepath[ filepath.rindex("."): ], "")
+    try:
+        name = filepath.replace(filepath[ filepath.rindex("."): ], "")
+    except ValueError:
+        name = filepath
     return "docs/" + path.basename(name) + ".html"
 
 # Shift items off the front of the `list` until it is empty, then return
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..f359b6d
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,10 @@
+from setuptools import setup
+
+setup(name="Pocco",
+      version="0.1",
+      description="""A Python port of Docco: the original quick-and-dirty, hundred-line-long,
+      literate-programming-style documentation generator.""",
+      author="Nick Fitzgerald",
+      author_email="fitzgen@gmail.com",
+      url="http://fitzgen.github.com/pocco",
+      scripts=["pocco"])