project: Fallback to directory name if project/name isn't set
authorW. Trevor King <wking@tremily.us>
Sat, 28 Mar 2015 19:56:15 +0000 (12:56 -0700)
committerW. Trevor King <wking@tremily.us>
Sat, 28 Mar 2015 20:05:52 +0000 (13:05 -0700)
I recommend folks set this explicitly, but Greg Wilson wanted a way
for folks to use update-copyright without having to tweak this name
after forking [1].  The approach I've used here isn't the same as the
one discussed in that issue (using the name of the upstream Git
repository), but I think it's a better choice.  Pros and cons:

+ Simple, VCS-agnostic implementation
+ Doesn't make assumptions about the upstream repository naming
- Assumes folks name their local repository appropriately
- Won't handle several projects stored in the same Git repository For
  example, if you have a branch for project-a and another for
  project-b that are both in your local project-a repository, you'll
  have to explicitly set project.name in the project-b branch's
  .update-copyright.conf.

[1]: https://github.com/swcarpentry/lesson-template/pull/197#discussion_r26456407

README
update_copyright/project.py

diff --git a/README b/README
index 7e85b80f9d464e4ad5342e7701a8480c27680d98..a91e6bbad43d3326e96151f4682db0d15564022d 100644 (file)
--- a/README
+++ b/README
@@ -77,7 +77,8 @@ Options
 
 project/name
   A string naming your project.  Replaces ``{project}`` in your
-  copyright blurbs.
+  copyright blurbs.  If this isn't set, ``update-copyright`` will fall
+  back to using the name of the repository directory.
 project/vcs
   The name of your version control system.
 files/authors
index 176ff68b317f5b66656b19e54538cdafd9cafa2b..0cb676ccb7669313b239b3c34c7f04a78ddd5213 100644 (file)
@@ -71,7 +71,7 @@ class Project (object):
             project = parser['project']
         except KeyError:
             project = {}
-        self._name = project.get('name')
+        self._name = project.get('name', _os_path.basename(self._root))
         vcs = project.get('vcs')
         kwargs = {
             'root': self._root,