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

Python: setup imports dir as a package #262

Merged
merged 1 commit into from
Jul 31, 2020

Conversation

cmclaughlin
Copy link
Contributor

@cmclaughlin cmclaughlin commented Jul 29, 2020

Running pylint main.py warns:

main.py:4:0: E0611: No name 'aws' in module 'imports' (no-name-in-module)

This change gets rid of that warning.

@skorfmann
Copy link
Contributor

Just having an empty __init__.py file will fix this?

But I'm not sure how to reference the codeMakerOutput directory name from
there.

It'd be either set in cdktf.json or default to .gen if unset. But yes, it'd be a bit disconnected. The info could be passed down to the template, though - see here. You'd have to load the config similar to here. What do you think @cmclaughlin ?

@cmclaughlin
Copy link
Contributor Author

@skorfmann thanks for the feedback!

Yep, adding an empty __init__.py file to a directory makes it a Python module. And that gets rid of the pylint warning, which I think is worth doing.

I was able to pass in codeMakerOutput to the template, but as you noted it defaults to .get at that point. So I refactored and simply read it in from cdktf.json which at that point has the right value.

Please take another look and let me know what you think.

@skorfmann
Copy link
Contributor

I was able to pass in codeMakerOutput to the template, but as you noted it defaults to .get at that point. So I refactored and simply read it in from cdktf.json which at that point has the right value.

Hm, with readConfigSync it should only be the default if not set in cdktf.json

@cmclaughlin
Copy link
Contributor Author

Guessing cdktf.json doesn't exist yet... I'll take another look.

@cmclaughlin
Copy link
Contributor Author

I double checked... with this change codeMakerOutput is .gen, not 'imports'.

diff --git a/packages/cdktf-cli/bin/cmds/init.ts b/packages/cdktf-cli/bin/cmds/init.ts
index c858054..9f80d01 100644
--- a/packages/cdktf-cli/bin/cmds/init.ts
+++ b/packages/cdktf-cli/bin/cmds/init.ts
@@ -8,6 +8,8 @@ import * as terraformCloudClient from './helper/terraform-cloud-client';
 import * as chalk from 'chalk';
 import { terraformCheck } from './terraform-check';
 import { displayVersionMessage } from './version-check'
+import { readConfigSync } from '../../lib/config';
+
 
 const chalkColour = new chalk.Instance();
 
@@ -75,9 +77,10 @@ This means that your Terraform state file will be stored locally on disk in a fi
     }
 
     const deps: any = await determineDeps(argv.cdktfVersion, argv.dist);
+    const config = readConfigSync();
 
     await sscaff(templateInfo.Path, '.', {
-      ...deps, ...projectInfo
+      ...deps, ...projectInfo, ...config
     });
   }
 }
diff --git a/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js
index d4af60b..ef9d801 100644
--- a/packages/cdktf-cli/templates/python/.hooks.sscaff.js
+++ b/packages/cdktf-cli/templates/python/.hooks.sscaff.js
@@ -22,6 +22,8 @@ exports.post = options => {
     terraformCloudConfig(options.$base, options.OrganizationName, options.WorkspaceName)
   }
 
+    console.log(options);
+

Which outputs:

{
  npm_cdktf: 'cdktf@^0.0.1',
  npm_cdktf_cli: 'cdktf-cli@^0.0.1',
  pypi_cdktf: 'cdktf~=0.0.1',
  Name: 'xxx',
  Description: 'xxx',
  OrganizationName: '',
  WorkspaceName: '',
  output: 'cdktf.out',
  codeMakerOutput: '.gen',
  '$base': 'turd5'
}

@skorfmann
Copy link
Contributor

Oh yeah, that makes sense when thinking about it. This will be loaded in the CLI before the template is applied. Sorry for the confusion.

@skorfmann
Copy link
Contributor

So, after having thought about this again: I think this should be part of the code making process, and not be retrofitted in the template. It'll be much simpler as well, since we have all the context we need at this point.

Sorry again for the initial confusion about this. Could you adapt it accordingly?

@cmclaughlin cmclaughlin force-pushed the python-imports branch 3 times, most recently from 041a14d to b4ec993 Compare July 30, 2020 20:31
@cmclaughlin
Copy link
Contributor Author

Thanks for the feedback! I think we're all set... I agree it's much cleaner now.

Running `pylint main.py` warns:

```
main.py:4:0: E0611: No name 'aws' in module 'imports' (no-name-in-module)
```

This change gets rid of that warning.
Copy link
Contributor

@skorfmann skorfmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks 👍

@skorfmann skorfmann merged commit a714429 into hashicorp:master Jul 31, 2020
@cmclaughlin cmclaughlin deleted the python-imports branch July 31, 2020 16:03
@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants