Associate additional extension with existing lexer - python

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.

Related

Using symbolic links to organize data without actually changing locations?

So I'm building a pipeline that is not going into a real production environment. Basically, I have some data in a defined folder structure, and I want to access it from different stages in my pipeline. Right now, data is ordered kind of like this
.../data/03-14-2019/unprocessed/raw/student_id_12345-raw.csv
or
.../data/05-04-2020/processed/position/student_id_1234345-position.csv
Now, I wrote a modular pipeline that looks in a folder and runs the pipeline all the .csv files in all the contained directories. If I point it at .../data/03-14-2019/unprocessed/raw/ then my pipeline will process all of the raw data for every student. I built this under the assumption that we were going to rename all the files to a more manageable schema, but things may have changed. My question is this: Using the os.link() functionality in python3, would it be possible to make an alternate filepath system that includes what I want? For example, one way I may want to go through files might be:
.../data/unprocessed/student_id_12345/2019/03/14/raw/student_id_12345-raw.csv
or maybe
.../data/unprocessed/raw/2019/03/14/student_id_12345/student_id_12345-raw.csv
depending on if I want to process a certain batch of students or only raw data from a certain day. I remember using a batch renaming tool as part of either Total Commander or Nautilus, but I don't remember if it could do symbolic links. Basically, I want to use symbolic links to build a directory structure on top of an existing structure.
I was going to try implementing this, but I figured I should check if anyone has already done this or there were already solutions before I started, as well as maybe some suggestions of where to start. Thanks!

Python Adding password to modify feature

I wanted to know if there was a way in python to enable a read only mode unless a password is specified. I can do it manually on excel through file -> save as -> tools -> general options, but I want to know if it is possible through python as well as I am trying to automate the process in my script
Thanks
openpyxl should have this capability, however being auto-generated, the easiest way to find out how to do it will be to create an empty excel workbook with the desired features, and search for how they were implemented in the xml structure. I did a very quick test to be able to find the openpyxl.workbook.protection module, but you will likely also need worksheet protection, and often generating the correct datatypes for the constructors can be tricky. This may be easier to do via file permissions with the OS if that's an option. Alternately, you might be able to export to something like a PDF which has plenty of security options with adobe.

python project structure: folder naming convention

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

using :ref: in Python docstrings using Sphinx

I'm using Sphinx to document a python project, and I'm trying to create a reusable tip to be used in several locations.
Typically, I'll use the following syntax in a python file:
"""
.. tip::
I want this tip to be used in several locations. Why?
- Save time
- Work less
"""
Now this works whether I put it at the beginning of the file, right under class definition or right under function definition.
I found Sphinx's manual for :ref:, which suggests to use a label:
.. _my_reusable_tip:
.. tip::
...
And then call this tip with :ref:`my_reusable_tip` anywhere I want.
The manual states that 'it works across files, when section headings are changed, and for all builders that support cross-references'
The thing is, it doesn't matter in which .py file in the project I write the label and tip definition, the :ref:`my_reusable_tip` just displays 'my_reusable_tip', and not the tip itself.
What I'm using to build the documentation is
sphinx-apidoc -f -F -o
make html
I'm pretty sure my logic is flawed in some way, but I can't figure out why.
I know that Sphinx searches the project for reStructuredText and renders it if it can, but I think I'm missing something here.
I tried to add this label in a seperate .py file enclosed in """, and in a separate .txt file without enclosed """.
I tried creating an .rst file with the label definition and rebuild the html documentation.
What am I missing here?
Python 3.4.3 BTW.
In sphinx, a :ref: is simply a more robust way of linking (or referencing) another part of the document. Thus, your use of :ref: will simply provide a hyperlink to the label.
It is not a way of substituting or expanding a block.
Inline substitutions are available using using |...|, however an inline substitution cannot be used to substitute a block as you seem to require.
RestructuredText is not a template language, and thus doesn't provide macro like facilities. In the event you need it, an alternative solution is to use a template library such as mako or jinja to deal with this kind of issue.
Just using reStructuredText directive
.. include:: ./my_reusable_tip.txt
in your rst files?

ST2- Adding custom directory for Auto Completion (SublimeRope)

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.

Categories

Resources