Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange Issue with ctx.cd (possibly within my env?) #577

Closed
haydenflinner opened this issue Sep 20, 2018 · 2 comments · Fixed by #607
Closed

Strange Issue with ctx.cd (possibly within my env?) #577

haydenflinner opened this issue Sep 20, 2018 · 2 comments · Fixed by #607

Comments

@haydenflinner
Copy link
Contributor

haydenflinner commented Sep 20, 2018

Hey, loving the library so far. Very handy and all it's missing to me is make-like dependency refresh recognition, which I might get around to working on eventually if there's any interest.

Had a script that was working, then stopped working after I poked around reading the source. Here's the traceback

Traceback (most recent call last):
  File "/spare/local/hflinner/venv-infra/bin/invoke", line 11, in <module>
	sys.exit(program.run())
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/program.py", line 363, in run
	self.execute()
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/program.py", line 532, in execute
	executor.execute(*self.tasks)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/executor.py", line 129, in execute
	result = call.task(*args, **call.kwargs)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/tasks.py", line 128, in call
	result = self.body(*args, **kwargs)
  File "/spare/local/hflinner/invoke/myproj/tools/tests/tasks.py", line 23, in build1
	ctx.run(release_cmd)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/context.py", line 94, in run
	return self._run(runner, command, **kwargs)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/context.py", line 100, in _run
	command = self._prefix_commands(command)Had a script that was working, then stopped working after I poked around reading 
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/context.py", line 242, in _prefix_commands
	current_directory = self.cwd
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/config.py", line 125, in getattr
	raise AttributeError(err)
AttributeError: No attribute or config key found for 'cwd'

Valid keys: ['Path', 'debug', 'find_config', 'find_here', 'lazy', 'listen', 'log_dir', 'make',  'market', 'mytarget', 'run', 'runners', 'server', 'set_paths', 'sudo', 'super_repo_root', 'task', 'tasks', 'workspace']

Valid real attributes: ['cd', 'clear', 'config', 'cwd', 'from_data', 'pop', 'popitem', 'prefix', 'run', 'setdefault', 'sudo', 'update']

Notice that the error is that cwd isn't found but cwd is a valid real attribute. This happened after I poked around in the source a bit, so I suspected it was my fault for accidentally changing something. So I rm -rf invoke* 'd in my site-packages directory and reinstalled, but the problem persists. There's nothing that seems suspicious to me in my config. I'm executing invoke build1 mytarget where build1 looks like this

@task
def build1(ctx, target):
   logging.info("Releasing {} to {}"
                .format(target, ctx.make.release_dir))
   cfg = ctx[target]
   with ctx.cd(ctx.server.repo_root):
       print(ctx)
       ctx.run(release_cmd)

Where the traceback is erroring out on the ctx.run. Adding a cwd field to my invoke.py "fixes" the issue. But this function used to work!

Note: Fixed my error, turned out to be something that I think could be handled better?
with ctx.cd(str(ctx.server.repo_root)):
Where repo_root is a pathlib2 Path obj, not a string (my invoke.py is somewhat large and involved).

@fndari
Copy link
Contributor

fndari commented Sep 26, 2018

This seems to be the same as #454. I submitted a mini-PR (#583) to do exactly what you ended up doing, but on the Context.cd() side.

@bitprophet
Copy link
Member

Let's consider this duplicated by the other issues @fndari mentions plus the other linked one above - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants