Tuesday, December 03, 2019
Pycharm IDE. How to fix missing source directories in Project view. Doesn't show file or folder structure.
Possibly due to a git merge between two of my computers on the same GIT project I lost the project structure.
<
I was able to research this and re-add the content root under Preferences > Project > Project Structure. I wasn't as intuitive as I initially thought but here is the dialogue where I add it.
All fixed!
Tuesday, June 18, 2019
Being more pythonic with the shortcut conditional : A if C else B
I had these two blocks of "if else" code that I found too crude.
As a side note: This same elegance in code I also found with the use of the "with," statement using the Context Manager.
But for this, a lot more compact, readable and Pythonic.
test_case_data = None
test_case_data2 = None
if test_already_exists(tests_object_list, test1_name) is not None:
print(">>>> Test 1 already exists. skipping the add")
else:
print(">>>> Test 1 doesn't exist. adding")
test_case_data = add_test_case(api_conn, int(project_id), test1_name)
if test_already_exists(tests_object_list, test2_name) is not None:
print(">>>> Test 2 already exists. skipping the add")
else:
print(">>>> Test 2 doesn't exist. adding")
test_case_data2 = add_test_case(api_conn, int(project_id), test2_name)
test_case_data2 = None
if test_already_exists(tests_object_list, test1_name) is not None:
print(">>>> Test 1 already exists. skipping the add")
else:
print(">>>> Test 1 doesn't exist. adding")
test_case_data = add_test_case(api_conn, int(project_id), test1_name)
if test_already_exists(tests_object_list, test2_name) is not None:
print(">>>> Test 2 already exists. skipping the add")
else:
print(">>>> Test 2 doesn't exist. adding")
test_case_data2 = add_test_case(api_conn, int(project_id), test2_name)
I took the code and applied Guido's "ternary solution," Link here.
All of the above code became three-four lines of code and I was able to apply a one-line Pythonic truthy and falsy evaluation on the return object. Very lambda-ish.
[Correction: What I had earlier with data = func_call if True else other_func_call, was incorrect. Corrected below. So it's really A if A (when A is not None) else B (which in this case creates a new test case object.]
for current_test in tests_lists:
test_exists_data = test_already_exists() # Note returns None or or existing test data
test_case_data = test_exists_data if test_exists_data else add_test_case()
...further code that doesn't contribute to A if C else B
test_exists_data = test_already_exists() # Note returns None or or existing test data
test_case_data = test_exists_data if test_exists_data else add_test_case()
...further code that doesn't contribute to A if C else B
Tuesday, May 21, 2019
When the default pip install won't work. Using pip directly with a github repo
I work at a company where we cannot publish some (or all) Python modules to pyPI.
95% of the time before last week I would use:
pip/pip3 install [module name]
to install modules that I needed.
If that doesn't work and you have access to the git repo, another command that might be successful is installing directly from the repo. Here's an example:
pip3 install git+https://github.com/[username]/repo
And if you've downloaded the repo using git clone and there's a setup.py, which should be standard for a properly maintained module - you can run:
pip3 install -e .
Remember, sometimes you need to work around less-standard, less user-friendly modules so thankfully there are other pip options that can hopefully serve your needs.
95% of the time before last week I would use:
pip/pip3 install [module name]
to install modules that I needed.
If that doesn't work and you have access to the git repo, another command that might be successful is installing directly from the repo. Here's an example:
pip3 install git+https://github.com/[username]/repo
And if you've downloaded the repo using git clone and there's a setup.py, which should be standard for a properly maintained module - you can run:
pip3 install -e .
Remember, sometimes you need to work around less-standard, less user-friendly modules so thankfully there are other pip options that can hopefully serve your needs.
Subscribe to:
Posts (Atom)
Exploring ELK (Elastic) Stack for hack-a-thon
At my current gig, our group finally got to do hack-a-thon week and I joined a team project that tied together a few of the technologies I...
-
When I first started using WebEx 3 years ago for my current job I accidentally set the WebEx One-click meeting topic to my colleagues' n...
-
I was having the toughest time trying to sync a new folder tree in my depot. I was getting this error: //depot/Some-path/some-sub-path/....
-
If you're doing security/cryptographic testing with Java - especially with JMeter - you might encounter errors in your testing where you...