{"action":"created","issue":{"url":"https://api.github.com/repos/mcgid/morenines/issues/10","repository_url":"https://api.github.com/repos/mcgid/morenines","labels_url":"https://api.github.com/repos/mcgid/morenines/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/mcgid/morenines/issues/10/comments","events_url":"https://api.github.com/repos/mcgid/morenines/issues/10/events","html_url":"https://github.com/mcgid/morenines/issues/10","id":150434287,"number":10,"title":"Set up default repo path in non-global scope","user":{"login":"mcgid","id":6307566,"avatar_url":"https://avatars.githubusercontent.com/u/6307566?v=3","gravatar_id":"","url":"https://api.github.com/users/mcgid","html_url":"https://github.com/mcgid","followers_url":"https://api.github.com/users/mcgid/followers","following_url":"https://api.github.com/users/mcgid/following{/other_user}","gists_url":"https://api.github.com/users/mcgid/gists{/gist_id}","starred_url":"https://api.github.com/users/mcgid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcgid/subscriptions","organizations_url":"https://api.github.com/users/mcgid/orgs","repos_url":"https://api.github.com/users/mcgid/repos","events_url":"https://api.github.com/users/mcgid/events{/privacy}","received_events_url":"https://api.github.com/users/mcgid/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mcgid/morenines/labels/bug","name":"bug","color":"ee0701"}],"state":"closed","locked":false,"assignee":{"login":"mcgid","id":6307566,"avatar_url":"https://avatars.githubusercontent.com/u/6307566?v=3","gravatar_id":"","url":"https://api.github.com/users/mcgid","html_url":"https://github.com/mcgid","followers_url":"https://api.github.com/users/mcgid/followers","following_url":"https://api.github.com/users/mcgid/following{/other_user}","gists_url":"https://api.github.com/users/mcgid/gists{/gist_id}","starred_url":"https://api.github.com/users/mcgid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcgid/subscriptions","organizations_url":"https://api.github.com/users/mcgid/orgs","repos_url":"https://api.github.com/users/mcgid/repos","events_url":"https://api.github.com/users/mcgid/events{/privacy}","received_events_url":"https://api.github.com/users/mcgid/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/mcgid/morenines/milestones/2","html_url":"https://github.com/mcgid/morenines/milestones/1.1.0","labels_url":"https://api.github.com/repos/mcgid/morenines/milestones/2/labels","id":1717142,"number":2,"title":"1.1.0","description":"This will incorporate significant changes to the way indexes are written, and to the command list.","creator":{"login":"mcgid","id":6307566,"avatar_url":"https://avatars.githubusercontent.com/u/6307566?v=3","gravatar_id":"","url":"https://api.github.com/users/mcgid","html_url":"https://github.com/mcgid","followers_url":"https://api.github.com/users/mcgid/followers","following_url":"https://api.github.com/users/mcgid/following{/other_user}","gists_url":"https://api.github.com/users/mcgid/gists{/gist_id}","starred_url":"https://api.github.com/users/mcgid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcgid/subscriptions","organizations_url":"https://api.github.com/users/mcgid/orgs","repos_url":"https://api.github.com/users/mcgid/repos","events_url":"https://api.github.com/users/mcgid/events{/privacy}","received_events_url":"https://api.github.com/users/mcgid/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":6,"state":"open","created_at":"2016-04-19T14:41:14Z","updated_at":"2016-05-03T00:03:45Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-04-22T18:02:01Z","updated_at":"2016-05-03T00:03:45Z","closed_at":"2016-05-03T00:03:45Z","body":"Right now, we define `DEFAULT_PATH` in global scope inside `application.py`. Global scope is bad, and this is a perfect example of why: currently, `DEFAULT_PATH` is defined at import time, instead of runtime. That means it is unaffected by `os.chdir()` calls. Which has been maddening to figure out.\r\n\r\nKids, don't define your variables in global scope.\r\n\r\n`DEFAULT_PATH` is used in `repo_path_callback()` and `_common_params`. Both of those are also defined in global scope at import time, which is not a problem since they are used by/for decorators on the commands below. But it means we need to refactor them to not depend on having the default path available. \r\n\r\nLooking into the future with issue #8, we're removing the `repo_path` argument from all commands except `init`. As such, we can modify `main()` to check which command it's executing, and if it isn't `init`, to open the repo with `os.getcwd()` passed as the path. If, on the other hand, the command actually is `init`, `main()` could set a `default_path` ivar on the `Repository`, which `init` could then use if it doesn't receive a `repo_path`.\r\n\r\nActually, this could be simplified: `main()` could set `Repository.default_path`, and then `Repository.create()` and `Repository.open()` could use `self.default_path` as a fallback. If we're doing that, we could use `click.pass_context` in `main()`, create the `Repository`, and make `default_path` an argument to `Repository.__init__()`. `main()` will still need to have conditional logic for opening the repo if the command isn't `init`.\r\n\r\n---\r\n\r\n##### Solution\r\n\r\n1. Make `Repository` require a `default_path` argument in its constructor.\r\n2. Make it use that as a default for `path` in `create()` and `open()`.\r\n3. In `main()`, if the command is not `init`, initialize the `Repository` object, passing `os.getcwd()` as the `default_path`.\r\n4. Remove `_common_params['repo_path']` and `repo_path_callback`."},"comment":{"url":"https://api.github.com/repos/mcgid/morenines/issues/comments/216400091","html_url":"https://github.com/mcgid/morenines/issues/10#issuecomment-216400091","issue_url":"https://api.github.com/repos/mcgid/morenines/issues/10","id":216400091,"user":{"login":"mcgid","id":6307566,"avatar_url":"https://avatars.githubusercontent.com/u/6307566?v=3","gravatar_id":"","url":"https://api.github.com/users/mcgid","html_url":"https://github.com/mcgid","followers_url":"https://api.github.com/users/mcgid/followers","following_url":"https://api.github.com/users/mcgid/following{/other_user}","gists_url":"https://api.github.com/users/mcgid/gists{/gist_id}","starred_url":"https://api.github.com/users/mcgid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcgid/subscriptions","organizations_url":"https://api.github.com/users/mcgid/orgs","repos_url":"https://api.github.com/users/mcgid/repos","events_url":"https://api.github.com/users/mcgid/events{/privacy}","received_events_url":"https://api.github.com/users/mcgid/received_events","type":"User","site_admin":false},"created_at":"2016-05-03T00:03:45Z","updated_at":"2016-05-03T00:03:45Z","body":"Done in 1.1.0."}}