question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More class, less dangling methods

See original GitHub issue

The more I hack into copier, the more I see the code is structured weirdly.

It seems like copier is thought as a library which also lets CLI usage, instead of the other way around.

Since #106, we leverage Plumbum for the CLI stuff, and it feels way more pythonic and comfortable to write it like this.

Now, the CopierApp class and its friends feature the invoke() method, which should be just enough to let downstream to use Copier as a lib in other python codebases.

If we refactor the codebase to make it more focused on that, we will save the pain to keep on passing arguments here and there. We will easily know if we’re updating or copying, know if the user forced the execution, and so on.


This is my mind map about what the new object model would be and what information could be obtained from each object:

  • Answer: what has been responded to a question. It can be obtained from asking the user, from API call, last answers in the Subproject, or defaults from the Question (which may be templated). It returns the best match for each Question.
  • Question: contains a question definition. It is obtained from the Template. Each question is related to an answer
  • Questionary: contains all questions and helpers to ask to the user.
  • Template: available versions, the questionary, local clone location, options defined in the template.
  • Subproject: is repo? is dirty? last update version, last answers, local path, folder exists?
  • Settings: the evolution of ConfigData. It won’t require passing through make_config() (I always thought that’s a weird design). It will hold references to all external settings sources (which are the Template, and the API call, and after #235 it will also be user config file). It will not hold answers data.
  • Renderer: takes care of rendering the files to disk.
  • Worker: combines all other objects and has 2 main methods: copy() and update().

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pykongcommented, Jan 21, 2020

The more I hack into copier, the more I see the code is structured weirdly.

It seems like copier is thought as a library which also lets CLI usage, instead of the other way around.

I am not sure I can concur, still I am committed to maximum code quality and hence I am open for improvements even radical refactoring required it makes sense.

the pain to keep on passing arguments here and there.

Carrying the extensive signatures around is indeed a major pain point which I could not tackle via my last big refactoring.

TL/DR: I am open to suggestions/PR. Ideally those should be made/merged before I am going to work on #79 again which could happen in the coming weeks.

0reactions
yajocommented, May 11, 2020

Yes, I know, that’s exactly the point in this issue. The code is hard to maintain as it is right now. Also, it’s impossible to know if an answer comes from .copier-answers.yml, from CLI or from user input, which makes it hard to implement things as “don’t ask me if I already answered”.

This needs a massive refactoring. Luckily, our test suite is big enough to warn us about any problems introduced.

I’d be glad to finish #173 before starting this task, but this one has to go for v4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dangling Modifiers and How To Correct Them - Purdue OWL
A dangling modifier is a word or phrase that modifies a word not clearly stated in the sentence. A modifier describes, clarifies, ...
Read more >
What is a misplaced modifier
As the above examples show, dangling modifiers result in inaccurate and sometimes ludicrous statements. Dangling modifiers may be corrected in two general ways...
Read more >
Misplaced and Dangling Modifiers – Advanced English
A dangling modifier is a word, phrase, or clause that describes something ... Note that there are two different ways the dangling modifier...
Read more >
Examples of Dangling Modifiers | YourDictionary
A dangling modifier can create confusion. Learn what a dangling modifier is and how dangling modifier examples can help you identify and avoid...
Read more >
How to resolve dangling const ref - c++ - Stack Overflow
One way to make your class less vulnerable could be to add a deleted constructor that takes a right-ref. This would stop your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found