I'm trying to rearrange my project files.
I'm having some hard time figuring out what is the correct way to name files and folders. I'm relying on PEP8. I see that I should avoid having underscores in file/folder name. But if I have a folder like functionalcoverage it seems weird and feels like I should call it functional_coverage instead and the same goes for files(securecopy.py and secure_copy.py).
In addition, I'm not sure if I should adhere to PEP8 regarding folders/files that aren't python(a folder containing a bunch of txt files for example)
Its prety much what you prefer, a lot of people use underscore, PEP8 is a guide you can follow or not, the important is to be consistant with your choice read more here
Related
Updating the question.
I am developing a command-line tool for a framework.
and I am struggling with how to detect if the current directory is a project of my framework.
I have two solutions in mind.
some hidden file in the directory
detect the project structure by files and folders.
What do you think is the best approach?
Thank you,
Shay
Thank you very much
In my opinion, a good idea would be to either have a project directory structure that you can use a signature for the project/framework, that you can use within the tool as a list of signature-like structures, for example
PROJECT_STRUCTURE_SIGNATURES = [ "custom_project", "custom_project/tests", "custom_project/build", "custom_project/config", "config/environments" ] and then just check if any(signature in os.getcwd() for signature in PROJECT_STRUCTURE_SIGNATURES).
if the project structure is not too complex, I suppose that would be a start in order to identify the requirements that you're looking for.
However, if this is not the case, then I suppose a dictionary-like structure that you could use to traverse the key-value pairs similar to the project's file structure and check the current directory against those would be a better idea, where if none of the elements from the nested dictionary traversal matches, then the directory is not within the project structure.
I have a directory structure for my Flask-Dash app:
I am following this tutorial: https://dash.plotly.com/integrating-dash
to combine one or more Dash apps with a Flask app.
But in wsgi.py, it could not find a reference for dash_app2.py until I renamed it using Roman numerals dash_appII.py.
Is there a naming convention in Python where two files in the same package or directory cannot have similar names like dash_app1.py and dash_app2.py?
It could not even find a reference to dash_app2.py in the __init__.py file in that directory which now looks like:
from .dash_app1 import dash_app1
from .dash_appII import dash_app2
I don't really want to use Roman numerals.
`
Are you importing dash_app1 somewhere else in your app? I've found that the explicit relative import can sometimes cause namespace collisions if you use it after importing the packages somewhere else with a non-explicit import. Worth a shot to take a look or simply remove the . explicit and give it a go. All else hold equal, you shouldn't have issues importing the numeric versions of your files.
Currently I'm working on automation in a project that has a very big site divided in sections and/or pages.
I'm using python-behave for the first time and I'm still learning (used to work with ProtractorJS)
Since I started I've been using the steps folder to put all my step files (each page has it's own step file) but in my case, it's not going to be scalable since the site has around 50 pages, with subsections each, so having all step files in one folder is going to get messy as I start adding files to the step folder.
What I want to do is be able to have folders to separate each of the pages and have step files in each of them to better organize the files.
Now, I know that this framework does not support having a folder structure inside the step definition folder, so i started looking around and found this post with a possible solution, but i noticed he uses wildcard import to add all nested step files.
I know wildcard imports are not considered a good practice in general, but i feel in this case is the only way to allow folder strucures for step files.
Is there any other way to achieve this?
Example
features
-->steps
---->*.py // This is where pyhton-behave expects to find the step definitions. The "recommended" way
What i'm trying to do
features
--->steps
----->login
-------->login_steps.py
----->some_page
-------->some_pages_steps.py
--->all_steps.py // file that imports nested step files using wildcard
// the only file that behave finds when looking for steps
Is there an easy way to add a filename and/or extension for existing lexer in pygments? I don't want to write or subclass existing one, as the language is the same, but the file has different extension/name.
I've tried to hack it and add it to the filenames class variable (somewhere in /usr/lib/python2.7/dist-packages/pygments/lexers/agile.py), but for some reason it didn't worked.
I was wondering for something like .pygments file, where users can associate additional names with the lexers, but looks like it's not possible right now.
What is the best way to achieve my goal then?
Okay, I've found solution: after adding filenames/extensions to required Lexer you have to regenerate the mapping:
cd /usr/lib/python2.7/dist-packages/pygments/lexers/; sudo python _mapping.py; cd -
This is not 100% clean solution, as in case of package update your changes will gone, but it pretty quick and easy.
http://sublimerope.readthedocs.org/en/latest/cache_mechanisms.html
I want to add a custom directory from where I want auto completion. The Old Way mentioned on the above page does that job with prefs.add('python_path', '/home/abc/custom/')
, but the page says it's not recommended.
How can I do add a custom directory (say /home/abc/custom/) with the newer way mentioned on the page? It only explains how to add modules not directories.
If you haven't already, you should already have defined folders in your project settings. It looks like SublimeRope looks in those folders automatically, and you just define the modules you want to be included.
If you haven't already, I recommend taking a look at SublimeCodeIntel as well. I'm not terribly familiar with SublimeRope, but SCI is quite useful for my Python coding needs.